


addLoadListener(setRollovers);


var whichPict = "";			// this is to grab the name of the pict for the if statements in the xmlHTTPresponse
var myImage = [];			// for preloading
timerID = null;
theSubNavPict = "";





function setRollovers()  {
	if (!document.getElementsByTagName)  {
		return;
	}
	
	var allLinks = document.getElementsByTagName('a');
	for (var i = 0; i < allLinks.length; i++) {
		var currLink = allLinks[i];
		if (currLink.className && (" " + currLink.className + " ").indexOf(" rollover ") != -1)  {
			if (currLink.hasChildNodes && currLink.childNodes.length == 1 && currLink.childNodes[0].nodeName.toLowerCase() == 'img') {
				currLink.onmouseover = doRollover;
				currLink.onmouseout = restoreImage;			
				
				// preload images:
				myImage[i] = new Image();
				myImage[i].src = currLink.childNodes[0].src.replace(/(\.[^.]+)$/, '_over$1');;
			}
		}
	}
}		// end setRollovers

function exposeSubNav(which) {
	//alert("which = " + which);	
	if (document.getElementById(which) != null) { 	// if this image really exists in the document:
		var currImage =	document.getElementById(which);
		currImage.src = currImage.src.replace(/(\.[^.]+)$/, '_over$1');
		theSubNavPict = which;			// set this to foil restoreImage functions on curr subNav image
	} else {
		theSubNavPict = "nadaZink"	
	}
}

function doRollover(e)  {
	var currTarget = findTarget(e);
	if (!currTarget) return;
	var currImage = currTarget.childNodes[0];
	
	if (currImage.src.indexOf("_over") == -1) {			// if it's already "over", don't roll it
		currImage.src = currImage.src.replace(/(\.[^.]+)$/, '_over$1');
	}
	
	
	// rollover the button exposes the sub-nav
	
	if (currImage.src.indexOf("btn_why") != -1) {
		getSubNav('Why');
	}
	if (currImage.src.indexOf("btn_products") != -1) {
		getSubNav('Products');
	}
	if (currImage.src.indexOf("btn_about") != -1) {
		getSubNav('About');
	}
	if (currImage.src.indexOf("btn_contact") != -1) {
		getSubNav('Contact');
	}
	
	
	stopTimer();
}


function restoreImage(e) {
	var currTarget = findTarget(e);
	if (!currTarget) return;	
	var currImage = currTarget.childNodes[0];

	 if (currImage.src.indexOf(theSubNavPict) == -1)  {		// if you are not the current sub-nav image, then roll off
	 	//alert("theSubNavPict = " + theSubNavPict + ". indexOf = " + currImage.src.indexOf(theSubNavPict));
		currImage.src = currImage.src.replace(/_over(\.[^.]+)$/, '$1');	
	 }
	
	// NO START HIDE ON SUB-NAV BUTTONS
	
	if (currImage.src.indexOf('sub_btn_') == -1) {		// NOT a sub button, apply start hide... must be a main nav button
		startHide();
	}

}



function findTarget(e) {
  var t; 

  if (window.event && window.event.srcElement) t = window.event.srcElement;
  else if (e && e.target) t = e.target;
  if (!t) return null;
  
  while (t != document.body && t.nodeName.toLowerCase() != 'a') t = t.parentNode;
  if (t.nodeName.toLowerCase() != 'a') return null;
  return t;
}


//

//----- dbro -----

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1; 
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
return "";
}

function getSeal()
{
  var hdcookie;
  hdcookie = getCookie('hdcvd');
  
  var output;
  
  if (hdcookie=='y')
  {
    output = '<td rowspan="3"><a href="http://www.homedepot.com"><img src="../images/global/hdseal.jpg" width="194" height="99" border="0" /></a></td>';
  }
  else
  {
    output = '<td rowspan="3"><a href="../products/warranty.html" class="rollover"><img src="../images/global/seal.jpg" width="194" height="99" border="0" /></a></td>'; 
  }
return output;
}

function getWhereToBuy()
{
  var hdcookie;
  hdcookie = getCookie('hdcvd');
  
  var output;
  
  if (hdcookie=='y')
  {
    output = '';
  }
  else
  {
    output = ' <a href="../contact/where.html">where to buy</a> |'; 
  }
return output;
}

