// JavaScript Document
var sCurrentSection = "";
var minPageHeight = 0;
//
function setNav(s) {
	rollNav(s, true);
	sCurrentSection = s;
}
//
function sizeMainRail() {
	minPageHeight = $("cnt").offsetHeight;
	equalHeights();
}
//
function retrieveComputedStyles(element, styleProperty)
{
		var computedStyle = null;

		if (typeof element.currentStyle != "undefined")
		{
			computedStyle = element.currentStyle;
		}
		else
		{
			computedStyle = document.defaultView.getComputedStyle(element, null);
		}
		return computedStyle[styleProperty];
}
//
function getWindowHeights() {
  var myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
   myHeight = document.body.clientHeight;
  }
  return myHeight;
}
//
function equalHeights() {
	var iHeight = getWindowHeights();
	var myLeftColumn = $("cnt");
	var myLeftHeight = myLeftColumn.offsetHeight;
	var myLeftBorderTopPixels = retrieveComputedStyles(myLeftColumn, "borderTopWidth");
	var myLeftBorderBottomPixels = retrieveComputedStyles(myLeftColumn, "borderBottomWidth");
	var myLeftPaddingTopPixels = retrieveComputedStyles(myLeftColumn, "paddingTop");
	var myLeftPaddingBottomPixels = retrieveComputedStyles(myLeftColumn, "paddingBottom");
	var myLeftBorderNumber = Number(myLeftBorderTopPixels.replace("px", "")) + Number(myLeftBorderBottomPixels.replace("px", ""));
	var myLeftPaddingNumber = Number(myLeftPaddingTopPixels.replace("px", "")) + Number(myLeftPaddingBottomPixels.replace("px", ""));
	var myLeftExtras = myLeftBorderNumber + myLeftPaddingNumber;
	if (iHeight > minPageHeight) {
			$("cnt").style.height = iHeight + "px";
	} else {
			$("cnt").style.height = minPageHeight + "px";
	}
}

//
function rollNav(s, bOver) {
	if (s != sCurrentSection) {
		var sOver = "";
		if (bOver) { sOver = "_f2"; }
		switch (s) {
			case "home":
				swapImg("btnHome", "/assets/img/common/btn-home" + sOver + ".gif");
				swapImg("btnSubHome", "/assets/img/common/btn-sub-home" + sOver + ".gif");
				break;
			case "products":
				swapImg("btnProducts", "/assets/img/common/btn-product" + sOver + ".gif");
				break;
			case "locate":
				swapImg("btnLocate", "/assets/img/common/btn-buy" + sOver + ".gif");
				break;
			case "uses":
				swapImg("btnSubUses", "/assets/img/common/btn-sub-uses" + sOver + ".gif");
				break;
			case "about":
				swapImg("btnSubAbout", "/assets/img/common/btn-sub-about" + sOver + ".gif");
				break;
			case "msds":
				swapImg("btnSubMSDS", "/assets/img/common/btn-sub-MSDS" + sOver + ".gif");
				break;
			case "press":
				swapImg("btnSubPress", "/assets/img/common/btn-sub-press" + sOver + ".gif");
				break;
			case "contact":
				swapImg("btnSubContact", "/assets/img/common/btn-sub-contact" + sOver + ".gif");
				break;
			case "privacy":
				swapImg("btnSubPrivacy", "/assets/img/common/btn-sub-privacy" + sOver + ".gif");
				break;				
		}
	}
}
//
function swapImg(s, path) {
	try {
		$(s).src = path;
	} catch(e) {
		//	
	}
}
//
function showResultsPnl() {
	try { $("cntResultsEngine").style.zIndex = 500; } catch(e) {}
	fade(false);
}
//
function hideResultsPnl() {
	try { $("cntResultsEngine").style.zIndex = 1; } catch(e) {}
	fade(true);
}
//
function doSearch(sType, sSearch) {
	// Called from inside swf via ExternalInterface
	showResultsPnl();
	// capture search
	var sUrl;
	sType = sType.toLowerCase()
	if (sType == "structured") {
		sUrl = "/data/put-re-search-phrase.asp";
	} else if (sType == "freeform") {
		sUrl = "/data/put-re-search-freeform.asp";
	} else {
		sType = "";
	}
	if (sType != "") {
		var data="search="+encodeURIComponent(unescape(sSearch));
		data+="&r="+Math.random();
		var myAjax = new Ajax.Request(sUrl,{asynchronous:true, method:'post', parameters:data, onSuccess:doSearchSC});
	}
}
//
function doSearchSC(r) {
	//alert(r.responseText);
}
//
function highlightFooter(s) {
	switch (s) {
		case "Facebook":
			swapImg("btnFacebook", "/assets/img/common/btn-facebook_f2.gif");
			swapImg("picFollowTitle", "/assets/img/common/pic-footer-facebook.gif");
			break;
		case "Twitter":
			swapImg("btnTwitter", "/assets/img/common/btn-twitter_f2.gif");
			swapImg("picFollowTitle", "/assets/img/common/pic-footer-twitter.gif");
			break;
		case "Youtube":
			swapImg("btnYouTube", "/assets/img/common/btn-youtube_f2.gif");
			swapImg("picFollowTitle", "/assets/img/common/pic-footer-youtube.gif");
			break;
	}
}
//
function unhighlightFooter(s) {
	switch (s) {
		case "Facebook":
			swapImg("btnFacebook", "/assets/img/common/btn-facebook.gif");
			break;
		case "Twitter":
			swapImg("btnTwitter", "/assets/img/common/btn-twitter.gif");
			break;
		case "Youtube":
			swapImg("btnYouTube", "/assets/img/common/btn-youtube.gif");
			break;
	}
	swapImg("picFollowTitle", "/assets/img/common/pic-footer-follow.gif");
}
//
function showVideo(strEmbed, iWidth, iHeight) {
	Shadowbox.open({
        content:    '<object width="' + iWidth + '" height="' +  iHeight + '"><param name="movie" value="http://www.youtube.com/v/' + strEmbed + '&hl=en&fs=1&rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/' + strEmbed + '&hl=en&fs=1&rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="' + iWidth + '" height="' + iHeight + '"></embed></object>',
        player:     "html",
        height:     iHeight,
        width:      iWidth
    });
}
//
function showDisclaimer() {
	Shadowbox.open({
			player: "iframe",
			content: "/data/disclaimer.asp",
			width: 675,
			height: 500
		});
}