// Animate the home page images by calling puff on them

// Hack for Mac IE - just show one image
if (navigator.userAgent.match(/MSIE.*Mac/))
	{
	window.onload = function(){
			document.getElementById('id_home_image_1').style.display = 'block';
		};
}
	
	


var HomeSlides = {
	delay : 8000, 
	timer : null,
	
	// Get hold of our slides, and set up a timer to animate
	init : function () {

	
		HomeSlides.slides = $A(document.getElementsByClassName('home_image'));
		HomeSlides.count = HomeSlides.slides.size();
		

		
		if (!HomeSlides.slides )
			return;
	
		new Effect.Appear('wide_text', {duration:3.0});	
		HomeSlides.current = 1;
		HomeSlides.current_slide().show();
		HomeSlides.slides.each(function(slide){
			if(slide != HomeSlides.current_slide())
			{
				new Effect.Fade(slide);
			}
			else
				new Effect.Appear(slide);	
		});
		
		HomeSlides.start();
		
	},

	// Start animating
	start: function(){
		if (HomeSlides.timer)
			{
			clearInterval(HomeSlides.timer);
	    	HomeSlides.animate();
			}
			
			new Effect.SwitchOff('control_play');
			new Effect.Appear('control_pause', {duration:1.0});
		//	$('control_play').hide();
		//	$('control_pause').show();
			HomeSlides.timer = setInterval("HomeSlides.animate();",HomeSlides.delay);
	},
	
	
	// Stop animating
	stop: function(){
				new Effect.SwitchOff('control_pause');
				new Effect.Appear('control_play', {duration:1.0});
	//	$('control_play').show();
	//	$('control_pause').hide();
		clearInterval(HomeSlides.timer);
	},
	
	current_slide: function() {
		return $("id_home_image_"+HomeSlides.current);
	},

	// Show one slide (the next one)
	show_next_slide: function() {
		
		// Hide the caption if not on slide 1
		if (HomeSlides.current == HomeSlides.count)
			{
			new Effect.Appear('wide_text', {duration:1.0});
			}
		else
			{
			new Effect.Fade('wide_text');	
			}
		
		// Make sure play controls are showing
		controls = $('play_controls');
		if (controls)
			controls.show();
		
		var curr_slide = HomeSlides.current_slide();
		HomeSlides.increment_counter();
		var next_slide = HomeSlides.current_slide();
		if (curr_slide)
			{
			curr_slide.style.top = "101px";
			next_slide.style.top = "101px";
			curr_slide.style.zIndex = "3";	
			next_slide.style.zIndex = "1";
			next_slide.show();
			new Effect.SlideUp(curr_slide, {duration:2.0});
			}
	},

	// Increment our counter (with overflow)
	increment_counter: function() {
		HomeSlides.current = HomeSlides.current + 1;
		if (HomeSlides.current > HomeSlides.slides.length) {HomeSlides.current = 1};
	},
	
	// called on a timer - animates our home page images
	animate: function(){
		// Show the next slide
		HomeSlides.show_next_slide();
	}
	
};


Event.observe(window,'load',HomeSlides.init,false);
	
