// JavaScript Document
var idname;
var classname;
var playInterval = "";

var gallery=function(){
	var index=0;
	var totalwidth=$('#gallery-content').width();
	var eachwidth=$('.gallery').width();
	var totalindex=totalwidth/eachwidth;

	$("#gallery-content").mouseenter(function() {
		clearInterval(playInterval);
	});
	
	$("#gallery-content").mouseleave(function() {
		setPlayInterval();
	});

	$("#right-arrow").click(function(){	
		clearInterval(playInterval);
		setPlayInterval();
		/*alert("right right");*/
		/*alert(totalindex);*/
		if(index<=totalindex-1){
			if(index==totalindex-1){
				/*$("#gallery-content").css({ "position": "relative", "left": "0px" });*/
				/*
				*/
				index=1;
				index--;
				
				$("#gallery-content").animate({left:(-eachwidth*index)},"slow");
				
				}else{
					index++;
					$("#gallery-content").animate({left:(-eachwidth*index)},"slow");
				}
				
			$("#dots ul li").removeClass("dot-activate");
			$("li#dot"+index).addClass("dot-activate");
		}
	});

	$("#left-arrow").click(function(){	
		clearInterval(playInterval);
		setPlayInterval();
		/*alert("right right");*/
		/*alert(totalindex);*/
		if(index>=0){
			if(index==0){
				/*$("#gallery-content").css({ "position": "relative", "left": -eachwidth*(totalindex-1) });*/
				/*index=1;
				index++;
				*/
				index=totalindex-1;
				
				$("#gallery-content").animate({left:(-eachwidth*index)},"slow");
				
				}else{
					index--;
					$("#gallery-content").animate({left:(-eachwidth*index)},"slow");
				}
			
			$("#dots ul li").removeClass("dot-activate");
			$("li#dot"+index).addClass("dot-activate");
		}
	});

};


var newstab=function(){
 	
	$("ul#news-tab li").click(function(){
		$("ul#news-tab li").removeClass("news-selected");
		$(".tab-con").hide();
		$(this).addClass("news-selected");
		
		var idname = $(this).attr('id')+"-con";
		$("."+idname).show();
		
   });
};


var showdetail=function(){
 	$("a.seemore").click(function(){		
			$(this).parent().parent().parent().children(".detail-content").toggle();
			$(this).parent().children("img.show-img").toggle();
			$(this).parent().children("img.hide-img").toggle();
			$(this).toggle();
			$(this).parent().children("a.seeclose").toggle();
			
			
	});
	
	$("a.seeclose").click(function(){		
			$(this).parent().parent().parent().children(".detail-content").toggle();
			$(this).parent().children("img.show-img").toggle();
			$(this).parent().children("img.hide-img").toggle();
			$(this).toggle();
			$(this).parent().children("a.seemore").toggle();
			
	});
	
};

	
$(window).load(function(){  
  // slide toggle
  
   if($('.listheader').length) $(".listheader").click(function(){
	$(this).next().next().slideToggle("slow");
	$(this).find(".hidebtn").toggle();
	$(this).find(".showbtn").toggle();
  });
   
	// nominate tab
	if($('#photo-gallery').length) gallery();
	if($('#news-content').length) newstab();
	if($('#news-content').length) showdetail();
    
	setPlayInterval();
	
});


function setPlayInterval(){
	// --- set interval to auto play banner ---
	playInterval = setInterval(function(){
		$("#right-arrow").click();
	}, 5000); 
}


