jQuery(function($){

	get_rate(40);
	$(".my_buy_title_button").click(function(){
		$(this).siblings(".my_buy_title").css("height","auto");
		$(this).css("display","none");
		$(this).siblings(".my_buy_title_button2").css("display","block");
	});
	$(".my_buy_title_button2").click(function(){
		$(this).siblings(".my_buy_title").css("height","40px");
		$(this).css("display","none");
		$(this).siblings(".my_buy_title_button").css("display","block");
	});
	$(".sia").hover(function(){
		$(".sia").removeClass("active");
		$(this).addClass("active");
	},function(){
		$(this).removeClass("active");
	});
	$(".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();
		}
	});
	
	/*$("#site_nav li").mouseover(function(){
				$(this).addClass("current");
			}).mouseout(function(){$(this).removeClass("current");});
	*/
	
	$(".deal").mouseover(function(){
				$(this).children(".dimg").children(".time").css("display","block");
			}).mouseout(function(){$(this).children(".dimg").children(".time").css("display","none");});
	$("#cate-nav-1 li").first().addClass("current");
	$("#cate-nav-1 li").hover(function(){
			$(this).addClass("current").siblings().removeClass("current");
									});
	$("#links .close").click(function(){
		$("#links").hide();
	});
	$("#qcity .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");
		});
	});

	/*收藏按钮特效*/
	$(".good_shoucang").mouseover(function(){


		/*var top=$(this).children("a").offset().top;
		var left=$(this).children("a").offset().left;
*/
		var top=0;
		var left=20;
		var goodsid=$(this).attr("attr");
		$(this).parent("div").siblings(".ping").show();
		$(".ping").css("bottom",22+"px");
		$(".ping").css("right",1+"px");
		$(this).parent("div").siblings(".ping").children("span").eq(0).attr("gsid",goodsid);
		$(this).parent("div").siblings(".ping").children("span").eq(1).attr("gsid",goodsid);
		$(this).parent("div").siblings(".ping").children("span").eq(0).next("input").val("1");

})

$(".good_shoucang_2").mouseover(function(){


		/*var top=$(this).children("a").offset().top;
		var left=$(this).children("a").offset().left;
*/
		var top=0;
		var left=20;
		var goodsid=$(this).attr("attr");
		$(this).parent("dd").siblings(".ping").show();
		$(".ping").css("bottom",20+"px");
		$(".ping").css("right",15+"px");
		$(this).parent("dd").siblings(".ping").children("span").eq(0).attr("gsid",goodsid);
		$(this).parent("dd").siblings(".ping").children("span").eq(1).attr("gsid",goodsid);
		$(this).parent("dd").siblings(".ping").children("span").eq(0).next("input").val("1");

})


		$(".ping").mouseover(function(){

				$(this).show();
		})
		$(".ping").mouseout(function(){

				$(this).hide();
		})


       //补充
	   $(".pings").mouseover(function(){

				$(this).show();
		})
		$(".pings").mouseout(function(){

				$(this).hide();
		})


		$(".good_shoucang").mouseout(function(){


					$(".ping").hide();
		})


	//默认只显示商圈

	$("#cate-nav-2 div:gt(0)").hide();


	 //分类选项卡

	$("#cate-nav-1 ul li").mouseover(function(){


				//$(this).css("background","#fff").siblings().css("background","");
				var t=$(this).index();
				$("#cate-nav-2 div").eq(t).show().siblings().hide();
	})


	//搜索时间插件

	$(".search_date").datepicker();

	$(".search_now").datepicker();
	
	$("#add_time").datepicker();
	

	//过期团购搜索框分类

	$(".allclass li a").click(function(){

			var pCateid=$(this).attr("cateid");
			$(".pcate").val(pCateid);
	})

	$(".selbut").click(function(){

				//获取时间
				var sttime=$("input[name=\"first_time\"]").val();
				var entime=$("input[name=\"last_time\"]").val();
				//获取类型
				var tm=$(".chose_nav ul li[class=\"current\"]").attr("tm");

			window.location="index.php?m=Goods&a=search&tm="+tm+"&sttime="+sttime+"&endtime="+entime;


	})


	//搜索排序

	$(".select").change(function(){


				var  url=$(this).val();

  			window.location="index.php?m=Index&a=search&"+url;

	})

	
	// 用户中心确认消费按钮
	
	$(".make_out").click(function(){
		
		$(".make_out_frame").hide();
		$(this).siblings(".make_out_frame").show();
		
	});
	
	$(".cons").click(function(){
		
		$(this).parent(".make_out_frame").hide();
		
	});
	//年货专区专题切换
	
	$("#zt_team .lm ul li").mouseover(
			function(){
				$(this).addClass("current").siblings("li").removeClass("current");
				var zt_id=$(this).attr("zt_id");
				$("div[zt_c="+zt_id+"]").fadeIn("normal").siblings("div").fadeOut("normal");
				})
	



	//Flash

	$("embed[type='application/x-shockwave-flash']").attr("height","253").attr("line-height","253");





	if($(".settime").length > 0)
		updateEndTime();
});
function get_rate(rate){
 rate=rate.toString();
 var s;
 var g;
 $("#g").show();
 if (rate.length>=3){
  s=10;
  g=0;
  $("#g").hide();
 }else if(rate=="0"){
  s=0;
  g=0;
 }else{
  s=rate.substr(0,1);
  g=rate.substr(1,1);
 }
 $("#s").text(s);
 $("#g").text("."+ g);
 $(".big_rate_up").animate({width:(parseInt(s)+parseInt(g)/10) * 20,height:20},1000);
 $(".big_rate_bak b").each(function(){
  $(this).mouseover(function(){
   $(".big_rate_up").width($(this).attr("rate") * 20 );
   $("#s").text($(this).attr("rate"));
   $("#g").text("");
  }).click(function(){
	$("#import_score").attr("value",$(this).attr("rate"));
   $("#f").text($(this).attr("rate"));
   $("#my_rate").show();
  })
 })
 $(".big_rate_bak").mouseout(function(){
  $("#s").text(s);
  $("#g").text("."+ g);
  $(".big_rate_up").width((parseInt(s)+parseInt(g)/10) * 20);
 })
}
function up_rate(rate){
 $(".big_rate_up").width("0");
 get_rate(rate);
}

function gotop(){
	document.getElementById("cate-nav").scrollIntoView();
}
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);
}

// 首页右侧广告为轮换代码

function slideSwitch() {
    var $active = $('#eventslide  IMG.active');
    if ( $active.length == 0 ) $active = $('#eventslide  IMG:last');
  var $next =  $active.parent("a").next("a").children("img").length ?  $active.parent("a").next("a").children("img"): $('#eventslide  IMG:first');
    $active.addClass('last-active');
    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}
$(function() {
    setInterval( "slideSwitch()", 3000 );
});



