	
	
    $(document).ready(function(){
		
		
		if($.browser.msie&&$.browser.version == "6.0"){
			$('.price').css('backgroundImage',"url('/templates/new2011/images/price_bg.gif')");
		}
		/***
		//new_tip
		$new_tip = getCookie('new_tip');
		$new_tip_open = $(".new_tip").attr("id");
		if(!$new_tip && $new_tip_open == 1){
			$(".new_tip").html("<img src = \"/new_tip/new_tip.jpg\"/>");
			$(".new_tip").click(function(){
				$(this).fadeOut(1000);
				var Days = 1; //此 cookie 将被保存 30 天
				var exp  = new Date();    //new Date("December 31, 9998");
				exp.setTime(exp.getTime() + Days*24*60*60*1000);
				document.cookie = "new_tip="+ escape ("1") + ";expires=" + exp.toGMTString();
			});
		}else{
			$(".new_tip").hide();
		}
		***/
		
		//左侧边栏随浏览器滚动
		var $sidebar = $(".left_p"), 
		$window = $(window), 
		offset = $sidebar.offset(), 
		topPadding = 95; 
		$window.scroll(function() { 
			if ($window.scrollTop() > offset.top) { 
				$sidebar.stop().animate({ 
					marginTop: $window.scrollTop() - offset.top + topPadding + 30
				},500); 
			} else { 
				$sidebar.stop().animate({ 
					marginTop: 95 
				},500); 
			} 
		}); 
		
		
		//红包点击
		$('.linghongbao').click(function(){
			//alert("着急了吧！红包功能还在调试中，过几天再试试吧，说不准有意外惊喜哦~");
			$(this).css("backgroundImage","url('/templates/new2011/images/hongbao_r2.gif')");
			$(this).html("<h1></h1><img src = \"/templates/new2011/images/hongbao_ok.gif\"/>");
			randh();
			//随机奖金
			function randh(){
				var number = Math.random();
				number = ForDight(number,1);
				$('.linghongbao').find("h1").html("￥"+number);
				suiji = setTimeout(randh,10);
			}
			
			$(this).click(function(){
				//clearTimeout(suiji);
				$(this).find('h1').hide();
				$number = Math.random();
				$number = ForDight($number,1);
				if($number == 0) $number = 0.1;
				$(this).prepend('<h2>￥'+$number+'</h2>');
				$(this).find('img').hide();
				$.ajax({
					type: "POST",
					url: domain+"/script/hongbao_ajax.php",
					data: "hongbao="+$number,
					global: false,
					beforeSend: function(){
						$('.linghongbao').append("<img src = '/templates/new2011/images/wait.gif'/>");
					},
					success: function(data){
						$('.linghongbao').find('img').remove();
						if(data == "ok"){
							$('.linghongbao').css("backgroundImage","url('/templates/new2011/images/hongbao_r_ok.gif')");
						}else if(data == "login"){
							$('.linghongbao').css("backgroundImage","url('/templates/new2011/images/hongbao_r_in.gif')");
							$('.linghongbao').click(function(){
								location.href="/login/";  
							});
						}else if(data == "err"){
							$('.linghongbao').css("backgroundImage","url('/templates/new2011/images/hongbao_r.gif')");
						}
					}
				});
				$(this).unbind();
			});
			
			
		});
		
		//红包
		$hongbao = getCookie('hongbao');
		if($hongbao > 0){
			$('.linghongbao').unbind();
			$hongbao_zt = getCookie('hongbao_zt');
			if($hongbao_zt == 'ok'){
				$('.linghongbao').css("backgroundImage","url('/templates/new2011/images/hongbao_r_ok.gif')");
				$('.linghongbao').click(function(){
					location.href="/i/credit/";
				});
			}else if($hongbao_zt == 'login'){
				$('.linghongbao').css("backgroundImage","url('/templates/new2011/images/hongbao_r_in.gif')");
				$('.linghongbao').click(function(){
					location.href="/login/";
				});
			}
			$('.linghongbao').prepend('<h2>￥'+$hongbao+'</h2>');
			
		}
		
		//购买人数
		$number = $('.number').attr('title');
		if($number < 200){
			$number = 130-($number/(200/130));
		}else{
			$number = 0;
		}
		$('.number').css('backgroundPosition',-$number);
		
		$('.header ul a').hover(function(){
			$(this).prev().hide();
			$(this).css('backgroundImage',"url('/templates/new2011/images/navi_bg_now.gif')");
		},function(){
			if(!$(this).attr('class')){
				$(this).prev().show();
				$(this).css('backgroundImage',"url('/templates/new2011/images/navi_bg.gif')");
			}
		});
		
		//导航栏,识别当前商品页面所属分类
		$i = $('.main .t_main_left .show').attr('id');
		$tuanid = $('.main .price').attr('id');	
		if($i){
			$('.top').css('height','172px');
			$('.top').css('backgroundImage',"url('/templates/new2011/images/top.gif')");
			$('.header').css('height','285px');
			$('.header ul a').css('backgroundImage',"url('/templates/new2011/images/navi_bg.gif')");
			$('.header ul li a').eq($i).prev().hide();
			$('.header ul li a').eq($i).css('backgroundImage',"url('/templates/new2011/images/navi_bg_now.gif')");
			$('.header ul li a').eq($i).addClass('now_nav');
			
			$.ajax({
				type: "POST",
				url: domain+"/script/top_navi_ajax.php",
				data: "i="+$i,
				global: false,
				beforeSend: function(){
					$('.top').html("<img style = 'margin:50px 435px' src = '/templates/new2011/images/wait.gif'/>");
				},
				success: function(html){
					$('.top').html(html);
					$('.header .list #'+$tuanid).css('backgroundColor',"#ff6600");
					$('.header ul a').hover(function(){
						$(this).prev().hide();
						$(this).css('backgroundImage',"url('/templates/new2011/images/navi_bg_now.gif')");
					},function(){
						if(!$(this).attr('class')){
							$(this).prev().show();
							$(this).css('backgroundImage',"url('/templates/new2011/images/navi_bg.gif')");
						}
					});
					
					if((!$.browser.msie || $.browser.version !== "6.0" && $.browser.version !== "7.0" && $.browser.version !== "8.0")){
						$('.top a').corner("4px");
						$('.top a span').corner("bottom 4px");
						$('.top a img').corner("4px");
					}
				}
			});
	
		}
		
		//导航栏点击
		$('.header ul a').click(function(){
			$('.header ul a').css('backgroundImage',"url('/templates/new2011/images/navi_bg.gif')");
			$('.header ul a').removeClass("now_nav");
			$(this).addClass("now_nav");
			$(".nav_shops_num").show();
			$(this).prev(".nav_shops_num").hide();
			$(this).css('backgroundImage',"url('/templates/new2011/images/navi_bg_now.gif')");
			$id = $(this).attr('id');
			
			$.ajax({
				type: "POST",
				url: domain+"/script/top_navi_ajax.php",
				data: "i="+$id,
				global: false,
				beforeSend: function(){
					$('.top').html("<img style = 'margin:50px 435px' src = '/templates/new2011/images/wait.gif'/>");
				},
				success: function(html){
					$('.top').css('height','172px');
					$('.top').css('backgroundImage',"url('"+domain+"/templates/new2011/images/top.gif')");
					$('.header').css('height','285px');
					$('.top').html(html);
					if((!$.browser.msie || $.browser.version !== "6.0" && $.browser.version !== "7.0" && $.browser.version !== "8.0")){
						$('.top a').corner("4px");
						$('.top a span').corner("bottom 4px");
						$('.top a img').corner("4px");
					}
				}
			});
			
			return false;
		});
		
		
		//TOP快捷商品选择区
		if((!$.browser.msie || $.browser.version !== "6.0" && $.browser.version !== "7.0" && $.browser.version !== "8.0")){
			$('.top a').corner("4px");
			$('.top a span').corner("bottom 4px");
			$('.top a img').corner("4px");
		}
		
		//在线提问选项卡
		$('.ask_button').addClass('ask_button_now');
		$('.ask_button').click(function(){
			$('.review_button').removeClass('ask_button_now');
			$(this).addClass('ask_button_now');
			
			$('.review_main').hide();
			$('.ask_main').show();
			
			$('.ask_list_div').remove();
			$('.ask_show').hide();
			$('.ask_open').show();
		});
		
		//开启在线提问
		$('.ask_open').click(function(){
			$id = $(this).attr('id');
			$num = $(".ask_list li:last").attr('id');
			$(this).hide();
			$('.ask_show').show();
			//$('.ask_list').hide();
			
			$.ajax({
				type: "POST",
				url: domain+"/script/ask_ajax.php",
				data: "tuanid="+$id+"&num="+$num,
				global: false,
				beforeSend: function(){
					$('.ask_list').html("<img style = 'margin:30px 374px' src = '/templates/new2011/images/wait.gif'/>");
				},
				success: function(html){
					$('.ask_list').html(html);
					$('.ask_more').corner("4px");
					//Q&A更多加载
					$('.ask_more').click(function(){
						$id = $(this).attr('id');
						$num = $(".ask_list li:last").attr('id');
						$.ajax({
							type: "POST",
							url: domain+"/script/ask_ajax.php",
							data: "tuanid="+$id+"&num="+$num,
							global: false,
							beforeSend: function(){
								$('.ask_list_div').append("<div id = \"ask_wait\"><img style = 'margin:30px 350px' src = '/templates/new2011/images/wait.gif'/></div>");
							},
							success: function(html){
								$('#ask_wait').remove();
								$('.ask_list_div').append(html);
								$('.ask_more').corner("4px");
							}
						});
						
					});
				}
			});		
		});
		
		//提交提问
		$('.ask_in .button').click(function(){
			
			$value = $('.ask_in .textarea').val();
			$id = $('.ask_open').attr('id');
			$userid = $('.ask_show').attr('id');
			if($value !== "" && $value.length > 2){
				alert("您的提问已经提交，请等候客服回复吧~");
				$('.ask_in .textarea').val("");
				$.ajax({
					type: "POST",
					url: domain+"/script/ask_in_ajax.php",
					data: "tuanid="+$id+"&value="+$value+"&userid="+$userid,
					global: false,
					beforeSend: function(){
						$('.ask_list').html("<img style = 'margin:30px 374px' src = '/templates/new2011/images/wait.gif'/>");
					},
					success: function(html){
						$('.ask_list').html(html).show(200);
						$('.ask_more').corner("4px");
					}
				});

			}else{
				alert("对不起，请输入您的提问内容~");
			}
		});
		
		//商品评论选项卡
		$('.review_button').click(function(){
			$('.ask_button').removeClass('ask_button_now');
			$(this).addClass('ask_button_now');
			
			$('.ask_main').hide();
			$('.review_main').show();
			
			$('.ask_list').html('');
			
			$id = $(".ask_open").attr('id');
			$num = $(".ask_list li:last").attr('id');
			
			$.ajax({
				type: "POST",
				url: domain+"/script/review_ajax.php",
				data: "tuanid="+$id+"&num="+$num,
				global: false,
				beforeSend: function(){
					$('.ask_list').html("<img style = 'margin:30px 374px' src = '/templates/new2011/images/wait.gif'/>");
				},
				success: function(html){
					$('.ask_list').html(html).show(200);
					$('.ask_more').corner("4px");
					
					//更多加载
					$('.ask_more').click(function(){
						$id = $(this).attr('id');
						$num = $(".ask_list li:last").attr('id');
						$.ajax({
							type: "POST",
							url: domain+"/script/review_ajax.php",
							data: "tuanid="+$id+"&num="+$num,
							global: false,
							success: function(html){
								$('.ask_list li:last').after(html).show(200);
								$('.ask_more').corner("4px");
							}
						});
					});
					
					//提交评价回复
					$('.reply .button').click(function(){
						
						$value = $('.reply :text').val();
						$id = $('.ask_open').attr('id');
						$userid = $('.ask_show').attr('id');
						$reviewid = $('.reviewid').html();
						if($value !== "" && $value.length > 2){							
							$('.reply_content').val("");
							$.ajax({
								type: "POST",
								url: domain+"/script/review_in_ajax.php",
								data: "tuanid="+$id+"&value="+$value+"&userid="+$userid+"&reviewid="+$reviewid,
								global: false,
								beforeSend: function(){
									$('.ask_list').html("<img style = 'margin:30px 374px' src = '/templates/new2011/images/wait.gif'/>");
								},
								success: function(html){
									$('.ask_list').html(html).show(200);
									$('.ask_more').corner("4px");
								}
							});

						}else{
							alert("对不起，请输入回应内容~");
						}
					});
					
				}
			});
			
		});
		
		
		
		//邀请按钮
		$(".invite_img").mouseover(function(){
			$(".invite_img").css("display","none");
			$(".invite_move_img").css("display","block");
		});
		$(".invite_move_img").mouseout(function(){
			$(".invite_move_img").css("display","none");
			$(".invite_img").css("display","block");
		});
			
		//订阅消息
		$('.sub_text').focus(function(){
			var sub_text = $('.sub_text').val();
			if(sub_text == "请输入您的E-Mail..." || sub_text == "请输入正确的Email"){
				$('.sub_text').val("");
			}
		});
		
		$('.sub_button').click(function(){
			var sub_text = $('.sub_text').val();
			if(sub_text == "" || (sub_text != "" && !/.+@.+\.[a-zA-Z]{2,4}$/.test(sub_text))){
				$('.sub_text').val('请输入正确的Email');
			}else{
				$.post("http://www.wetuan.com/sub.php",{
					email: $('.sub_text').val()
					},function (data, textStatus){
					if(data == "0"){
						$('.sub_text').val('恭喜您，成功订阅！');
					}else{
						$('.sub_textn').val('抱歉，该邮箱已参与订阅');
					}
				});
			}			
		});
		
		//日期计算
		$last = $('div #last').val();
		if($last){
			$start = $('div #date_of').val();
			$end = $('div #last').val();
			$str = AddDays($start,$end);
			$('div #last').next().html($str);
		}
		
		$('div #last').keyup(function(event){
			$start = $('div #date_of').val();
			$end = $('div #last').val();
			$str = AddDays($start,$end);
			$(this).next().html($str);
		});
		
	});

	
	function _fc(){
		//January February March April May June July August September October November December
		var endtime=new Date(overtime+" 00:00:00");
		var nowtime = new Date();
		var leftsecond=parseInt((endtime.getTime()-nowtime.getTime())/1000);
		if(leftsecond<0){leftsecond=0;}
		//__d=parseInt(leftsecond/3600/24);
		__h=parseInt(leftsecond/3600);
		__m=parseInt((leftsecond/60)%60);
		__s=parseInt(leftsecond%60);
		//__all = __d+"天"+__h+"小时"+__m+"分"+__s+"秒";
		//if(__h == 0){
			//if(__m < 10) __m = "0"+__m;
			//if(__s < 10) __s = "0"+__s;
			//__all = __m+"分"+__s+"秒"+"后结束";
			//__all = "<h1>"+__m+"</h1><i>:</i><h1>"+__s+"</h1>";
		//}else{
			if(__m < 10) __m = "0"+__m;
			if(__h < 10) __h = "0"+__h;
			if(__s < 10) __s = "0"+__s;
			//__all = __h+"时"+__m+"分"+__s+"秒"+"后结束";
			__all = "<h1>"+__h+"</h1><h2>:</h2><h1>"+__m+"</h1><h2>:</h2><h1>"+__s+"</h1>";
		//}
		$(".fc").html(__all);
	}
	
	function orderinfo_open(id){
		$('.orderinfo').hide();
		$(id).show();
	}
	
	function orderinfo_close(id){
		$(id).hide();
	}
	
	function inviteinfo_open(id){
		$('.inviteinfo').hide();
		$(id).show();
	}
	
	function inviteinfo_close(id){
		$(id).hide();
	}
	
	function fahuoinfo_open(id){
		$('.fahuoinfo').hide();
		$(id).show();
	}
	
	function fahuoinfo_close(id){
		$(id).hide();
	}
	
	//cookie
	function SetCookie(name,value){//两个参数，一个是cookie的名子，一个是值
		var Days = 1; //此 cookie 将被保存 30 天
		var exp  = new Date();    //new Date("December 31, 9998");
		exp.setTime(exp.getTime() + Days*24*60*60*1000);
		document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
	}
	function getCookie(name){
		var strCookie=document.cookie;
		var arrCookie=strCookie.split("; ");
		for(var i=0;i<arrCookie.length;i++){
			var arr=arrCookie[i].split("=");
			if(arr[0]==name){
				return unescape(arr[1]);
			}
		}	
		return false;
	}
	
	function AddDays(obj1,obj2) {  //obj1：原始时间 obj3：天数
		DaysToAdd=obj2;
		var sjrqq=obj1;
		var tmp = sjrqq.split('-');
		var sjrqqtmp=tmp[0]+"/"+tmp[1]+"/"+tmp[2];
		var newdate=new Date(sjrqqtmp);          //yyyy-MM-dd转化为日期格式
		var lx=2;
		if(lx=="2"){   //加
		var newtimems=newdate.getTime()+(DaysToAdd*24*60*60*1000);
		}
		else{            //减
		var newtimems=newdate.getTime()-(DaysToAdd*24*60*60*1000);
		}
		newdate.setTime(newtimems);
		var date = formatDate(newdate);  
		return date;
	}
 

	//日期格式转化为yyyy-MM-dd
	function formatDate(_date){
		var day = _date;
		var Year = 0;
		var Month = 0;
		var Day = 0;
		var CurrentDate = "";
		//初始化时间
		//Year       = day.getYear();//有火狐下2008年显示108的bug
		Year       = day.getFullYear();//ie火狐下都可以
		Month      = day.getMonth()+1;
		Day        = day.getDate();

		CurrentDate += Year + "-";

		if (Month >= 10 )
		{
		CurrentDate += Month + "-";
		}
		else
		{
		CurrentDate += "0" + Month + "-";
		}
		if (Day >= 10 )
		{
		CurrentDate += Day ;
		}
		else
		{
		CurrentDate += "0" + Day ;
		}
		return CurrentDate;
	}
	
	//四舍五入
	function ForDight(Dight,How){  
		Dight = Math.round(Dight*Math.pow(10,How))/Math.pow(10,How);  
		return Dight;  
	}  
