﻿// Global Variables

/* About Global Variables

   This image replacement script assumes a the existence of a standard image naming convention
   for all over/out state images.
   
   For example, all out state images are named as <descriptive name>_up.<extension>, and all
   over state images are <descriptive name>_over.<extension>.
   
   imageOverSuffix and imageOutSuffix represent the standard nomenclature chosen for the site.
   
   imageReplace receives a target object (typically passed using 'this'), an action (either 'over' or 'out'),
   and an exclusionObj (which represents an object to examine if there is a situation where the image replace
   should not occur).
   
*/
  
    
var imageOverSuffix = "_over";
var imageOutSuffix = "_up";



/***** Image Replace *****/

function imageReplace(target, action) {

            var s = getImageSrc(target);
            var t = '.' + getImageType(target);
            var newImg = imageOverSuffix;
            
            if (action == 'out') {
                newImg = imageOutSuffix;
            }
          
            target.src = s + newImg + t;

}

function getImageSrc(target) {
    var s = target.src;
    var targetSuffix = imageOutSuffix;
    
    if (s.indexOf(targetSuffix + '.') == -1) {
        targetSuffix = imageOverSuffix;
    }
    
    s = s.substring(0, s.indexOf(targetSuffix + '.'));
    return s;
}

function getImageType(target) {
    var s = target.src;
    var t = s.substring(s.length - 3, s.length);
    return t;
}

/***** Right Navigation *****/

function rightNavEvent(target, action) {
    
    var paddingObj = {origTopBottomPadding:3, zeroLeftPadding:29, oneLeftPadding:40, twoLeftPadding:50, threeLeftPadding:60};
    var colorObj = {zeroColor:'#02165a', oneColor:'#968177', twoColor:'#715C52', threeColor:'#715C52' };
    var exclusionClass = "Menu-Selected";
    var levelNumber = getLevelNumber(target.parentNode);
    
    switch (levelNumber) {
        case 0: levelNumber = "zero";
                break;
        case 1: levelNumber = "one";
                break;
        case 2: levelNumber = "two";
                break;
        case 3: levelNumber = "three";
                break;
    }
    

    if (target.parentNode.className.indexOf(exclusionClass) == -1) {
        
        var levelPaddingName =  levelNumber + 'LeftPadding';
        var levelColorName = levelNumber + 'Color';
        if (action == 'over') {
        test = target;
            target.style.backgroundColor = '#f8f8f8';
            target.style.border = '1px solid #f1ece8';
            target.style.paddingTop = '2px';
            target.style.paddingBottom = '2px';
            target.style.paddingLeft = (paddingObj[levelPaddingName] - 1) + 'px';
            target.style.color = '#a4071e';
            //target.childNodes[0].nodeValue = '> ' + target.childNodes[0].nodeValue;
        } else if (action == 'out') {
            target.style.backgroundColor = '';
            target.style.border = '0';
            target.style.paddingTop = '3px';
            target.style.paddingBottom = '3px';
            target.style.paddingLeft = paddingObj[levelPaddingName] + 'px';
            target.style.color = colorObj[levelColorName];
            //target.childNodes[0].nodeValue = target.childNodes[0].nodeValue.substring(2, target.childNodes[0].nodeValue.length);
        }
    }
}


function getLevelNumber(startingPoint) {
    var targetID = "right_nav_list";
    var currentID = "";
    var nextNode = startingPoint;
    var counter = 0;
    
   while (targetID != currentID) {
        nextNode = nextNode.parentNode;
        if (nextNode.nodeName.toLowerCase() == "ul") {
            if (nextNode.id) {
                if (nextNode.id == targetID) {
                    currentID = targetID;
                } else {
                    counter++;
                }
            } else {
                counter++;
            }
        }
    }
    return counter;
}
/***** Pop Up Menus *****/

function mainNavEvent(obj, location, action) {

    if (location == 'main') {
        if (obj.className.indexOf("Selected") == -1) {
            var imageNode = getChildNodeByTagName(obj, 'a');
            imageNode = getChildNodeByTagName(imageNode, 'img');
            imageReplace(imageNode, action);
        }
        
        var listNode = getChildNodeByTagName(obj, 'ul');
        
        if (action == 'over') {
            listNode.style.visibility = 'visible';
        } else if (action == 'out') {
            listNode.style.visibility = 'hidden';
        }
        
    } else if (location == 'sub') {
        if (action == 'over') {
            obj.style.backgroundColor = '#f8f8f8';
            obj.style.border = '1px solid #f1ece8';
            obj.style.paddingTop = '2px';
            obj.style.paddingBottom = '2px';
            obj.style.paddingLeft = '19px';
            obj.style.color = '#a4071e';
        } else if (action == 'out') {
            obj.style.backgroundColor = '';
            obj.style.border = '0';
            obj.style.paddingTop = '3px';
            obj.style.paddingBottom = '3px';
            obj.style.paddingLeft = '20px';
            obj.style.color = '#02165a';
        }
    }
}

function getChildNodeByTagName(obj, targetName) {
    var children = obj.childNodes;
    var nextNode;
    
    for (var i=0; i < children.length; i++) {
        nextNode = children[i];
        if (nextNode.nodeName.toLowerCase() == targetName.toLowerCase()) {
            break;
        }
    }
    
    return nextNode;
}
/***** Printer-Friendly Window *****/

function openPrintWindow(url) {
    window.open(url, 'GCAAR', 'width=600,height=500,chrome=no');
}

function printPage() {
    alert("printing page.");
    window.print();
}

/***** Pop Ups *****/

function popUp(url, width, height) {
    window.open(url, "GCAAR", "width=" + width + ",height=" + height + ",toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no,scrollbars=yes");
}