
// PRELOAD MAIN ROLLOVER IMAGES
var preloadFlag = false;
function preloadImages() {
	if (document.images && preloadFlag == false) {
		
		products_over = newImage("/common/images/headlink-products2.gif");
		//services_over = newImage("/common/images/headlink-services2.gif");
		mediakit_over = newImage("/common/images/headlink-mediakit2.gif");
		about_over = newImage("/common/images/headlink-about2.gif");
		contact_over = newImage("/common/headlink-contact2.gif");
		home_over = newImage("/common/images/logo2.gif");
		
		products_active = newImage("/common/images/headlink-products-a.gif");
		//services_active = newImage("/common/images/headlink-services-a.gif");
		mediakit_active = newImage("/common/images/headlink-mediakit-a.gif");
		about_active = newImage("/common/images/headlink-about-a.gif");
		contact_active = newImage("/common/headlink-contact-a.gif");
		
		products_white = newImage("/common/images/head-photo-over_01.gif");
		//services_white = newImage("/common/images/head-photo-over_02.gif");
		mediakit_white = newImage("/common/images/head-photo-over_02.gif");
		about_white = newImage("/common/images/head-photo-over_03.gif");
		contact_white = newImage("/common/images/head-photo-over_04.gif");
		
		preloadFlag = true;
	}
}

// NAVIGATION FUNCTIONALITY AND HIGHLIGHTING
var highlightMenuLinkOverride = null;

function getStripParamFromURL( url ) {

	if( url.substr( 0, url.lastIndexOf( "?" ) ) != '' )
		return url.substr( 0, url.lastIndexOf( "?" ) );
	else
		return url;
}

function setNav(){
	pageFolder="";
	if(document.URL.lastIndexOf( '/' ) != document.URL.length-1){
		pageFolder = window.location.href.match(/.*\/([^\/]*)\/.*\.aspx/)[1];	
	}
	if(pageFolder=="products"){
		products_nav.onmouseover="";
		products_nav.onmouseout="";
		products_nav.src="/common/images/headerlink-products-a.gif";
		products_white.src="/common/images/head-photo-over_01.jpg";
	}else if(pageFolder=="mediakit"){
		mediakit_nav.onmouseover="";
		mediakit_nav.onmouseout="";
		mediakit_nav.src="/common/images/headerlink-mediakit-a.gif";
		mediakit_white.src="/common/images/head-photo-over_02.jpg";
	}else if(pageFolder=="about" ){
		about_nav.onmouseover="";
		about_nav.onmouseout="";
		about_nav.src="/common/images/headerlink-aboutus-a.gif";
		about_white.src="/common/images/head-photo-over_03.jpg";
	}else if(pageFolder=="contact"){
		contact_nav.onmouseover="";
		contact_nav.onmouseout="";
		contact_nav.src="/common/images/headerlink-contactus-a.gif";
		contact_white.src="/common/images/head-photo-over_04.jpg";
	}
}

function getPathFromURL( url ) {

	return url.substr( 0, url.lastIndexOf( "/" )+1 );
}

function highlightMenuLink() {

	// make an alternate 'document.URL' that contains the default page name 'default.shtml'
	//  to make URL matching easier
	if( document.URL.lastIndexOf( '/' ) == document.URL.length-1 ) {
		var documentURL = document.URL.toLowerCase() + 'default.aspx';
	} else {
		var documentURL = document.URL.toLowerCase();
	}

	//
	// Pass #1: check for the override
	//
	if( highlightMenuLinkOverride != null ) {

		// loop through the links in the document
		for( var i=document.links.length-1; i >= 0; i-- ) {
			if( highlightMenuLinkOverride.toLowerCase() == document.links[i].href.toLowerCase() ) {
				document.links[i].className = 'mmhide_secondaryNav mmhide_secondaryNavOn';
				break;
			}
		}				
		return;
	}

	//
	// Pass #2: loop through the links in the document, looking for an EXACT match
	//
	
	// strip the parameters
	docUrl = getStripParamFromURL( documentURL ).toLowerCase();
	
	for( var i = 0; i < document.links.length; i++ ) {
		
		// is this a 'menuLink' class link?
		if( document.links[i].className == 'mmhide_secondaryNav' ) {
		
			// if the end of the href ends in a '#', skip it -- it's probably a test link that goes nowhere
			if( document.links[i].href.lastIndexOf( '#' ) == document.links[i].href.length-1 )
				continue;
		
			// append 'default.aspx' if the <a href=> ends in '/'
			if( document.links[i].href.lastIndexOf( '/' ) == document.links[i].href.length-1 ) {
				if( docUrl.toLowerCase() == document.links[i].href.toLowerCase() + 'default.aspx' ) {
					document.links[i].className = 'mmhide_secondaryNav mmhide_secondaryNavOn';
					return;			
				}
			// otherwise, just compare em'			
			} else {
				if( docUrl.toLowerCase() == document.links[i].href.toLowerCase() ) {
					document.links[i].className = 'mmhide_secondaryNav mmhide_secondaryNavOn';
					return;			
				}
			}
		}
	}
	
	//
	// Pass #3: if an exact match was not found, loop through and look for a directory match
	//
	
		// fetch the directory only
	docUrl = getPathFromURL( documentURL ).toLowerCase();

	for( var i=document.links.length-1; i >= 0; i-- ) {
		
		// if the end of the href ends in a '#', skip it -- it's probably a test link that goes nowhere
		if( document.links[i].href.lastIndexOf( '#' ) == document.links[i].href.length-1 )
				continue;
		
		// is this a 'menuLink' class link?
		if( document.links[i].className == 'mmhide_secondaryNav' ) {
						
			s = getPathFromURL( document.links[i].href ).toLowerCase();		// strip the file
		
			if( s == docUrl.substr( 0, s.length ) ) {						// a match?			
				document.links[i].className = 'mmhide_secondaryNav mmhide_secondaryNavOn';
				return;
			}
		}
	}
}

// RANDOM HOME PAGE IMG
function showRandomHomePageImg() {
	
	var rand1 = 0;
	var useRand = 0;
	var imgnum = 3;

	do {
		var randnum = Math.random();
		rand1 = Math.round(imgnum * randnum);
	} while (rand1 == useRand);

	image = new Image();
	image.src = "/home/images/leading-the-way" + rand1 + ".gif";
	document.homePageImg.src = image.src;
}