var canload=true;
var curpage;
var pagenum;

$(document).ready(function(){
	
	curpage=Number($("#curpage").html());
	pagenum=Number($("#pagenum").html());
	
	$(".topbanner").hide();
	$(".topbanner").fadeIn(600);
	$(".topbanner").fadeOut();
	$(".topbanner").fadeIn(600);
	
    var myos = appInfo();
   /* if (!myos.msie){
    	$(".postweibo a.weibo5").css("padding-left","18px");
    	$(".postweibo a.weibo2").css("padding-left","18px");
    	$(".postweibo a.weibo6").css("padding-left","18px");
    }*/
	
    $("#subscribe_layer").hide();
	$("#close_subscribe").click(function(){
		$("#subscribe_tip").html("");
			$("#popup_overlay").remove();
			$("#subscribe_layer").fadeOut();
		});
	
	$("#subscribe_text").focus(function(){
		$(this).attr("value",'');
		$("#subscribe_tip").html("");
	});
	
	$("#reffer_sub").click(function(){
		subscribe();
	});
	
	$(".goodss_innerbox").css("position","relative");
	$("#date_span0").css("background-color","red");
	
	var l=$(".contentbody").offset().left+$(".contentbody").width()+30;
	$("a.top").css("left",l+"px");
	$("a.allshop").css("left",l+"px");
	
	$(window).resize(function() {
		  if($(this).width()<$(".contentbody").width()+100){
			  $("a.top").css("left","auto");
			  $("a.allshop").css("left","auto");
			  $("a.top").css("right","9px");
			  $("a.allshop").css("right","9px");
		  }else{
			  var l=$(".contentbody").offset().left+$(".contentbody").width()+30;
			  $("a.top").css("left",l+"px");
			  $("a.allshop").css("left",l+"px");
			  $("a.top").css("right","auto");
			  $("a.allshop").css("right","auto");
		  }
	});

	
	$(window).scroll(function(){
			if($(window).scrollTop()>0){
				$("a.top").fadeIn();
				$("a.allshop").fadeIn();
				findDimensions();
				
				var myos = appInfo();
				if (myos.msie&&myos.version=="6.0"){
					var y=$(window).scrollTop()+400;
					$("a.allshop").css("top",y+"px");
					$("a.allshop").css("position","absolute");
					$("a.top").css("top",y+70+"px");
					$("a.top").css("position","absolute");
				}
			}else{
				$("a.top").fadeOut();
				$("a.allshop").fadeOut();
			}
	});
	
	$('a.top').click(function(){
	    $body.animate({scrollTop: $('#top').offset().top}, 400);
	    return false;
	});
	
	$("img.hoverimg").mouseover(function(){
			$("img.hoverimg").removeClass("current");
			$(this).addClass("current");
		})
		.mouseout(function(){
			$(this).removeClass("current");
		});
	
	$(window).scroll(function(){
			var y=$(window).scrollTop()+1200;
			var h=$(document).height();
			var tag="";
			if($("#nav").html()!="index"){
				tag=$(".here a").html();
			}
			var filter = '';
			if($('.sort-list').length>0){
				filter = $('.sort-list li a.here').attr('id');
			}
			if(y > h){
				if(curpage<pagenum && curpage<3){
					if(canload){
						canload=false;
						$.get("pageload.php", {p:curpage+1,tag:tag,filter:filter},
								function(data){
									$("#curpage").html(curpage+1)
									$(".yhqbox").append(data);
									curpage++;
									if(curpage<pagenum && curpage<3){
										canload=true;
									}else{
										$("#loading").remove();
										$("#ckqbbtn").show();
									}
								});
					}
				}
			}
	});
	
	
});



function appInfo(){
    var browser = {
            msie: false, firefox: false, opera: false, safari: false, 
            chrome: false, netscape: false, appname: 'unknown', version: 0
        },
        userAgent = window.navigator.userAgent.toLowerCase();
    if ( /(msie|firefox|opera|chrome|netscape)\D+(\d[\d.]*)/.test( userAgent ) ){
        browser[RegExp.$1] = true;
        browser.appname = RegExp.$1;
        browser.version = RegExp.$2;
    } else if ( /version\D+(\d[\d.]*).*safari/.test( userAgent ) ){ // safari
        browser.safari = true;
        browser.appname = 'safari';
        browser.version = RegExp.$2;
    }
    return browser;
}

self.setInterval("goodss_scroll()",10000);

function goodss_scroll(){
	$(".goods_scrollbox").each(function(){
			var goodid = $(this).attr("id");
			goodss_scrolldown(goodid);
	});
}

