jQuery(function($){
	$("#navs-sites .nvas li.cate a").focus(function(){
		this.blur();										
	});
	
	$("#navs-sites .nvas li.cate").click(function(){
		$("#navs-sites .nvas li.cate").removeClass("current");
		$(this).addClass("current");
		
		if(this.getAttribute("rel") != "")
		{
			$("#navs-sites .sites .sites-item").hide();
			$("#navs-sites .sites .sites-item[rel='"+this.getAttribute("rel")+"']").show();
		}
	});
	
	$("#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();
		return false;
	});
	
	$(".e-item").each(function(i){
		$(this).hover(function(){
			$(this).addClass("cur");
		},function(){
			$(this).removeClass("cur");
		});
	});

	if($(".settime").length > 0)
		updateEndTime();
});

function cates(rec_module,rec_id)
{
	$.ajax({
		  type: "POST", 	
		  url: ROOT_PATH+"/index.php?"+VAR_MODULE+"=Collect&"+VAR_ACTION+"=doCollect&rec_module="+rec_module+"&rec_id="+rec_id,
		  cache: false,
		  success:function (html){	
			 var data = $.evalJSON(html);
			 if(data.status == 0 || data.status == 1|| data.status == 3)
			 {
				 alert(data.msg);
			 }
			 else if(data.status == 2)
			 {
				 alert(data.msg);	
				 location.href = ROOT_PATH+"/index.php?"+VAR_MODULE+"=User&"+VAR_ACTION+"=login";
			 }
			
				 
		  }	  
		});		
}

function updateEndTime()
{
	var date = new Date();
	var time = date.getTime();
	
	$(".settime").each(function(i){
		var endDate =new Date(this.getAttribute("endTime"));
		var startDate=this.getAttribute("addTime");
		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(startDate+"，剩余"+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);
}

