// JavaScript Document
// this is version 1.1 of the initialization script. I has been updated to work with jquery 1.1   Last Update 2/15/07
var t="";

/* 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
	{
		wolFunctions[wolFunctions.length] = myFunction;
	}
}


$(function() { //Initialization function, runs when the DOM has loaded
	var columnsList = "#col1, #col2, #col3";
//	equalHeight(columnsList);
	setLeftRightWidth();
//	$("#footer").css({margin: "5px 0 0 0"});
	$(window).load(function() {
//		equalHeight(columnsList);
		setLeftRightWidth();
	});
	customInit(); // this will fire off any customized affiliate "load" functions
});

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).css("position") == "static") {
			staticTop = findPos(document.getElementById($(this).attr("id"))).y;
		}	
	});
	topHeight = topHeight + "px";
	staticTop = staticTop + "px"
	$(colList).each(function() {
		$(this).height(topHeight);
		if (staticTop != -1) $(this).css("top",staticTop);
	});
};

function equalHeightLR() {
	var topHeight = 0;
	var leftCol = "div.left_half";
	var rightCol = "div.right_half";
	$(leftCol).each(function(i) {
		$(this).height("auto");
		$(rightCol).eq(i).height("auto");
		topHeight = $(this).height();
		if ($(rightCol).eq(i).height() >= topHeight) {
			topHeight = $("div.right_half").eq(i).height();
		}
		topHeight = topHeight + "px";
		$(this).height(topHeight);
		$(rightCol).eq(i).height(topHeight);
	}); 
};

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 setLeftRightWidth() {
	if(window.leftRightWidth) {
		$("div.left_half").each(function(i){
			if(i < leftRightWidth.length){ // Check to see if a custom width has been defined for this DIV
				if(leftRightWidth[i][0]<=100) { // Only apply left width if it is less than or equal to 100
					$(this).width(leftRightWidth[i][0]+"%");
				}
			}
		})
		$("div.right_half").each(function(i){
			if(i < leftRightWidth.length){ // Check to see if a custom width has been defined for this DIV
				if(leftRightWidth[i][0]<=100) { // Only apply right width if the left width is less than or equal to 100
					if(leftRightWidth[i][0]+leftRightWidth[i][1]>=100) { // If sum of the left and right widths is greater than 100 adjust right width
						leftRightWidth[i][1]=99-leftRightWidth[i][0]; //using 99 here to avoid problems with border widths
					}
					$(this).width(leftRightWidth[i][1]+"%");
				}
			}
		})
		equalHeightLR();
	}
}

function customInit() {
	for(var i=0; i < dolFunctions.length; i++)
	{
		eval(dolFunctions[i]);
	}
}

function initLoad(){
	for(var i=0; i < wolFunctions.length; i++)
	{
		eval(wolFunctions[i]);
	}
}
addEvent(window,'load',initLoad);