//---------------


function getSubNavString() {
	
	// why sub nav table:
	subNavString = '<div id="sub_nav_why" style="display:none; height:16px;" onMouseOut="startHide();" onMouseOver="stopTimer();">'		
	subNavString += '<table width="454" border="0" cellspacing="0" cellpadding="0">'
	subNavString +=	'<tr>'
	subNavString +=	'<td><a href="../why/technology.html" class="rollover"><img id="technology" src="../images/global/sub_btn_technology.gif" alt="technology" width="113" height="16" border="0" /></a></td>'
	subNavString +=	'<td><a href="../why/features.html" class="rollover"><img id="features" src="../images/global/sub_btn_features.gif" alt="features" width="123" height="16" border="0" /></a></td>'	
	subNavString +=	'<td><a href="../why/faq.html" class="rollover"><img id="faq" src="../images/global/sub_btn_faqs.gif" alt="faq" width="112" height="16" border="0" /></a></td>'
	/*
	subNavString +=	'<td><a href="../why/specs.html" class="rollover"><img id="specifications" src="../images/global/sub_btn_specifications.gif" alt="specifications" width="112" height="16" border="0" /></a></td>'	
	*/
	
	// remove this next line if ever restoring the specifications button above:
	//subNavString +=	'<td><img src="../images/global/s_brown.gif" alt=" " width="112" height="16" /></td>'
	subNavString +=	'<td><img src="../images/global/s_brown.gif" alt=" " width="106" height="16" /></td>'
	subNavString +=	'</tr>'
	subNavString +=	'</table>'
	subNavString +=	'</div>'
	
		// products sub nav table:
	subNavString += '<div id="sub_nav_products" style="display:none; height:16px;" onMouseOut="startHide();" onMouseOver="stopTimer();">'		
	subNavString += '<table width="454" border="0" cellspacing="0" cellpadding="0">'
	subNavString +=	'<tr>'
	subNavString +=	'<td><a href="../products/doors.html" class="rollover"><img id="doors" src="../images/global/sub_btn_doors.gif" alt="doors" width="57" height="16" border="0" /></a></td>'
	subNavString +=	'<td><a href="../products/windows.html" class="rollover"><img id="windows" src="../images/global/sub_btn_windows.gif" alt="windows" width="74" height="16" border="0" /></a></td>'	
	subNavString +=	'<td><a href="../products/power.html" class="rollover"><img id="power" src="../images/global/sub_btn_power.gif" alt="power screens" width="102" height="16" border="0" /></a></td>'	
	subNavString +=	'<td><a href="../products/gallery.html" class="rollover"><img id="gallery" src="../images/global/sub_btn_gallery.gif" alt="gallery" width="63" height="16" border="0" /></a></td>'
	subNavString +=	'<td><a href="../products/warranty.html" class="rollover"><img id="warranty" src="../images/global/sub_btn_warranty.gif" alt="warranty" width="74" height="16" border="0" /></a></td>'	
	subNavString +=	'<td><a href="../products/maintenance.html" class="rollover"><img id="maintenance" src="../images/global/sub_btn_maintenance.gif" alt="maintenance" width="84" height="16" border="0" /></a></td>'
	subNavString +=	'</tr>'
	subNavString +=	'</table>'
	subNavString +=	'</div>'
	
			// about sub nav table:
	subNavString += '<div id="sub_nav_about" style="display:none; height:16px;" onMouseOut="startHide();" onMouseOver="stopTimer();">'		
	subNavString += '<table width="454" border="0" cellspacing="0" cellpadding="0">'
	subNavString +=	'<tr>'
	subNavString +=	'<td><img src="../images/global/s_brown.gif" alt=" " width="186" height="1" /></td>'
	subNavString +=	'<td><a href="../about/events.html" class="rollover"><img id="events" src="../images/global/sub_btn_events.gif" alt="events" width="76" height="16" border="0" /></a></td>'		
	subNavString +=	'<td><a href="../about/news.html" class="rollover"><img id="news" src="../images/global/sub_btn_news.gif" alt="news" width="59" height="16" border="0" /></a></td>'
	subNavString +=	'<td><a href="../about/careers.html" class="rollover"><img id="careers" src="../images/global/sub_btn_careers.gif" alt="careers" width="69" height="16" border="0" /></a></td>'
	subNavString +=	'<td><img src="../images/global/s_brown.gif" alt=" " width="64" height="1" /></td>'
	subNavString +=	'</tr>'
	subNavString +=	'</table>'
	subNavString +=	'</div>'
	
			// contact sub nav table:
	subNavString += '<div id="sub_nav_contact" style="display:none; height:16px;" onMouseOut="startHide();" onMouseOver="stopTimer();">'		
	subNavString += '<table width="454" border="0" cellspacing="0" cellpadding="0">'
	subNavString +=	'<tr>'	
	subNavString +=	'<td><img src="../images/global/s_brown.gif" alt=" " width="175" height="1" /></td>'
	
	
	//----- dbro -----	
	var hdcookie;
  hdcookie = getCookie('hdcvd');
	
	if (hdcookie=='y')
  {    
	  subNavString +=	'<td><a href="../contact/HDmap.html" class="rollover"><img id="map" src="../images/global/sub_btn_hdmap.gif" alt="" width="83" height="16" border="0" /></a></td>'
  }
  else 
  {
    subNavString +=	'<td><a href="../contact/dealer.html" class="rollover"><img id="dealer" src="../images/global/sub_btn_dealer.gif" alt="become a dealer" width="113" height="16" border="0" /></a></td>'
	  subNavString +=	'<td><a href="../contact/USAmap.html" class="rollover"><img id="map" src="../images/global/sub_btn_map.gif" alt="dealer map" width="83" height="16" border="0" /></a></td>'
	}
	//----------------
	
		
	<!--subNavString +=	'<td><a href="../Contact/where.html" class="rollover"><img id="where" src="../Images/Global/sub_btn_where.gif" alt="where to buy" width="83" height="16" border="0" /></a></td>'-->
	subNavString +=	'<td><img src="../images/global/s_brown.gif" alt=" " width="83" height="1" /></td>'
	subNavString +=	'</tr>'
	subNavString +=	'</table>'
	subNavString +=	'</div>'	
	
	return subNavString;
	
}

