var cookieMainNav='true';
var divWrapMainNav;
var divWrapCalcNav;
var redirectToPage=false;
var cookiePopUp=0;
var popupUrl='http://cheatsheet.mathfinance.com'

//Loads the YUI menu element
function initialize() {

    divWrapMainNav= new switchObj('divWrapMainNav', true);
    divWrapCalcNav= new switchObj('divWrapCalcNav',false);

    //Check cookie for navigation panels and apply corresponding settings
    if(cookieMainNav=='false'){
        createCookie('divWrapMainNav',cookieMainNav,0.5);
    }
    if(cookieMainNav=='true'){
        cookieMainNav = readCookie('divWrapMainNav');
        if (cookieMainNav == null ){
            cookieMainNav='true';
            createCookie('divWrapMainNav',cookieMainNav,0.5);
        }
    }

    if (cookieMainNav=='false') {
        $('divWrapMainNav').hide();
        divWrapMainNav.expanded_=false;
        divWrapCalcNav.expanded_=true;
    }
    else {
        $('divWrapCalcNav').hide();
        divWrapMainNav.expanded_=true;
        divWrapCalcNav.expanded_=false;
    }

    YAHOO.util.Event.onContentReady("productsandservices", function () {

        /*
	         Instantiate a Menu:  The first argument passed to the
	         constructor is the id of the element in the page
	         representing the Menu; the second is an object literal
	         of configuration properties.
	    */

        var oMenu1 = new YAHOO.widget.Menu("productsandservices", {
            position: "static",
            hidedelay:  750,
            lazyload: true
        });

        /*
	         Call the "render" method with no arguments since the
	         markup for this Menu instance is already exists in the page.
	    */

        oMenu1.render();

    });

    YAHOO.util.Event.onContentReady("calculatorNav", function () {

        /*
	         Instantiate a Menu:  The first argument passed to the
	         constructor is the id of the element in the page
	         representing the Menu; the second is an object literal
	         of configuration properties.
	    */

        var oMenu2 = new YAHOO.widget.Menu("calculatorNav", {
            position: "static",
            hidedelay:  750,
            lazyload: true
        });

        /*
	         Call the "render" method with no arguments since the
	         markup for this Menu instance is already exists in the page.
	    */

        oMenu2.render();

    });

    YAHOO.util.Dom.setStyle('divWrapMainNav','height','auto');
    YAHOO.util.Dom.setStyle('divWrapMainNav','visibility','visible');
    YAHOO.util.Dom.setStyle('divWrapCalcNav','height','auto');
    YAHOO.util.Dom.setStyle('divWrapCalcNav','visibility','visible');


    //Execute initialization subroutines of specific pages
    try {
        initializeLevel2();
    } catch (e) {

    }

    /*Check cookie to popup ad window
    cookiePopUp = readCookie('cookiePopUp');
    if (cookiePopUp == null){
        cookiePopUp=0;
        createCookie('cookiePopUp',cookiePopUp,0.4);
    }
    popup();*/

    //initializeSub
    setTimeout("redirect()",4000);

    startScrollTop();
    return;
}

function redirect(){
    //alert(redirectToPage);
    if(redirectToPage!=false){
        window.location=redirectToPage;
    }
}

function popup(){

    if(location.href.search(popupUrl)!=-1) return;

    if(cookiePopUp<2){
        cookiePopUp++;
        createCookie('cookiePopUp',cookiePopUp,0.4);
        var newwindow=window.open(popupUrl,'name','height=800,width=1000');
        if (window.focus && newwindow!=null) {newwindow.focus()}
    }
}