jQuery(function() {
	var index=0;
	jQuery('#spMakes').html('');
	jQuery('#specialsContainer > ul').each(function() {
		jQuery('#spMakes').append( jQuery("<a href='#' id='spa_"+(index)+"' onclick='indexGallery.show("+(index++)+"); return false;'>"+jQuery("li.make",this).html()+"</a>") )
	})
	
	jQuery("#spArrForward").click(function() {
		indexGallery.next();
	}).css("")
	jQuery("#spArrBack").click(function() {
		indexGallery.prev();
	})
	
	indexGallery.bind(index);
})

indexGallery =
{
	interval: null,
	current: 0,
	count: 0,
	bind: function(count)
	{
		indexGallery.count = count;
		jQuery('#spa_0').addClass('selected');
		
		indexGallery.launch();
	},
	launch: function()
	{
		clearInterval(indexGallery.interval);
		indexGallery.interval = setInterval(indexGallery.next,10000);
		
	},
	show: function(ind)
	{
		indexGallery.current = ind;
		obj = jQuery('#specials_'+ind);
		
		jQuery("#spImage").html( jQuery('li.image',obj).html());
		jQuery("#spSite").html( jQuery('li.site',obj).html());
		jQuery("#spTitle").html( jQuery('li.title',obj).html());
		jQuery("#spDesc").html( jQuery('li.description',obj).html());
		
		jQuery('#spMakes > a').removeClass("selected");
		jQuery("#spa_"+ind).addClass("selected");
		
		indexGallery.launch();
	},
	next: function()
	{
		if(indexGallery.current==indexGallery.count-1) indexGallery.current = 0;
		else indexGallery.current++;
		
		indexGallery.show(indexGallery.current);
	},
	prev: function()
	{
		if(indexGallery.current==0) indexGallery.current = indexGallery.count -1;
		else indexGallery.current--;
		
		indexGallery.show(indexGallery.current);
	}
}