// this function is needed externally because it is called directly by the page
function getSubNav(which) {
	
		hideAllDivs();
		
	switch(which) {
		case 'Home':
			// nothing
			break;		
		case 'Why':
			// show the appropriate div:
			document.getElementById("sub_nav_why").style.display = "inline";
			break;
		case 'Products':
			document.getElementById("sub_nav_products").style.display = "inline";
			break;
		case 'About':
			document.getElementById("sub_nav_about").style.display = "inline";
			break;			
		case 'Contact':
			document.getElementById("sub_nav_contact").style.display = "inline";
			break;	
		default:
			return "sorry, no luck";
		
	}
}


function hideAllDivs() {
	// turn them all off:
	document.getElementById("sub_nav_why").style.display = "none";
	document.getElementById("sub_nav_products").style.display = "none";
	document.getElementById("sub_nav_about").style.display = "none";
	document.getElementById("sub_nav_contact").style.display = "none";
}

function startHide() {
	timerID = setTimeout("finishHide()", 1200);	
}

function finishHide() {
	hideAllDivs();	
	
	// re-show the sub nav that belongs on this page:
	if (document.location.href.indexOf("/why/") != -1) {
		getSubNav('Why');
	}
	if (document.location.href.indexOf("/products/") != -1) {
		getSubNav('Products');
	}
	if (document.location.href.indexOf("/about/") != -1) {
		getSubNav('About');
	}
	if (document.location.href.indexOf("/contact/") != -1) {
		getSubNav('Contact');
	}	

	

	clearTimeout(timerID);
	timerID = null;
}

function stopTimer() {      // if you rolled back onto a button or a layer
	clearTimeout(timerID);
	timerID = null;
}


function addLoadListener(fn) {
  if (typeof window.addEventListener != 'undefined') {
    window.addEventListener('load', fn, false);
  } else if (typeof document.addEventListener != 'undefined') {
    document.addEventListener('load', fn, false);
  } else if (typeof window.attachEvent != 'undefined') {
    window.attachEvent('onload', fn);
  } else {
    var oldfn = window.onload;
    if (typeof window.onload != 'function') {
      window.onload = fn;
    } else {
      window.onload = function() {
        oldfn();
        fn();
      };
    }
  }
}

