//document.observe("dom:loaded", wireup);
Event.observe(window, 'load', wireup);

var Application = {
    init: function() {
        Application.SlidingPanels = new Spry.Widget.SlidingPanels("SlidingPanels1", { duration: 1500 });
        Application.BASE_TITLE = 'Merrill Lynch - ';
        Application.COOKIE_NAME = 'dontshowMLHelp2flash';
        Application.SECTIONS = $H({ help2achieve: 'Home', help2retire: 'retire comfortably', help2retire: 'retire comfortably', help2care: 'care for my family', help2rebuild: 'rebuild my portfolio', help2know: 'stay informed about the markets', help2transfer: 'transfer wealth and values', help2grow: 'grow my business', help2imagine: 'live my dreams' });

        var url = window.location.search.toLowerCase().toQueryParams();
        var target;

        if (document.location.hash.split('#') != '' && document.location.hash.split('#') != undefined) {
            target = document.location.hash.split('#')[1].toLowerCase();
            Application.deepLinkProcessor(target);
        } else if (url['initialview'] != undefined) {
            target = url['initialview'];
            Application.deepLinkProcessor(target);
        } else {
            Application.loadDartTag();
        }

        Application.setUpHoverAndClicks();

        var backHomeLink = "<a href=\"#\" onclick=\"Application.SlideToHomePanel();_cmCreatePageviewTag(\'GWIM:Mkt:Investments:TotalMerrill:Help2;HomepageLp\',null, null,\'GWIM:Mkt:Investments:TotalMerrill:Help2\',false,false,null,false,false,null,null,null,null,null,null,null,null,null,null); return false;\" title=\"help2achieve\">help2achieve</a>";

        $$('div.back-to-menu').each(function(element) {
            new Insertion.Top(element, backHomeLink);
        });

        $$('ul.breadcrumb li.active').each(function(element) {
            new Insertion.Top(element, backHomeLink);
        });

    },
    checkToShowHelp2Flash: function() {
        if (GetCookie(Application.COOKIE_NAME) == 'true') {
            showHomePage();
        } else {
            SetCookie(Application.COOKIE_NAME, 'true');
        }
    },
    deepLinkProcessor: function(target) {
        // coremetrics tagging
        switch (target) {
            case "retire":

                window.location = "http://www.totalmerrill.com/TotalMerrill/Pages/help2retire.aspx?mb=1";
                break;
            case "retire1":
                _cmCreatePageviewTag('GWIM:Mkt:Investments:TotalMerrill:Help2;PrintAd', null, null, 'GWIM:Mkt:Investments:TotalMerrill:Help2', false, false, null, false, false, null, null, null, null, null, null, null, null, null, null);

                window.location = "http://www.totalmerrill.com/TotalMerrill/Pages/help2retire.aspx?mb=1";
                break;
            case "retire2":

                window.location = "http://www.totalmerrill.com/TotalMerrill/Pages/help2retire.aspx?mb=1";
                break;
            case "retire3":

                window.location = "http://www.totalmerrill.com/TotalMerrill/Pages/help2retire.aspx?mb=1";
                break;
            case "retire4":

                window.location = "http://www.totalmerrill.com/TotalMerrill/Pages/help2retire.aspx?mb=1";
                break;
            case "retire5":

                window.location = "http://www.totalmerrill.com/TotalMerrill/Pages/help2retire.aspx?mb=1";
                break;
            case "retire6":

                window.location = "http://www.totalmerrill.com/TotalMerrill/Pages/help2retire.aspx?mb=1";
                break;
            case "comethrough":
                _cmCreatePageviewTag('GWIM:Mkt:Investments:TotalMerrill:Help2;CareForMyFamily', null, null, 'GWIM:Mkt:Investments:TotalMerrill:Help2', false, false, null, false, false, null, null, null, null, null, null, null, null, null, null);
                Application.SlideToPanel('help2care');
                break;
            case "rebuild":
                _cmCreatePageviewTag('GWIM:Mkt:Investments:TotalMerrill:Help2;MyPortfolio', null, null, 'GWIM:Mkt:Investments:TotalMerrill:Help2', false, false, null, false, false, null, null, null, null, null, null, null, null, null, null);
                Application.SlideToPanel('help2rebuild');
                break;
            case "know":
                _cmCreatePageviewTag('GWIM:Mkt:Investments:TotalMerrill:Help2;StayOnTopMkts', null, null, 'GWIM:Mkt:Investments:TotalMerrill:Help2', false, false, null, false, false, null, null, null, null, null, null, null, null, null, null);
                Application.SlideToPanel('help2know');
                break;
            case "transferwealth":
                _cmCreatePageviewTag('GWIM:Mkt:Investments:TotalMerrill:Help2;WealthValues', null, null, 'GWIM:Mkt:Investments:TotalMerrill:Help2', false, false, null, false, false, null, null, null, null, null, null, null, null, null, null);
                Application.SlideToPanel('help2transfer');
                break;
            case "grow":
                _cmCreatePageviewTag('GWIM:Mkt:Investments:TotalMerrill:Help2;GrowMyBuz', null, null, 'GWIM:Mkt:Investments:TotalMerrill:Help2', false, false, null, false, false, null, null, null, null, null, null, null, null, null, null);
                Application.SlideToPanel('help2grow');
                break;
            case "imagine":
                _cmCreatePageviewTag('GWIM:Mkt:Investments:TotalMerrill:Help2;MyDreams', null, null, 'GWIM:Mkt:Investments:TotalMerrill:Help2', false, false, null, false, false, null, null, null, null, null, null, null, null, null, null);
                Application.SlideToPanel('help2imagine');
                break;
            case "imagine":
                _cmCreatePageviewTag('GWIM:Mkt:Investments:TotalMerrill:Help2;MyDreams', null, null, 'GWIM:Mkt:Investments:TotalMerrill:Help2', false, false, null, false, false, null, null, null, null, null, null, null, null, null, null);
                Application.SlideToPanel('help2imagine');
                break;
            case "one":
                _cmCreatePageviewTag('GWIM:Mkt:Investments:TotalMerrill:Help2;OneonOneRelationship', null, null, 'GWIM:Mkt:Investments:TotalMerrill:Help2', false, false, null, false, false, null, null, null, null, null, null, null, null, null, null);
                var element = $('first-tab');
                Application.pilars(element);
                break;
            case "advice":
                _cmCreatePageviewTag('GWIM:Mkt:Investments:TotalMerrill:Help2;FinancialAdviceTailored ', null, null, 'GWIM:Mkt:Investments:TotalMerrill:Help2', false, false, null, false, false, null, null, null, null, null, null, null, null, null, null);
                var element = $('second-tab');
                Application.pilars(element);
                break;
            case "insights":
                _cmCreatePageviewTag('GWIM:Mkt:Investments:TotalMerrill:Help2;ResearchInsights', null, null, 'GWIM:Mkt:Investments:TotalMerrill:Help2', false, false, null, false, false, null, null, null, null, null, null, null, null, null, null);
                var element = $('third-tab');
                Application.pilars(element);
                break;
            case "resources":
                _cmCreatePageviewTag('GWIM:Mkt:Investments:TotalMerrill:Help2;BacAndML', null, null, 'GWIM:Mkt:Investments:TotalMerrill:Help2', false, false, null, false, false, null, null, null, null, null, null, null, null, null, null);
                var element = $('fourth-tab');
                Application.pilars(element);
                break;
            default:
                _cmCreatePageviewTag('GWIM:Mkt:Investments:TotalMerrill:Help2;HomepageLp', null, null, 'GWIM:Mkt:Investments:TotalMerrill:Help2', false, false, null, false, false, null, null, null, null, null, null, null, null, null, null);
                Application.SlideToPanel('help2achieve');
                break;
        }
    },
    setUpHoverAndClicks: function() { // Setup hover elements

        $$("#sections-menu a").invoke("observe", "click", function(event) {
            Event.stop(event);
            var element = Event.element(event);

            if (element.up().hasClassName('retire')) {
                //                if (GetCookie('ml-help2retire') == 'retire1') {
                //                    window.location.hash = '#retire1';
                //                    _cmCreatePageviewTag('GWIM:Mkt:Investments:TotalMerrill:Help2;PrintAd', null, null, 'GWIM:Mkt:Investments:TotalMerrill:Help2', false, false, null, false, false, null, null, null, null, null, null, null, null, null, null);
                //                    setPromoParam('retire1');
                //                }
                //                else if (GetCookie('ml-help2retire') == 'retire2') {
                //                    window.location.hash = '#retire2';
                //                    _cmCreatePageviewTag('GWIM:Mkt:Investments:TotalMerrill:Help2;DirectMail', null, null, 'GWIM:Mkt:Investments:TotalMerrill:Help2', false, false, null, false, false, null, null, null, null, null, null, null, null, null, null);
                //                    setPromoParam('retire2');
                //                }
                //                else if (GetCookie('ml-help2retire') == 'retire3') {
                //                    window.location.hash = '#retire3';
                //                    _cmCreatePageviewTag('GWIM:Mkt:Investments:TotalMerrill:Help2;OLA', null, null, 'GWIM:Mkt:Investments:TotalMerrill:Help2', false, false, null, false, false, null, null, null, null, null, null, null, null, null, null);
                //                    setPromoParam('retire3');
                //                }
                //                else if (GetCookie('ml-help2retire') == 'retire4') {
                //                    window.location.hash = '#retire4';
                //                    _cmCreatePageviewTag('GWIM:Mkt:Investments:TotalMerrill:Help2;Dotcom', null, null, 'GWIM:Mkt:Investments:TotalMerrill:Help2', false, false, null, false, false, null, null, null, null, null, null, null, null, null, null);
                //                    setPromoParam('retire4');
                //                }
                //                else if (GetCookie('ml-help2retire') == 'retire5') {
                //                    window.location.hash = '#retire5';
                //                    _cmCreatePageviewTag('GWIM:Mkt:Investments:TotalMerrill:Help2;PaidSrch', null, null, 'GWIM:Mkt:Investments:TotalMerrill:Help2', false, false, null, false, false, null, null, null, null, null, null, null, null, null, null);
                //                    setPromoParam('retire5');
                //                }
                //                else if (GetCookie('ml-help2retire') == 'retire6') {
                //                    window.location.hash = '#retire6';
                //                    _cmCreatePageviewTag('GWIM:Mkt:Investments:TotalMerrill:Help2;IRAStatement', null, null, 'GWIM:Mkt:Investments:TotalMerrill:Help2', false, false, null, false, false, null, null, null, null, null, null, null, null, null, null);
                //                    setPromoParam('retire6');
                //                }
                //                else {
                //                    window.location.hash = '#retire';
                //                    _cmCreatePageviewTag('GWIM:Mkt:Investments:TotalMerrill:Help2;Natural', null, null, 'GWIM:Mkt:Investments:TotalMerrill:Help2', false, false, null, false, false, null, null, null, null, null, null, null, null, null, null);
                //                    setPromoParam('retire');
                //                }

                //                Application.SlideToPanel('help2retire');

  _cmCreatePageviewTag('GWIM:Mkt:Investments:TotalMerrill:Help2;TMHome', null, null, 'GWIM:Mkt:Investments:TotalMerrill:Help2', false, false, null, false, false, null, null, null, null, null, null, null, null, null, null);
                window.location = "http://www.totalmerrill.com/TotalMerrill/Pages/help2retire.aspx?mb=1";
				
            }
            else if (element.up().hasClassName('comethrough')) {
                window.location.hash = '#comethrough';
                _cmCreatePageviewTag('GWIM:Mkt:Investments:TotalMerrill:Help2;CareForMyFamily', null, null, 'GWIM:Mkt:Investments:TotalMerrill:Help2', false, false, null, false, false, null, null, null, null, null, null, null, null, null, null);
                Application.SlideToPanel('help2care');
            }
            else if (element.up().hasClassName('rebuild')) {
                window.location.hash = '#rebuild';
                _cmCreatePageviewTag('GWIM:Mkt:Investments:TotalMerrill:Help2;MyPortfolio', null, null, 'GWIM:Mkt:Investments:TotalMerrill:Help2', false, false, null, false, false, null, null, null, null, null, null, null, null, null, null);
                Application.SlideToPanel('help2rebuild');
            }
            else if (element.up().hasClassName('know')) {
                window.location.hash = '#know';
                _cmCreatePageviewTag('GWIM:Mkt:Investments:TotalMerrill:Help2;StayOnTopMkts', null, null, 'GWIM:Mkt:Investments:TotalMerrill:Help2', false, false, null, false, false, null, null, null, null, null, null, null, null, null, null);
                Application.SlideToPanel('help2know');
            }
            else if (element.up().hasClassName('transferwealth')) {
                window.location.hash = '#transferwealth';
                _cmCreatePageviewTag('GWIM:Mkt:Investments:TotalMerrill:Help2;WealthValues', null, null, 'GWIM:Mkt:Investments:TotalMerrill:Help2', false, false, null, false, false, null, null, null, null, null, null, null, null, null, null);
                Application.SlideToPanel('help2transfer');
            }
            else if (element.up().hasClassName('grow')) {
                window.location.hash = '#grow';
                _cmCreatePageviewTag('GWIM:Mkt:Investments:TotalMerrill:Help2;GrowMyBuz', null, null, 'GWIM:Mkt:Investments:TotalMerrill:Help2', false, false, null, false, false, null, null, null, null, null, null, null, null, null, null);
                Application.SlideToPanel('help2grow');
            }
            else if (element.up().hasClassName('imagine')) {
                window.location.hash = '#imagine';
                _cmCreatePageviewTag('GWIM:Mkt:Investments:TotalMerrill:Help2;MyDreams', null, null, 'GWIM:Mkt:Investments:TotalMerrill:Help2', false, false, null, false, false, null, null, null, null, null, null, null, null, null, null);
                Application.SlideToPanel('help2imagine');
            }
            else {
                window.location.hash = '#home';
                _cmCreatePageviewTag('GWIM:Mkt:Investments:TotalMerrill:Help2;HomepageLp', null, null, 'GWIM:Mkt:Investments:TotalMerrill:Help2', false, false, null, false, false, null, null, null, null, null, null, null, null, null, null);
                Application.SlideToPanel('help2achieve');
            }

            return false;

        });

        $$('div.back-to-menu a').invoke("observe", "click", function(event) {
            Event.stop(event);
            Application.SlideToHomePanel();
        });

        $$('ul.breadcrumb li.active a').invoke("observe", "click", function(event) {
            Event.stop(event);
            Application.SlideToHomePanel();
        });

        $$('#wycefs > li').invoke("observe", "click", function(event) {

            var element = Event.element(event);

            if (element.id != 'first-tab' && element.id != 'second-tab' && element.id != 'third-tab' && element.id != 'fourth-tab') {
                element = element.up();
            }

            if (element.hasClassName('active')) {
                return false;
            }

            //hide all body
            $('first-tab-body', 'second-tab-body', 'third-tab-body', 'fourth-tab-body').invoke('hide');
            $$('#wycefs > li').invoke("removeClassName", "active");

            createVideoPlayer();

            // wire up coremetrics
            if (element.id == 'first-tab') {
                window.location.hash = '#one';
                _cmCreatePageviewTag('GWIM:Mkt:Investments:TotalMerrill:Help2;OneonOneRelationship', null, null, 'GWIM:Mkt:Investments:TotalMerrill:Help2', false, false, null, false, false, null, null, null, null, null, null, null, null, null, null);
            } else if (element.id == 'second-tab') {
                window.location.hash = '#advice';
                _cmCreatePageviewTag('GWIM:Mkt:Investments:TotalMerrill:Help2;FinancialAdviceTailored ', null, null, 'GWIM:Mkt:Investments:TotalMerrill:Help2', false, false, null, false, false, null, null, null, null, null, null, null, null, null, null);
            } else if (element.id == 'third-tab') {
                window.location.hash = '#insights';
                _cmCreatePageviewTag('GWIM:Mkt:Investments:TotalMerrill:Help2;ResearchInsights', null, null, 'GWIM:Mkt:Investments:TotalMerrill:Help2', false, false, null, false, false, null, null, null, null, null, null, null, null, null, null);
            } else {
                window.location.hash = '#resources';
                _cmCreatePageviewTag('GWIM:Mkt:Investments:TotalMerrill:Help2;BacAndML', null, null, 'GWIM:Mkt:Investments:TotalMerrill:Help2', false, false, null, false, false, null, null, null, null, null, null, null, null, null, null);
            }

            Application.pilars(element);
            Application.loadDartTag();
        });

        $$('a.lnkFinancialAdvisor').each(function(element) {
            element.hover(
                function() { element.up(0).addClassName('hover'); },
                function() { element.up(0).removeClassName('hover'); }
            );
        });

        $$('#sections-menu').each(function(element) {
            element.hover(
                function() { element.down(0).removeClassName('init'); },
                function() { element.down(0).addClassName('init'); }
            );
        });

        $$('#sections-menu div.pngfix').each(function(element) {
            element.hover(
                function() {
                    if (element.hasClassName('retire')) {
                        element.addClassName('hover2');
                    } else {
                        element.addClassName('hover');
                    }
                },
                function() {
                    if (element.hasClassName('retire')) {
                        element.removeClassName('hover2');
                    } else {
                        element.removeClassName('hover');
                    }
                }
            );
        });

        $$('#wycefs > li').each(function(element) {
            element.hover(
                function() { element.addClassName('hover'); },
                function() { element.removeClassName('hover'); }
            );
        });

        $$('ul.list-help2 li').each(function(element) {
            element.hover(
                function() { element.addClassName('hover'); },
                function() { element.removeClassName('hover'); }
            );
        });

        $$('#articlePDFs div.material_download a').invoke("observe", "click", function() {
            _cmCreatePageviewTag('GWIM:Mkt:Investments:TotalMerrill:Help2;DirectMailPDF', null, null, 'GWIM:Mkt:Investments:TotalMerrill:Help2', false, false, null, false, false, null, null, null, null, null, null, null, null, null, null);
        });

        $$('#articlePDFs div.white_paper_download a').invoke("observe", "click", function() {
            _cmCreatePageviewTag('GWIM:Mkt:Investments:TotalMerrill:Help2;RetirementWhitePDF', null, null, 'GWIM:Mkt:Investments:TotalMerrill:Help2', false, false, null, false, false, null, null, null, null, null, null, null, null, null, null);
        });

        $$('#articlePDFs #roth_download').invoke("observe", "click", function() {
            cmCreateManualPageviewTag('GWIM:Mkt:Investments:TotalMerrill:Help2;RothConvWpFinal', 'GWIM:Mkt:Investments:TotalMerrill:Help2', 'http://www.totalmerrill.com/publish/mkt/pdfs/409401PM1109RothConvWP_FINAL.pdf', 'http://www.totalmerrill.com/TotalMerrill/Pages/help2.aspx?initialview=retire6');
        });

    },
    pilars: function(element) {

        if ($('wycefs').hasClassName('expand')) {
            element.addClassName('active');
            $(element.id + "-body").setStyle({ display: 'block' });
            return false;

        } else {
            $('main-nav-block').setStyle({ visibility: 'visible' });
            $('wycefs').addClassName("expand");
            element.addClassName("active");
            $(element.id + "-body").show();
            $('wycefs-footer').show();
            var expand = $$('.container.home-page .bottom-box');
            if (expand.size() > 0) {
                new Effect.Move(expand[0],
                {
                    x: 0,
                    y: -385,
                    duration: 0.75,
                    beforeStart: function() {
                        new Effect.Opacity('main-nav-block', { from: 1.0, to: 0, duration: 0.5 });
                        new Effect.Opacity('sections-menu', { from: 1.0, to: 0, duration: 0.5 });
                        new Effect.toggle("btn-close", 'Appear', { duration: 0.25 });
                        new Effect.Morph('SlidingPanels1', { style: 'height:880px', duration: 1.5 });
                        new Effect.Morph('organic-page-wrapper', { style: 'height:880px', duration: 0.5 });
                    },
                    afterFinish: function() { }
                });
            }
        }

    },
    loadDartTag: function() {
        var url = window.location.search.toLowerCase().toQueryParams();
        var target;

        if (document.location.hash.split('#') != '' && document.location.hash.split('#') != undefined) {
            target = document.location.hash.split('#')[1].toLowerCase();
        } else if (url['initialview'] != undefined) {
            target = url['initialview'];
        }

        var axel = Math.random() + "";
        var a = axel * 10000000000000;

        // dart tags
        if (target != undefined) {
            switch (target) {
                case "retire":
                    $('DartFrame').src = "http://fls.doubleclick.net/activityi;src=1359940;type=sdlpb511;cat=mlcd1115;ord=1;num=" + a + "?";
                    break;
                case "retire1":
                    $('DartFrame').src = "http://fls.doubleclick.net/activityi;src=1359940;type=sdlpb511;cat=mlcd1115;ord=1;num=" + a + "?";
                    break;
                case "retire2":
                    $('DartFrame').src = "http://fls.doubleclick.net/activityi;src=1359940;type=sdlpb511;cat=mlcd1115;ord=1;num=" + a + "?";
                    break;
                case "retire3":
                    $('DartFrame').src = "http://fls.doubleclick.net/activityi;src=1359940;type=sdlpb511;cat=mlcd1115;ord=1;num=" + a + "?";
                    break;
                case "retire4":
                    $('DartFrame').src = "http://fls.doubleclick.net/activityi;src=1359940;type=sdlpb511;cat=mlcd1115;ord=1;num=" + a + "?";
                    break;
                case "retire5":
                    $('DartFrame').src = "http://fls.doubleclick.net/activityi;src=1359940;type=sdlpb511;cat=mlcd1115;ord=1;num=" + a + "?";
                    break;
                case "retire6":
                    $('DartFrame').src = "http://fls.doubleclick.net/activityi;src=1359940;type=sdlpb511;cat=mlcd1115;ord=1;num=" + a + "?";
                    break;
                case "comethrough":
                    $('DartFrame').src = "http://fls.doubleclick.net/activityi;src=1359940;type=sdlpb511;cat=mlcd1207;ord=1;num=" + a + "?";
                    break;
                case "rebuild":
                    $('DartFrame').src = "http://fls.doubleclick.net/activityi;src=1359940;type=sdlpb511;cat=mlcd1465;ord=1;num=" + a + "?";
                    break;
                case "know":
                    $('DartFrame').src = "http://fls.doubleclick.net/activityi;src=1359940;type=sdlpb511;cat=mlcd1194;ord=1;num=" + a + "?";
                    break;
                case "transferwealth":
                    $('DartFrame').src = "http://fls.doubleclick.net/activityi;src=1359940;type=sdlpb511;cat=mlcd1561;ord=1;num=" + a + "?";
                    break;
                case "grow":
                    $('DartFrame').src = "http://fls.doubleclick.net/activityi;src=1359940;type=sdlpb511;cat=mlcd1816;ord=1;num=" + a + "?";
                    break;
                case "imagine":
                    $('DartFrame').src = "http://fls.doubleclick.net/activityi;src=1359940;type=sdlpb511;cat=mlcd1385;ord=1;num=" + a + "?";
                    break;
                case "one":
                    $('DartFrame').src = "http://fls.doubleclick.net/activityi;src=1359940;type=sdlpb511;cat=mlcd1851;ord=1;num=" + a + "?";
                    break;
                case "advice":
                    $('DartFrame').src = "http://fls.doubleclick.net/activityi;src=1359940;type=sdlpb511;cat=mlcd1431;ord=1;num=" + a + "?";
                    break;
                case "insights":
                    $('DartFrame').src = "http://fls.doubleclick.net/activityi;src=1359940;type=sdlpb511;cat=mlcd1383;ord=1;num=" + a + "?";
                    break;
                case "resources":
                    $('DartFrame').src = "http://fls.doubleclick.net/activityi;src=1359940;type=sdlpb511;cat=mlcd1783;ord=1;num=" + a + "?";
                    break;
                default:
                    $('DartFrame').src = "http://fls.doubleclick.net/activityi;src=1359940;type=sdlpb511;cat=mlcd1164;ord=1;num=" + a + "?";
                    break;
            }
        } else {
            $('DartFrame').src = "http://fls.doubleclick.net/activityi;src=1359940;type=sdlpb511;cat=mlcd1164;ord=1;num=" + a + "?";
        }


    },
    SlideToPanel: function(id) {
        $$('div.SlidingPanelsContentGroup div.container').invoke('hide');
        $$('div.container.home-page').invoke('show');
        $(id).show();
        Application.SlidingPanels.showPanel(id);
        document.title = Application.BASE_TITLE + Application.SECTIONS[id];

        if (id == 'help2rebuild') {
            new Effect.Appear('help2rebuild-footer');
        }

        Application.loadDartTag();
    },
    SlideToHomePanel: function() {
        window.location.hash = '#home';
        Application.SlidingPanels.showPanel('help2achieve');
        document.title = Application.BASE_TITLE + Application.SECTIONS['help2achieve'];

        new Effect.Fade('help2rebuild-footer');

        Application.loadDartTag();
    }
}

