﻿
    Cufon.replace('h1'); 
    Cufon.replace('.cg6');
    Cufon.replace('h2:not(.res):not(.smap)', {hover: true});
    Cufon.replace('h3');
    
    var hoverTimer;
    var hideTimer;
    var transTimer;
    var transTimerOn;
    var navSizerTimer;
    var htTip;
    
    var isIE;
    var isIE6;
    var isGTIE6;
    var isIE7;
    var isIE8;
    var isIE9;
    
    if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){
        isIE = true;
        var ieversion=new Number(RegExp.$1)
        if (ieversion>=9) isIE9 = true;
        else if (ieversion>=8) isIE8 = true;
        else if (ieversion>=7) isIE7 = true;
        else if (ieversion>=6) isIE6 = true;
    }
    
    if (isIE && !isIE6) {isGTIE6 = true;}
    
    function setSelectedTabs(tab) {
        
        $(".selected").removeClass("selected");
        var clickedTabID = tab.attr("id");     
        tab.parent().find(".tab").each(function() {
            $(this).addClass("selected");
            if (clickedTabID == $(this).attr("id")) {
                return false;
            }
        });
          
    }
    
    function setActiveTab(tab, dock) {
    
        if (tab.hasClass("active_tab")) {
            $(".active_tab").find("span.close").hide();  
            $(".active_tab").find("span.title").show();
            return false;
        }
        
        $(".active_tab").find("span.close").hide();  
        $(".active_tab").find("span.title").show(); 
        $(".active_tab").removeClass("active_tab");
        
        tab.addClass("active_tab");
        $(".active_tab").find("span.title").hide();
        $(".active_tab").find("span.close").show();   
        
//        $.ajax({
//            type: 'POST',
//            url: "/sessions.aspx",
//            data: "which=tab&id=" + tab.attr("id").replace("tab_", "")
//        });
        
    }
    
    function manageDock(tab) {
        
        
        var dock = $("#slideDock");
        var height = 32;
        var resizeTo = "190px";
        
        if (tab == undefined) {
            animateTimer = setTimeout(function() { animateDock(dock, null, height, false, resizeTo) },35);
            $(".active_tab").removeClass("active_tab");
            return false;
        } 
        
        var dockPanel = $("#dock_panel_" + tab.attr("id"));
        
        setSelectedTabs(tab);
        setActiveTab(tab, dock);

        if (dock.hasClass("closed")) {
            $("#slideDock").css("margin-left", "auto").css("width", calcWidth + "px");
            height = 167;
            resizeTo = "100px";
            dock.removeClass("closed");
            animateTimer = setTimeout(function() { animateDock(dock, tab, height, true, resizeTo) },35);
            dockPanel.show().addClass("active_dock");
        }
        else {
            if (dockPanel.hasClass("active_dock")) {
//                $.ajax({
//                    type: 'POST',
//                    url: "/sessions.aspx",
//                    data: "which=closetab"
//                });
                animateTimer = setTimeout(function() { animateDock(dock, tab, height, false, resizeTo, dockPanel) },35);
               dockPanel.hide().removeClass("active_dock");
                tab.removeClass("active_tab");
            }
            else {
                $(".active_dock").hide().removeClass("active_dock");
                dockPanel.show().addClass("active_dock");
            }
        }
    }
    
    var tabOpenTimer;
    var tabCloseTimer;

    $(function(){
    
        // dropdown selector
        
        if ($("#country").length > 0)
        {
            var domain = document.domain;
            if (domain.toLowerCase() == "vispring-ml-staging-en-us.conrandesigngroup.com" || domain.toLowerCase() == "www.vispring.com") {
                $(".map_search #country").val("USA");
		$(".forms #country").val("United States");
            }

        }
    
        $(".current_id_088f941db67c4c40adc0a65b9b2f98d5 #body").css("background-color","#daddcc");
        
        $("#cultureSelect").mouseenter(function(){
            $(this).hide();
            $("#culturePicker").show();
        });

        $("#culturePicker").mouseleave(function()
        {
	     	     $(this).hide();
            $("#cultureSelect").show();
        });
          
	    toggleInfoPanel(true);   
	    
	    sizerTimer = setTimeout(function() { sizer(true) },75);

	    $(".accordion .control").gtaccordion();
	    
	    $("#dockControl .tab").click(function() {
            manageDock($(this));
        });

//        $("#dockControl .tab").mouseenter(function() {
//            var tab = $(this);
//            if ($(this).hasClass("active_tab")) return false;
//            tabOpenTimer = setTimeout(function() { 
//                manageDock(tab);
//            },100);
//        }); 
//  
//        $("#dockControl .tab").mouseleave(function() {
//            clearTimeout(tabOpenTimer);
//        });       

//        $("#slideDock").mouseleave(function() {
//            tabCloseTimer = setTimeout(function() { 
//                manageDock();
//            },1250);
//        });  
//        
//        $("#slideDock").mouseenter(function() {
//            clearTimeout(tabCloseTimer);
//        }); 

        if ($(".forceOpen").length > 0) {
            $(".forceOpen").addClass("active");
            $(".forceOpen").width($(".forceOpen .content").width());
        }
        
        $(".searchTrigger").mouseenter(function() {
            $("#header-tools").css("visibility", "hidden");
            $(".search_box").show();
        });  
        
        $(".search_box").mouseleave(function() {
            $("#header-tools").css("visibility", "visible");
            $(".search_box").hide();
        });  
        
            var ua = navigator.userAgent; 
            var isiPad = /iPad/i.test(ua) || /iPhone OS 3_1_2/i.test(ua) || /iPhone OS 3_2_2/i.test(ua);
            if (isiPad) {
                
                $(".baseLeft").click(function() { 
                    triggerTimer = setTimeout(function() { go($(".baseLeft .control")) },200);  
                });  
                
            }
            else {
            
        $(".baseLeft").mouseenter(function() {
            if ($(this).find(".active").length > 0) {
                clearTimeout(triggerTimer);
                triggerTimer = null;
                clearTimeout(hideTimer);
                hideTimer = null;
                return false;
            }
            triggerTimer = setTimeout(function() { go($(".baseLeft .control")) },200);  
        });  

        $(".baseLeft").mouseleave(function() {
            if ($(this).find(".active").length > 0) {
                triggerTimer = setTimeout(function() { go($(".baseLeft .control")) },200);  
                return false;
            }
            clearTimeout(triggerTimer);
            triggerTimer = null;
        }); 
            
            }
        

        
        var txt_holder = "";
        
        $(".dock_thumb.inactive").mouseenter(function() {
          $(".dock_thumb:not(.inactive)").addClass("inactive");
        });
        
        function isHoverFade(Object) {
            if (Object.parents(".hoverFade").length > 0) {
                return true;
            }
            return false;
        }
        
        $('.dock_thumb.inactive, .dock_thumb.hoverOn').live('mouseenter mouseleave', function(event) {
            if (event.type == 'mouseenter') {
                if (!isHoverFade($(this))) {
                    $("h2.dock_swap span").text($(this).find("img").attr("alt")); 
                    return false;
                }
                clearTimeout(transTimer);
                clearTimeout(transTimerOn);
                $("h2.dock_swap span").text($(this).find("img").attr("alt")); 
                $(this).fadeTo(100, 1, function() {});
                
                $(this).addClass("active");
                transTimerOn = setTimeout(function() { 
                    $(".dock_thumb:not(.active)").fadeTo(500, 0.5, function() {});
                },25);
            };
            if (event.type == 'mouseleave') {
                if (!isHoverFade($(this))) {
                    return false;
                }
                $(this).removeClass("active");
                clearTimeout(transTimerOn);
                transTimer = setTimeout(function() { 
                    $(".dock_thumb").fadeTo(70, 1, function() {
                      // Animation complete.
                    });
                 },10);  
            };
            return false;
        });

        $(".accordion").click(function() {
          clearTimeout(hideTimer);
          hideTimer = null;
        });
        
        $(document).click(function() {
            toggleToolTip();
        });
                
        $(".readmore img, .blogTrigger").click(function() {
            var id = $(this).attr('id').replace("blog_id_", ""); 
            openBlog(id);
            $(document).scrollTop(0);

            
        }); 
        
       $('.article_close').live('click', function(event) {
            $("#sleep_detail").hide();
            $("#overlay").fadeTo(750, 0, function() {
              $("#overlay").css("height", "100%");
              $("#overlay").hide();
              $("#sleep_detail").html("");
              $("#sleep_detail").removeClass("active");
              $("#body").removeClass("active");
            });
            return false;
        });
        
//       $('body').live('click', function(event) {
//       alert("click");
//            if ($(".baseLeft .active .control").length == 0) {
//                alert("no");
//                return false;
//            }
//               
//                alert("yes");
//            var ua = navigator.userAgent; 
//            var isiPad = /iPad/i.test(ua) || /iPhone OS 3_1_2/i.test(ua) || /iPhone OS 3_2_2/i.test(ua);
//            if (isiPad) {
//                go($(".baseLeft .control"));
//            }
//        });
        
        var mouse_is_inside;
        
       $('#sleep_detail').hover(function(){          
            mouse_is_inside=true;      
       }, function(){          
            mouse_is_inside=false;      
       }); 
        
       $("body").live('click', function(event) {
            if ($("#sleep_detail.active").length > 0) {
                if (!mouse_is_inside) {
                $("#sleep_detail").hide();
                $("#overlay").fadeTo(750, 0, function() {
                  $("#overlay").css("height", "100%");
                  $("#overlay").hide();
                  $("#sleep_detail").html("");
                  $("#sleep_detail").removeClass("active");
                  $("#body").removeClass("sleeping");
                });
                return false;
                }
            }
            
        });
        
        $(".dress tr").click(function() {
              
              $(".dress input").removeClass("checked").attr('checked', false);
              
              var radio = $(this).find("input");
              if ($(radio).hasClass("checked")) {
                $(radio).removeClass("checked");
                $(radio).attr('checked', false);
              }
              else {
                $(radio).addClass("checked");
                $(radio).attr('checked', true);
              }
              var imagePath = $(radio).attr("rel");
              var id = $(radio).attr("id");
              if (imagePath != undefined) {
                    $("#scaler img").attr("src", imagePath); 
              }
        });
        
        $(".bg_switcher").click(function() {
              var imagePath = $(this).attr("rel");
              var id = $(this).attr("id");
              if (imagePath != undefined) {
                var clicked = $(this).parent();
                clicked.addClass("loading");
                var t; //create an img so the browser will download the image:   
                t = $('<img />')     
                .attr('src', imagePath)     
                .load(function(){ //attach onload to set background-image      
                        setTimeout(function(){clearLoader(t, clicked, imagePath)},750);  
                 });  
             
              }
              if ($(this).hasClass("swatches")) {
                 $("td .active").removeClass("active");
                 $(this).parent().addClass("active");
              }
        });
        
        // tipTop tooltip
        $('.toolTip').live('mouseenter mouseleave', function(event) {
        
            var ua = navigator.userAgent; 
            var isiPad = /iPad/i.test(ua) || /iPhone OS 3_1_2/i.test(ua) || /iPhone OS 3_2_2/i.test(ua);
            if (isiPad) return false;
            if (event.type == 'mouseenter') {
                clearTimeout(htTip);
                var Object = $(this);
                var tip = Object.attr("alt");
                htTip = setTimeout(function(){toolTip(Object, tip)},100);
            };
            if (event.type == 'mouseleave') {
                toggleToolTip();
                clearTimeout(htTip);
            };
            return false;
        });
               
        $(".article_close").click(function() {
            $("#sleep_detail").hide();
            $("#overlay").fadeTo(750, 0, function() {
              $("#overlay").css("height", "100%");
              $("#overlay").hide();
              $("#body").removeClass("sleeping");
            });
        }); 

        if ($("#materials").length > 0) {
            $.ajax({
                url: "/ajax/materials.aspx",
                success: function(data) {
                    $("#materials").html(data);
                             $(".materials_cell").mouseenter(function() {
            var material = $(this);
            material.find(".banner").animate(
                { height: '157px' }, // what we are animating
                {
                duration: openSpeed, // how fast we are animating
                easing: 'easeInOutQuad', // the type of easing
                complete: function() { // the callback
                    //material.find(".banner p").show();
                }
            });
        });  
        
        $(".materials_cell").mouseleave(function() {
            var material = $(this);
            //material.find(".banner p").hide();
            material.find(".banner").animate(
                { height: '12px' }, // what we are animating
                {
                duration: openSpeed, // how fast we are animating
                easing: 'easeInOutQuad', // the type of easing
                complete: function() { // the callback
                    
                }
            });
        });  
                }
            });
        }
       
        $('#gSearch').keypress(function(e){       
            if(e.which == 13){        
                doGSearch();
                e.preventDefault();   
            }       
        });

        $(".submit").click(function(e) {
            e.preventDefault();
            if ($("#txtSearch").val() != "") {
                window.location.href = "/page.aspx?pointerid=1ab6d06a798a447fa86e59bc7449fffb&searchText=" + $("#txtSearch").val();
            }
        }); 
        
        $('#txtSearch').keypress(function(e){       
            if(e.which == 13){        
                if ($("#txtSearch").val() != "") {
                    window.location.href = "/page.aspx?pointerid=1ab6d06a798a447fa86e59bc7449fffb&searchText=" + $("#txtSearch").val();
                }
                e.preventDefault();     
            }       
        });
        
        $("body").keypress(function(e){       
            if(e.which == 13){        
                e.preventDefault();   
            }       
        });

       
        if ($(".doCompare .switch").length > 0) {
            $.ajax({
                url: "/ajax/compare.aspx",
                data: "id=" + $(".baseOptions").attr("id").replace("bed_ID_", ""),
                success: function(data) {
                    $(".doCompare .switch").html(data);
                }
            });
        }
        
        if ($("#sitemap").length > 0) {
            $.ajax({
                url: "/ajax/sitemap.aspx",
                success: function(data) {
                    $("#sitemap").html(data);
                }
            });
        }
        
        if ($(".comparison-table").length > 0) {
            $.ajax({
                url: "/ajax/compareTable.aspx",
                success: function(data) {
                    $(".comparison-table").html(data);
                }
            });
        }
        
        if ($("#guarantee").length > 0) {
            $.ajax({
                url: "/ajax/guarantee.aspx",
                success: function(data) {
                    $("#guarantee").html(data);
                    $(".accordion .control").gtaccordion();
        if ($("#country").length > 0)
        {
            var domain = document.domain;
            if (domain.toLowerCase() == "vispring-ml-staging-en-us.conrandesigngroup.com" || domain.toLowerCase() == "www.vispring.com") {
		$(".forms #country").val("United States");
            }

        }
                }
            });
        }
        
        if ($("#brochure").length > 0) {
            $.ajax({
                url: "/ajax/brochure.aspx",
                success: function(data) {
                    $("#brochure").html(data);
                    $("#.accordion .control").gtaccordion();
        if ($("#country").length > 0)
        {
            var domain = document.domain;
            if (domain.toLowerCase() == "vispring-ml-staging-en-us.conrandesigngroup.com" || domain.toLowerCase() == "www.vispring.com") {
		$(".forms #country").val("United States");
            }

        }
                }
            });
        }
        
        $(".submit_guarantee").live('click', function() {
            if ($(this).hasClass("step1")) {
                $("#step1 .error").hide();
                if (validateForm("step1")) {
                    $("#step1").hide();
                    $("#step2").show();
                }
                else {
                    $("#step1 .error").show();
                }
            }
            if ($(this).hasClass("step2")) {
                $("#step2 .error").hide();
                $("#step2 .error2").hide();
                validateForm("guaranteeForm");
            }
        });
        
        $(".submit_brochure").live('click', function() {
            $("#brochure .error").hide();
            $("#brochure .error2").hide();
            validateForm("brochure");
        });
        
        $(".checkbox-compare tr").live('click', function() {
            
            var cbox = $(this).find("input");
            
            if (cbox.attr("disabled")) return false;
            
            var id = cbox.attr("id").replace("compare_id_", "");
            
            if ($(cbox).hasClass("checked")) {
                $(cbox).removeClass("checked");
                $(cbox).attr('checked', false);
                $.ajax({
                    url: "/ajax/compareTable.aspx",
                    data: "action=remove&id=" + id,
                    success: function(data) {
                        $(".comparison-table").html(data);
                    }
                }); 
            }
            else {
                $(cbox).addClass("checked");
                $(cbox).attr('checked', true);
                $.ajax({
                    url: "/ajax/compareTable.aspx",
                    data: "action=add&id=" + id,
                    success: function(data) {
                        $(".comparison-table").html(data);
                    }
                });
            }
        
            checkBoxLimiter();

        });
                
        checkBoxLimiter();        
        
        $(".compare_switch").live('click', function() {
            if ($(this).hasClass("compare_remove")) {
                $.ajax({
                    url: "/ajax/compare.aspx",
                    data: "action=remove&id=" + $(".baseOptions").attr("id").replace("bed_ID_", ""),
                    success: function(data) {
                        $(".doCompare .switch").html(data);
                    }
                }); 
            }
            else {
                $.ajax({
                    url: "/ajax/compare.aspx",
                    data: "action=add&id=" + $(".baseOptions").attr("id").replace("bed_ID_", ""),
                    success: function(data) {
                        $(".doCompare .switch").html(data);
                    }
                });
            }
        }); 
        	     
	    if ($("#Map").length > 0 && $(".current_id_5dcae79db579412ea5242ef28fe9a553").length == 0) {
	        setTimeout(function(){ initializeMap() },250);
	    }
	    
	    if ($("#slideShow img").length > 0) {
	        slideShowTimer = setTimeout(function(){ doSlideShow() },6000);
	        
	    }
	    
	    
        
    });
    
    function openBlog(id) {
        $("#overlay").css("height", $(document).height() + "px");
        $("#overlay").fadeTo(750, 0.5, function() {
          $.ajax({
            url: "/ajax/blog.aspx?id=" + id,
            success: function(data) {
                $("#sleep_detail").html(data);
                $("#sleep_detail").show();
                    Cufon.replace('h1'); 
                    Cufon.replace('.cg6');
                    Cufon.replace('h2');
                    Cufon.replace('h3');
                    $("#sleep_detail").addClass("active");
                    $("#body").addClass("sleeping");
            }
          });
        });
    }
    
    var slideShowTimer;
    
    function doSlideShow() {
        var Object;
        if ($("#slideShow img.active").length == 0) {
            Object = $("#slideShow img")[1];
        }
        else {
            Object = $("#slideShow img.active").next();
            if (Object == null) {
                Object = $("#slideShow img")[0]; 
            }
        }
        $('#body_overlay').fadeTo(200, 1, function() {
            $("#scaler img").attr("src", $(Object).attr("src"));
            $("#slideShow img.active").removeClass("active");
            $(Object).addClass("active");
            $('#body_overlay').fadeTo(200, 0, function() {
                slideShowTimer = setTimeout(function(){ doSlideShow() },4000);
            });      
        });
        
    }
    
    function clearLoader(t, clicked, imagePath) {
        $("#scaler img").attr("src", imagePath);
        clicked.removeClass("loading");
        t = null;
    }

    function loadImg(url, func) {     
        var img = new Image();     
        img.onload = func;     
        img.src = url;     
        return img; 
    }  
    
        
    function resizeSlider(bodyHeight) {
   
        $(".bodyHeightTrackMargin").height(bodyHeight - 20);
        $(".carousel-feature").width(calcWidth - 300 - 20);
        setTimeout(function(){ 
            $("#welcome").fadeOut('5000', function() {
                $("#carousel-container").show();
                $("#carousel-container").gtslider(); 
            });

        },5000);
        
    }
    
    function doImageScaler(imageURL, undressedImageURL) {
             
        if (imageURL != "" && imageURL != undefined) {
            
            var myImg = loadImg(imageURL, function() {   
                
                var imgWidth = $(myImg).width();
                var imgHeight = $(myImg).height();
                $("#scaler").html($(myImg)); 
                var width = $("#scaler").width();
                var height = $("#scaler").height();
                
                var scaler = width / imgWidth;
                
                var newHeight = scaler * imgHeight;
                
                if (newHeight < height) {
                    var scaler = height / imgHeight;
                    var newWidth = scaler * imgWidth;
                    $("#scaler img").width(newWidth);
                    $("#scaler img").height(height);

                }
                else {
                    $("#scaler img").width(width);
                    $("#scaler img").height(newHeight);

                }
                $('#body_overlay').fadeTo(1000, 0, function() {
                  // Animation complete.
                });

                if (undressedImageURL != undefined && undressedImageURL != "") {
                    var myUndressedImg = loadImg(undressedImageURL, function() { 
                        $("#preLoadUndressed").html(myUndressedImg);
                    });
                }
            });  
            
        }
        else {
            var myImg = $("#scaler img");
            if (myImg.length == 0) {
                $('#body_overlay').hide();
                return false;
            }
            var imgWidth = $(myImg).width();
            var imgHeight = $(myImg).height();
            var width = $("#scaler").width();
            var height = $("#scaler").height();
            
            var scaler = width / imgWidth;
            
            var newHeight = scaler * imgHeight;
            
            if (newHeight < height) {
                var scaler = height / imgHeight;
                var newWidth = scaler * imgWidth;
                $("#scaler img").width(newWidth);
                $("#scaler img").height(height);

            }
            else {
                $("#scaler img").width(width);
                $("#scaler img").height(newHeight);

            }
        }
    }
    
    var loaded = "";
    
    $.fn.smartBackgroundImage = function(url, id){   
        
        if (loaded.indexOf(id) > -1) {
            switchBodyImage(url, true)
            return false;
        }
        $("#body_overlay").fadeIn(250, function() {});
        var t = this; //create an img so the browser will download the image:   
        $('<img />')     
        .attr('src', url)     
        .load(function(){ //attach onload to set background-image        
            t.each(function(){            
                switchBodyImage(url);
                loaded = loaded + " " + id;
            });     
         });   
         return false;
    }
    
    function checkBoxLimiter() {
    
        var $b = $('.checkbox-compare input[type=checkbox]');
        
        if ($b.filter(':checked').length > 2) {
            $(".checkbox-compare input[type=checkbox]").each(function() {
                if (!$(this).hasClass("checked")) {
                    $(this).attr("disabled", "disabled");
                }
            });
        }
        else {
            $(".checkbox-compare input[type=checkbox]").each(function() {
                $(this).attr("disabled", "");
            });
        }
        
    }
    
    function switchBodyImage(url, fadeOut) {
        if (fadeOut) {
            $("#body_overlay").fadeIn(250, function() {
               $("#body").css('backgroundImage', 'url('+url+')' ); 
               $("#body_overlay").fadeOut(250, function() {});
            });
        }
        else {
           $("#body").css('backgroundImage', 'url('+url+')' ); 
           $("#body_overlay").fadeOut(250, function() {});
        }
    }
    
    function resizeTabs(inSize) {
        var width = 0;
        var closedTab = $(".title.hidden").parents(".tab");
        closedTab.find(".close").addClass("hidden");
        closedTab.find(".title").removeClass("hidden");
        $("#tab_wrapper .tab").each(function() {
            width = width + $(this).width();
            $(this).find(".body").width($(this).find(".body").width());
        });
         $("#tab_wrapper").width(width);
         closedTab.find(".title").addClass("hidden");
         closedTab.find(".close").removeClass("hidden");
         if (isIE7) {
            $("#slideDock").css("margin-left", "0px").css("width", "auto");
         }
         else {
            $("#slideDock").css("margin-left", (calcWidth / 2) - (width / 2) + "px").css("width", "auto");
         }
         
    }
    
    function flashClosePanel() {
        go($(".active .close.control"), true);
    }
    
    
    function toggleInfoPanel(checkSession) {
    
        if ($(".baseLeft .panel.active").length > 0) {
            go($(".baseLeft .control"));
            return false;
        }
        if (checkSession) {
            $.ajax({
                url: "/sessions.aspx",
                data: "which=leftnav&id=" + getNavID() + "&currentId=" + getCurrentNavID(),
                success: function(data) {
                    if (data == "open") {
                        go($(".baseLeft .control"));
                        hideTimer = setTimeout(function() { toggleInfoPanel() },5000);
                    }
                }
            });
            return false;
        }
        go($(".baseLeft .control"));
    }
    
    function getNavID() {
        if ($(".accordion.baseLeft").length > 0) {
            return $(".accordion.baseLeft").attr("id").replace("nav_id_", "");
        } 
        return "";
    }
 
    function getCurrentNavID() {
        return $("#wrapper").attr("class").replace("current_id_", "");
    }   
   
    function showAccordion() {
        $("#welcome").fadeOut('300', function() {
            $("#carousel-container").show();
            $("#carousel").featureCarousel({
              topPadding:10,
              sidePadding:10,
              smallFeatureWidth: 0.8,
              smallFeatureHeight: 0.8
            });
        });
    }
    
    function animateDock(dock, tab, height, isClosed, resizeTo, dockPanel) {
        dock.animate({
            height: height
            }, {
            duration: 500,
            specialEasing: {
              height: 'easeInOutCirc'
            },
            complete: function() {
              if (!isClosed) {
                //if (dockPanel != null && dockPanel != undefined) {
                    $(".active_dock").hide().removeClass("active_dock");
                //}
                dock.addClass("closed");
                dock.removeClass("bodyWidthTrack");
                dock.css("width", "auto");
                resizeTabs();
              }
            }
        });
    }
    
    $(window).resize(function() {
        sizerTimer = setTimeout(function() { sizer() },75);
    });
    
    // globals 
    var docWidth;
    var docHeight;
    var calcWidth;
    var calcHeight;
    
    var maxWidth = 1280;
    var maxHeight = 810; 
    
    var minWidth = 1020;
    var minHeight = 700;
    
    wrapperMargin = 30;
    wrapperPadding = 10;
    
    function sizer(show) {

       	docWidth = $(window).width();
        docHeight = $(window).height();

        calcWidth = docWidth
        calcHeight = docHeight

        if (docWidth > maxWidth) { calcWidth = maxWidth; }
        if (docWidth < minWidth) { calcWidth = minWidth; }
        if (docHeight > maxHeight) { calcHeight = maxHeight; }   
        if (docHeight < minHeight) { calcHeight = minHeight; }   
        
        //positionBG();
        
        calcHeight = calcHeight - (wrapperMargin * 2)
        calcWidth = calcWidth - (wrapperMargin * 2)
        
        resizeDoc();
        resizeTabs();
        
        doImageScaler();
        
        if ($(".dock_panel.promos .promo").length > 0) {
            var ua = navigator.userAgent; 
            var isiPad = /iPad/i.test(ua) || /iPhone OS 3_1_2/i.test(ua) || /iPhone OS 3_2_2/i.test(ua);
            if (isiPad) {
                $(".dock_panel.promos").css("margin-left", (calcWidth - (291 * $(".dock_panel.promos .promo").length)) / 2 - 25 + "px");
            }
            else {
                $(".dock_panel.promos").css("margin-left", (calcWidth - (291 * $(".dock_panel.promos .promo").length)) / 2 + "px");
            }
        }
        
        navSizerTimer = setTimeout(function() { resizeNav() },75);
        
        if (show) {
            showTimer = setTimeout(function() { $("#overlay").hide(); },120);
        }
                   
    }
    
    function positionBG() {
        $("#body").css("background-position", "-" + (maxWidth - calcWidth) / 2 + "px -" + (maxHeight - calcHeight) / 2 + "px");
    }
    
    function resizeDoc() {
    
   
        $("#wrapper").removeClass("min").removeClass("max").addClass("fluid");
        $("#wrapper:not(.sleep):not(.deep)").height(calcHeight);
        $("#wrapper").width(calcWidth);
        $("#wrapper").css("margin-left", "-" +  (calcWidth + (wrapperPadding * 2)) / 2  + "px");
        $(".bodyWidthTrack").width(calcWidth);
        
        var bodyHeight = calcHeight - $("#header").height() - $("#footer").height();
        $("#body:not(.sleep):not(.deep)").height(bodyHeight);
        $(".bodyHeightTrack").height(bodyHeight);
        $(".bodyHeightTrackMargin").height(bodyHeight - 20);
        $("#map_wrapper").css("margin-left", "24px");
        $(".bodyWidthViewableTrack").width(calcWidth - 48);
        $(".bodyHeightViewableTrack").height(bodyHeight - 48);

        $(".video_margin").css("margin-left", (calcWidth - 940) / 2  + "px");
        $(".video_margin").css("margin-top", (bodyHeight - 450) / 2  + "px");
        
        $(".video_margin_video").css("margin-left", (calcWidth - 940) / 2  + 24 + "px");
        $(".video_margin_video").css("margin-top", (bodyHeight - 450) / 2  + "px");
        
        resizeSlider(bodyHeight);
        
    }
    
    function resizeNav() {
        var navWidth = 0;
        $("#header ul#nav li:not(.spacer, .fixed)").each(function() { navWidth = navWidth + $(this).width(); });
        var spacerWidth = ((calcWidth - (28 * 2)) - navWidth) / 6;
        $("#header ul li.spacer:not(.fixed)").each(function() { $(this).width(spacerWidth); });
    }
    
   
  
    function getCulture(){
        var url = $("#culturePicker").val();
        
        if (url != "" || url != "select"){
            url.replace("http://", "");
            window.location = "http://"+ url;
        }
        
    }
    
    
