// JavaScript Document
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function open_win(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
// Function to Clear intial value in a form field
function clearText(thefield){
if (thefield.defaultValue==thefield.value)
thefield.value = ""
}
function close_window() {
    window.close();
}
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
// Begin Drop Menus
var mmOpenContainer = null;
var mmOpenMenus = null;
var mmHideMenuTimer = null;

function MM_menuStartTimeout(hideTimeout) {
	mmHideMenuTimer = setTimeout("MM_menuHideMenus()", hideTimeout);	
}

function MM_menuResetTimeout() {
	if (mmHideMenuTimer) clearTimeout(mmHideMenuTimer);
	mmHideMenuTimer = null;
}

function MM_menuHideMenus() {
	MM_menuResetTimeout();
	if(mmOpenContainer) {
		var c = document.getElementById(mmOpenContainer);
		c.style.visibility = "inherit";
		mmOpenContainer = null;
	}
	if( mmOpenMenus ) {
		for(var i in mmOpenMenus) {
			var m = document.getElementById(mmOpenMenus[i]);
			m.style.visibility = "hidden";			
		}
		mmOpenMenus = null;
	}
}

function MM_menuHideSubmenus(menuName) {

	if( mmOpenMenus ) {
		var h = false;
		var c = 0;
		for(var i in mmOpenMenus) {			
			if( h ) {
				var m = document.getElementById(mmOpenMenus[i]);
				m.style.visibility = "hidden";
			} else if( mmOpenMenus[i] == menuName ) {
				h = true;
			} else {
				c++;
			}
		}
		mmOpenMenus.length = c+1;
	}
}

function MM_menuOverMenuItem(menuName, subMenuSuffix) {
	MM_menuResetTimeout();
	MM_menuHideSubmenus(menuName);
	if( subMenuSuffix ) {
		var subMenuName = "" + menuName + "_" + subMenuSuffix;
		MM_menuShowSubMenu(subMenuName);
	}
}

function MM_menuShowSubMenu(subMenuName) {
	MM_menuResetTimeout();
	var e = document.getElementById(subMenuName);
	e.style.visibility = "inherit";
	if( !mmOpenMenus ) {
		mmOpenMenus = new Array;
	}
	mmOpenMenus[mmOpenMenus.length] = "" + subMenuName;
}

function MM_menuShowMenu(containName, menuName, xOffset, yOffset, triggerName) {
	MM_menuHideMenus();
	MM_menuResetTimeout();
	MM_menuShowMenuContainer(containName, xOffset, yOffset, triggerName);
	MM_menuShowSubMenu(menuName);
}

function MM_menuShowMenuContainer(containName, x, y, triggerName) {	
	var c = document.getElementById(containName);
	var s = c.style;
	s.visibility = "inherit";
	
	mmOpenContainer = "" + containName;
}
// End Drop Menus

// Copyright year snippet
function setCopyright(element)
{
theSpan = document.getElementById(element);
var date = parseInt(theSpan.innerHTML);
var year = new Date().getFullYear();
if(year > date)
theSpan.innerHTML = year;
else
theSpan.innerHTML = date;
}

// Homepage ad rotator
var adImages = ['moon','snowmen','greek-temple','doghouse'];
var adAlts = ["3 Day Shipping to Most Locations - CoolR\256 Energy Efficient Roofing Metal Only From Sheffield Metals","Put it Where the Sun Does Shine - CoolR\256 Energy Efficient Roofing Metal Only From Sheffield Metals","Protection That Lasts - CoolR\256 Guard Weather Tightness Warranty Only From Sheffield Metals","Custom Cuts and Small Orders Welcomed - CoolR\256 Energy Efficient Roofing Metal Only From Sheffield Metals"];
var adTexts = ["That's no pie-in-the-sky promise. Sheffield Metals can ship every order out within three days because of our huge inventory - including 40 in-stock colors. Call today and our sales/support staff will go to the ends of the earth to slit and prep your order before it leaves the floor.","Sheffield Metals' knowledgeable sales/support staff can help reduce a building's energy costs and keep your customers from having a meltdown. Every order ships in three days or less and we maintain a huge inventory that includes 40 in-stock colors. Call today for the coolest product under the sun.","Sheffield Metals' COOLR\256 Guard weather tightness warranty assures you a quality roof system that stands the test of time. Our Approved installers are trained and certified, and their installation is inspected by an independent third-party. For quality and peace-of-mind, insist on a COOLR\256 Guard Weather Tightness Warranty.","We're your best friend when it comes to custom jobs and small orders. That's because we'll manage the scraps and ship your Small order in three days or less. Call today and let our responsive sales and support staff help you bring your job in on time and under budget - which should keep you out of the doghouse."];
var index = 0;
function randomAdInit() {
	var mainDiv = document.getElementById('main-ad');
	var adImg = document.createElement('img');
	var adHeadline = document.createElement('img');
	var adText = document.createElement('p');
	var theIndex = Math.floor(Math.random()*adImages.length);
	var index = theIndex;
	var theSrc = '/images/home-rotator/'+adImages[theIndex]+'.jpg';
	adImg.src = theSrc;
	adImg.alt = adAlts[theIndex];
	adImg.width = '518';
	adImg.height = '405';
	adImg.id = 'adImg';
	adHeadline.src = '/images/home-rotator/'+adImages[theIndex]+'-headline.gif';
	adHeadline.alt = adAlts[theIndex];
	adHeadline.width = '518';
	adHeadline.height = '60';
	adHeadline.id = 'adHeadline';
	var adTextNode = document.createTextNode(adTexts[theIndex]);
	adText.appendChild(adTextNode);
	adText.id = 'adText';
	mainDiv.appendChild(adImg);
	mainDiv.appendChild(adHeadline);
	mainDiv.appendChild(adText);
	setTimeout('randomAdChange()',20000);
}
function randomAdChange() {
	var adImg = document.getElementById('adImg');
	var adHeadline = document.getElementById('adHeadline');
	var adText = document.getElementById('adText');
	if (index<(adImages.length-1)) {
		index++;
	} else { index = 0; }
	adImg.src = '/images/home-rotator/'+adImages[index]+'.jpg';
	adImg.alt = adAlts[index];
	adHeadline.src = '/images/home-rotator/'+adImages[index]+'-headline.gif';
	adHeadline.alt = adAlts[index];
	adText.firstChild.nodeValue = adTexts[index];
	setTimeout('randomAdChange()',20000);
}
// Homepage CTA text display
var contractor = ['Your order is ready for roll forming or fabricating when it reaches your site.','We do the slitting, cut-to-length preparation, re-rolling, and the application of strippable PVC.','40 colors in stock'];
var architect = ['Improve thermal comfort reduce environmental impacts and save construction costs with COOLR\256.','40 colors in stock','COOLR\256 Guard warranty for a quality roof system that stands the test of time.','Gain LEED points'];
var owner = ['COOLR\256 Guard warranty for a quality roof system that stands the test of time.','Energy Star compliant roofing product benefits the environment and your budget.','40 colors in stock'];
function CTAInit() {
	var contractorTxt = document.getElementById('contractorTxt');
	var architectTxt = document.getElementById('architectTxt');
	var ownerTxt = document.getElementById('ownerTxt');
	var contractorNode = document.createTextNode(contractor[Math.floor(Math.random()*contractor.length)]);
	var architectNode = document.createTextNode(architect[Math.floor(Math.random()*architect.length)]);
	var ownerNode = document.createTextNode(owner[Math.floor(Math.random()*owner.length)]);
	contractorTxt.appendChild(contractorNode);
	architectTxt.appendChild(architectNode);
	ownerTxt.appendChild(ownerNode);
}