function ClosePage() {

    _cmCreatePageviewTag('GWIM:Mkt:Investments:TotalMerrill:Help2;HomepageLp', null, null, 'GWIM:Mkt:Investments:TotalMerrill:Help2', false, false, null, false, false, null, null, null, null, null, null, null, null, null, null);

    var expand = $$('.container.home-page .bottom-box');
    if (expand.size() > 0) {
        new Effect.Morph('SlidingPanels1',
        {
            style: 'height:755px',
            duration: 0.5,
            afterFinish: function() {
                new Effect.Morph('organic-page-wrapper', { style: 'height:755px', duration: 0.5 });
            }
        });
        new Effect.toggle("btn-close", 'Appear', { duration: 0.25 });
        new Effect.Move(expand[0],
        {
            x: 0,
            y: 385,
            duration: 0.5,
            beforeStart: function() { },
            afterFinish: function() {
                new Effect.Morph('SlidingPanels1', { style: 'height:755px', duration: 1.5 });

                $('first-tab-body', 'second-tab-body', 'third-tab-body', 'fourth-tab-body').invoke('hide');
                $('wycefs').removeClassName("expand");
                $$('#wycefs > li').invoke('removeClassName', 'hover');
                $$('#wycefs > li').invoke('removeClassName', 'active');
                $('wycefs-footer').hide();
            }
        });

        new Effect.Opacity('main-nav-block', { from: 0, to: 1.0, duration: 0.50 });
        new Effect.Opacity('sections-menu', { from: 0, to: 1.0, duration: 0.50 });
        $('main-nav-block').setStyle({ visibility: 'visible' });
    }
    
    removePlayerFromPilar();
}

