jQuery(function($){
	$(".site-cates li.i").click(function(){
		$(".site-cates li").removeClass("current");
		$(this).addClass("current");
		if(this.getAttribute("rel") != "")
		{
			$("#site-list .item").hide();
			$("#site-list .item[rel='"+this.getAttribute("rel")+"']").show();
		}
	});
	
	$("#links .close").click(function(){
		$("#links").hide();
	});
	
	$("#head .toggle").click(function(){
		if($("#city-list").css("display") == "none")
		{
			$("#city-list").bgiframe();
			$("#city-list").show();
			$("body").one("click", function(){
				$("#city-list").hide();
			}); 
		}
		else
			$("#city-list").hide();
		this.blur();
		return false;
	});
	
	$(".e-item").each(function(i){
		$(this).hover(function(){
			$(this).addClass("cur");
		},function(){
			$(this).removeClass("cur");
		});
	});
	
	if($(".settime").length > 0)
		updateEndTime();
});

function updateEndTime()
{
	var date = new Date();
	var time = date.getTime();
	
	$(".settime").each(function(i){
		var endDate =new Date(this.getAttribute("endTime"));
		var endTime = endDate.getTime();
		var lag = (endTime - time) / 1000;
		if(lag > 0)
		{
			var second = Math.floor(lag % 60);     
			var minite = Math.floor((lag / 60) % 60);
			var hour = Math.floor((lag / 3600) % 24);
			var day = Math.floor((lag / 3600) / 24);
			$(this).html("剩余："+day+"天"+hour+"小时"+minite+"分"+second+"秒");
		}
		else
			$(this).html("团购已经结束啦！");
	});
	
	setTimeout("updateEndTime()",1000);
}

function clockTime()
{
	var date = new Date();
	var D="";
	switch(parseInt(date.getDay()))
	{
		case 0:
		 D="天";
		 break;
		case 1:
		 D="一";
		 break;
		case 2:
		 D="二";
		 break;
		case 3:
		 D="三";
		 break;
		case 4:
		 D="四";
		 break;
		case 5:
		 D="五";
		 break;
		case 6:
		 D="六";
		 break;
	}
	
	var year = date.getFullYear();
	var month = date.getMonth()+1;
	if(month < 10)
		month = "0"+ month;
		
	var date1 = date.getDate();
	if(date1 < 10)
		date1 = "0"+ date1;
		
	var hours = date.getHours();
	if(hours < 10)
		hours = "0"+ hours;
		
	var minutes = date.getMinutes();
	if(minutes < 10)
		minutes = "0"+ minutes;
		
	var seconds = date.getSeconds();
	if(seconds < 10)
		seconds = "0"+ seconds;
	
	var str=year+"年"+month+"月"+date1+"日 "+"星期"+D+" "+hours+":"+minutes+":"+seconds;
	
	$("#clock_box").html(str);
	
	setTimeout("clockTime()",1000);
}

