
var imagePath; //"/BrandEnsembleWebApp/themes/BrandEnsemble.Themes.Default/images/";
var navlead;
// initial values for form elements
var searchTextLabel = "";
var searchTextColor = "";
var clientLoginLabel = "";
var clientLoginColor = "";
var clientPasswordLabel = "";
var clientLoginColor = "";

// values used later
var emailWindowHeight = "255";
var emailWindowWidth = "350";


// open SWF
function openNewSWF() {
    navlead = $("#logo-link").attr("href");
    window.open(navlead + 'themes/brandensemble.themes.default/creatingbrandchampions.html', 'NewWindow', 'height=519,width=618,status=0,toolbar=0,menubar=0,resizable=1,scrollbars=1')

}


// common form element functions
function textFocus(input, oldValue) {
    if (input.value == oldValue)
        input.value = "";
    input.style.color = "#000";
}

function textBlur(input, newValue, newColor) {
    if (input.value.length == 0) {
        input.value = newValue;
        input.style.color = newColor;
    }
}

function buttonOver(src) {
    return src.replace(/CCCCCC/, "FF0000");
}

function buttonOut(src) {
    return src.replace(/FF0000/, "CCCCCC");
}

function buttonBlackOver(src) {
    return src.replace(/000000/, "FF0000");
}

function buttonBlackOut(src) {
    return src.replace(/FF0000/, "000000");
}

function submitOver(src) {
    return src.replace(/7F7F7F/, "FF0000");
}

function submitOut(src) {
    return src.replace(/FF0000/, "7F7F7F");
}

// generates checkboxes with images and script
function checkboxReplacement(i, checkbox) {
    var newid = i;
    var inputid = (checkbox.id && checkbox.id.length > 0) ? checkbox.id : (checkbox.name && checkbox.name.length > 0) ? checkbox.name : "checkinput" + i;
    var initialcheckedsrc = (checkbox.checked) ? "-checked" : "";

    // add label event
    var labelFor = checkbox.id;
    $("label[for='" + labelFor + "']").click(function() {
        var checkImage = document.getElementById("checkimage" + i);
        checkimage_onclick(checkImage, null);
    }
	);

    // return new check box image HTML
    return "<img id=\"checkimage" + newid + "\" src=\"" + imagePath + "checkbox" + initialcheckedsrc + ".png\" alt=\"checkbox\" class=\"checkimage\" onclick=\"checkimage_onclick(this, '" + inputid + "');\" />";
}

function checkimage_onclick(checkImg, checkID) {
    if (checkImg.src.indexOf("checkbox.png") >= 0) {
        checkImg.src = imagePath + "/checkbox-checked.png";
        if (checkID != null) $("#" + checkID).attr("checked", "checked");
    }
    else {
        checkImg.src = imagePath + "/checkbox.png";
        if (checkID != null) $("#" + checkID).attr("checked", "");
    }
}

