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

localhost.site.theme = {

    menuFadeTime: 250,
    menuHoldTime: 10,

	browserIsOld: false,

    onReady: function(){
        var script = this;

        //$("head link").remove();

		this.browserIsOld = ($.browser.msie && $.browser.version < 7);

        this.tidyButtons();

        $("#MainContent p:first").each(function(){
           $(this).addClass("first");
        });

        $("#DateAndStats > i").text(" as of ");

        /*
		$.ajax({

			url: 		"http://tools.vezea.net/textimage.js",
			dataType: 	"script",
			async: 		false,

			success: function(){
				script.applyTextImages();
			}

		});
		*/

        this.initMenu();
    },

    tidyButtons: function() {
		var theme = this;

		if (this.browserIsOld) {
			$("a.button").each(function(){
				$(this).removeClass("button");
			});
			return;
		}

        $("a.button").each(function(){
           var $this = $(this);
           var text = $this.text();
           $this.empty().append($("<span/>").text(text));
           $this.wrap($("<span/>").addClass("button"));
        });
        $("input.button").each(function(){
            var $this = $(this);
            var $image = $("<input/>").attr({
                type: "image",
                value: "",
                src: "http://tools.vezea.net/textimage?content=" + $this.val()
            });
            var $button = $('<button type="submit"/>').attr({
            }).append($("<span/>").text($this.val())).click($this.get(0).onclick);
            $(this).replaceWith($button);
        });
    },

    applyTextImages: function(){

    /*
		vezea.tools.textimage.apply({
			selector: "#PageTitle, #PageHeading"
		});
		*/

    },

    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.theme.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"
		});
		*/
        }
    };
}
