home_coupons_button_timeout_initial=new Array;
home_coupons_button_timeout_restart=new Array;
home_coupons_button_timeout=new Array;
home_coupons_button_timer=new Array;
home_coupons_button_fadetime=new Array;
home_coupons_button_index=new Array;
home_coupons_button_started=new Array;
home_coupons_button_index=new Array;
home_coupons_button_animating=new Array;

/*****************/
/* JQUERY onload */
/*****************/

jQuery(document).ready(function() 
{

	var ss_areas=jQuery("DIV.home_coupons_button_scroll");  
	var delay=0;
	for(var i=0;i<ss_areas.length;i++)
	{
		var parent_id=ss_areas.get(i).id;
		var scroller=ss_areas.get(i);

		//ea. vars.
		home_coupons_button_timeout_initial[parent_id]=4000;
		home_coupons_button_timeout[parent_id]=4000;
		home_coupons_button_timer[parent_id]=0;
		home_coupons_button_fadetime[parent_id]=250;
		home_coupons_button_index[parent_id]=0;
		home_coupons_button_started[parent_id]=false;
		home_coupons_button_index[parent_id]=0;
		home_coupons_button_animating[parent_id]=false;

		delay+=home_coupons_button_timeout[parent_id];

		//start
		//home_coupons_buttonSetTimeout(parent_id,home_coupons_button_timeout_initial[parent_id]);	

		//pause on over/out.		
		//jQuery(scroller).hover(function() {home_coupons_buttonKillTimeout(parent_id);},function() {home_coupons_buttonSetTimeout(parent_id,home_coupons_button_timeout_restart[parent_id]);});		
	}	
});

/**********************************/
/* 			fading				  */
/**********************************/

function home_coupons_buttonKillTimeout(parent_id)
{
	if(home_coupons_button_timer[parent_id])
	{
		window.clearTimeout(home_coupons_button_timer[parent_id]);		
		home_coupons_button_timer[parent_id]=0;
	}
}

function home_coupons_buttonSetTimeout(parent_id,time)
{
  	home_coupons_buttonKillTimeout(parent_id);
	home_coupons_button_timer[parent_id]=window.setTimeout(function(){home_coupons_button(parent_id);},time);
}


function home_coupons_button(parent_id)
{
	//get all images in current slideshow
	var home_coupons_button_items=jQuery("DIV#"+parent_id+" DIV.home_coupons_button");	
	if(home_coupons_button_items.length>1)
		home_coupons_buttonNextItem(parent_id);
	home_coupons_buttonSetTimeout(parent_id,home_coupons_button_timeout[parent_id]);
}

function home_coupons_buttonNextItem(parent_id)
{
	//amimating semaphor
  	if(home_coupons_button_animating[parent_id])
  		return;
  	home_coupons_button_animating[parent_id]=true;

	//stop slideshow/clear timer....
	home_coupons_buttonKillTimeout(parent_id);

 	//elemtns to maniputate
	var home_coupons_button_items=jQuery("DIV#"+parent_id+" DIV.home_coupons_button");	
	var home_coupons_button_scroller=jQuery("DIV#"+parent_id+" DIV.home_coupons_button_container");	
		
	//images
	home_coupons_button_scroller.animate({left:"-158px"},home_coupons_button_fadetime[parent_id],'',function()
	{
	  	home_coupons_button_scroller.append(home_coupons_button_items[0]);
	  	home_coupons_button_scroller.css({left:"0px"});
	  	home_coupons_button_animating[parent_id]=false;
	}); 

	//ss...
	home_coupons_button_started[parent_id]=true;

	//restart....
	//home_coupons_buttonSetTimeout(parent_id,home_coupons_button_timeout_restart[parent_id]);

}

function home_coupons_buttonPrevItem(parent_id)
{
	//amimating semaphor
  	if(home_coupons_button_animating[parent_id])
  		return;
  	home_coupons_button_animating[parent_id]=true;

	//stop slideshow/clear timer....
	home_coupons_buttonKillTimeout(parent_id);

 	//elemtns to maniputate
	var home_coupons_button_items=jQuery("DIV#"+parent_id+" DIV.home_coupons_button");	
	var home_coupons_button_scroller=jQuery("DIV#"+parent_id+" DIV.home_coupons_button_container");	
		
	//images
  	home_coupons_button_scroller.prepend(home_coupons_button_items[home_coupons_button_items.length-1]);
  	home_coupons_button_scroller.css({left:"-158px"});
	home_coupons_button_scroller.animate({left:"0px"},home_coupons_button_fadetime[parent_id],'',function()
	{
	  	home_coupons_button_scroller.css({left:"0px"});
	  	home_coupons_button_animating[parent_id]=false;
	}); 

	//ss...
	home_coupons_button_started[parent_id]=true;

	//restart....
	//home_coupons_buttonSetTimeout(parent_id,home_coupons_button_timeout_restart[parent_id]);

}
