// JavaScript Document

/* Custom onload handler */
var dolFunctions = new Array();	// array to hold customized affiliate functions and params for "DOM load" functions
var wolFunctions = new Array(); // array to hold customized affiliate functions and params for "window load" functions

// add custom load fucntions to correct array
function onloadFunctions(myFunction,flag) {
	if(flag == "d")
	{
		dolFunctions[wolFunctions.length] = myFunction;
	}
	else if(flag == "w")
	{
		wolFunctions[wolFunctions.length] = myFunction;
	}
}

$(function() { //Initialization function, runs when the DOM has loaded
	customInit(); // this will fire off any customized affiliate "load" functions
});

function insertContentDiv (elem) {
	$(elem).html("<div class='content'>" + $(elem).html() + "</div>");
};

function insertPageContainerDiv () {
	$("body").html("<div id='pageContainer'>" + $("body").html() + "</div>");
};

function equalHeight(colList) {
	$(colList).each(function() {$(this).height("auto");}); 
	var topHeight = 0;
	var staticTop = -1;
	$(colList).each(function() {
		if ($(this).height() >= topHeight) {
			topHeight = $(this).height();
		}
		if ($(this).position() == "static") {
			staticTop = findPos(document.getElementById($(this).id())).y;
		}	
	});
	topHeight = topHeight + "px";
	staticTop = staticTop + "px"
	$(colList).each(function() {
		$(this).height(topHeight);
		if (staticTop != -1) $(this).top(staticTop);
	});
};

function findPos(obj) { //returns the x & y coordinates of an element
	var curleft = obj.offsetLeft || 0;
	var curtop = obj.offsetTop || 0;
	while (obj = obj.offsetParent) {
		curleft += obj.offsetLeft
		curtop += obj.offsetTop
	}
	return {x:curleft,y:curtop};
}

function customInit() {
for(var i=0; i < dolFunctions.length; i++)
	{
		eval(dolFunctions[i]);
	}
}

window.onload=function(){
for(var i=0; i < wolFunctions.length; i++)
	{
		eval(wolFunctions[i]);
	}
}