var strHeaderPrefix = 'header_';
var intCurrentSlideIndex = 0;
var intPreviousSlideIndex = null;

var strTestimonialPrefix = 'testimonial_';
var intCurrentTestimonialIndex = 0;

var boolSlideTweenDone = true;
var boolCurrentSlideTweenDone = true;

var intTotalTestimonials = 10;

var arrMouseInBox = new Array();

window.addEvent('domready', function() 
{		
	rotate_testimonials.periodical(8000);

	arrMouseInBox[0] = false;
	arrMouseInBox[1] = false;
	arrMouseInBox[2] = false;
	arrMouseInBox[3] = false;

	$('box_1').addEvents(
						 {	'mouseenter': function(){this.className = 'BoxOn'; arrMouseInBox[1] = true; setTimeout('handle_box_mouseenter(1)', 400);}, 
						 	'mouseleave': function(){this.className = "Box"; handle_box_mouseleave(1);}							
						 });


	$('box_2').addEvents(
						 {	'mouseenter': function(){this.className = 'BoxOn'; arrMouseInBox[2] = true; setTimeout('handle_box_mouseenter(2)', 400);}, 
						 	'mouseleave': function(){this.className = "Box"; handle_box_mouseleave(2);}
						 });
	
	$('box_3').addEvents(
						 {	'mouseenter': function(){this.className = 'BoxOn'; arrMouseInBox[3] = true; setTimeout('handle_box_mouseenter(3)', 400);}, 
						 	'mouseleave': function(){this.className = "Box"; handle_box_mouseleave(3);}
						 });

	$('link_1').addEvents(
						 {	'mouseenter': function(){arrMouseInBox[1] = true; setTimeout('handle_box_mouseenter(1)', 400);}, 
						 	'mouseleave': function(){handle_box_mouseleave(1);}							
						 });


	$('link_2').addEvents(
						 {	'mouseenter': function(){arrMouseInBox[2] = true; setTimeout('handle_box_mouseenter(2)', 400);}, 
						 	'mouseleave': function(){handle_box_mouseleave(2);}
						 });
	
	$('link_3').addEvents(
						 {	'mouseenter': function(){arrMouseInBox[3] = true; setTimeout('handle_box_mouseenter(3)', 400);}, 
						 	'mouseleave': function(){handle_box_mouseleave(3);}
						 });
	
	$('mainBanner').addEvents(
						 {	'mouseleave': function(){arrMouseInBox[0] = true; setTimeout('handle_box_mouseenter(0)', 350);},
						 	'mouseenter': function(){arrMouseInBox[0] = false;}
						 });

});


function handle_box_mouseenter(intBoxIndex)
{
	if( arrMouseInBox[intBoxIndex] == true )
	{
		switch_slide(intBoxIndex);
	}
}

function handle_box_mouseleave(intBoxIndex)
{
	arrMouseInBox[intBoxIndex] = false;
}

function wait_for_complete()
{
   if (boolSlideTweenDone)
   {
      return true;
   } 
   else 
   {
      setTimeout(wait_for_complete, 1000);
   }
}


function display_next_slide()
{
	if(intCurrentSlideIndex < intTotalSlides-1)
	{		
		intSlideIndex = intCurrentSlideIndex+1;
	}
	else
	{
		intSlideIndex = 0;
	}
	
	switch_slide(intSlideIndex);
}

function switch_slide(intSlideIndex)
{		   
	if(intSlideIndex != intCurrentSlideIndex)
	{				
		strCurrentSlideId = strHeaderPrefix + intCurrentSlideIndex;
		strSlideId = strHeaderPrefix + intSlideIndex;		

		$(strSlideId).setStyle('left','950px'); 

		if(intPreviousSlideIndex != null)
		{
			strPreviousSlideId = strHeaderPrefix + intPreviousSlideIndex;
			
			if($(strPreviousSlideId))		
			{	
				$(strPreviousSlideId).setStyle('left','950px'); 
				$(strPreviousSlideId).setStyle('z-index','10'); 
			}
		}
		

		$(strCurrentSlideId).setStyle('z-index','1'); 
		
		myFx = new Fx.Tween($(strSlideId));	
		myFx.addEvents(
				 {'complete': function(){boolSlideTweenDone = true;}
				 });
		boolSlideTweenDone = false;
		myFx.start('left', null, '0px');


		myFx = new Fx.Tween($(strCurrentSlideId));	
		myFx.addEvents(
				 {'complete': function(){boolCurrentSlideTweenDone = true;}				  
				 });
		boolCurrentSlideTweenDone = false;
		myFx.start('left', null, '-950px');
					
		intPreviousSlideIndex = intCurrentSlideIndex;
		intCurrentSlideIndex =  intSlideIndex;
	}
}


function rotate_testimonials()
{	
	strTestimonialId = strTestimonialPrefix + intCurrentTestimonialIndex;

	objTestimonialTween = new Fx.Tween($(strTestimonialId));
	objTestimonialTween.start('left', null, '290px');	
	
	if(intCurrentTestimonialIndex < intTotalTestimonials-1)
	{		
		intCurrentTestimonialIndex++;
	}
	else
	{
		intCurrentTestimonialIndex = 0;
	}
	strTestimonialId = strTestimonialPrefix + intCurrentTestimonialIndex;

	objTestimonialTween = new Fx.Tween($(strTestimonialId));	

	objTestimonialTween.start('left', null, '0px');			
}
