var rotator = {
	currents: new Array(),
	counts: new Array(),
	
	init: function() {
		$('.rotator').each(function() 
		{
			id = $(this).attr('id').replace('rotator_','');
			rotator.counts[id]=$('#container_'+id+' div').length;
		    rotator.currents[id]=1;
		    
		    
		    $('#rotator_icons_'+id).html('');			
		    for(i=1;i<=rotator.counts[id];i++)
		    {		
		    	
		    	$('#rotator_icons_'+id).append("<a href='#' style='padding: 0 2px;' id='rotator_icon_"+id+"_"+i+"' onclick='rotator.show(\""+id+"\","+i+"); return false;'><img src='/images/icon_rotator_"+(i==1?'active':'passive')+".gif' border=0 /></a>");
		    }
		    
		    $('#btn_next_'+id).click(rotator.next).css('cursor','pointer');
		    $('#btn_prev_'+id).click(rotator.prev).css('cursor','pointer');
		})
		
	},
	next: function ()
	{
		collection = $(this).attr('id').replace('btn_next_','');
		
		if(rotator.currents[collection]==rotator.counts[collection]) rotator.currents[collection]=1;
		else rotator.currents[collection]++;
		
		rotator.show(collection,rotator.currents[collection]);
	},
	prev: function ()
	{
		collection = $(this).attr('id').replace('btn_prev_','');
		
		if(rotator.currents[collection]==1) rotator.currents[collection]=rotator.counts[collection];
		else rotator.currents[collection]--;
		
		rotator.show(collection,rotator.currents[collection]);
	},
	show: function(collection,index)
	{
		$('#rotator_'+collection).html($('#items_'+collection+'_'+index).html());
		$('#rotator_icons_'+collection+' img').attr('src','/images/icon_rotator_passive.gif');
		$('#rotator_icon_'+collection+'_'+index+' img').attr('src','/images/icon_rotator_active.gif');
	}
}

jQuery(function() {
	rotator.init()
});