$(document).ready(function() {
    var dhead = $("#dhead");
    var dcontent = $("#dcontent");
    if(dhead.length > 0 && dcontent.length > 0){
        dhead.css('display',"block");
        dcontent.css('display',"block");
        /* ----[  ### set up effects */
        //var dashboardRollup = $("#dbody").effect('height', {duration: 1000});
        /* ----[  hide the dashboard */

        $('#dbody').css('height',"0px");

        //var findoutRollup = $("#dtopmessexp").effect('height');
        $('#dtopmessexp').css('height',0);

       // var aboutRollup = $("#dtopaboutexp").effect('height', {duration:200});
        $('#dtopaboutexp').css('height',0);

        /* ----[  set onclicks for elements in the dashboard */
        dhead.click( function() {
            var soC = new SWFObject("/web/bhg/flash/dashboard/dashflash.swf?PROFILE_ID="+ mdp.profile.id, "dashflash", "330", "505", "7", "#FFFFFF");
            soC.addParam("quality", "high");
            soC.addParam("wmode", "transparent");
            soC.addVariable("PROFILE_ID", mdp.profile.id);
            soC.addVariable("PROFILE_NAME", mdp.profile.name);
            soC.addVariable("PROFILE_EMAIL", mdp.profile.email);
            soC.addVariable("CURR_CHANNEL", mdp.profile.currChannel);
            soC.addVariable("DEBUG", false);
            soC.write("clippings");

             /* don't hide the button on the gardening channel */
             if(window.location.href.indexOf("gardening") == -1){
                $('#dhead').css('display','none');
             }
             $('#dash').css({
                 'height' : '1000px',
                   'zIndex' :       5000,
                   'overflow' : 'auto'
             });

             try{
             if($('#dleftcontent').length > 0){
                 var dashLeftContentAjax = $.ajax({
                     url:'/common/dashboard/recentclippings.jsp',
                     type:'get',
                     success:function(html){
                         $("#dleftcontent").html(html);
                     }
                 });
             }
             if($('#dpromocontent').length > 0){
                 var dashLeftAjax = $.ajax({
                     url:'/bhg/templates/marketing/dashboardPromo.jsp',
                     type:'get',
                     success:function(html){
                         $("#dpromocontent").html(html);
                     }
                 });
             }
             }catch(e){
               /*  var dashLeftContentAjax = new XHR({method: 'get', onSuccess: function(req){alert('hey')}}).send('/common/dashboard/recentclippings.jsp');
                 var dashLeftAjax = new XHR({method: 'get', onSuccess:  function(req){$('#dpromocontent').innerHTML=req}}).send('/bhg/templates/marketing/dashboardPromo.jsp');*/
                 if(typeof(console.log)!='undefined'){console.log('ajax overwritten! (probably prototype)');}
             }


            $('#dbody').height(1000);
             //dashboardRollup.start(0,1000);

             /* Send reporting event */
            sendLinkEvent('','myBHG:OpenDashboard');

        });/* ----[  opens / closes the dashboard */;


        if($("#dtopclose").length > 0){
            $("#dtopclose").click(function() {
                 //dashboardRollup.start();
              $('#dhead').css('display','block');
             $('#dash').css('height','1px');
             $('#dash').css('zIndex' ,'-1');
        });}

        if($("#dtopideas").length > 0 && $("#dtopaboutyou").length > 0){
            $("#dtopideas").click(function(){ window.location.href = "/bhg/mybhg/"; });

            $("#dtopaboutyou").click (function() {
                openDashAbout();
            });
        };

        $("#dclose").click(function() {
             //dashboardRollup.start();
             $('#dhead').css('display','block');
             $('#dash').css('height','1px');
             $('#dash').css('zIndex' ,'-1');
        }); /* ----[  opens / closes the dashboard */;
            $('#dclose').css('display','block');

        $("#mybhgfindout").click(function() {
             if($('#dtopmessexp').height() != 50){
                 $('#dtopmessexp').css('height','50px');
             }else{
                  $('#dtopmessexp').css('height','0px');
             }
        });

        $("#dtopaboutyou").click(function() {
            if($('#dtopaboutexp').css('display') != "block"){
                $("#dtopaboutexp").css('display',"block");
                $("#dtopaboutexp").click(function() {
                    this.css('display', "none");
                });
            }else{
                 $("#dtopaboutexp").css('display',"block");
            }
        });

        /* ----[  Onclick Functions for the top of the dashboard */
        var openDashAbout = function() {
        // aboutRollup.set(100);
            $('#dtopaboutexp').height(100);
        };

    }
});

