﻿// starting the script on page load
$(document).ready(function(){
    tooltip();
	setPrintAction();
	reRenderTables();
	styleButtons();
	setHomePageLink();
	lightBoxImage(".enable_lightbox");
	setFontSize();

    fixIE6();

    // When update_progress is present update scroll position
    // to keep the lightBox in the right spot
    if ($(".update_progress").length > 0) {
        $(window).scroll(function() {
            renderProgressDialog();
        });
    }
	
    // After Ajax PostBack ReRender buttons
    var prm = Sys.WebForms.PageRequestManager.getInstance(); 
    prm.add_endRequest(reDrawButtons); 	
});

$(window).load(function () { 
    setFooterHeight(); 
});

function setHomePageLink() {
    $("h1.branding").each(function() {
        $(this).click(function() {
            $("#channel_link a").each(function(){
                if (!$(this).hasClass("show")) {
                    window.location.href = $(this).attr("href");
                }
            })
        });
    });
}

function setFooterHeight() {
    if ($("#footer").offset().top < $(window).height()) {
        var winH = $(window).height();
        var top = $("#footer").offset().top;
        var footerH = $("#footer").height();
        if (winH > (footerH + top)) {
            var heightDiff = winH - (footerH + top);
            var newHeight = footerH + heightDiff;
            $("#footer").height(newHeight-33);
        }
    }
}

function insertSubNav(idx) {
    var arrLink = new Array($("#link_who_we_are a").clone(), $("#link_in_media a").clone(), $("#link_partners").clone());
    
    var subNav = jQuery(document.createElement("ul")).attr("id","site_nav_local_sub");
    for (var i=0; i<3; i++) {
        var item = jQuery(document.createElement("li"));
        if (i===0) {
            $(item).addClass("child_1");
        }
        if (i===idx) {
            $(item).addClass("current");
        }
        $(arrLink[i]).html(($(arrLink[i]).html().replace(/:/g,"")));
        $(item).append($(arrLink[i]));
        $(subNav).append(item);
    }
    $("#content").prepend($(subNav));
}
function fixIE6() {
    if($.browser.msie){
        if ($.browser.version.indexOf("6") != -1) {
            $("#site_nav_local_primary").css("zoom",1);
            $("#site_nav_local").css("zoom",1);
            
            if (($("#content").length > 0) && ($(".homepage").length === 0)) {
                if (document.getElementById("content").clientHeight < 312) {
                    $("#content").css("height","26em");
                }
            }
        }
    }    
}