$.noConflict();
var timestopvideo_check=false /*used for filter so moodalbox(moodalbox.v1.2.full.js) can stop automatic change or video*/
/*Change Photos on time */
var c=0 /* position for first item to show */
var y=c-1
var photos_num=7 /* number of switchable items */
var timeout /* contain setTimeout function */
var timestopphotos = false
var timeout_delay= 4000 /* change photo timer in 1000 = 1sec */

function timedPhotos()
{
if (photos_num>1){
if (timestopphotos==false){
	if(y!=c-1) y=c-1
timeout = setTimeout(timedPhotos,timeout_delay)
jQuery('#contents_gallery .items li').eq(y).fadeTo((timeout_delay/4),0)
jQuery('#contents_gallery .items_button a.selected').removeClass('selected')
jQuery('#contents_gallery .items_button a').eq(c).addClass('selected')
jQuery('#contents_gallery .items li').css('z-index','0')
jQuery('#contents_gallery .items li').eq(c).css('z-index','10')
jQuery('#contents_gallery .items li').eq(c).fadeTo((timeout_delay/4),1, function(){
	if (c<(photos_num-1))
	{
	c=c+1
	}else c=0
	y=c-1
})
}
}
}
/*end of Change photos on time */
/*Change Video on time */
var c2=0 /* position for first item to show */
var y1=c2-1
var video_num=7 /* number of switchable items */
var timeout_video /* contain setTimeout function */
var timestopvideo = false
var timeout_delay_video= timeout_delay /* change video timer in 1000 = 1sec */

