﻿//cookie
function comm_read_cookie(name){var cookieValue = "", 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;cookieValue = unescape(document.cookie.substring(offset, end));}}return cookieValue;};
function comm_set_cookie(name,value,expirehours){var expiration = new Date((new Date()).getTime() +expirehours*3600000);document.cookie = name+ "=" + value + ";expires=" + expiration.toGMTString()+";domain=www.7k7k.com;path=/;";};
//skin
function setskin(n){var o=document.getElementById("skins");o.href=skin[n];comm_set_cookie("skins",n,7);}
//vote
$("#vote").bind("click",function(){$.getScript("http://count.7k7k.com/vote/?id="+_gameid,function(){$("#vote").fadeOut("fast");$("#vote").fadeIn("slow");$("#vote").unbind("click");});});
function changevote(v){alert('投票成功,共得'+v+'票');$("#vote").html("投票：<span>"+v+"</span>");};
//score
(function(n){
	var objs = $("#score > span");
	var set = function(s){
		if(s > objs.length) return;
		for(var i=0;i<objs.length;i++){
			if(i<s) objs[i].className = "on";
			else objs[i].className = "";
		}
	};
	set(n);
	for(var j=0;j<objs.length;j++){
		objs[j].index = j+1;
		$(objs[j]).bind("mouseover",function(e){set(this.index);});
		$(objs[j]).bind("click",function(){$.getScript("http://count.7k7k.com/star/?id="+_gameid+"&star="+ this.index,function(){$("#score").fadeOut("fast");$("#score").fadeIn("slow");});});
	}
	$("#score").bind("mouseout",function(e){set(n);});
})(_gamestar);
function restar(v,t){alert('评分成功,平均得'+ v +'分');}
//search
$("#k").bind("focus",function(){if(this.value === this.title) this.value = "";});
$("#k").bind("blur",function(){if(this.value === "") this.value = this.title;});
$("#sobtn").bind("click", function(){if($("#k").val()=="" || $("#k").val()==$("#k").attr("title")){$("#k").focus();return false;}else{$("#so").submit();}});
//fullscreen
$("#fs_a").bind("click",function(){$("#fs_a").attr("target","_blank");$("#fs_a").attr("href","../swf.htm?gamepath="+_p+"&gamevar="+_v+"&gamemark="+_gamemark);});
$("#down_a").attr("href","../down/"+ _gameid +".htm");
$("#fav_a").bind("click",function(){var _k = comm_read_cookie("uid");if(_k){$.getScript("http://my.7k7k.com/fav.php?do=list&action=add&gameid="+_gameid+"&gamename="+ encodeURI(_gamename) +"&image="+ _gamepic +"&type=1",function(){$("#fav_a").unbind("click");alert("收藏添加成功！");});$.getScript("http://count.7k7k.com/fav/?id="+_gameid,function(){return;});}else{if(document.all){window.external.addFavorite(location.href+'?fav5',document.title);}else if(window.sidebar){window.sidebar.addPanel(document.title,location.href+'?fav5','');}}});
function StoredGame(o){if(o.result == "True"){alert("收藏成功");}else{alert("收藏失败");}};
$("#send_a").bind("click",function(){window.clipboardData.setData("text",location.href+'?clip\n这个是我很喜欢的小游戏，名字叫《'+_gamename+'》，真诚向你推荐，希望你也会喜欢哦!');alert("网址已复制好，粘贴发给好朋友一起玩吧^_^");});
//右侧相关选项卡
var tabcard = function(){
	//初始化
	var ctrls = $("#slide_game > li"),
	contents = $("#right_box > div"),
	activecss = "active",
	normalcss = "content",
	preindex;
	//绑定事件
	for(var i=0;i<ctrls.length;i++){
		if(contents[i].className === (normalcss + " " + activecss)){preindex = i;$(ctrls[i]).addClass(activecss);}
		else{$(ctrls[i]).removeClass(activecss);}
		$(ctrls[i]).bind("click", (function(i){return function(){jump(i);};})(i));
	}
	var jump = function(num){
		$(contents[preindex]).removeClass(activecss);
		$(ctrls[preindex]).removeClass(activecss);
		$(contents[num]).addClass(activecss);
		$(ctrls[num]).addClass(activecss);
		preindex = num;
	};
	return jump;
}();
$("#playmethod").bind("click",function(){tabcard(1);});
//相关游戏分页
(function(){
	//初始化
	var ctrls = $("#pages > span > img"),
	contents = $("#slide_page > div.list"),
	activecss = "current",
	normalcss = "list",
	preindex = 0;
	//绑定事件
	for(var i=0;i<contents.length;i++){
		if(contents[i].className === (normalcss + " " + activecss)){preindex = i;$(ctrls[i]).addClass(activecss);contents[i].datastatus = 1;}
		else{$(ctrls[i]).removeClass(activecss);contents[i].datastatus = 0;}
		$(ctrls[i]).bind("click", (function(i){return function(){jump(i);};})(i));
	}
	$("#pre").bind("click",function(){if(preindex>0){jump(preindex-1);}});
	$("#next").bind("click",function(){if(preindex<ctrls.length-1){jump(preindex+1);}});
	var jump = function(num){
		if(!contents[num].datastatus){
			var htmlstr = $(contents[num]).html(),htmlstr = htmlstr.replace("<!--",""),htmlstr = htmlstr.replace("-->","");
			$(contents[num]).html(htmlstr);
			contents[num].datastatus = 1;
		}
		$(contents[preindex]).removeClass(activecss);
		$(ctrls[preindex]).removeClass(activecss);
		$(contents[num]).addClass(activecss);
		$(ctrls[num]).addClass(activecss);
		preindex = num;
	};
})();
//随机背景切换
(function(){
	var curbgnum = Math.floor(Math.random()*skin.length);
	$("#ctrlbg").bind("click",function(){if(curbgnum >= skin.length)curbgnum = 0;setskin(curbgnum);curbgnum += 1;return false;});
})();
//comment
$("#comment").html('<iframe name="comment" frameborder="0" width="928" height="1" marginwidth="0" marginheight="0" scrolling="no" src="http://comment.7k7k.com/web_1/?id='+_gameid +'&amp;type=1&amp;up=1&amp;title='+escape(_gamename)+'"></iframe>');
