//////////////
//MM Scripts//
//////////////
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  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=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//////////////////
//End MM Scripts//
//////////////////

///////////////////
////Popup Class////
///////////////////

Popup.static = new Object();
Popup.static.popups = new Array();
Popup.static.topZ = 1000;
Popup.static.baseZ = 900;

//node = HTML element's id attribute as string | reference to html node | null
//parent = popup's parent popup | null
//hides = true | false, can this popup close (be hidden)
function Popup(node, parent, hides) //ctor
{
	if(typeof node == 'string')
	{node = document.getElementById(node);}
	
	this.ndPopup = node;
	this.parent = parent;
	this.hides = hides;

	this.visible = !hides;
	this.children = new Array();
	this.timeoutHide = null;

	this.idNumber = Popup.static.popups.length;
	Popup.static.popups[this.idNumber] = this;

	if(parent != null)
		parent.children[parent.children.length] = this;

	if(node == null)
	{
		this.onMouseOverOriginal = null;
		this.onMouseOutOriginal = null;
	}
	else
	{
		
		if(typeof this.ndPopup.onmouseover == "function")
			this.onMouseOverOriginal = this.ndPopup.onmouseover;

		this.ndPopup.onmouseover = new Function("Popup.static.popups[" + this.idNumber + "].onMouseOver();");

		if(typeof this.ndPopup.onmouseout == "function")
			this.onMouseOutOriginal = this.ndPopup.onmouseout;

		this.ndPopup.onmouseout = new Function("Popup.static.popups[" + this.idNumber + "].onMouseOut();");
	}
}



//makes associated node visible; doesn't open next level of children
function Popup_show()
{
	if(this.timeoutClose != null)
	{
		clearTimeout(this.timeoutClose);
		this.timeoutClose = null;
	}

	if(this.hides == true && this.ndPopup != null)
	{
		//jQuery(this.ndPopup).fadeIn(200);
		this.ndPopup.style.visibility = "visible";
		this.ndPopup.style.zIndex = Popup.static.topZ;
		this.visible = true;
	}
}
Popup.prototype.show = Popup_show;



//shows associated node and opens next level of children
function Popup_activate()
{
	//if we have siblings, hide siblings
	if(this.parent != null)
	{
		for(var i in this.parent.children)
		{
			if(this.parent.children[i] != this)
				this.parent.children[i].hide();
		}
	}

	this.show();
	this.keepAlive();

	//show children
	if(this.children != null)
	{
		for(var i in this.children)
		{
			this.children[i].show();
		}
	}
}
Popup.prototype.activate = Popup_activate;



//ensures this popup doesn't close
function Popup_keepAlive()
{
	if(this.timeoutHide != null)
	{
		clearTimeout(this.timeoutHide);
		this.timeoutHide = null;
	}

	if(this.ndPopup != null)
	{this.ndPopup.style.zIndex = Popup.static.topZ;}

	if(this.parent != null)
		this.parent.keepAlive();
}
Popup.prototype.keepAlive = Popup_keepAlive;



//makes element and children invisible if appropriate
function Popup_hide()
{
	if(this.visible == false){return;}
	
	if(this.timeoutHide != null)
	{
		clearTimeout(this.timeoutHide);
		this.timeoutHide = null;
	}

	for(var i in this.children)
	{this.children[i].hide();}

	if(this.hides == true && this.ndPopup != null)
	{
		//jQuery(this.ndPopup).fadeOut(150);
		//jQuery(this.ndPopup).slideUp(150);
		this.ndPopup.style.visibility = 'hidden';
		this.visible = false;
	}

}
Popup.prototype.hide = Popup_hide;



//sets node to hide after an interval of time
function Popup_deactivate()
{	
	if(this.timeoutHide != null)
	{clearTimeout(this.timeoutHide);}

	this.timeoutHide = setTimeout("Popup.static.popups[" + this.idNumber + "].hide();", 600);
	
	if(this.ndPopup != null)
	{this.ndPopup.style.zIndex = Popup.static.baseZ;}
	
	for(var i=0; i < this.children.length; ++i)
	{
		if(this.children[i].ndPopup != null)
		{this.children[i].ndPopup.style.zIndex = Popup.static.baseZ;}
	}
}
Popup.prototype.deactivate = Popup_deactivate;



function Popup_onMouseOver()
{
	if(this.onMouseOverOriginal != null)
		this.onMouseOverOriginal();

	this.activate();
}
Popup.prototype.onMouseOver = Popup_onMouseOver;



function Popup_onMouseOut()
{
	if(this.onMouseOutOriginal != null)
		this.onMouseOutOriginal();

	this.deactivate();
}
Popup.prototype.onMouseOut = Popup_onMouseOut;

///////////////////
//End Popup Class//
///////////////////

//////////////////
//RollOver Class//
//////////////////

RollOver.prototype.rollOvers = new Array();

//ctor
function RollOver(imgNode, overUrl)
{
	if(typeof imgNode == 'string')
	{imgNode = document.getElementById(imgNode);}
	
	this.imgNode = imgNode;
	this.outUrl = imgNode.src;
	this.overUrl = overUrl;
	this.imageObj = new Image;
	this.imageObj.src = this.overUrl;

	this.idNum = RollOver.prototype.rollOvers.length;
	RollOver.prototype.rollOvers[this.idNum] = this;

	//set event handlers on img element
	this.imgNode.onmouseover = new Function("RollOver.prototype.rollOvers[" + this.idNum + "].over();");
	this.imgNode.onmouseout = new Function("RollOver.prototype.rollOvers[" + this.idNum + "].out();");
}


function RollOver_over()
{
	this.imgNode.src = this.overUrl;
}
RollOver.prototype.over = RollOver_over;


function RollOver_out()
{
	this.imgNode.src = this.outUrl;
}
RollOver.prototype.out = RollOver_out;

//////////////////////
//END RollOver Class//
//////////////////////

/////////////////////////
//BEGIN Rollover Script//
/////////////////////////

function addRollover(outFileName, overFileName)
{
	if(window.rolloverFileNames == undefined)
	{window.rolloverFileNames = new Array();}
	
	rolloverFileNames.push({"out":outFileName, "over":overFileName});
}

var rollovers = new Array();//holds rollover objects

function makeRollovers(rolloverFileNames)
{

	var rolloverFileNamesByOutFileName = new Object();
	var rolloverFileNamesByOverFileName = new Object();
	
	for(var i=0; i < rolloverFileNames.length; ++i)
	{
		rolloverFileNamesByOutFileName[rolloverFileNames[i].out] = rolloverFileNames[i];
		rolloverFileNamesByOverFileName[rolloverFileNames[i].over] = rolloverFileNames[i];
	}

	for(var i=0; i < document.images.length; ++i)
	{
		var imgSrc = document.images[i].src;
		var slashIndex = imgSrc.lastIndexOf("/");
		
		if(slashIndex >= 0)
		{
			var path = imgSrc.slice(0, slashIndex);
			var filename = imgSrc.slice(slashIndex+1,imgSrc.length);
			
			if(rolloverFileNamesByOutFileName[filename] != undefined)
			{
				var ro = rolloverFileNamesByOutFileName[filename];
				rollovers.push(new RollOver(document.images[i], path+"/"+ro.over));
			}
			else if(rolloverFileNamesByOverFileName[filename] != undefined)
			{
				var ro = rolloverFileNamesByOverFileName[filename];
				rollovers.push(new RollOver(document.images[i], path+"/"+ro.out));
			}

		}
	}
}

///////////////////////
//END Rollover Script//
///////////////////////

