var gallery_timer = 0;
$(document).ready(function(){
	$("#gallery2,#gallery3,#gallery4,#gallery5").css({"opacity":"0.0","z-index":"1"});
	$("#gallery1").css({"z-index":"10"});
	$("#counter1").css({"color":"#ECEC18"});
	$("#gallery-bottom-bar").html($("#caption1").html());
	
	gallery_timer = setTimeout(switch_gallery2,5000);
	
	$("#counter1").click(function(){
		counter_click(5);
	});
	$("#counter2").click(function(){
		counter_click(1);
	});
	$("#counter3").click(function(){
		counter_click(2);
	});
	$("#counter4").click(function(){
		counter_click(3);
	});
	$("#counter5").click(function(){
		counter_click(4);
	});
});	
var current_gallery = 1;
var previous_gallery = 1;		
function switch_gallery2()
{
	current_gallery++;
	if(current_gallery > 5){current_gallery = 1}
	$("#gallery" + previous_gallery).stop().animate({"opacity":"0.0"},700);
	$("#gallery" + current_gallery).stop().animate({"opacity":"1.0"},700);
	$("#gallery" + previous_gallery).css({"z-index":"1"});
	$("#gallery" + current_gallery).css({"z-index":"10"});
	$("#gallery-bottom-bar").stop().animate({"height":"0px"},400,'linear',function(){
		$("#gallery-bottom-bar").html($("#caption" + current_gallery).html());
		$("#gallery-bottom-bar").animate({"height":"59px"},400);
		$(".counter").css({"color":"#ffffff"});
		$("#counter" + current_gallery).css({"color":"#ECEC18"});
	});
	previous_gallery = current_gallery;
	gallery_timer = setTimeout(switch_gallery2,5000);
}

function counter_click(num)
{
	clearTimeout(gallery_timer);
	current_gallery = num;
	switch_gallery2();
	return false;
}