function showHomePage() {
    $('SlidingPanels1').setStyle({ visibility: 'visible' });
    $('main-flash-wrapper').hide();
}


function wireup() {
    Application.init();
    
    var customHeight = 699; //default setting
    $$('.custom_modal').each(function(element) {
        new Control.Modal(element, { width: 870, height: customHeight, containerClassName: 'custom_modal_container', overlayClassName: 'custom_modal_overlay', /*position: 'absolute',*/iframe: true });
    });
    
}

function _cmCreatePageviewTag(PAGEID, a, b, CATID, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q) {
    try {
        //alert("PageID: " + PAGEID + " CATID: " + CATID);
        cmCreatePageviewTag(PAGEID, null, null, CATID, false, false, null, false, false, null, null, null, null, null, null, null, null, null, null);
    } catch (Error) {
        //alert(Error);
    }
}



// Create a cookie with the specified name and value.
function SetCookie(name, value) {
    document.cookie = name + "=" + escape(value);
    // Expires the cookie
    //var date = new Date
    //date.setDate(date.getDate());
    document.cookie += (";path=/;");
    
}

// Retrieve the value of the cookie with the specified name.
function GetCookie(name) {
    // cookies are separated by semicolons
    var aCookie = document.cookie.split("; ");
    for (var i = 0; i < aCookie.length; i++) {
        // a name/value pair (a crumb) is separated by an equal sign
        var aCrumb = aCookie[i].split("=");
        if (name == aCrumb[0])
            return unescape(aCrumb[1]);
    }
    // a cookie with the requested name does not exist
    return null;
}

