﻿$(document).ready(function() {
	/* Implement sIFR replacable type */
	if (typeof sIFR == "function") {
		sIFR.replaceElement("h1", named({sFlashSrc: "/include/Helvetica.swf", sColor: "#4b4b4b", sWmode: "transparent"}));
		sIFR.replaceElement("h2", named({sFlashSrc: "/include/Helvetica.swf", sColor: "#4b4b4b", sWmode: "transparent"}));
		sIFR.replaceElement("h5", named({sFlashSrc: "/include/Helvetica.swf", sColor: "#ffffff", sWmode: "transparent"}));
		sIFR.replaceElement("h6", named({sFlashSrc: "/include/Helvetica.swf", sColor: "#ffffff", sWmode: "transparent"}));
	};
	var tables = document.getElementsByTagName("table");
	for (var i=0;i<tables.length; i++)
		if (tables[i].className == "expanding")
			frameWire(tables[i]);
});

/* Browser sensing */
var isNew = 0;
var isNS4 = 0;
var isIE4 = 0;
var brow = ((navigator.appName) + (parseInt(navigator.appVersion)));
if (parseInt(navigator.appVersion) >= 5) {
	isNew = 1
} else if (brow == "Netscape4") {
	isNS4 = 1;
} else if (brow == "Microsoft Internet Explorer4") {
	isIE4 = 1;
}
/* cross-browser DOM */
if (isNS4) {
	docObj = 'document.layers' + '[';
	styleObj = ']';
} else if (isIE4) {
	docObj = 'document.all' + '[';
	styleObj = ']' + '.style';
	closeVar = ']';
} else if (isNew) {
	docObj = 'document.getElementById' + '(';
	styleObj = ')' + '.style';
	closeVar = ')';
}
function chgColor(divID,theClass) {
	dom = eval(docObj + 'divID' + closeVar);
	dom.className = theClass;
}	

// Netscap window resize bug, this script corrects the bug in netscape that makers the Layers crash
if(document.layers){origWidth=innerWidth;origHeight=innerHeight;onresize=function(){
if(innerWidth!=origWidth||innerHeight!=origHeight)location.reload()}}

//Swap Image, this script is for the swap image restore function for the left hand Navs.
function findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document); return x;
}

/* Functions that swaps images. */
function swapImage() { //v3.0
  var i,j=0,x,a=swapImage.arguments; document.sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=findObj(a[i]))!=null){document.sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function swapImgRestore() { //v3.0
  var i,x,a=document.sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

/* Functions that handle preload. */
function preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.p) d.p=new Array();
   var i,j=d.p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.p[j]=new Image; d.p[j++].src=a[i];}}
}

/* Add expanding frames */
function frameWire(frame)
{
	if (frame.rows.length>1)
	{
		// Add expander
		var expander = document.createElement("img");
		frame.rows[0].cells[0].insertBefore(expander, frame.rows[0].cells[0].childNodes[0]);
		expander.parentFrame = frame;
		expander.width = 9;
		expander.height = 9;
		expander.style.cursor="pointer";
		expander.style.position = "absolute";
		expander.style.marginLeft = "-15px";
		expander.style.marginTop = "2px";
		expander.onclick = function(element) { frameExpand(this.parentFrame); };
		
		// Setup frame
		frame.state = true;
		frame.expander = expander;
		frameExpand(frame);
	}
	else
		frame.className = "";
}
function frameExpand(frame)
{
	frame.state = !frame.state;
	for (var i=1; i<frame.rows.length; i++)
		frame.rows[i].style.display = (frame.state)?"":"none";
	frame.expander.src = (frame.state)?"/images/icon_minus.gif":"/images/icon_plus.gif";
}

// Imagescale Helper Class
function ImageScale(reference)
{
    var breakdown = reference.split(".");
    var size = breakdown[breakdown.length-2].split("x");

    this.width = size[0];
    this.height = size[1];
    this.src = reference;
    
    this.popup = function () {
	    var openWindow = window.open("", "", "resizable=no,menubar=no,scrollbars=no,status=no,titlebar=no,toolbar=no,height="+this.height+",width="+this.width+"", false);
	    openWindow.document.body.style.border = "0px";
	    openWindow.document.body.style.padding = "0px";
	    openWindow.document.body.style.margin = "0px";
	    openWindow.document.body.innerHTML = '<center><img src="' + ((this.src.indexOf("//")==-1)?document.location.protocol + "//" + document.location.host + "/":"") + this.src + '"/></center>';
    }
    
    this.apply = function (image, width, height){
        image.style.display = "none";
        image.src = this.src;
        image.width = this.width;
        image.height = this.height;
        if (width)
        {
            var px = Math.round((width - this.width)/2);
            image.style.marginLeft = px + "px";
            image.style.marginRight = (width - this.width - px) + "px";
        }
        if (height)
        {
            var px = Math.round((height - this.height)/2);
            image.style.marginTop = px + "px";
            image.style.marginBottom = (height - this.height - px) + "px";
        }
        image.style.display = "inline";
    }
}