// generates select drop-downs with images and script
function selectReplacement(index, select) {
    var inputid = (select.id && select.id.length > 0) ? select.id : (select.name && select.name.length > 0) ? select.name : "select" + index;
    select.id = inputid; // for selects without any id attribute set

    // use default message if none selected by default
    var defaultSelectText = "Click to select an item";

    var optionContainerHTML = "<ol id=\"optionsList" + index + "\" class=\"replacedOptions\">";
    var optionGroupBeginHTML = "<li class=\"optgroup\">@@optgroupLabel@@<ol class=\"optgroup\">";
    var optionGroupEndHTML = "</ol></li>";
    var optionItemHTML = "<li id=\"optionsList" + index + "item@@itemIndex@@\" onclick=\"optionsListItem_onclick(this, '" + inputid + "', " + index + ", @@itemIndex@@);\">@@itemText@@</li>";
    var optionIndex = 0;

    $("select#" + inputid + ">optgroup, select#" + inputid + ">option").each(function(x) {
        // add each option or optgroup
        if (this.tagName == "OPTGROUP") {
            // if optgroup, also add inner options to it
            optionContainerHTML += optionGroupBeginHTML.replace(/@@optgroupLabel@@/, this.label);
            $(this).find("option").each(function(c) {
                if (this.selected && this.selected == "selected") {
                    defaultSelectText = this.text;
                }
                optionContainerHTML += optionItemHTML.replace(/@@itemText@@/, this.text).replace(/@@itemIndex@@/g, optionIndex);
                optionIndex++;
            }
				);
            optionContainerHTML += optionGroupEndHTML;
        }
        else {
            if (this.selected && this.selected == "selected") {
                defaultSelectText = this.text;
            }
            optionContainerHTML += optionItemHTML.replace(/@@itemText@@/, this.text).replace(/@@itemIndex@@/g, optionIndex);
            optionIndex++;
        }
    }
	);
    optionContainerHTML += "</ol>";

    // return main select box html plus options
    return "<div id=\"selectReplacement" + index + "\" class=\"selectArea\" onclick=\"selectReplacement_onclick(this);\" onmouseover=\"selectReplacement_onmouseover(this);\" onmouseout=\"selectReplacement_onmouseout(this);\"><div id=\"mySelectButton" + index + "\" class=\"selectButton\" onclick=\"mySelectButton_onclick(this);\"></div><div id=\"mySelectTextButton" + index + "\" class=\"selectTextButton\" onclick=\"mySelectTextButton_onclick(this);\">" + defaultSelectText + "</div></div>" + optionContainerHTML;
};

var bodyClickSkip = false;

function showOptions(optionsListIndex) {
    $("#optionsList" + optionsListIndex).show();
    $(document.body).one("click", hideLastOption);
}

function hideLastOption() {
    $("ol.replacedOptions").hide();
    $("div.selectButton").css("background-image", "url(" + imagePath + "/PullDownCCCCCC.png)");
    $(document.body).unbind("click", body_onclick);
}

function body_onclick() {
    if (bodyClickSkip) {
        bodyClickSkip = false;
    }
    else {
        hideLastOption();
    }
}

function selectReplacement_onclick(selectReplacementBox) {
    var selectIndex = parseInt(selectReplacementBox.id.replace(/selectReplacement/, ""))
    var isShowing = (document.getElementById("optionsList" + selectIndex).style.display == "inline");
    hideLastOption();
    if (!isShowing) {
        $("#optionsList" + selectIndex).show();
        $("#mySelectButton" + selectIndex).css("background-image", "url(" + imagePath + "/PullDownFF0000.png)");
        // add event to body, but don't fire it this time
        bodyClickSkip = true;
        $(document.body).click(body_onclick);
    }
}

function selectReplacement_onmouseover(selectReplacementBox) {
    var selectIndex = parseInt(selectReplacementBox.id.replace(/selectReplacement/, ""))
    $("#mySelectButton" + selectIndex).css("background-image", "url(" + imagePath + "/PullDownFF0000.png)");
}

function selectReplacement_onmouseout(selectReplacementBox) {
    var selectIndex = parseInt(selectReplacementBox.id.replace(/selectReplacement/, ""))
    var isShowing = (document.getElementById("optionsList" + selectIndex).style.display == "inline");
    if (!isShowing) {
        $("#mySelectButton" + selectIndex).css("background-image", "url(" + imagePath + "/PullDownCCCCCC.png)");
    }
}

function mySelectButton_onclick(mySelectButton) {
}

function mySelectTextButton_onclick(mySelectTextButton) {
}

function optionsListItem_onclick(optionsListItem, selectFieldId, selectIndex, optionIndex) {
    selectMe(selectFieldId, selectIndex, optionIndex);
}

