// JavaScript Document
function setTab(name,cursel,n){
	for(i=0;i<=n;i++){
		var con=document.getElementById("con_"+name+"_"+i);
		con.style.display=i==cursel?"block":"none";
		
		var curtab=document.getElementById(name+i);
		curtab.style.color=i==cursel?"#fff":"#3F7DA7";
		curtab.style.backgroundColor=i==cursel?"#3F7DA7":"#fff";
	}
}

function openWin(theLoc,theWidth,theHeight){
	win=window.open(theLoc,"NewWin","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width="+theWidth+",height="+theHeight);
	if(win.opener==null) win.opener=window;
	win.opener.name="opener";
}


$(document).ready(function(){
	//	left nav
	var sn = $("#left li li a[class]").attr("class");
	$("#"+sn).addClass("cur");
	
	//	footer fix
	if ($("#footerdv").length > 0)
	{
		var hh1 = document.body.clientHeight;
		var hh2 = document.documentElement.clientHeight-15;
		if(hh1<hh2)
		{
			$("#wrapper").height(hh2);
			$("#footerdv").css("position","absolute");
			$("#footerdv").css("bottom","0");
		}
		menuwd = 0;
		$("#footer ul").each(function(){
			menuwd = menuwd + $(this).width();
		});
		var pad = Math.floor((830-menuwd)/2/$("#footer ul").length);
		$("#footer ul").css("padding","0px "+pad+"px");
	}
	
	//	tabs fix
	var tabwh = 0;
	var tabpad = 0;
	$("#tabs li").each(function(){
		tabwh = tabwh + $(this).width();						
	});
	tabpad = Math.floor((510-tabwh)/2);
	$("#tabs ul").css("padding-left",tabpad+"px");
	
	//homepage slideshow
	if ($('#slideshow').length>0)
	{
		setTimeout(function(){
			$('#slideshow img:first').fadeIn(1500);
			$('#slideshow').cycle({timeout:mainBannerSpeed});
		}, mainBannerSpeed);
	}
	
	if ($('#adbanner_slideshow').length>0)
	{
		setTimeout(function(){
			$('#adbanner_slideshow img:first').fadeIn(1500);
			$('#adbanner_slideshow').cycle({timeout:adBannerSpeed});
		}, adBannerSpeed);
	}
	
	if ($('#partners_slideshow').length>0)
	{
		setTimeout(function(){
			$('#partners_slideshow img:first').fadeIn(1500);
			$('#partners_slideshow').cycle();
		}, 2500);
	}
	
	//left nav
//	$("#left a.toplevel").click(function(){
//		$(this).next("ul").toggle();
//		$(this).parent().addClass("cur");
//		$("#left a.toplevel").not($(this)).next("ul:visible").hide();
//		$(this).toggleClass("active");
//		$(this).siblings("a").removeClass("active");
//	});

	if($("#right li.toplevel").length>0)
	{$("#right li.toplevel:last").addClass("last");}
	
	$("#productlist li:last").css("border-bottom","none");

	if($("#product").length>0)
	{
		$("a.zoomimg").eq(0).jqzoom({
			zoomWidth: 410,
			zoomHeight: 410,
			xOffset: 9,
			yOffset: 0,
			lens: true,
			title: false,
			showPreload: true,
			preloadText: 'Loading zoom',
			preloadPosition: 'center'
		});

		$("#productslist li:last").css("border-bottom","none");

		$("#thumbs a[href='#'][id!='enlarge']").click(function(){
			openWin("/large.asp?path="+$(this).children("img").attr("src").replace("/pimg/tiny_",""),820,820);
			return false;
		});
		
		$("#enlarge").click(function(){
			openWin("/large.asp?path="+$("a.zoomimg").attr("href").replace("/pimg/lg_",""),820,820);
		});
		
		if($("#thumbs img").length>1)
		{
			$("#thumbs a[href='#'] img").mouseover(function(){
				var strHtml = '';
				strHtml = '<a href="'+$(this).attr("src").replace("tiny_","lg_")+'" class="zoomimg"><img src="'+$(this).attr("src").replace("tiny_","med_")+'" width="240" height="240" alt="" /></a>';
				$(".imgdv").html(strHtml);
				
				var index = $("#thumbs img").index(this);
				$("a.zoomimg").eq(0).jqzoom({
					zoomWidth: 410,
					zoomHeight: 410,
					xOffset: 9,
					yOffset: 0,
					lens: true,
					title: false
				});
			});
		}
		
	}
	
	$("#search_fm").submit(function(){
		var tmp = $.trim($("#search_fm input[name='Search']").val().replace("Search",""));
		if (tmp == "")
		{alert("Please enter a value.");$("#search_fm input[name='Search']").focus();return false;}
	});
	
	//	entry learn more links fix
	if($("#entrybox a").length>0)
	{
		$("#entrybox a").each(function(){
			if($.trim($(this).text().toLowerCase())=='learn more')
			{$(this).addClass("learnmore");}
		});
	}
	
	//	product registration
	$("#product_registration_fm").submit(function(){
		if ($("#ModelNumber").val()=="")
		{alert("Please select an item for the \"Model Name / Number\" field.");$("#ModelNumber").focus();return false;}
		
		if ($("input#SerialNumber").val()=="")
		{alert("Please enter a value for the \"Serial Number\" field.");$("input#SerialNumber").focus();return false;}
		
		if ($("input#Name").val()=="")
		{alert("Please enter a value for the \"Name\" field.");$("input#Name").focus();return false;}
		
		if ($("#ModelNumber option:selected").attr("class") == 'unique')
		{$("#formName").val('Product Registration - English - Unique');}
		else
		{$("#formName").val('Product Registration - English');}

		if ($('#ModelNumber').val()=='CDPF' || $('#ModelNumber').val()=='PAN8008DW')
		{$("#addform").html($("#addform").html()+'<input type="hidden" name="next" value="cdpf">');}
		else
		{$("#addform").html('');}
	});
	
	//	select a language
	if($("#registration_fm").length>0)
	{
		$("#Language").change(function(){
			window.location.href=$("#Language option:selected").val();
		});
	}

	$('.zebra tr:even').css('background','#F2F2F2');
	
	
	//$("#topnav").hover(
	//	function(){$("#topnav").css("background-image","url(/images/topnav-hover.png)");},
	//	function(){$("#topnav").css("background-image","url(/images/topnav-normal.png)");}
	//);
	
	if ($('#bgresize').length > 0) {
		$("#bgresize").ezBgResize();
	}
	
});