function showFindAdvisorPopup(passurl) {
	var popup = window.open(passurl, "popup", "menubar=0,toolbar=0,location=0,status=0,scrollbars=1,height=640,width=980");
	popup.focus();
	popup.moveTo(0,0);
	return false;
}

function setPromoParam(paramVal) {
    
    $('roth_download').show();
    
	switch (paramVal) {
		case "retire":
			//$('findAdvisor').href = "#"+paramVal;
			$('findAdvisor').rel = "http://www.totalmerrill.com/TotalMerrill/Pages/help2retire_8885237002.aspx?confirm=help2retire_8885237002_confirm";
			break;
		case "retire1":
			//$('findAdvisor').href = "#"+paramVal;
			$('findAdvisor').rel = "http://www.totalmerrill.com/TotalMerrill/Pages/help2retire_8668201493.aspx?confirm=help2retire_8668201493_confirm";
			break;
		case "retire2":
			//$('findAdvisor').href = "#"+paramVal;
			$('findAdvisor').rel = "http://www.totalmerrill.com/TotalMerrill/Pages/help2retire_8663654279.aspx?confirm=help2retire_8663654279_confirm";
			$('roth_download').hide();
			$('material_download').show();
			break;
		case "retire3":
			//$('findAdvisor').href = "#"+paramVal;
			$('findAdvisor').rel = "http://www.totalmerrill.com/TotalMerrill/Pages/help2retire_8666729096.aspx?confirm=help2retire_8666729096_confirm";
			break;
		case "retire4":
			//$('findAdvisor').href = "#"+paramVal;
			$('findAdvisor').rel = "http://www.totalmerrill.com/TotalMerrill/Pages/help2retire_8666379325.aspx?confirm=help2retire_8666379325_confirm";
			break;
		case "retire5":
			//$('findAdvisor').href = "#"+paramVal;
			$('findAdvisor').rel = "http://www.totalmerrill.com/TotalMerrill/Pages/help2retire_8665406101.aspx?confirm=help2retire_8665406101_confirm";
			break;
        case "retire6":
            $('findAdvisor').rel = "http://www.totalmerrill.com/TotalMerrill/Pages/help2retire_8668201306.aspx?confirm=help2retire_8668201306_confirm";
            break;
		default: 
			//$('findAdvisor').href = "#"+paramVal;
			$('findAdvisor').rel = "http://www.totalmerrill.com/TotalMerrill/Pages/help2retire_8885237002.aspx?confirm=help2retire_8885237002_confirm";
			break;
	}
}


function popitup(url) {
    newwindow = window.open(url, 'name');
    if (window.focus) { newwindow.focus() }
    return false;
}