function selectMe(selectFieldId, selectIndex, optionIndex) {
    hideLastOption();
    //feed selected option to the actual select field
    var selectField = document.getElementById(selectFieldId);
    $(selectField).find("option").each(function(i) {
        this.selected = "";
    }).end();
    selectField.options[optionIndex].selected = "selected";

    //show selected option
    var selectedText = document.getElementById("mySelectTextButton" + selectIndex);
    selectedText.innerHTML = selectField.options[optionIndex].text;
}

// add scrollbars to content; more about mousewheel events: http://adomas.org/javascript-mouse-wheel/
var scrollCancelID;

function handleWheel(delta) {
    //TODO: factor delta into the scroll amount
    //document.getElementById("searchText").value = parseInt(document.getElementById("searchText").value) + delta;

    window.clearTimeout(scrollCancelID);
    if (delta < 0)
        dw_scrollObj.initScroll('scrollContainer', 'down');
    else
        dw_scrollObj.initScroll('scrollContainer', 'up');
    //dw_scrollObj.speed = default_scroll_speed * Math.abs(delta);
    scrollCancelID = window.setTimeout("dw_scrollObj.stopScroll('scrollContainer')", 500);
}

function wheel(event) {
    var delta = 0;
    if (!event) event = window.event;
    if (event.wheelDelta) {
        delta = event.wheelDelta / 120;
        if (window.opera) delta = -delta;
    }
    else if (event.detail) {
        delta = -event.detail / 3;
    }
    if (delta) handleWheel(delta);
    if (event.preventDefault) event.preventDefault();
    event.returnValue = false;
}

function addScrollbars() {
    var scrollContainer = "<div id=\"scrollContainer\"></div>";
    var scrollBarController = "<div id=\"scrollbar\"><div id=\"scrollLine\" oncontextmenu=\"return false;\"></div><div id=\"scrollGrab\" oncontextmenu=\"return false;\"></div><img id=\"upArrow\" src=\"" + imagePath + "ArrowUpCCCCCC.png\" onmousedown=\"dw_scrollObj.initScroll('scrollContainer','up');\" onmouseup=\"dw_scrollObj.stopScroll('scrollContainer');\" oncontextmenu=\"return false;\" alt=\"up arrow\"><img id=\"downArrow\" src=\"" + imagePath + "ArrowDownCCCCCC.png\" onmousedown=\"dw_scrollObj.initScroll('scrollContainer', 'down');\" onmouseup=\"dw_scrollObj.stopScroll('scrollContainer');\" oncontextmenu=\"return false;\" alt=\"down arrow\"></div>";
    //TODO: refactor with $(window).scroll(function () { });

    // add scroll container and scrollbar to content for basic, person and search templates
    if ((document.getElementById("content").offsetHeight > 320) && ($("body.basic, body.search, body.person").size() > 0)) {
        $("#content").wrap(scrollContainer);
        $("#scrollContainer").append(scrollBarController);

        // initialize scrollbar elements and events (scrollbars.js)
        initScroll("content");

        // add mousewheel scrolling events
        if (window.addEventListener)
            window.addEventListener('DOMMouseScroll', wheel, false);
        window.onmousewheel = document.onmousewheel = wheel;
    }
    // add scroll container and scrollbar to component for two-column templates
    if ($("#components").length > 0) {
        if ((document.getElementById("components").offsetHeight > 320) && ($("body.twocolumn").size() > 0)) {
            $("#components").wrap(scrollContainer);
            $("#scrollContainer").append(scrollBarController);

            // initialize scrollbar elements and events (scrollbars.js)
            initScroll("components");
        }
        // add mousewheel scrolling events
        if (window.addEventListener)
            window.addEventListener('DOMMouseScroll', wheel, false);
        window.onmousewheel = document.onmousewheel = wheel;
    }
}

// slide navigation
var mediaTypes = [];
var thumbIDs = [];
var thumbExts = [];

