// pap.js
// Global javaScript routines for the Pet-a-Porter site.


// W3CDOM (level 1 DOM) indicator.
var W3CDOM = (document.createElement && document.getElementsByTagName);

// Add initMO to the Window.onload chain.
// window.onload = initMO;
AddOnLoad(window, InitMO);


// Image Mouseover Javascript.
function InitMO() {
	// This only works in "modern" level 1 DOMs...
	if (!W3CDOM) 
		return;

	// Only handle the IMG's in the 'main' div.
	var div = document.getElementById('main');
	var imgs = div.getElementsByTagName('img');

	// Check all the img's...
	for (var i=0; i<imgs.length; i++) {
		// Is there a mouseover image given for this IMG?
		// I "misuse" the name attribute for this.
		if (imgs[i].name != '') {
			imgs[i].mosrc = new Image();
			imgs[i].mosrc = imgs[i].name;
			imgs[i].onmouseover = SwitchSrc;
			imgs[i].onmouseout = SwitchSrc;
		}
	}
}

// SwitchSrc switches the two SRC's in an IMG element.
function SwitchSrc() {
	var tempsrc = this.src;
	this.src = this.mosrc;
	this.mosrc = tempsrc;
}

// OpenWin function
function OpenWin(FileName) {
  return(window.open(FileName,'_blank','scrollbars=yes,resizable=yes,status=no,menubar=no'));
}

// OpenWinXY function
function OpenWinXY(FileName,W,H) {
  return(window.open(FileName,'_blank','scrollbars=yes,resizable=yes,status=no,menubar=no,width='+W+',height='+H+',innerWidth='+W+',innerHeight='+H));
}

// AddOnLoad
// To add an init function to the onload chain.
// Target = window, etc.
function AddOnLoad (target, onload_fn) {
	if (target.addEventListener) // W3CDOM / DOM-2
		target.addEventListener("load", onload_fn, false)
	else 
		if (target.attachEvent) // MS IE5+/Win only
			target.attachEvent("onload", onload_fn)
		else 
			if (document.getElementById) { // We're down to Jurassic browsers here...
				var PrevOnLoad = target.onload; // DOM-0 ?
				if ((PrevOnLoad != NULL) && (typeof PrevOnLoad == 'function'))
					target.onload = function() { PrevOnLoad(); onload_fn; }
				else
					target.onload = onload_fn;
			}
}

