$(document).ready(function() {

    $("dd").mouseover(function(){
                $(this).css({ border: "1px solid #FF5500"});
	});
        $("dd").mouseout(function(){
                $(this).css({ border: "1px solid #cccccc"});
	});

	$(".nav_off").mouseover(function(){
		
		var submenu = this.id;
		//qiehuan(submenu);
	});
	$(".nav_off").click(function(){
		var submenu = this.id;
		setCookie("menu", submenu);
	});

	$("#qty").keyup(function() {
		if (this.value != '')
		{		
			if (!isNumber($("#qty").val()))
			{
				alert("Quantity need number(eg: 1,2,3)");
				$("#qty").val("1");
				$("#qty").focus();
				return false;
			}
			$("#add").val($("#qty").val());
		}
	});
	$("#submit").click(function() {
//		if (!window.confirm("Dear Valued Customers, \n\nPlease be informed that our branches throughout China will be closed for the Chinese New Year Holidays from 5th February 2010 to 19th February 2010. Any orders received on 5th February 2010 will be shipped on first come first serve basis from 19th February 2010 onwards. \n\nWe will be operating as usual from 19th February 2010 onwards. We take this opportunity to wish all customers a happy and prosperous year of Tiger.\n\nBest Wishes \nManagement of http://www.samsungusbcable.com \n5th February 2010 "))
//		{
//			return false;
//		}
		var goods_items = getCookie("goods_item");
		var goods_money = getCookie("goods_money");
		if (goods_items == '') goods_items =0;
		if (goods_money == '') goods_money =0;

		goods_items = Number(goods_items)+1;
		goods_money = Number(goods_money)+Number($("#amount").val())

		
		setCookie("goods_item", goods_items);
		setCookie("goods_money", goods_money);

		$("#cart_item").html(goods_items + " Item(s) ");
		$("#cart_price").html("&#163;" + goods_money.toFixed(2));
		$.getJSON("http://www.samsungusbcable.com/orderlog.php?domain="+document.location.hostname+"&name="+$("#item_name").val()+"&callback=?");

	});

	//show tab (1.product detail 2.shipping 3.payment) 
	if($("#tabs").length>0)
	{
		$("#tabs a").click(function() {
			$('#tabs ul > li').removeClass('current');
			$(this).parent().addClass("current");
			
			if (this.id=='detail')
			{
				$("#product_detail_infomation").show();
				$("#product_shipping").show();
				$("#product_payment").hide();
			}
			if (this.id=='ship')
			{
				$("#product_detail_infomation").hide();
				$("#product_shipping").show();
				$("#product_payment").hide();
			}
			if (this.id=='payment')
			{
				$("#product_detail_infomation").hide();
				$("#product_shipping").hide();
				$("#product_payment").show();
			}
		});
	}

	//top my cart 
	var goods_items = getCookie("goods_item");
	var goods_money = getCookie("goods_money");
	if (goods_items !="")
	{
		$("#cart_item").html(goods_items+" Item(s) ");
	}
	if (goods_money !="")
	{
		goods_money = Number(goods_money);
		$("#cart_price").html("$" + goods_money.toFixed(2));
	}

	//show you hui message
	//var message = document.createElement("div");
	//message.innerHTML = "hello,   world.";   

	//document.getElementById("search_div").appendChild(message); 
	//var newDiv = document.createElement("div");
	//newDiv.setAttribute("class", "ad_shipping");
	
	//newDiv.innerHTML = "<h1 class='ad_shipping'>Get 55% up to $4.99, Shipping Worldwide: $4.99 </h1>";


	// add the newly created element and it's content into the DOM
	//var my_div = document.getElementById("search_div");
	//var parentDiv = my_div.parentNode;
	//parentDiv.insertBefore(newDiv, my_div);
	//$("search_div").insertBefore("#foo");
	
	$("#close-button").click(function() {
		$("#pop_tip").fadeOut("fast");
	});
	$("#shipping_help").click(function(e) {
		var xOffset = 8;
		var yOffset = 145;
		$("#pop_tip").css("top",(e.pageY + xOffset) + "px")//为id为tooltip的元素设置css样式 
			  .css("left",(e.pageX - yOffset) + "px") 
			  .fadeIn("fast");
	});
	$("#select_shipping").change(function() {
		$("#shipping_cost").html(this.value);
		$("#shipping_cost2").html(this.value);
		//Number(goods_money)+Number($("#amount").val())
		
		$("#totle_amount").html(Number($("#amount").val())+Number(this.value));
		$("#shipping").val(this.value);
		$("#shipping2").val(this.value-2);

	});

	//change current main menu
	//curr = getCookie("menu");	
	///qiehuan(curr);
});
//check s weather number
function isNumber(s){   
	var regu = "^[0-9]+$";
	var re = new RegExp(regu);
	if (s.search(re) != -1) {
	   return true;
	} else {
	   return false;
	}
}

//cookie save
function setCookie(sName, sValue)
{
	date = new Date();
	document.cookie = sName + "=" + escape(sValue) + "; ";
}
//get cookie value
function getCookie(sName)
{

	var the_cookie = document.cookie;
	var sValue="";
	the_cookie_split = the_cookie.split("; ");
	for (loop=0;loop<the_cookie_split.length;loop++) {

		var part_of_split = the_cookie_split[loop];
		var find_name = part_of_split.indexOf(sName)
		if (find_name!=-1) {
			sValue = part_of_split.split("=");
			return sValue[1];
			break;
		}
	}
	return sValue;
}
//delete cookie
function delCookie(sName)
{

   var expdate = new Date(); 
   expdate.setTime(expdate.getTime() - (86400 * 1000 * 1)); 
   setCookie(sName, "", expdate); 
}
