$(function(){
	//没点击过才显示
	if ((getCookie("zhekou")=="")) {
		$(document.body).append("<a href=\"#\" class=\"eggs\"></a>");
	}

	var zhekou = parseInt(Math.random() * 9);
	while (zhekou < 6) {
		zhekou = parseInt(Math.random() * 9);
	}
	$(".eggs").css({
	left:Math.abs((document.body.scrollWidth - 200) * Math.random()),
	top:Math.abs((document.body.scrollHeight - 200) * Math.random()),
	}).attr("class","eggs egg"+zhekou).click(function(){
		setCookie("zhekou",zhekou,30);
		alert("恭喜您获得了一枚彩蛋！\n\n请将您的幸运码 "+parseInt(Math.random()* 999999)+" 截图发送给客服。\n\n购买产品可以享受 "+zhekou+" 折优惠！！");
		$(this).hide();
	});
	setInterval(function(){$(".eggs").fadeTo("slow",0.5).fadeTo("slow",1);},1000);
});
function getCookie(Name) //cookies读取
{
	var search = Name + "="
	if(document.cookie.length > 0)
	{
		offset = document.cookie.indexOf(search)
		if(offset != -1)
		{
			offset += search.length
			end = document.cookie.indexOf(";", offset)
			if(end == -1) end = document.cookie.length
			return unescape(document.cookie.substring(offset, end))
		 }
	else return ""
		}
}
function setCookie(name, value) //cookies设置
{
	var argv = setCookie.arguments;
	var argc = setCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	if(expires!=null)
	{
		var LargeExpDate = new Date ();
		LargeExpDate.setTime(LargeExpDate.getTime() + (expires*1000*3600*24));
	}
	document.cookie = name + "=" + escape (value)+((expires == null) ? "" : ("; expires=" +LargeExpDate.toGMTString()));
}