function initSlides() {
    // read hash and skip to that page, if it exists
    var slideshowClientID = $("div #clientIDContainer").text();
    var currentPage = 1;
    if (location.hash.length > 0) {
        currentPage = parseInt(location.hash.match(/Freeform(\d+)/)[1]);
    }
    currentPage = (!(isNaN(currentPage)) && ($("#content #" + slideshowClientID + "_Freeform" + (currentPage) + "_plcContent1").size() > 0)) ? currentPage : 1;
    setSlideNavVisibility(currentPage);
    hideSlides();
    showSlide("#" + slideshowClientID + "_Freeform" + currentPage + "_plcContent1_FreeformContent");

    // get initial thumb ID and extension values
    initThumbs();

    // set thumbs, change thumbs	
    setThumbsForPage(currentPage);

    // set main image, change main image with each slide
    setMainImage(currentPage);
}

function initThumbs() {
    mediaTypes = new Array();
    thumbIDs = new Array();
    thumbExts = new Array();
    var mediaPattern = /media\/(\d)\/([a-f0-9]{32})\.(\w{3})/;
    $("#thumb-navigation li a img").each(function(i) {
        var result = this.src.match(mediaPattern);
        if (result != null) {
            mediaTypes[i] = result[1];
            thumbIDs[i] = result[2];
            thumbExts[i] = result[3];
        }
    });
}

// sets main image based on current page, images must have same size, ID and extension for each slideshow page
function setMainImage(currentPage) {
    $("#components a").hide();
    if ($.browser.safari) {
        // Safari fadeIn fix- just display it straight.
        $("#components a.SingleImage" + currentPage + "_plcSideContent1").css("display", "inline");
    }
    else {
        $("#components a.SingleImage" + currentPage + "_plcSideContent1").fadeIn("fast");
    }
}

function setThumbsForPage(currentPage) {
    var blankPattern = /Themes\/BrandEnsemble\.Themes\.Default\/images\/SST\_blank\.gif/;
    var imagePattern = /media\/\d\/[a-f0-9]{32}\.\w{3}/;
    $("#thumb-navigation li.selected").removeClass("selected");
    $("#thumb-navigation li a img").each(function(i) {
        if (i < currentPage) {
            this.src = this.src.replace(blankPattern, "media/" + mediaTypes[i] + "/" + thumbIDs[i] + "." + thumbExts[i])

            // set selected LI's class
            if (i == (currentPage - 1)) {
                $(this.parentNode.parentNode).addClass("selected");
            }
        }
        else {
            this.src = this.src.replace(imagePattern, "Themes/BrandEnsemble.Themes.Default/images/SST_blank.gif")
        }
    });
}

function setSlideNavVisibility(currentPage) {
    // test previous, hide previous on 1st page
    var slideshowClientID = $("div #clientIDContainer").text();
    if ($("#thumb-navigation #" + slideshowClientID + "_SlideShowController1_plcContent1_thumb" + (currentPage - 1)).size() > 0) {
        $("#previous-next-navigation li.previous a").each(function(i) {
            $(this).show();
            this.href = "#" + slideshowClientID + "_Freeform" + (currentPage - 1) + "_plcContent1_FreeformContent";
        }
		);
    }
    else {
        $("#previous-next-navigation li.previous a").hide();
    }

    // test next, hide next on last page
    if ($("#thumb-navigation #" + slideshowClientID + "_SlideShowController1_plcContent1_thumb" + (currentPage + 1)).size() > 0) {
        $("#previous-next-navigation li.next a").each(function(i) {
            $(this).show();
            this.href = "#" + slideshowClientID + "_Freeform" + (currentPage + 1) + "_plcContent1_FreeformContent";
        });
    }
    else {
        $("#previous-next-navigation li.next a").hide();
    }
}

function hideSlides() {
    $("#content .freeform-content").hide();
}

function showSlide(pageID) {
    $("#content " + pageID).fadeIn("fast");
}

