// JavaScript Rotating Banner Using jQuery
var top_vCurrent = 0;
var top_vTotal = 0;
var top_vDuration = 5000;
var top_intInterval = 0;
var top_vGo = 1;
var top_vIsPause = false;
var top_tmp = 20;
var top_title;
var top_imgW = 902;
var top_imgH = 340;

jQuery(document).ready(function() {	
	top_vTotal = $(".top_slides").children().size() -1;
	$(".top_info").text($(".top_slide").attr("title"));	
	top_intInterval = setInterval(top_fnLoop, top_vDuration);
			
	//Horizontal
	$("#top_object").find(".top_slide").each(function(i) { 
		top_tmp = ((i - 1)*top_imgW) - ((top_vCurrent -1)*top_imgW);
		$(this).animate({"left": top_tmp+"px"}, 500);
	});
	
	/*
	//Vertical
	$("#top_object").find(".top_slide").each(function(i) { 
		top_tmp = ((i - 1)*top_imgH) - ((top_vCurrent -1)*top_imgH);
		$(this).animate({"top": top_tmp+"px"}, 500);
	});
	*/
	
	$("#btn_pauseplay").click(function() {
		if(top_vIsPause){
			top_fnChange();
			top_vIsPause = false;
			$("#btn_pauseplay").removeClass("top_btn_play");
			$("#btn_pauseplay").addClass("top_btn_pause");
		} else {
			clearInterval(top_intInterval);
			top_vIsPause = true;
			$("#btn_pauseplay").removeClass("top_btn_pause");
			$("#btn_pauseplay").addClass("top_btn_play");
		}
	});
	$("#btn_prev").click(function() {
		top_vGo = -1;
		top_fnChange();
	});
		
	$("#btn_next").click(function() {
		top_vGo = 1;
		top_fnChange();
	});
});

function top_fnChange(){
	clearInterval(top_intInterval);
	top_intInterval = setInterval(top_fnLoop, top_vDuration);
	top_fnLoop();
}

function top_fnLoop(){
	if(top_vGo == 1){
		top_vCurrent == top_vTotal ? top_vCurrent = 0 : top_vCurrent++;
	} else {
		top_vCurrent == 0 ? top_vCurrent = top_vTotal : top_vCurrent--;
	}
	
			
	$("#top_object").find(".top_slide").each(function(i) { 
		if(i == top_vCurrent){
			top_title = $(this).attr("title");
			$(".top_info").animate({ opacity: 'hide', "left": "-50px"}, 250,function(){
				$(".top_info").text(top_title).animate({ opacity: 'show', "left": "0px"}, 500);
			});
		} 
			
			
		//Horizontal Scrolling
		top_tmp = ((i - 1)*top_imgW) - ((top_vCurrent -1)*top_imgW);
		$(this).animate({"left": top_tmp+"px"}, 500);
		
		
		/*
		//Vertical Scrolling
		top_tmp = ((i - 1)*top_imgH) - ((top_vCurrent -1)*top_imgH);
		$(this).animate({"top": top_tmp+"px"}, 500);
		*/
		
		/*
		//Fade In & Fade Out
		if(i == top_vCurrent){
			$(".top_info").text($(this).attr("title"));
			$(this).animate({ opacity: 'show', height: 'show' }, 500);
		} else {
			$(this).animate({ opacity: 'hide', height: 'hide' }, 500);
		}
		*/
		
	});


}






