// JavaScript Document

$(document).ready(function() {

    swapValues = [];
    $(".text").each(function(i) {
        swapValues[i] = $(this).val();
        $(this).focus(function() {
            if ($(this).val() == swapValues[i]) {
                $(this).val("");
            }
        }).blur(function() {
            if ($.trim($(this).val()) == "") {
                $(this).val(swapValues[i]);
            }
        });
    });


    $('#printbtnLink').click(function() {
        print();
    });
    $('#bookmarkLink').click(function() {
        CreateBookmarkLink();
    });

    $("div.flyover div ul").each(function() {
        $(this).children(" li:last").css("border", "none");
    });
    $("div.flyover ul li:last").css("border", "none");
    $('#main-nav ul li').hover(function() {
        showWhat = $(this).attr('class');
        $(this).children().eq(0).addClass('active');
        $('#' + showWhat + '-fly').fadeIn('fast');
    }, function() {
        showWhat = $(this).attr('class');
        $(this).children().eq(0).removeClass('active');
        $('#' + showWhat + '-fly').fadeOut('fast');
    });


    $("ul#mark-print li a").hover(function() {

        getAttr = $(this).attr("rel");
        $(this).parent().siblings("li[class=" + getAttr + "]").css("display", "block");
    }, function() {
        $(this).parent().siblings("li:lt(3)").stop().css({ "display": "none" });
    });

    //colored OL
    $('ol li').wrapInner('<span class="olcontent"></span>').addClass('olcolor')

    //Activates #content-tabs

    if ($('#content-tabs').length) {
        $('#content-tabs').tabs();
    }

    $("dt").hover(function() {
        $(this).addClass("hover");
        $(this).next("dd").addClass("hover");
    }, function() {
        $(this).removeClass("hover");
        $(this).next("dd").removeClass("hover");
    });

    $("dd").hover(function() {
        $(this).addClass("hover");
        $(this).prev("dt").addClass("hover");
    }, function() {
        $(this).removeClass("hover");
        $(this).prev("dt").removeClass("hover");
    });

    $("ul.dl li").hover(function() {
        $(this).addClass("hover");
    }, function() {
        $(this).removeClass("hover");
    });

    $("table.careers tr").hover(function() {
        $(this).addClass("hover");
        $(this).children("td:first").addClass("hover-first");
        $(this).children("td:last").addClass("hover-last");
    }, function() {
        $(this).removeClass("hover");
        $(this).children("td:first").removeClass("hover-first");
        $(this).children("td:last").removeClass("hover-last");
    });
    //Expandable dl
    $("div.expand dl").each(function() {
        totalKids = $(this).children();
        totalKidsSize = $(totalKids).size();
        for (i = 0; i < totalKidsSize; i++) {
            if (i > 5) {
                $(totalKids[i]).addClass("hide");
            }
        }
    });

    $("a.view-all", $("div.expand h2")).toggle(function() {
        $(this).parent().next("span").children("dl").children().slideDown().removeClass('hide');
        $(this).addClass('view-top3');
        return false;
    }, function() {
        totalKids = $(this).parent().next("span").children("dl").children();
        totalKidsSize = $(totalKids).size();
        for (i = 0; i < totalKidsSize; i++) {
            if (i > 5) {
                $(totalKids[i]).addClass("hide").slideUp();
            }
        }
        $(this).removeClass('view-top3');
        return false;
    });




    //Select Multiple
    $("a.select-multiple").click(function() {
        $("#select-multiple").fadeIn();
        return false;
    });

    $("input.done").click(function() {
        var arr = [];
        var i = 0;
        var output_string = "";
        var whatcheck = $("#select-multiple").children("div").children("div").children(":checkbox:checked");
        $(whatcheck).each(function() {
            arr[i] = $(this).attr("value");
            i += 1;
        });

        for (var i = 0; i < arr.length; i++) {
            if (i == (arr.length - 1)) {
                output_string += arr[i];
            } else {
                output_string += arr[i] + ", ";
            }
        }

        $(this).parent().prev().append("<option value='" + output_string + "' selected='selected'>" + output_string + "</option>");
        $("#select-multiple").fadeOut();
        return false;
    });

    $("a.change").click(function() {
        winHeight = $(document).height();
        $("#change-overlay").css({ "opacity": "0.6", "display": "block", "height": winHeight + "px" });
        $("#change").css("display", "block");

        return false;
    });
    $("#change a.close").click(function() {
        $("#change-overlay").css("display", "none");
        $("#change").css("display", "none");

        return false;
    });

    if (jQuery.browser.msie) {
        $("#browse select.browseCategory").css({ "width": "auto" });
        width1 = parseInt($("#browse select.browseCategory").eq(0).width());
        width2 = parseInt($("#browse select.browseCategory").eq(1).width());
        if (width1 < 170) { $("#browse select.browseCategory").eq(0).css("width", "170px"); }
        if (width2 < 170) { $("#browse select.browseCategory").eq(1).css("width", "170px"); }
        $("#browse select.browseCategory").eq(1).css({ "margin-top": "5px", "margin-bottom": "5px" });
    }
});

function CreateBookmarkLink() {

    title = document.title;
    url = window.location.href;

    if (window.sidebar) { // Mozilla Firefox Bookmark
        window.sidebar.addPanel(title, url, "");
    } else if (window.external) { // IE Favorite
        window.external.AddFavorite(url, title);
    }
    else if (window.opera && window.print) { // Opera Hotlist
        return true;
    }
    function addBookmark(title, url) {
        if (window.sidebar) { // Firefox
            window.sidebar.addPanel(title, url, '');
        } else if (window.opera) { //Opera
            var a = document.createElement("A");
            a.rel = "sidebar";
            a.target = "_search";
            a.title = title;
            a.href = url;
            a.click();
        } else if (document.all) { //IE
            window.external.AddFavorite(url, title);
        }
    }
}


