﻿$(document).ready(function() {
    if($.browser.msie && $.browser.version=="6.0"){
        $('#banner_logo').attr('src','/assets/images/main_logo.gif')
    };
    //HideSitefinityClasses();

    $("#framemask").each(function() {        
        $(this).css("height", $(this).next().css("height"));        
    });

    //$("#mainNavContainer .mainNavParentChildren:last").css("margin-left","-120px");
    //('left', '-118px');
    
    $("#mainNavContainer div ul li").hover(function(){
        $(this).addClass('submenuHover');
    },function(){
        $(this).removeClass('submenuHover');
    });
    
    $(".mainNavParent").hover(function() {
        //$(".mainNavParentChildren").hide();
        ul = $(this).find("ul"); //.show();
        $(this).addClass('hovered');
        var position=$(this).position();
        //alert(position.left);
        //alert(ul.html());
        ul.show();
        ul.css('position','absolute');
        ul.css('left',position.left);

    },function(){
    //hovers require 2 statments
    $(this).removeClass('hovered');
            ul = $(this).find("ul");
            ul.hide();
    });
    $(".current").parent().show();

    // interior expand collapse menu
    $(".group").click(function() {
        ul = $(this).next();  /* $(this).find("ul"); */
        ul.slideToggle();
    });

    var mainAlert = 'mainAlert';
    var smallAlert = 'smallAlert';

    if (!AlertShown(mainAlert)) {
        $("#rumorControl").animate({ height: "200px" }, 1500);
    }
    else {
        $("#rumorControl").hide();
    }

    if (!AlertShown(smallAlert)) {
        $("#smallRumorControl").show(); //animate({ height: "200px" }, 1500);
    }
    else {
        $("#smallRumorControl").hide();
    }

    //$("#rumorControl").animate({ height: "200px" }, 1500);

    $("#rumorClose").click(function() {
        HideAlert(mainAlert);
        $("#rumorControl").slideUp();
    });

    $("#smallRumorClose").click(function() {
        HideAlert(smallAlert);
        $("#smallRumorControl").slideUp();
    });

    //watermark
    $(".watermark").focus(function() {
        $(this).val("");
        $(this).removeClass("watermark");
    });

    $(".watermark").each(function() {
        if ($(this).val() != "Search") {
            $(this).removeClass("watermark");
        }
    });

    $(".watermark").blur(function() {
        if ($(this).val().length == 0) {
            $(this).addClass("watermark");
            $(this).val("Search");
        }

    });

    $("#banner_logo").click(function() {
        document.location = "/";
    });

    $(".summaryToggle").click(function() {
        $(this).next().slideToggle();
    });


    $("#footerlinks li:first-child a").css("color", "#9d9d9d");
    $("#rightNav .sf_simpleList li:last-child").css("border", "none");
    $("#rightNav .sf_simpleList li:last-child").css("padding", "0");
    $("#breadcrumb").css("color", "#033F73");

    try {
        if ($("#breadcrumb").length > 0) {

            if ($("#breadcrumb").html().length === 0) {
                $("#breadcrumb").hide();
            }
        }

    }
    catch (e) {
    }

    //events: hide table rows where content isn't present
    $(".eventPanel table td").each(function(index) {

        if ($(this).text().length === 0) {
            $(this).parent().css("display", "none");
        }
        //alert(index + ': ' + $(this).text());
    });

    $("iframe").load(function() {
        $("#framemask").fadeOut("slow");
        //alert('frame loaded');
    });

    if ($("#int_slideShow").length > 0) {

        if ($("#int_slideShow li").size() > 1) {
            $("#int_slideShow").slidepanel({ autoPlay: false, trans: 'fade', slideButtonsAutoActions: true, nextBtn: '.next', prevBtn: '.prev' });
        }
        else {
            $("#int_slideShow .prev").hide();
            $("#int_slideShow .next").hide();
        }
        
        $("#int_slideShow").fadeIn() 
    }
    
     $("a").each(function() {
        if( $(this).attr("href").indexOf("pdf") > -1 )
        {
            $(this).attr("target","_blank");           
        }  
        if( $(this).attr("href").indexOf("investors/financial_information/financial_packet.aspx") > -1 )
        {
            $(this).attr("target","_blank");            
        }               
    });

    // EXPAND/COLLAPSE BOXES
    //(".ecb_content_container")
    $(".ecb_title").each(function() {
         $(this).click(function() {
            $(this).next().slideToggle("slow");
         })
                    
    });
})

function HideSitefinityClasses() {
    /* $("sf_readMore").css("background-color","red");
    $("sf_newsAuthor").hide();
    $("sf_postCategory").hide();
    $("sf_postTags").hide(); */
}


function AlertShown(cookieName) {

    //return false;
    try {
    
    
    if ($.cookies.get(cookieName) === null) {

        //$.cookies.set(AlertShownCookieName, '1', { expiresAt: AlertShownCookieExpires });
        //alert('f');
        return false;
    }
    else {
        //alert('t');
        return true;
    }

}
catch (e)
    { }
    
}

function HideAlert(cookieName) {

    AlertShownCookieExpires = new Date();
    AlertShownCookieExpires.setTime(AlertShownCookieExpires.getTime() + (1000 * 60)); //60 minutes

    $.cookies.set(cookieName, '1', { expiresAt: AlertShownCookieExpires });
}