

var auto_show = true;
var auto_ms = 10000;

function auto_animate() {
	if (auto_show) {
		$(".next").addClass("hover");
		setTimeout("auto_animate_go()", 200);
		setTimeout('removeSimulateHover();', 800);
	}
}


	function removeSimulateHover() {
		$(".next").removeClass("hover");
	}
	

	
	function auto_animate_go() {
		if (auto_show) {
			if (services_slides_animating)	return false;
			var selected_slide_idx = current_home_idx;
			var total_slides = $(".home_slides").size() -1;	
			var next_slide = (selected_slide_idx+1 > total_slides) ? 0 : selected_slide_idx+1;
			
			current_home_idx = next_slide;
			homepage_toggle(selected_slide_idx, next_slide);
			//$(".next").addClass("hover");
			
			setTimeout("auto_animate()", auto_ms);
		}	
	}



	function homepage_toggle(current_idx, goto_idx) {
		var services_slide_current = '#home_' + current_idx;
		var services_slide_next = '#home_' + goto_idx;
		
	
		var total_slides = $(".home_slides").size() -1;	
		
		// if slide is after OR the current slide is the last slide & the next slide is the first
		if (goto_idx > current_idx || current_idx == total_slides && goto_idx == 0) {

	
			/*******************
			* ANIMATE TO LEFT  *
			*******************/
			
			$(services_slide_next).css( { left: "0", display: 'block' } );
			$(services_slide_next + " .header").css( { left: "0", display: 'block', opacity: 0  } );
			
			services_slides_animating = true;
			$(services_slide_current + " .header").animate({
				opacity: 0
			}, {
				duration: 1000,
				easing: 'easeOutQuad',
				complete: function() { }
			});
			
			//animate next slide in
			$(services_slide_next + " .header").animate({
				opacity: 1
			}, {
				duration: 1000,
				easing: 'easeOutQuad',
				complete: function() { services_slides_animating  = false; }
			});
				
	
		} else {
	
	
			
			
			/*******************
			* ANIMATE TO RIGHT *
			*******************/
			$(services_slide_next).css( { left: "0", display: 'block' } );
			$(services_slide_next + " .header").css( { left: "0", display: 'block', opacity: 0  } );
			
			services_slides_animating = true;
			$(services_slide_current + " .header").animate({
				opacity: 0
			}, {
				duration: 1000,
				easing: 'easeOutQuad',
				complete: function() { }
			});
			
			//animate next slide in
			$(services_slide_next + " .header").animate({
				opacity: 1
			}, {
				duration: 1000,
				easing: 'easeOutQuad',
				complete: function() { services_slides_animating  = false; }
			});
			
			
		
		}

		
	}




$(document).ready(function() {
						   
	
	setTimeout("auto_animate()", auto_ms);
	

						   
	//preload images
	
	var img = new Image();
	
	$("a.image_choose").each(function() {
		img.src = $(this).attr("href");
	});


	$("a.image_choose").click(function() { return false; } );	//cancel opening the actual image
	$("a.image_choose").hover(function() {
		$("a.image_choose").removeClass("current");
		$(this).addClass("current");
		
	
		$(".image_container").after("<div class=\"image_container\"><img src=\"" + $(this).attr("href") + "\" width=\"430\" height=\"143\" alt=\"\" /></div>").remove();
		
		return false;
	}, function() {
		
	
	
	});
	
	

	
	

	/**************************
	* homepage slides animate *
	**************************/

	$("a#next_home").click(function() {
		if (services_slides_animating)	return false;
		auto_show = false;
		var selected_slide_idx = current_home_idx;
		var total_slides = $(".home_slides").size() -1;	
		var next_slide = (selected_slide_idx+1 > total_slides) ? 0 : selected_slide_idx+1;
		
		//find slide id for deep link by index & remove slide_nav_
		//var next_slide_deep_link = $("a.deep_link:eq(" + next_slide + ")").attr("id").substr(10);
		//window.location = '#' + next_slide_deep_link;
		//scrollTo(0,0);
		
		current_home_idx = next_slide;
		homepage_toggle(selected_slide_idx, next_slide);
	});
	
	$("a#prev_home").click(function() {
		if (services_slides_animating)	return false;
		auto_show = false;
		var selected_slide_idx = current_home_idx;
		var total_slides = $(".home_slides").size() -1;	
		var prev_slide = (selected_slide_idx == 0) ? total_slides : selected_slide_idx-1;
		
		//find slide id for deep link by index & remove slide_nav_
		//var prev_slide_deep_link = $("a.deep_link:eq(" + prev_slide + ")").attr("id").substr(10);
		//window.location = '#' + prev_slide_deep_link;

		//alert("selected_slide_idx: " + selected_slide_idx + "\nprev_slide: " + prev_slide);

		current_home_idx = prev_slide;
		homepage_toggle(selected_slide_idx, prev_slide);
	});


	
	
	
	
	

});

