subMenu = ''
var subFadingTime = 300

$(document).ready(function(){
						   
						   
	$("#poll_vote").click(function(){
		var pollVal = $("input[name='poll']:checked").val()
		$("#poll").load("poll_vote.php?vote="+pollVal)
	})
	
	
	$(".thumbs").click(function(){
		var thisId = parseInt($(this).attr('id'))
		var url = '';
		switch(thisId) {
			case 1:
				url = "sealyback62.1.flv";
				break;
			case 2:
				url = "sealyback61.1.flv";
				break;
			case 3:
				url = "sealynewad3.flv";
				break;
			case 4:
				url = "sealynewad1.flv";
				break;
			case 5:
				url = "sealynewad4.flv";
				break;
			case 6:
				url = "sealynewad2.flv";
				break;
			//new videos
			case 7:
				url = "sealynewad7.flv";
				break;
			case 8:
				url = "sealynewad8.flv";
				break;
			case 9:
				url = "SDJ30_TVC.flv";
				break;
			case 10:
				url = "SDJ15_TVC.flv";
				break;
		}
		var so = new SWFObject("tv-ads.swf", "tv-ads", "351", "320", "8", "#ffffff");
		so.addParam("allowScriptAccess", "always");
		so.addParam("wmode", "transparent");
		so.addParam("loop", "false");
		so.addVariable("loadVid", "videos/"+url);
		so.addParam("autoplay", "true");
		so.write("player");
	})
						   
	$("#Left_Menu li a").hover(function(){
		//$(".subNav").fadeOut(subFadingTime)
		$(".subNav").css('display','none')
		$("#Left_Menu").stopTime()
		thisId = $(this).parent().attr('id')
		subMenu = $("#subNav_"+thisId)
		//alert(subMenu.attr('id'))
		if(subMenu.length) {
			subMenu.fadeIn(subFadingTime)
		}
	},function(){
		$("#Left_Menu").oneTime(300,function(){
			//subMenu.css('display','none')
			subMenu.fadeOut(subFadingTime)
		})
	})
	
	$(".subNav").hover(function(){
		thisId = $(this).attr('id')
		$("#Left_Menu").stopTime()
	},function(){
		$("#Left_Menu").oneTime(300,function(){
			//$('#'+thisId).css('display','none')
			$('#'+thisId).fadeOut(subFadingTime)
		})
	})
	
	$("#search_txt").focus(function(){
		if($(this).val() == 'Search') $(this).val('')
	})
	
	
	showHideSub("#bg-bnav-sleep","#bg-bnav-content");
	showHideSub("#find-retailer","#div-find-retailer");
	$(".article:first").css('display','block')
	
	// Bnav Section show
	$("#bg-bnav-content li").click(function(){
		//alert($("#bg-bnav-content li").length)
		//alert($(this).index())
		var thisIndex = $(this).index()
		$(".article").css('display','none')
		$(".article:nth-child("+(thisIndex+1)+")").css('display','block')
	})
	
	
	// Tabcontent
	$(".tabcontent:first").css('display','block')
	$("#sealy-tabs li").click(function(){
		$(".tabcontent").css('display','none')
		$("#sealy-tabs li, #sealy-tabs li a").removeClass('selected')
		$(this).addClass('selected')
		$(this).children('a').addClass('selected')
		var thisRel = $(this).children('a').attr('rel')
		$("#"+thisRel).css('display','block')
	})
	
 	/*$("#poll").mouseover(function(){
		$('.tooltip').show('100');																						
	});
  
  	$("#poll").mouseout(function(){
		 $('.tooltip').hide('normal');
	});
	*/


	$(".single-tabs li a").click(function(){
		var thisRel = $(this).attr('rel')
		if(thisRel == 'sealy2') $("#single-img").attr('src','images/sealy-single.gif')
		else $("#single-img").attr('src','images/logo-sealysingles.gif')
	})
	
	/*$("#articlesGroup div:first ul.mRange li").click(function(){
		var thisIndex = $(this).index()
		alert(thisIndex)
	})*/
	
	
})

function showArticle(index) {
	$(".article").css('display','none')
	$(".article:nth-child("+(index+1)+")").css('display','block')
}


function showHideSub(trigger,element) {
	var both = trigger+','+element
	$(both).hover(function(){
		$(trigger).stopTime()
		$(element).css('display','block')
	},function(){
		$(trigger).oneTime(500,function(){$(element).fadeOut(250)})
	})
}
