// loads links in new windows when designated by the rel="ext" attribute //
function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "ext")
       anchor.target = "_blank";
	}
}

// basic image swap script
function swap(el,which){
  el.src=el.getAttribute(which || "origsrc");
}

function swapSetup(){
  var x = document.getElementsByTagName("img");
  for (var i=0;i<x.length;i++){
    var oversrc = x[i].getAttribute("oversrc");
    if (!oversrc) continue;
    // preload image
    // comment the next two lines to disable image pre-loading
    x[i].oversrc_img = new Image();
    x[i].oversrc_img.src=oversrc;
    // set event handlers
    x[i].onmouseover = new Function("swap(this,'oversrc');");
    x[i].onmouseout = new Function("swap(this);");
    // save original src
    x[i].setAttribute("origsrc",x[i].src);
  }
}

window.onload = function() {	
	externalLinks();
	swapSetup();

}

function ShowImage(url) {
	var win = window.open(url, 'window_'+Math.floor(Math.random()*1001), 'width=250,height=250');
	win.document.write('<html><head><title>White\'s Outdoor</title></head>');
	win.document.write('<body style="margin: 0; padding: 0;" onclick="window.close()"><img id="doc_img" src="'+url+'" onload="window.opener.resizeWindow(window);" style="margin: 0; padding: 0;" /></body></html>');
	win.document.close();
}

window.resizeWindow = function(win) {
	var img = win.document.getElementById("doc_img");
	if (win.innerWidth) {
		var width = 8 + img.clientWidth;
		var height = 56 + img.clientHeight;
	} else {
		if (win.document.documentElement.clientWidth > 0) {
			var width = (250 - win.document.documentElement.clientWidth) + img.clientWidth;
			var height = (250 - win.document.documentElement.clientHeight) + img.clientHeight;
		} else {
			var width = 12 + img.clientWidth;
			var height = 36 + img.clientHeight;
		}
	}
	win.resizeTo(width, height);
	
	win.focus();
}
