jQuery(function($){
	var navcurrent = $("#nav li.current");
	navcurrent.prev("#nav ul.nav-list li.j").addClass("e");
	navcurrent.next("#nav ul.nav-list li.j").addClass("e");

	if($(".scroll-news li").length > 1)
	{
		$(".scroll-news div").jCarouselLite({
			auto: 2000,
			speed: 500,
			vertical: true,
			visible: 1,
			over:true
		});
	}



	$(".site-cates li.i").hover(function(){
		$(".site-cates li").removeClass("current");
		$(this).addClass("current");
		$("#site-list .item").hide();
		$("#site-list .item[rel='"+this.getAttribute("rel")+"']").show();
		$("#site-listnav .item").hide();
		$("#site-listnav .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;
	});*/

	$("#close-div").click(function(){
		$("#city-listbox").hide();
		return false;
	});

	$("#close-div2").click(function(){
		$("#city-listbox").hide();
		return false;
	});

	$("#head .toggle").click(function(){
		if($("#city-listbox").css("display") == "none"){
			$("#city-listbox").bgiframe();
			$("#city-listbox").show();
		}
		else{
			$("#city-listbox").hide();
		}	
		return false;
	});

	if($(".settime").length > 0)
	updateEndTime();
});

/*function showdiv(divid,closeid){
	$("#"+closeid).hide();
	if($("#"+divid).css("display") == "none"){
		$("#"+divid).bgiframe();
		$("#"+divid).show();
	}else
		$("#"+divid).hide();	
	return false;
}*/

function change_letter_city(letter){
	$.ajax({
		url: "/index.php?m=Ajax&a=letterCity",
		type: "post",
		data: "letter="+letter,
		dataType: "html",
		success: function(html)
		{
			$("#letter_city").html(html);
		}
	});
}

function change_province_city(pid){
	$.ajax({
		url: "/index.php?m=Ajax&a=provinceCity",
		type: "post",
		data: "pid="+pid,
		dataType: "html",
		success: function(html)
		{
			$("#province_city").html(html);
		}
	});
}

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 siterank(siteid){
	$.get("/index.php?m=Site&a=go&id=" + siteid,null,null);
}

function goodsrank(goodsid){
	$.get("/index.php?m=Goods&a=go&id=" + goodsid,null,null);
}