function goodss_scrolldown(id){
	var num=Number($("#goodss_innerbox"+id).attr("count"));
	var count = Math.floor((num-1)/4+1);
	if(count>1){
		var current=Number($("#goodss_innerbox"+id).attr("current"));
		current=(current+1)%count;
		var t=current*(-150);
		$("#goodss_innerbox"+id).animate({top:t});
		$("#goodss_innerbox"+id).attr("current",current);
	}
}

function subscribe(){
	temp_contact=$("#subscribe_text").attr("value");
	var email_partten = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
	var phone_partten = /^(13|15|18)[0-9]{9}$/;
	shopid=$("#reffer_sub").attr("shopid");
	shopids=new Array();
	shopids[0]=shopid;
	if(!temp_contact || !(email_partten.test(temp_contact)||phone_partten.test(temp_contact))){
		$("#subscribe_tip").html("手机或邮箱格式错误");
	}else{
		$.post("fpost.php", { ac: "subscribe", contact:temp_contact, 'shopids[]':shopids },
			function(data){
				$("#subscribe_text").hide();
				$("#subscribe_titlebar").css("left","0px");
				$(".btn14").css({"left":"180px","position":"absolute","top":"77px"});
				$("#subscribe_content").css({"position":"absolute","width":"93%","text-align":"center"});
				if(data=="success"){
					$("#subscribe_titlebar").html("订阅成功！");
					$("#subscribe_content").html('订阅成功！我们将在开售当天通过第一时间通知您！');
				}else{
					$("#subscribe_titlebar").html("提示信息");
					$("#subscribe_content").html('订阅失败，请稍后再试');
				}
				$("#reffer_sub").unbind("click");
				$("#reffer_sub").click(function(){
					$("#popup_overlay").remove();
					$("#subscribe_layer").fadeOut();
				});
			});
	}
}

function shareToSina(goodid){
	var url = encodeURIComponent('http://www.zuitao.com/?utm_source=sinaweibo');
	if($("#goodtit"+goodid).attr("s")==0){
		var title = encodeURIComponent('这个还不错，@最淘网 上的'+$("#goodtit"+goodid).html());
	}else{
		var title = encodeURIComponent('这个还不错，@最淘网 上正在热卖的代金券：'+$("#goodtit"+goodid).html());
    }
	var purl = 'http://www.zuitao.com/cache/img/logo/logo_'+$("#goodtit"+goodid).attr('sid')+'.gif';
	var pic = encodeURIComponent(purl);
	var tsinaUrl = 'http://v.t.sina.com.cn/share/share.php?url=' + url + '&title=' + title +'&pic='+pic; 
    window.open(tsinaUrl);
}

function shareToQQ(goodid){
	var url = encodeURIComponent(APP_ROOT+'?utm_source=qqweibo');
	if($("#goodtit"+goodid).attr("s")==0){
		var title = encodeURIComponent('这个还不错，@zuitaoinc 上的'+$("#goodtit"+goodid).html());
	}else{
		var title = encodeURIComponent('这个还不错，@zuitaoinc 上正在热卖的代金券：'+$("#goodtit"+goodid).html());
   }
	var purl = 'http://www.zuitao.com/cache/img/logo/logo_'+$("#goodtit"+goodid).attr('sid')+'.gif';
	var pic =	encodeURIComponent(purl);
	var tqqUrl = 'http://v.t.qq.com/share/share.php?title=' + title + '&url=' + url + '&site=' + title +'&pic='+pic;
    window.open(tqqUrl);
}

function shareToQzone(goodid){
	var url = encodeURIComponent('http://www.zuitao.com/?utm_source=qzone');
	if($("#goodtit"+goodid).attr("s")==0){
		var title = encodeURIComponent('这个还不错，#最淘网#上的'+$("#goodtit"+goodid).html());
	}else{
		var title = encodeURIComponent('这个还不错，#最淘网#上正在热卖的代金券：'+$("#goodtit"+goodid).html());
   	}
	var summary =encodeURIComponent("最淘网是中国第一家代金券网上商城，这里有超多代金券(京东、凡客、乐淘、1号店等各大网上商城)正在低价出售，，购买后可立即使用，你也快来看看吧！"); 
	var purl = 'http://www.zuitao.com/cache/img/logo/logo_'+$("#goodtit"+goodid).attr('sid')+'.gif';
	var pics = encodeURIComponent(purl);
	var qzoneUrl = 'http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=' + url + '&title=' + title + '&summary=' + summary +'&pics=' +pics;
	window.open(qzoneUrl);
}

