/* mod_generic_carousel */
YAHOO.namespace('mod_generic_carousel');
var mod_generic_carousel_timeout = null;

YAHOO.mod_generic_carousel.scroll_to = function(tab_id,root_id,carousel_id,offset)
{
	var d = YAHOO.util.Dom;
	var next_push_index = null;
	var max_id = 6;
	
	for(var i=1;i<7;i++)
	{
		var calc_id = 'tb_'+root_id+'_'+i.toString();
		if(calc_id == 'tb_'+tab_id ) next_push_index = i;
		var el = document.getElementById(calc_id);
		if(el!=null) { d.removeClass(el,'selected'); }
		else { max_id = Math.min(max_id,i-1); }
	}
	
	var el = document.getElementById('tb_'+tab_id);
	d.addClass(el,'selected');

	// Now scroll the carousel information to the requested position.
	var animation = new YAHOO.util.Motion(document.getElementById(carousel_id), { left: { to: -offset } },0.2,YAHOO.util.Easing.easeOut);
	animation.animate();

	// Kill any existing timeout.
	if(mod_generic_carousel_timeout!=null) clearTimeout(mod_generic_carousel_timeout);
	
	// Calculate the next tab.
	next_push_index++; if(next_push_index>max_id) next_push_index = 1;
	next_push_index = root_id + '_' + next_push_index.toString();
	var scroll_timeout = 15000;
	if(mod_carousel_increase_timout==1) { mod_carousel_increase_timout = 0; scroll_timeout=30000; }
	mod_generic_carousel_timeout = setTimeout("YAHOO.mod_generic_carousel.scroll_to('"+next_push_index+"','"+root_id+"','"+carousel_id+"',"+mod_carousel_offset_array[next_push_index]+")",scroll_timeout);
};

YAHOO.mod_generic_carousel.scroll_to_no_anim = function(tab_id,root_id,carousel_id,offset)
{
	var d = YAHOO.util.Dom;
	var next_push_index = null;
	var max_id = 6;
	
	for(var i=1;i<7;i++)
	{
		var calc_id = 'tb_'+root_id+'_'+i.toString();
		if(calc_id == 'tb_'+tab_id ) next_push_index = i;
		var el = document.getElementById(calc_id);
		if(el!=null) { d.removeClass(el,'selected'); }
		else { max_id = Math.min(max_id,i-1); }
	}
	
	var el = document.getElementById('tb_'+tab_id);
	d.addClass(el,'selected');
	
	// Now scroll the carousel information to the requested position.
	var animation = new YAHOO.util.Motion(document.getElementById(carousel_id), { left: { to: -offset } },0,YAHOO.util.Easing.easeOut);
	animation.animate();
	
	// Kill any existing timeout.
	if(mod_generic_carousel_timeout!=null) clearTimeout(mod_generic_carousel_timeout);
	
	// Calculate the next tab.
	next_push_index++; if(next_push_index>max_id) next_push_index = 1;
	next_push_index = root_id + '_' + next_push_index.toString();
	var scroll_timeout = 5000;
	if(mod_carousel_increase_timout==1) { mod_carousel_increase_timout = 0; scroll_timeout=10000; }
	mod_generic_carousel_timeout = setTimeout("YAHOO.mod_generic_carousel.scroll_to('"+next_push_index+"','"+root_id+"','"+carousel_id+"',"+mod_carousel_offset_array[next_push_index]+")",scroll_timeout);
};