function timedVideo()
{
if (video_num>1){
if (timestopvideo==false){
	if(y1!=c2-1) y1=c2-1
timeout_video = setTimeout(timedVideo,timeout_delay_video)
jQuery('#contents_gallery_video .items li').eq(y1).fadeTo((timeout_delay_video/4),0)
jQuery('#contents_gallery_video .items_button a.selected').removeClass('selected')
jQuery('#contents_gallery_video .items_button a').eq(c2).addClass('selected')
jQuery('#contents_gallery_video .items li').css('z-index','0')
jQuery('#contents_gallery_video .items li').eq(c2).css('z-index','10')
jQuery('#contents_gallery_video .items li').eq(c2).fadeTo((timeout_delay_video/4),1, function(){
	if (c2<(video_num-1))
	{
	c2=c2+1
	}else c2=0
	y1=c2-1
})
}
}
}
/*end of Change Video on time */
/*Change news on time */
var c1=1 /* position for first item to show */
var news_num=4 /* number of switchable items */
var timeout_news /* contain setTimeout function */
var timestopnews = false
var timeout_delay_news= 3000 /* change photo timer in 1000 = 1sec */
function timedNews(){
	if (news_num>1){
	if (timestopnews==false){
		timeout_news = setTimeout(timedNews,timeout_delay_news)
		jQuery('#contents_news .items li.show').removeClass('show')
		jQuery('#contents_news .items_button a.selected').removeClass('selected')
		jQuery('#contents_news .items li:nth-child('+c1+')').addClass('show')
		jQuery('#contents_news .items_button a:nth-child('+c1+')').addClass('selected')
		height_change = jQuery('#contents_news .items li:nth-child('+c1+') .text').height()
		jQuery('#contents_news .items li:nth-child('+c1+') .transperant_bg').css('height',height_change+'px')
		if (c1<(news_num))
		{
		c1=c1+1;
		}else c1=1
		;}
	}
}
/*end of Change News on time */
jQuery(document).ready(function(jQuery) {
	/*start automatic photo change*/
	jQuery('#contents_gallery .items li').addClass('hide')
	jQuery('#contents_gallery .items li:nth-child(1)').removeClass('hide')
	photos_num=jQuery('#contents_gallery .items li').size()
	timedPhotos()
	/*stop automatic photos change and start it on mouseenter mouseout*/
	jQuery("#contents_gallery").mouseenter(function (){timestopphotos=true})
	jQuery("#contents_gallery").mouseleave(function (){timestopphotos=false;clearTimeout(timeout);timeout = setTimeout(timedPhotos,timeout_delay)})
	/*change photos on click*/
	jQuery('#contents_gallery .items_button a').click(function(){
		if (c!=y) c=y
		position = jQuery("#contents_gallery .items_button a").index(this)
		jQuery('#contents_gallery .items li').stop
		jQuery('#contents_gallery .items li').eq(c).fadeTo((timeout_delay/4),0)
		c=position
		y=c
		jQuery('#contents_gallery .items li').css('z-index','0')
		jQuery('#contents_gallery .items li').eq(c).css('z-index','10')
		jQuery('#contents_gallery .items_button a.selected').removeClass('selected')
		jQuery('#contents_gallery .items_button a').eq(c).addClass('selected')
		jQuery('#contents_gallery .items li').eq(c).fadeTo((timeout_delay/4),1)
		}
	)
	/*start automatic video change*/
	jQuery('#contents_gallery_video .items li').addClass('hide')
	jQuery('#contents_gallery_video .items li:nth-child(1)').removeClass('hide')
	video_num=jQuery('#contents_gallery_video .items li').size()
	timedVideo()
	/*stop automatic video change and start it on mouseenter mouseout*/
	jQuery("#contents_gallery_video").mouseenter(function (){timestopvideo=true})
	jQuery("#contents_gallery_video").mouseleave(function (){
		if (timestopvideo_check==false){
			timestopvideo=false;clearTimeout(timeout_video);timeout_video = setTimeout(timedVideo,timeout_delay_video)
		}
		})
	/*change video on click*/
	jQuery('#contents_gallery_video .items_button a').click(function(){
		if (c2!=y1) c2=y1
		position = jQuery("#contents_gallery_video .items_button a").index(this)
		jQuery('#contents_gallery_video .items li').stop()
		jQuery('#contents_gallery_video .items li').eq(c2).fadeTo((timeout_delay_video/4),0)
		c2=position
		y1=c2
		jQuery('#contents_gallery_video .items li').css('z-index','0')
		jQuery('#contents_gallery_video .items li').eq(c2).css('z-index','10')
		jQuery('#contents_gallery_video .items_button a.selected').removeClass('selected')
		jQuery('#contents_gallery_video .items_button a').eq(c2).addClass('selected')
		jQuery('#contents_gallery_video .items li').eq(c2).fadeTo((timeout_delay_video/4),1)
		}
	)
	/*start automatic news change*/
	jQuery('#contents_news .items li:nth-child(1)').addClass('show')
	news_num=jQuery('#contents_news .items li').size()
	height_change = jQuery('#contents_news .items li:nth-child(1) .text').height()
	jQuery('#contents_news .items li:nth-child(1) .transperant_bg').css('height',height_change+'px')
	timedNews()
	/*stop automatic news change and start it on mouseenter mouseout*/
	jQuery("#contents_news").mouseenter(function (){timestopnews=true;})
	jQuery("#contents_news").mouseleave(function (){timestopnews=false;clearTimeout(timeout_news);timeout_news = setTimeout(timedNews,timeout_delay_news)})
	/*change news on click*/
	jQuery('#contents_news .items_button a').click(function(){
		jQuery('#contents_news .items li.show').removeClass('show')
		jQuery('#contents_news .items_button a.selected').removeClass('selected')
		position = jQuery("#contents_news .items_button a").index(this)
		c1=position+1
		jQuery('#contents_news .items li:nth-child('+c1+')').addClass('show')
		jQuery('#contents_news .items_button a:nth-child('+c1+')').addClass('selected')
		height_change = jQuery('#contents_news .items li:nth-child('+c1+') .text').height()
		jQuery('#contents_news .items li:nth-child('+c1+') .transperant_bg').css('height',height_change+'px')
		}
	)

}
)
