// Flyout Navigation functions

/*
function changeCSS() {
	var chckIE6=/MSIE 6/;
	var chckIE7=/MSIE 7/;
	var getBrwsr=navigator.userAgent;
	var getBrwsr=navigator.userAgent;
	if ((chckIE6.test(getBrwsr)==true) || (chckIE7.test(getBrwsr)==true)) {
		document.getElementById('ctl00_stylesFile').href="styles/thewhitecompanyIE.css";
		//document.getElementById('alert_line').innerHTML="THIS IS IE < 8";
	}
}
*/

function initVars() {
	var navElmCount=$("ul.hd_mainmenu li ul").length; // Count number of main categories
	var navElmTrvrs=1;	// initialise the counter used to traverse the navigation
	var getNavElmSize;	// initialise variable to collect widths
	var getNavElmPos;	// initialise variable used to collect element position
	var allWidths=0;	// initialise and set variable used to collect widths
}

// PREVIOUS adjuster function
//function adjustFlyouts(a) {

// IE7 nav functions

//var chckIE7=/MSIE 7/;
//var chkIE6=/MSIE 6/;
//var getBrwsr=navigator.userAgent;
	
	
/* adjust top*/

	//if ((chckIE7.test(getBrwsr) == true) || (chkIE6.test(getBrwsr) == true)) {
	//	$("ul.hd_mainmenu li ul").css("margin-top","20px");
	//}
	
	//for (a=1;a<=navElmCount;a++) {
	
	//var getNavElmSize=$("ul.hd_mainmenu li:nth-child("+a+")").width(); 
	//var getNavElmPos=$("ul.hd_mainmenu li:nth-child("+a+")").position().left;
	// allWidths=allWidths+getNavElmSize+32;
	//if ((getNavElmPos+300) >= 980) {
	//	calcNavAdjust=(300-getNavElmSize);
	//	$("ul.hd_mainmenu li:nth-child("+a+") ul").css("margin-left",-calcNavAdjust+"px");
	//	}
//	allWidths=0; 		 reset variable
	
	//}
	
//}

function adjustFlyouts() {
	
	// IE7 nav functions

	var chckIE7=/MSIE 7/;
	var chkIE6=/MSIE 6/;
	var getBrwsr=navigator.userAgent;

	var navElmCount=$("ul.hd_mainmenu").children();
	
	/* adjust top*/

	if ((chckIE7.test(getBrwsr) == true) || (chkIE6.test(getBrwsr) == true)) {
		$("ul.hd_mainmenu li ul").css("margin-top","20px");
	}
	
	navElmCount.each(function(cElmNo) {
		calcOffset=$(this).position().left;
		getNavElmSize=$(this).width();
		if ((calcOffset+214) >=980) {
			calcNavAdjust=(214-getNavElmSize);
			$("ul.hd_mainmenu li:nth-child("+(cElmNo+1)+") ul").css({"margin-left":-calcNavAdjust+"px","left":"17px"});	
		}
		
	});
}

// navigation jQuery functions

// jQuery navigation for IE6


$(document).ready(function() {	
	var chkIE6=/MSIE 6/;
	if (chkIE6.test(navigator.userAgent)==true) { 
	$("ul.hd_mainmenu li").hover(function () {
		// Format main cat tab - over state
		$(this).addClass("main_hover");
		//$("ul.inner", this).css("display","block");
		$("select").css("visibility","hidden");
		/*$(this).css({"padding":"4px 16px 5px 16px","background-color":"#b9b1a9","border":"solid #e2e1dd","border-width":"1px 1px 0px 1px"});
		$("a", this).css("color","#ffffff");
		$("ul.inner li a", this).css("color","#000000");*/
		$("ul.inner", this).fadeIn(10);	
	},function () { 
		// Format main cat tab - over state
		$(this).removeClass("main_hover");
		//$("ul.inner", this).css("display","none");
		$("ul.inner", this).fadeOut(10);
		//$(this).css({"padding":"5px 17px 5px 17px","background-color":"transparent","border":"none #e2e1dd","border-width":"0px"});
		//$("a", this).css("color","#777777");
		//$("a", this).css({"color":"#777777","font-weight":"normal","font-size":"12px","margin-left":"11px"});
		$("select").css("visibility","visible");
	});
	$("ul.inner li").hover(function () {
		$(this).css("background-color","#ececec");
	},function () {
		$(this).css("background-color","white");
	});
	}    
	adjustFlyouts();
	//var pageHeight=document.height;
	//document.getElementById('chko_blackout_div').height=document.height+"px";
	$('#chko_blackout_div').css("height",$(document).height());
	//$('#address').css("width",$(window).width());
	/*other browser specific adjustsments*/
	/*var chkIE8=/MSIE 8/;
	var chkChrome=/Chrome/;
	if (chkIE8.test(navigator.userAgent)==true) {
		document.getElementById('topSectionctl_Searchbar1_bGo').style.marginTop="-3px";	// id changed removed ctl00_ prefix
	}
	if (chkChrome.test(navigator.userAgent)==true) {
		document.getElementById('topSectionctl_Searchbar1_bGo').style.marginTop="-11px";	// id changed removed ctl00_ prefix
	}*/
	$('div.bedlister_text_container span.price_txt').each(function(index){
		var price_txt = $(this).text();
		price_txt = price_txt.replace('Standard /','');
		price_txt = price_txt.replace('/ Square','');
		price_txt = price_txt.replace('/ Rectangle','');
		price_txt = price_txt.replace('/ Large Square','');
		$(this).text(price_txt);
	});
});

// call adjustFlyouts on load

// function for cookie creation
function resetLookCookie() {
	var exDt=new Date();
	exDt.setDate(exDt.getDate()+10);
	document.cookie="look=1;expires="+exDt+";path=/";
}

// twc original badge funcions
function checkForBadge() {
	var tabId="tab1"; 
	var tabToCheck=document.getElementById(tabId);
	var tabImgs=tabToCheck.getElementsByTagName("img");
	for (i=0; i<=(tabImgs.length-1); i++) {
		if (tabImgs[i].src=="http://"+document.domain+"/SupplyImages/statics/product-badges/twc_original_description.png") {
			addBadge()	
			break;	
		}
	}
}
function addBadge() {
	var parent="entire_container";
	var siteBody="site_body";
	var getSiteBody=document.getElementById(siteBody);
	var getParent=document.getElementById(parent);
	
	var positionDiv=document.createElement("div");
	positionDiv.setAttribute("id","badge_container");
	getParent.insertBefore(positionDiv,getSiteBody);

	var badgeImg=document.createElement("img");
	badgeImg.setAttribute("src","/SupplyImages/statics/product-badges/twc_original_product.png");
	badgeImg.setAttribute("alt","White Company Original");
	badgeImg.setAttribute("class","twcoriginal");
	positionDiv.appendChild(badgeImg);
}
