function wheel_finish_tabs()
{
	$('.tabs > a','#wheel_image').each(function(){
		var img = new Image();
		img.src = $(this).attr('href');
	});
	
	var tabs = $('.tabs > a','#wheel_image');
	
	$("li","#wheel_info > dd.finish").each(function(i){
		$(this).wrapInner('<a></a>').mouseover(function(){ $(tabs[i]).trigger('click'); })
		.css('cursor','pointer');
	});
	
	$('.tabs > a','#wheel_image').click(function(){
		$('#wheel_image > a > img').attr('src',$(this).attr('href'));
		$('.tabs > a','#wheel_image').each(function(){ $(this).removeClass('selected'); } );
		$(this).addClass('selected');
		
		if(/\bsupersize\b/.exec($(this).attr('class'))) {
			var str = $(this).attr('href');
			str = str.substring(0,str.length-4);
			str = str + '-l.jpg';
			$('#wheel_image > p#img_supersize > a.thickbox').attr('href',str);
			$('#wheel_image > p#img_supersize > a.thickbox').attr('title',$(this).attr('title'));
			$('#wheel_image > p#img_supersize').css('display','block');
		} else {
			$('#wheel_image > p#img_supersize').css('display','none');
		}
		return false;
	});
	
}

function home_page_tabs()
{
	if($('#home').length==1)
	{
		$('#tabbox').addClass('scripted');
		$('#tabbox > ul#tabs > li').each(function(){
			$('a',this).click(function(){
				$('#tabbox > ul#tabs > li > a').removeClass('selected');
				$(this).addClass('selected');
				$('#tabbox > div').removeClass('selected');
				id = this.href.split('#')[1];
				$('#'+id).addClass('selected');
				return false;
			});
		});
	}
}

function sidebar_specials()
{
	$('#top-specials > ul').addClass('scripted');
	
	$('#top-specials > ul > li').css('display','none');
	
//	$('#top-specials > ul > li').removeClass('show');
	
	var total = $('#top-specials > ul > li').length;
	
	$('#top-specials > ul > li').each(function(i){
		if(i<window.current_pos&&i>=(window.current_pos-4))
		{
			$(this).fadeIn(300);
		}
	});

	if(window.current_pos < total) window.current_pos = window.current_pos + 4;
	else { window.current_pos = 4; }
	
	var interval = setTimeout('sidebar_specials()',9000);
}

function setup_tyre_sizes()
{
	if($('#tyres').length==1)
	{
		$('dd.pr-sizes').css('display','none');
		$('dd.pr-sizes').before('<dd class="pr-show-sizes"><a href="#" title="Click to display tyre size options">Show size options</a></dd>');
		$('dd.pr-show-sizes > a').click(function() {
			txt = $(this).html();
			if(txt=='Show size options')
			{
				$(this).html('Hide size options');
			}
			else
			{
				$(this).html('Show size options');
			}
			$('dd.pr-sizes').slideToggle();
			return false;
		});
	}
}

window.current_pos = 4;




$(document).ready(wheel_finish_tabs);
$(document).ready(home_page_tabs);
$(document).ready(sidebar_specials);
//$(document).ready(setup_tyre_sizes);

