if (!localhost) var localhost = {};
if (!localhost.site) localhost.site = {};

localhost.site.skin = {

    menuFadeTime: 250,
    menuHoldTime: 10,

    onReady: function(){
        this.initMenu();
        this.regressButtons();
    },

    regressButtons: function() {
        $("a.button").each(function(){
           var $this = $(this);
           var $button = $('<input type="button" class="button"/>').val($this.text());
           $button.click(function(){
              document.location = $this.attr("href");
           });
           $this.replaceWith($button);
        });
    },


    initMenu: function() {
        var www = this;

        var hoverClass = "Hover";
        var dropmenuClass = "DropMenu";
        
        $("#MainMenu a, #UserMenu a").each(function(){
            var href = $(this).attr("href");
            if (href) {
                var $dropmenu = $("#Navigation a[href='"+href+"'] ~ ul").clone();
                if ($dropmenu.length) {

                    //
                    // Add formatting to dropmenu.
                    //
                    $dropmenu.addClass($(this).parents("div").attr("class") + "-" + dropmenuClass);
                    $dropmenu.addClass($(this).attr("class") + "-" + dropmenuClass);
                    $dropmenu.addClass(dropmenuClass);

                    //
                    // Add dropmenu to document.
                    //
                    $("body").append($dropmenu.hide());
                    
                    //
                    // Link menu item and dropmenu to each other.
                    //
                    this.dropmenu = $dropmenu.get(0);
                    this.dropmenu.upmenu = this;
                    
                    //
                    // Wire show and hide for dropmenu.
                    //
                    this.dropmenu.doShow = function(){
                        $(this.upmenu).addClass(hoverClass);
                        $(this).slideDown(www.menuFadeTime);
                    };
                    this.dropmenu.doHide = function(){
                        $(this.upmenu).removeClass(hoverClass);
                        $(this).slideUp(www.menuFadeTime);
                    };

                    //
                    // Wire hover for menu item.
                    //
                    $(this).hover(function(){
                        var $this = $(this);
                        
                        clearTimeout(this.hider);    // clear previously initiated hide
                        
                        $(this.dropmenu).appendTo($("body")).css({
                            position: "absolute",
                            left: $this.offset().left - 1,  // 1 for border
                            top: $this.offset().top + this.offsetHeight
                        });
                        
                        this.dropmenu.doShow();
                        
                    },function(){                 
                        //
                        // Instead of hiding dropmenu, allow brief interval
                        // to let mouse pass to dropmenu (which then clears
                        // this hide call if hover is detected.)
                        //       
                        var dropmenu = this.dropmenu;
                        this.hider = setTimeout(function(){
                            dropmenu.doHide();
                        }, www.menuHoldTime);
                    });
                    
                    //
                    // Wire hover for dropmenu.
                    //
                    $dropmenu.hover(function(){
                        clearTimeout(this.upmenu.hider);    // clear previously initiated hide
                    },function(){
                        var dropmenu = this;
                        this.upmenu.hider = setTimeout(function(){
                            dropmenu.doHide();
                        }, www.menuHoldTime);
                    });
                }
            }
        });
    }

}
$(document).ready(function(){
    localhost.site.skin.onReady();
});

if (false) {
    com.taxsaleprograms.affil.load = function() {
        com.taxsaleprograms.affil.resize();
    };
    com.taxsaleprograms.affil.resize = function() {
        $("#MainSpacer").remove();

        var layoutObj = $("#Layout");
        //var bodyObj   = $("#Body");
        var mainObj   = $("#MainContent");
        //var sideObj   = $("#SideContent");
        var windowObj = $(window);

        if (windowObj.height() > layoutObj.height()) {
            mainObj.append('<div id="MainSpacer"></div>');
            $("#MainSpacer").css({
                height: (windowObj.height() - layoutObj.height()) + "px"
            });
        /*
		mainObj.animate({
			height: (mainObj.height() + windowObj.height() - layoutObj.height()) + "px"
		});
		*/
        }
    };
}
