﻿function OpenWindow(url, height, width, scrollable) {
    if (!height) height = 300;
    if (!width) width = 300;
    scrollable = scrollable ? ",scrollbars" : "";
    var win = window.open(url, "", "resizable=1,toolbar=0,location=0,status=0,menubar=0" + scrollable + ",width=" + width + ",height=" + height);
    win.focus();
}

function InitHoverButtons() {
    $("img.j-hover").hover(
        function() {
            $(this).attr('src', $(this).attr('src').replace('.', '-hover.'));
        },
        function() {
            $(this).attr('src', $(this).attr('src').replace('-hover.', '.'));
        }   
    );
}

function InitSpriteButtons() {
    $("a.sprite").hover(
        function() {
            $(this).css("background-position", "0 -" + $(this).height() + "px");
        },
        function() {
            $(this).css("background-position", "0 0");
        }
    );
}

function InitSearch() {
    $("#tbSearch").focus(function() {
        if (this.value.toLowerCase() == "search...") this.value = "";    
    }).blur(function() {
        if (this.value == "") this.value = "Search...";
    });
}

/*function InitDropMenus() {
	var menuItems = $("#top-menu td");
    
   	menuItems.each(function(i) {
	    $(this).attr("i", i + 1);
        $(this).mouseover(function() {
            $(this).css("cursor", "pointer");
            DropMenuHide();
            var a = $(this).find("a");
            var c = a.attr("class");
            var o = c;
            if (c.indexOf("-active") == -1) {
                if (c.indexOf("-hover") == -1) {
                    c += "-hover";
                    a.removeClass(o);
                    a.addClass(c);
                }
            }
	        var drop = $("#d" + $(this).attr("i"));
	        if (!drop.attr("init")){
    	        drop.mouseover(function() {
                    DropMenuCancelHide();
                }).mouseout(function() {
                    DropMenuStartHide();
                });
                drop.attr("init", true);
            }
            var td = $(this);
            var offset = td.offset().left - ($(drop).width() / 2) + (td.width() / 2);
            var leftEdge = $("#outer").offset().left + 2;
            var rightEdge = leftEdge + $("#outer").width() - 2;
            if (offset < leftEdge) offset = leftEdge;
            else if (offset + $(drop).width() > rightEdge) offset = rightEdge - $(drop).width();
    	    drop.css("left", offset + "px");
    	    drop.css("top", $("#top-menu").offset().top + $("#top-menu").height() + "px");
            drop.show();    
        }).mouseout(function() {
	        DropMenuStartHide();
	    });
    });
}

var dropMenuTimeout = null;

function DropMenuStartHide() {
    dropMenuTimeout = setTimeout("DropMenuHide()", 250);
}

function DropMenuHide() {
    DropMenuCancelHide();
    $(".dm").hide();
    var activeItem = $("#top-menu a[class$='-hover']");
    if (activeItem.length > 0) $(activeItem).attr("class", $(activeItem).attr("class").replace("-hover", ""));
}

function DropMenuCancelHide() {
    if (dropMenuTimeout) clearTimeout(dropMenuTimeout);
}*/

$(document).ready(function() {
	//InitDropMenus();
	InitSearch();
	InitHoverButtons();
	InitSpriteButtons();
});