$(document).ready(function () {
    $(document).pngFix();
    $('#e').Watermark("Email Sign Up", "#666666");
    if (typeof (section) != "undefined") {
        try {
            var i$ = $("#mainnav img[alt='" + section + "']");
            i$.addClass("on");
            SetImage(i$, i$.attr('src').replace('.jpg', '_f3.jpg'));
        } catch (e) {

        }
    }
    Menu.Init();

    $("#go").click(function () {
        $('#ea').val($('#e').val());
        $('#ccoptin').submit();
    });
    $('a.tips').cluetip({ local: true, hideLocal: false, arrows: true, cursor: 'pointer' });


    $('#tabs li').hide();
    $('#tab a img').click(function () {
        $('#tabs li').hide();
        $("#" + $(this).parent().attr("rel")).show();
        $("#tab img").each(function (i) {
            SetImage($(this), $(this).attr('src').replace('_f2.jpg', '.jpg'));
        });
        SetImage($(this), $(this).attr('src').replace('.jpg', '_f2.jpg'));
    });
    $('#Balsam').show();

    $("#aboutusnav li").click(function () {
        $("#aboutusnav li").removeClass("selected");
        $(this).addClass("selected");
        var index = $(this).prevAll().length + 1;
        $("#principals li.principal").hide();
        $("#principals li:nth-child(" + index + ")").show();
        return false;
    });
    $("#principals li:nth-child(1)").show();


    $("#research li").click(function () {
        $("#research li").removeClass("selected");
        $(this).addClass("selected");
        var index = $(this).prevAll().length + 2;
        $("#researchcontents li.researchcontent").hide();
        $("#researchcontents li:nth-child(" + index + ")").show();
        $("#sidenav li").removeClass("selected");
        
        if ($(this).attr("id") == "researchwhitepapers") {
            $("#viewrw").addClass("selected");
        } else {
            $("#sidenav li").removeClass("selected");
        }
        return false;
    });
    $("#researchcontents li:nth-child(1)").show();



    $('.editable').hover(function () {
        $(this).addClass("editback");
        $(this).attr("title", "Double Click to edit this content.");
    }, function () {
        $(this).removeClass("editback");
    });


    $(".editable").bind("dblclick", function () {
        $.fancybox(root + 'admin/editcontent.aspx?ID=' + $(this).attr("rel"), {
            autoDimensions: false,
            margin: 0,
            width: '100%',
            height: '100%',
            type: 'iframe'
        });
        return false;
    });

});
Menu = {
    ImageBase: root,
    Init: function () {
        $('.nav img').preload({
            find: '.jpg',
            replace: '_f2.jpg'
        });
        $('.nav img').hover(function () {
            Menu.Over(this);
        }, function () {
            Menu.Out(this);
        });
    },
    Over: function (elt) {
        if (!$(elt).hasClass('on')) {
            SetImage(elt, $(elt).attr('src').replace('.jpg', '_f2.jpg'));
        }
    },
    Out: function (elt) {
        if (!$(elt).hasClass('on')) {
            SetImage(elt, $(elt).attr('src').replace('_f2', ''));
        }
    }
}
function SetImage(elt, src) {
    $(elt).attr('src', src);
}

function GotoValidationSummary() {
    if (typeof (ValidatorOnSubmit) == "function") {
        var isValidated = ValidatorOnSubmit();
        if (!isValidated) {
            var pos = $(".validationsummary").show().position();
            window.scrollTo(pos.left, pos.top);
            return false;
        }
        return true;
    }
}
function RefreshContent(id, content) {
    $('[rel=' + id + ']').html(content);
}