$(document).ready(function(){
						  
	swapGraph();//Graph change function
	$('.swap a').click(function(){
		clearTimeout(clrTime);
		selected = $(this).index()-1;
		clicked = true;
		swapGraph();
		return false;
	});
	//set z-index for rotator li anchors
	/*var galleryAnchor = $('.intro ul li').hasClass('show');
	if(galleryAnchor){
		$('.intro ul li.show a').css('z-index','10');
	}else{
		$('.intro ul li a').css('z-index','0');
	}*/
	//home page gallery clicks
	$('.tempurpedic').click(function(){
		$('.tempurpedic').attr({target:"_blank"})
		window.location=$(this).find("a").attr("href");
		//$('#tempurA').click();
		return false;
	});
	
});

var selected = $('.swap a.selected').index();
var clrTime = 0;
var clicked = false;
//graph swapping
function swapGraph(){
	selected++;
	if(selected == $('.swap a').length)selected = 0;
	$('.swap a').removeClass('selected');
	$('.swap a:eq('+ selected +')').addClass('selected');
	$('.graph img').fadeOut("slow", function(){ $('.graph img').attr('src', templatepath +'images/price_graph'+ selected +'.jpg'); $('.graph img').fadeIn("slow"); });
	
	if(!clicked) clrTime = setTimeout("swapGraph()", 10000);
}



