$(document).ready(function() {

$('#content').animate({opacity: 'toggle'}, 1000);

if ($('#static_gal').length > 0){	
	$('#static_gal img:gt(0)').hide();
	setInterval(
		function(){$('#static_gal :first-child')
			.fadeOut(1000)
	    	.next('img')
	    	.fadeIn(1000)
	       	.end()
	       	.appendTo('#static_gal');}
	    ,3000);
	$('#static_gal').animate({opacity: 'toggle'}, 1000); 
}


if ($('#gallery').length > 0){
	//init nav 
	$('#next').click(function (){switchImg('next');});
	$('#prev').click(function (){switchImg('prev');});
	
	//init first element
	$('#text').html($('#gallery div:eq(0) p').html());
	$('#gallery div:eq(0)').fadeIn(1000);
	$('#text').fadeIn(1000);
	
	var imgAct = 0;
	var imgMax = $('#gallery div').length;
	
	function switchImg(dir){
		if (dir == 'next'){
			imgNext = imgAct+1;
			if (imgNext >= imgMax){
				imgNext = 0;
			}
		}else{
			imgNext = imgAct-1;
			if (imgNext < 0){
				imgNext = imgMax-1;
			}	
		}
		
		$('#gallery div:eq('+imgAct+')').fadeOut(1000);
		$('#gallery div:eq('+imgNext+')').fadeIn(1000);
		$('#text').fadeOut(500, function(){
			$('#text').html($('#gallery div:eq('+imgNext+') p').html());
			$('#text').fadeIn(500);
		});
		
		imgAct = imgNext;	
	}
}


});