function linkToSlide(link) {
    hideSlides();
    showSlide(link.hash);

    // match second digit
    var currentPage = parseInt(link.hash.match(/Freeform(\d+)/)[1]);
    setSlideNavVisibility(currentPage);
    setThumbsForPage(currentPage);
    setMainImage(currentPage);
}

function previousSlide_onclick(link) {
    linkToSlide(link);
}

function nextSlide_onclick(link) {
    linkToSlide(link);
}

function gotoSlide_onclick(link) {
    linkToSlide(link);
}

// contact events
function showAllServices_onclick(link) {
    $("#more-services").show();
    link.className += " shown";
}

function contactSubmit_onmouseover(input) {
    input.src = buttonBlackOver(input.src);
}

function contactSubmit_onmouseout(input) {
    input.src = buttonBlackOut(input.src);
}

// people finder
function peopleSubmit_onmouseover(input) {
    input.src = submitOver(input.src);
}

function peopleSubmit_onmouseout(input) {
    input.src = submitOut(input.src);
}

// search results
function searchResultsSubmit_onmouseover(input) {
    input.src = submitOver(input.src);
}

function searchResultsSubmit_onmouseout(input) {
    input.src = submitOut(input.src);
}

// footer form element events
function searchText_onfocus(input) {
    textFocus(input, searchTextLabel);
}

function searchText_onblur(input) {
    textBlur(input, searchTextLabel, searchTextColor);
}

function searchSubmit_onmouseover(input) {
    input.src = buttonOver(input.src);
}

function searchSubmit_onmouseout(input) {
    input.src = buttonOut(input.src);
}

function clientLogin_onfocus(input) {
    textFocus(input, clientLoginLabel);
}

function clientLogin_onblur(input) {
    textBlur(input, clientLoginLabel, clientLoginColor);
}

function clientPassword_onfocus(input) {
    textFocus(input, clientPasswordLabel);
    input.type = "password";
}

function clientPassword_onblur(input) {
}

function clientSubmit_onmouseover(input) {
    input.src = buttonOver(input.src);
}

function clientSubmit_onmouseout(input) {
    input.src = buttonOut(input.src);
}

function getInput(id) {
	return $('*[id$="' + id + '"]')[0];
}

function initFooter() {
    searchTextLabel = getInput("searchText").value;
    searchTextColor = getInput("searchText").style.color;
    clientLoginLabel = getInput("clientLogin").value;
    clientLoginColor = getInput("clientLogin").style.color;
    clientPasswordLabel = getInput("clientPassword").value;
    clientPasswordColor = getInput("clientPassword").style.color;
}

// footer link events
function printLink_onclick(anchor) {
	window.print();
	return false;
}

function emailLink_onclick(anchor) {
	window.open(anchor.href, "email", "scrollbars=no,menubar=no,height=" + emailWindowHeight + ",width=" + emailWindowWidth + ",resizable=yes,toolbar=no,location=no,status=yes");
	return false;
}


// jquery style tweaks

