var value = 0;

$(document).ready(function() {	

	var timer = setInterval(function(){animateSlide(value,1)},6500);

	$(".main_image .desc").show(); 
	$(".main_image .block").animate({ opacity: 0.85 }, 1 ); 

	$(".image_thumb ul li:first").addClass('active');
	
	$(".image_thumb ul li").click(function(){animateSlide($(this).attr('id'),0); clearInterval(timer)}) 
	
	.hover(function(){
		$(this).addClass('hover');
		}, function() {
		$(this).removeClass('hover');
	});
	
	$("a.collapse").click(function(){
		$(".main_image .block").slideToggle();
		$("a.collapse").toggleClass("show");
	});
	
	
	function animateSlide($value,type){
	
	if(type==1)
	{
		if(value==2)
		{
			value = 0;
		}
		else
		{
			value++;
		}
	}
	else
	{
		value = $value;	
	}
		
		var imgAlt = $('#'+value).find('img').attr("alt");
		var imgTitle = $('#'+value).find('a').attr("href"); 
		var imgDesc = $('#'+value).find('.block').html(); 	
		var imgDescHeight = $(".main_image").find('.block').height();	
		
		if ($('#'+value).is(".active")) { 
			return false; 
		} else {
			
			$(".main_image .block").animate({ opacity: 0, marginBottom: -imgDescHeight }, 250 , function() {
				$(".main_image .block").html(imgDesc).animate({ opacity: 0.85,	marginBottom: "0" }, 250 );
				$(".main_image img").attr({ src: imgTitle , alt: imgAlt});
			});
		}
		
		$(".image_thumb ul li").removeClass('active');
		$('#'+value).addClass('active');

	}

	function onBlur() {
		clearInterval(timer);
	};
	function onFocus(){
		animateSlide(value);
	};
	
	if (/*@cc_on!@*/false) { 
		document.onfocusin = onFocus;
		document.onfocusout = onBlur;
	} else {
		window.onfocus = onFocus;
		window.onblur = onBlur;
	}

});
