$(function(){	
//dropdonw menu
	$("#topNav li.hover").hover(
	  function () {
		$(this).children("div.subdiv").show(); 
	  },
	  function () {
		$(this).children("div.subdiv").hide();
	  }
	);
		
// validation size
	$("#cart_quantity").submit( function () {
	 var a = document.getElementById("attrib-grid-table") ;
	  if (a){
	  	var totalCount = 0;
			var counts_input = $("#attrib-grid-table input.qtyInput");
			for(i=0; i<counts_input.length; i++){
				totalCount += Number(counts_input[i].value);
			}
			if (totalCount == 0){$("#message_size").html("Please select a size"); return false;}
			return true;
	  }
	} ); 

//header shopping cart detail	
	$("#checkoutBasket .cart").mouseover(function () {
		showCart();
	});
	
	$("#cart_detail .close").click(function () {
		hideCart();
		return false;
	});
	
	$("#cart_detail").hover(
	  function () {
		showCart();
	  },
	  function () {
		hideCart();
	  }
	); 	

	//categroy page description more click
	$("#categoryDescription .show").click(function () {
		$("#categoryDescription .more").addClass("click");
	});
	$("#categoryDescription .hide").click(function () {
		$("#categoryDescription .more").removeClass("click");
	});

	
//attrib-grid-table
	$("#attrib-grid-table .add_qty").click(function () {
		$obj = $(this).prevAll(".qtyInput");
		setAmount.add($obj);
		return false;
	});
	$("#attrib-grid-table .reduce_qty").click(function () {
		$obj = $(this).next(".qtyInput");
		setAmount.reduce($obj);
		return false;
	});
	$("#attrib-grid-table input.qtyInput").keyup(function(){
		setAmount.modify(this);
	})


})

var setAmount = {
    min: 0,
    max: 999,
    reg: function(x) {
        return new RegExp("^[0-9]\\d*$").test(x);
    },
    amount: function(obj, mode) {
        var x = $(obj).val();
        if (this.reg(x)) {
            if (mode) {
                x++;
            } else {
                x--;
            }
        } else {
            alert("Please type right number!");
            $(obj).val(0);
            $(obj).focus();
        }
        return x;
    },
    reduce: function(obj) {
        var x = this.amount(obj, false);
        if (x >= this.min) {
            $(obj).val(x);
        } else {
           // alert("Min Number is " + this.min);
            $(obj).val(0);
            $(obj).focus();
        }
    },
    add: function(obj) {
        var x = this.amount(obj, true);
        if (x <= this.max) {
            $(obj).val(x);
        } else {
            alert("Max Number is " + this.max);
            $(obj).val(999);
            $(obj).focus();
        }
    },
    modify: function(obj) {
        var x = $(obj).val();
        if (x < this.min || x > this.max || !this.reg(x)) {
            alert("Please type right number!");
            $(obj).val(0);
            $(obj).focus();
        }
    }
}


//header shopping cart detail	
function showCart(){	
	$("#cart_detail").fadeIn();
}
function hideCart(){
	$("#cart_detail").fadeOut();
}
function show_hide_Cart(){	
	showCart();
	setTimeout(hideCart, 4000);
}
//end header shopping cart detail	

function Open_NewWindow(C) {
    var B = "width=590,height=550,left=0,top=0,resizable=yes,menubar=no,location=no,status=yes,scrollbars=yes";
    var A = window.open(C, "", B);
    //A.focus();
	return false;
}