function shareToRenren(goodid){
	var url = encodeURIComponent('http://www.zuitao.com/?utm_source=renren');
	if($("#goodtit"+goodid).attr("s")==0){
		var title = encodeURIComponent('这个还不错，最淘网上的'+$("#goodtit"+goodid).html());
	}else{
		var title = encodeURIComponent('这个还不错，最淘网上正在热卖的代金券：'+$("#goodtit"+goodid).html());
   	}
	var purl = 'http://www.zuitao.com/cache/img/logo/logo_'+$("#goodtit"+goodid).attr('sid')+'.gif';
	var summary =encodeURIComponent("最淘网是中国第一家代金券网上商城，这里有超多代金券(京东、凡客、乐淘、1号店等各大网上商城)正在低价出售，，购买后可立即使用，你也快来看看吧！"); 
	var pic = encodeURIComponent(purl);
	var renrenUrl = 'http://share.renren.com/share/buttonshare/post/4001?url=' + url + '&title=' + title+'&pic='+pic+'&content=' + summary;
	window.open(renrenUrl);
}

function subscribeOpen(goodid,shopid){
	$("#reffer_sub").attr("shopid",shopid);
	
	var top=$("#goodtit"+goodid).position().top;
	top+=50;
	findDimensions();
	var w=$("#subscribe_layer").width();
	var left=(winWidth-w)/2;
	
	$("#subscribe_text").attr("value",'手机号或邮箱');
	$("#subscribe_layer").css("position","absolute");
	$("#subscribe_layer").css("top",top+"px");
	$("#subscribe_layer").css("left",left+"px");
	$("#subscribe_titlebar").html("订阅");
	$("#subscribe_text").show();
	$("#subscribe_content").html('请输入您的手机号或者邮箱(Email)地址，我们将在开售当天通过短信或邮件通知您。');
	$("#subscribe_titlebar").css("left","100px");
	$(".btn14").css({"position":"relative","left":"0px","top":"1px"});
	var myos = appInfo();
	if (myos.msie){
		$(".btn14").css("top","3px");
	}
	$("#subscribe_content").css({"position":"relative","width":"93%","text-align":"left"});
	
	$("#reffer_sub").unbind("click");
	$("#reffer_sub").click(function(){
		subscribe();
	});
	
	$("body").append('<div id="popup_overlay"></div>');
	$("#popup_overlay").css({
		position: 'absolute',
		zIndex: 1,
		top: '0px',
		left: '0px',
		width: '100%',
		height: $(document).height(),
		background: '#000000',
		opacity: .30
	});
	
	$("#subscribe_layer").fadeIn();
}

<!-- 
var winWidth = 0;
var winHeight = 0;
function findDimensions()
{
	if (window.innerWidth)
		winWidth = window.innerWidth;
	else if ((document.body) && (document.body.clientWidth))
		winWidth = document.body.clientWidth;
	
	if (window.innerHeight)
		winHeight = window.innerHeight;
	else if ((document.body) && (document.body.clientHeight))
		winHeight = document.body.clientHeight;
	
	if (document.documentElement && document.documentElement.clientHeight && document.documentElement.clientWidth)
	{
		winHeight = document.documentElement.clientHeight;
		winWidth = document.documentElement.clientWidth;
	}
}


function shareToSina_item(title,url,pic,summary){
	title=encodeURIComponent(title);
	url= encodeURIComponent('http://'+document.domain+url);
	pic= encodeURIComponent(pic);
	var tsinaUrl = 'http://v.t.sina.com.cn/share/share.php?url=' + url + '&title=' + title +'&pic='+pic; 
    window.open(tsinaUrl);
}

function shareToQQ_item(title,url,pic,summary){
	title=encodeURIComponent(title);
	url= encodeURIComponent('http://'+document.domain+url);
	pic= encodeURIComponent(pic);
	var tqqUrl = 'http://v.t.qq.com/share/share.php?title=' + title + '&url=' + url + '&site=' + title +'&pic='+pic;
    window.open(tqqUrl);
}

function shareToQzone_item(title,url,pic,summary){
	title=encodeURIComponent(title);
	url= encodeURIComponent('http://'+document.domain+url);
	pic= encodeURIComponent(pic);
	var qzoneUrl = 'http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=' + url + '&title=' + title + '&summary=' + summary +'&pics=' +pic;
	window.open(qzoneUrl);
}

function shareToRenren_item(title,url,pic,summary){
	title=encodeURIComponent(title);
	url= encodeURIComponent('http://'+document.domain+url);
	pic= encodeURIComponent(pic);
	var renrenUrl = 'http://share.renren.com/share/buttonshare/post/4001?url=' + url + '&title=' + title+'&pic='+pic+'&content=' + summary;
	window.open(renrenUrl);
}


//-->


