// --- Harvey Mackay --- www.harveymackay.com --
// --- Common JS functions --------------------
// --- Created by ideapark -- May 2007! ------
// Functions in this file are meant to run (or at least be accessible) on every page of the site


// addLoadEvent() is a method of running multiple functions at window.onload
// To avoid onload conflicts, run all such functions using this method

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

// Call site-wide window.onload functions here

addLoadEvent(startList);




function startList() {
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("topNav");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" over";
				}
				node.onmouseout=function() {
					this.className=this.className.replace(/ ?over/, "");
				}
			}
		}
	}
}



/* randomProduct modifies the href of an anchor and the src of its first nested image with a random item from a speficied list */

function randomProduct(source,targetAnchor,hrefPath,imgPath) {
	
	if (source.indexOf('URL:') != 0) {
		var contents = source;
	}
	
	var targetAnchor = document.getElementById(targetAnchor);
	
	var products = new Array();
	products = contents.split('\n');
	
	var rnumb = Math.floor(Math.random()*products.length);
	
	targetAnchor.href = hrefPath + products[rnumb].replace(/(.+?),.+/,'$1');
	targetAnchor.getElementsByTagName('img')[0].src = imgPath + products[rnumb].replace(/.+?,(.+)/,'$1');
	
}


