/* Note: We have decided against using the equal height functions for moving things around on the page because
the bouncing has not been well received by clients. We're stripping out the uneeded scripting and leaving the bare
essentials needed for a new site. -jd  */

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
        setLeftRightWidth();
        $(window).load(function() {
                setLeftRightWidth();
        });
        customInit(); // this will fire off any customized affiliate "load" functions
});


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 equalHeight() {}

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);
        });
};

/* This function is meant to be a replacement for setLeftRightWidth. The only difference is that it writes inline styles out instead of directly modifying the styles on the left right divs themselves. Updating your components to the latest on cm2 will use the appropriate method. */
function setWidthStyles(leftRightWidth) {
        document.write("<style type=\"text/css\">\n");
        for ( var i = leftRightWidth.length - 1; i >= 0; i--)
        {
                document.write("div.left_" + (i + 1) + " { width: " + leftRightWidth[i][0] + "%; }\n");
                document.write("div.right_" + (i + 1) + " { width: " + leftRightWidth[i][1] + "%; }\n");
        }
        document.write("</style>\n");
}

/* This method is scheduled to be depreciated. As soon as nobody is using this function and is using setColWidth, this can be removed. Calls in the init function can be removed as soon as it's no longer being used. */
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]=100-leftRightWidth[i][0];
                                        }
                                        $(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);