// setup document
$(document).ready(function() {
    $("a[rel=_new]").click(function() {
        window.open($(this).attr("href"), "_article", "");
        return false;
    });

    //    if ($(".peopleUl").length > 0) {
    //        $("#scrollContainer").css("width", "530px").css("margin-left", "20px");
    //        $("#content").css("width", "480px");
    //        $("#primary-navigation").css("margin-left", "-710px");
    //    }
    var number = 1;
    $itemContainers = $(".item-container");
    $itemContainers.each(function(i) { $(this).addClass("individualItem" + number); number++; });



    //Case Studies Rollovers	$("#relatedBarContainer .item-container:nth-child(1)").addClass("firstBar");	$("#relatedBarContainer .item-container:nth-child(5)").addClass("lastBar");        var parentObj = $(".bigLI").find("li"); $(".bigLI:nth-child(1) li").children(".inactiveLink").css("display", "none"); $(".bigLI:nth-child(1) li").children(".activeLink").css("display", "inline"); $(".bigLI:nth-child(1) li").children(".caseStudiesLink").css("color", "#ff0000"); $(".bigLI:nth-child(1) li").children(".caseStudiesLink").css("font-weight", "bold");
    var parentObj = $(".bigLI").find("li");
    var $firstBigLI = $(".bigLI:nth-child(1) li");
    $firstBigLI.children(".inactiveLink").css("display", "none");
    $firstBigLI.children(".activeLink").css("display", "inline");
    $firstBigLI.children(".caseStudiesLink").css("color", "#000");
    $firstBigLI.children(".caseStudiesLink").css("font-weight", "bold");

    $(".bigLI").mouseover(function() {
        var parentObj = $(this).find("li");
        $firstBigLI.children(".activeLink").css("display", "none");
        $firstBigLI.children(".inactiveLink").css("display", "inline");
        $firstBigLI.children(".caseStudiesLink").css("color", "#999");
        $firstBigLI.children(".caseStudiesLink").css("font-weight", "normal");
        $(parentObj).children(".inactiveLink").css("display", "none");
        $(parentObj).children(".activeLink").css("display", "inline");
        $(parentObj).children(".caseStudiesLink").css("color", "#000000");
        $(parentObj).children(".caseStudiesLink").css("font-weight", "bold");
    }).mouseout(function() {
        var parentObj = $(this).find("li");
        $(parentObj).children(".activeLink").css("display", "none");
        $(parentObj).children(".inactiveLink").css("display", "inline");
        $(parentObj).children(".caseStudiesLink").css("color", "#999");
        $(parentObj).children(".caseStudiesLink").css("font-weight", "normal");
    });

    var $storiesList = $(".storieslist");
    $storiesList.find("li.imageLI:last").css("border-bottom", "solid 1px #999");
    $storiesList.find("li.imageLI:first").css("border-top", "solid 1px #999")
    $storiesList.find("li.linksLI:last").css("border-bottom", "solid 1px #999");
    $(".linksLI").css("font-weight", "normal");

    /*$(function() { $(document).pngFix(); });*/
    var themepath = navlead + "themes/BrandEnsemble.themes.default/";
    if ($.browser.msie && $.browser.version == 6) {
        document.styleSheets[0].addRule('div', 'behavior: url(' + themepath + 'scripts/iepngfix.htc)');
    }

    navlead = $("#logo-link").attr("href");
    imagePath = navlead + "themes/BrandEnsemble.themes.default/images/";

    //$("#content-wrapper").css("background-image", "url(" + imagePath + "/body_background_shadow.png)");


    $("#nav li:last a").css("width", "80px");


    // $("#content-wrapper-shadow").css("float", "right");
    var imagePathRegex = /[\w\/\.]*\//;
    imagePath = imagePathRegex.exec($("#footer > #search > a > img[src]").attr("src"));

    // initialize footer form elements
    initFooter();

    // slideshow template, init slides
    if ($("body.slideshow").length > 0) {
        initSlides();
    }

    // IE specific issues
    // IE6 = 5.6, IE7 = 5.7 (@_jscript_version < 5.7)
    /*@cc_on
    @if (@_jscript)
    // IE background image flicker hack
    try {
        document.execCommand('BackgroundImageCache', false, true);
    } catch (e) { }

    @if (@_jscript_version <= 5.6)
    // reset h1+p, h2+p, h3+p, etc., p:first-child for IE6
    $("#content h1+p, #content h2+p, #content h3+p, #content h4+p, #content h5+p, #content h6+p, #content img+p, #content p:first-child").css("text-indent", "0");
    @end
    @end
    @*/

    // contact form, hide options
    if ($("body.contact").size() > 0) {
        $("#more-services").hide();
    }

    // search results
    if ($("body.search").size() > 0) {
        $("#content div.search p.query").each(function(i) {
            $("#search-box").append(this);
        }
			);
        $("#content div.search p.query").hide();
    }



    $(".item-hover").hide();
    $(".inactiveImages").hide();
    // $(".item-container").each(function(i) {
    $(".item-container").bind("mouseenter", function() {

        //make sure the related menu item isn't showing
        if ($(this).hasClass("selectedMenuItem")) {

        }
        else {
            $(".selectedMenuItem").parent().find(".item-hover").hide();
            $(".selectedMenuItem").parent().find(".inactiveImages").hide();
            $(".selectedMenuItem").parent().find(".activeImages").show();

            $(".selectedMenuItem").parent().find(".inner-div").css("background", "none");
            $(".selectedMenuItem").removeClass("selectedMenuItem");
        }

        var i;
        $(this).find(".item-hover").show();
        $(this).find(".activeImages").hide();
        $(this).find(".inactiveImages").show();
        $(this).addClass("selectedMenuItem");
        //$imagesrc = imagePath + "/background_subpage_mm"+number+".png;
        for (var x = 1; x <= 5; x++) {
            if ($(this).hasClass("individualItem" + x)) {
                i = x;
            }
        }
        if ($("body.contact").hasClass("fullBody")) {
            $(this).find(".inner-div").css("background", "url(" + imagePath + "/background_subpage_mm" + i + "_contact.png) no-repeat");

        }
        else {
            $(this).find(".inner-div").css("background", "url(" + imagePath + "/background_subpage_mm" + i + ".png) no-repeat");
            if (x == '1') {
                $(this).find(".inner-div").css("margin-left", "-7px");
            }
        }

    }).bind("mouseleave", function() {
        /*$(this).find(".item-hover").hide();
        $(this).find(".inactiveImages").hide();
        $(this).find(".activeImages").show();

        $(this).find(".inner-div").css("background", "none");*/

    });
    //  });
    // show the selected relatedmenu item
    var i;
    $(".selectedMenuItem").parent().find(".item-hover").show();
    $(".selectedMenuItem").parent().find(".activeImages").hide();
    $(".selectedMenuItem").parent().find(".inactiveImages").show();

    //$imagesrc = imagePath + "/background_subpage_mm"+number+".png;
    for (var x = 1; x <= 5; x++) {
        if ($(".selectedMenuItem").parent().hasClass("individualItem" + x)) {
            i = x;
        }
    }
    if ($("body.contact").hasClass("fullBody")) {
        $(".selectedMenuItem").parent().find(".inner-div").css("background", "url(" + imagePath + "/background_subpage_mm" + i + "_contact.png) no-repeat");

    }
    else {
        $(".selectedMenuItem").parent().find(".inner-div").css("background", "url(" + imagePath + "/background_subpage_mm" + i + ".png) no-repeat");
        if (x == '1') {
            $(".selectedMenuItem").parent().find(".inner-div").css("margin-left", "-7px");
        }
    }




    // add scrollbars to content
    addScrollbars();

    if ($("div.admin").size() <= 0) {
        // checkbox replacement
        //        $("input[@type='checkbox']").each(function(i) {
        //            $(this).before(checkboxReplacement(i, this)).hide();
        //        });

        // select dropdown replacement
        $("select").each(function(i) {
            if (!(this.size) || (this.size <= 1)) {
                var selectSize = this.offsetWidth;
                $(this).before(selectReplacement(i, this)).hide();
                $("#selectReplacement" + i).css("width", (selectSize - 2) + "px");
                var selectReplacementObject = document.getElementById("selectReplacement" + i);
                $("#optionsList" + i).css("margin-top", selectReplacementObject.offsetTop + "px").css("margin-left", selectReplacementObject.offsetLeft + "px").css("width", (selectReplacementObject.offsetWidth - 25) + "px").hide();
                $("#optionsList" + i + " li").mouseover(function() {
                    $(this).addClass("hover");
                }).mouseout(function() {
                    $(this).removeClass("hover");
                });

                // set text to selected option
                $("option[selected]", this).each(function(x) {
                    $("#mySelectTextButton" + i).text(this.text);
                });
            }
        });
    }

    // process custom forms
    $("fieldset.form input:image, fieldset.form input:submit").click(function() {
        var action = $(this).siblings("input:hidden[name='action']");
        action.remove();
        $(this).parents("fieldset:first").wrap("<form method='get' action='" + action.val() + "'></form>");
    });

    // search box
    $("#footer #search input:text").keydown(function(e) {
        if (e.keyCode == 13 || e.keyCode == 10) // enter key
        {
            $("form").submit(function() {
                return false;
            });
            // logo-link will give us navlead
            window.location.href = $("#logo-link").attr("href") + 'search/-/?q=' + encodeURIComponent($(this).val());
            return false;
        }
    });

    // search mouseover highlight
    $("#ctl00_Footer1_imgSearch").mouseover(function() {
        var src = $(this).attr("src").replace("CCCCCC", "FF0000");
        $(this).attr("src", src);
    }).mouseout(function() {
        var src = $(this).attr("src").replace("FF0000", "CCCCCC");
        $(this).attr("src", src);
    });

    // login mouseover highlight
    $("#ctl00_Footer1_imgClient").mouseover(function() {
        var src = $(this).attr("src").replace("CCCCCC", "FF0000");
        $(this).attr("src", src);
    }).mouseout(function() {
        var src = $(this).attr("src").replace("FF0000", "CCCCCC");
        $(this).attr("src", src);
    });

    // test for CSS16 & CSS17
    var $captionUL = $("ul.captions");
    if ($captionUL.length > 0) {
        // hide text blocks
        if ($captionUL.hasClass("CSS17")) {
            $("li.subitem:not(:nth-child(2))", $captionUL).hide();
        } else {
            $("li.subitem:not(#firstitem)", $captionUL).hide();
        }

        // add roll-over events to thumbs
        $("ul.caption-thumbs li a").each(function(i) {
            $(this).mouseover(function() {
                $("li", $captionUL).hide();
                $(this.hash).show();
                $("ul.CSS17>#firstitem").show();
            });
        });
    }

    // update date on news page
    var $currentNews = $("#content .freeform-content p:contains('Current News')");
    if ($currentNews.length > 0) {
        var today = new Date();
        var shortDate = (today.getMonth() + 1) + "/" + today.getDate() + "/" + today.getFullYear();
        $currentNews.html("<strong>Current news</strong> - " + shortDate);
    }
    else {
        var $currentNews = $("#content .freeform-content p:contains('Current news')");
        if ($currentNews.length > 0) {
            var today = new Date();
            var shortDate = (today.getMonth() + 1) + "/" + today.getDate() + "/" + today.getFullYear();
            $currentNews.html("<strong>Current news</strong> - " + shortDate);
        }
    }

    /* if ($(".peopleUl").length > 0) {
    $("#scrollContainer").css("width", "530px").css("margin-left", "20px");
    $("#content").css("width", "480px");
    $("#primary-navigation").css("margin-left", "-740px");
    $("#body").removeClass("person");
    $("#body").addClass("fullbody");
    }*/

    /*highlight($(".bigLI:first"));
    $(".linksLI > a").css("text-decoration", "none");
    $(".bigLI:first").css("margin-bottom", "-10px");
    
    $(".bigLI").mouseover(function() {
    highlight(this);
    }).mouseout(function() {
    lowlight(this);
    });

    var caseStudyLink = $(".linksLI > a").attr("href");
    $(".imageLI > a").attr({
    href: caseStudyLink
    });*/
});

/*function highlight(sender) {
    $(sender).find("a").css("font-weight", "bold");
    $(sender).find("a").css("color", "#000000");
}

function lowlight(sender) {
    $(sender).find("a").css("color", "#999999");
    $(sender).find("linksLI > a:last").css("font-weight", "normal");
}*/