﻿$(function(){
    initECommerce();
    initClearInputs();

    //initFlashBorders();
    $("#menu li ul").each(function(){
            $(this).parent().find("a").click(function()
                {
                    if ($(this).parent().find("ul").size() > 0)
                    {
                        if ($(this).parent().find("ul").css("display") == "none")
                            $(this).parent().find("ul").show();
                        else
                            $(this).parent().find("ul").hide();
                        
                        return false;     
                    }       
                });
        });
        
    $(".scroll").jScrollPane({showArrows:false, scrollbarWidth: 34});

});

/* Flash Border Removal
===================================================================================== */
function initFlashBorders(){
    if ($.browser.msie){
        $("object[@type='application/x-shockwave-flash']").each(function(){
                var h = this.outerHTML ;
				var params = '' ;
				var j = this.childNodes.length - 1 ;
				do {
					var p = this.childNodes[j] ;
					if (p.tagName == "PARAM") params += p.outerHTML ;
				} while (j--) ;
				var tag = h.split(">")[0] + ">" ;
				this.outerHTML = tag + params + this.innerHTML + " </object>" ;
            });
    }
}

/* Form Element Methods
===================================================================================== */
function initClearInputs(){
    $("input.autoClear").each(function(){
            $(this).attr("default",$(this).val());
            $(this).focus(function(){if($(this).val() == $(this).attr("default")) $(this).val("");});
            $(this).blur(function(){if ($(this).val() == "") $(this).val($(this).attr("default"));});
        });
}

/* E-Commerce Methods
===================================================================================== */
function initECommerce() {
    // Checkout page helpers
    if ($("#Checkout input[@type=password]").size() > 0){
        $("#Checkout input[@type=password]").keyup(function(){
                var id = ($(this).val().length > 0) ? "#ctl00_MainContent_optReturningCustomer" : "#ctl00_MainContent_optNewCustomer";
                $(id).attr("checked","checked");
            });
    }
}