/* Search */
function strlen(str){var i;var len = 0;for (i=0;i<str.length;i++) if (str.charCodeAt(i)>255) len+=2; else len++;return len;}

function checksearch(obj) {if (obj.k.value=="" || obj.k.value=="搜索小游戏"){obj.k.className = "sh text clicked";obj.k.value="";alert("请输入搜索关键字.");obj.k.focus();return false;}if (strlen(obj.k.value)<2){alert("关键字不能少于2个字节.");obj.k.focus();return false;}}

function chkSosmart(){
	if($g("smart_input").value=="搜索小游戏"){
		$g("smart_input").value = "";
	}
	$g("smart_input").className = "sh text clicked";
}

/*排行切换*/
function ShowTag2(strTargetId){
	var tag = document.getElementById("tags2").getElementsByTagName("a");
	for(i=3; i<5; i++){
		if(strTargetId=='tagContent'+i){
				if(i==3){
					tag[i-3].className = "listltit-1-on";
				}else{
					tag[i-3].className = "listltit-2-on";
				}
				document.getElementById('tagContent'+i).style.display = "block";
		}else{
				if(i==3){
					tag[i-3].className = "listltit-1";
				}else{
					tag[i-3].className = "listltit-2";
				}
				document.getElementById('tagContent'+i).style.display = "none";
		}
	}
}
/*我玩过的游戏*/
function $g(o){return document.getElementById(o)}

function $s(i,a){$g(i).style.display=a?'':'none';}

function getCookie(name){var strCookies = document.cookie;var cookieName = name + "=";var valueBegin, valueEnd, value;valueBegin = strCookies.indexOf(cookieName);if (valueBegin == -1) return null;valueEnd = strCookies.indexOf(";", valueBegin);if (valueEnd == -1)valueEnd = strCookies.length;value = strCookies.substring(valueBegin+cookieName.length,valueEnd);return unescape(value);}

function setCookie (name, value) {var argv = setCookie.arguments;var argc = setCookie.arguments.length;var path = (argc > 2) ? argv[2] : null;var expireDays = (argc > 3) ? argv[3] : 365;var domain = (argc > 4) ? argv[4] : ".xmobil.net";var secure = (argc > 5) ? argv[5] : false;var date=new Date();date.setTime(date.getTime()+expireDays*24*3600*1000);deleteCookie (name);document.cookie = name + "=" +  escape(value) + ((expireDays == null) ? "" : ("; expires=" + date.toGMTString())) + ((path == null) ? "" : ("; path=" + path));}

function checkCookieExist(name){	if (getCookie(name))return true;else return false;}

function deleteCookie (name) {  var exp = new Date();  exp.setTime (exp.getTime() - 1); var cval = getCookie (name); document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();}

var hsgames_length=30;

function gethsgames(){var c=getCookie('cookie_hs');if(!c)return new Array();var t=c.split("|||");if(t[0]!=="xmobil.net")return new Array();t.shift();return t}

function getlastgame(){var a=document.location;a=a.href.replace(a.hash,'').replace(a.search,'').replace('?','');var c=a.split("/");a=c[c.length-1];a=a.substr(0,a.length-4);var b=[title,a];return b}

function ordergame(h){var c=new Array();for(var i in h){var ogame=h[i].split("||");c[i]=ogame}return c.sort(function(a,b){return b[2]-a[2]})}

function sethscookie(){var a=getlastgame();var b=gethsgames();var c=false;for(var i in b){var ohsgame=b[i].split("||");if(ohsgame.slice(0,2).join()==a.join()){ohsgame[2]++;b[i]=ohsgame.join("||");c=true;break}}if(!c){a.push("0");b.unshift(a.join("||"));if(b.length>hsgames_length)b.pop()}b.unshift("xmobil.net");var d=b.join("|||");setCookie('cookie_hs',d,'/',999999)}

function editCookie(deleteid,sname){
	var aa = confirm("确实要删除 "+sname+" 的游戏记录吗?");
	if(aa==true){
		var a="xmobil.net";
		var b=ordergame(gethsgames());
		if(b.length>0){
			for(var i in b){
				if(b[i][1]!=deleteid){
					if(a==""){
						a=b[i][0]+"||"+b[i][1]+"||"+b[i][2];
					}else{
						a=a+"|||"+b[i][0]+"||"+b[i][1]+"||"+b[i][2];
					}
				}
			}
		}
		setCookie('cookie_hs',a,'/',999999);
	}
}

function showdelete(deleteid){
	var b=ordergame(gethsgames());
	if(b.length>0){
		for(var i in b){
			var slink = b[i][1];
			var sname = b[i][0];
			var controlname = 'close'+slink;
			var blankname = 'blank'+slink;
			if(b[i][1]==deleteid){
				//选中的那个出现删除
				document.getElementById(controlname).style.display="";
				document.getElementById(blankname).style.display="none"
			}else{
				//选中的那个出现删除
				document.getElementById(controlname).style.display="none";
				document.getElementById(blankname).style.display=""				
			}
		}
	}
}

var hsfast=false;

function showhsgames(){
	var a="";var b=ordergame(gethsgames());
	if(b.length>0){
		$g('myhistory').style.display='block';
		for(var i in b){
			var slink = b[i][1];
			var sname = b[i][0];
			var hsgamelink=slink+'.htm';
			var controlname = 'close'+slink;
			var blankname = 'blank'+slink;
			a+="<a href='/flash/"+hsgamelink+"?1024' title='玩了"+(++b[i][2])+"次,鼠标点击右侧删除图标可以从记录中删掉此游戏记录' onmousemove='showdelete(\""+slink+"\")'>"+b[i][0]+"</a><span style='cursor:pointer;vertical-align:middle;display:none;background:url(/images/close6.gif) no-repeat 0 0;' onclick='editCookie(\""+slink+"\",\""+sname+"\")' id='"+controlname+"'>&nbsp;&nbsp;</span><span id='"+blankname+"' style='display:\"\"'>&nbsp;&nbsp;</span>";
		}
		$g('hscontent').innerHTML='<div id="hscontentdiv">'+a+'</div>';
		if($g('hscontent').scrollWidth>$g('hscontent').offsetWidth){$g('hscontent').style.width=($g('myhistory').offsetWidth-160)+"px";$s('hsb',1)}
	}
	else{$g('myhistory').style.display='none'}
	$g('hsl').onmouseover=function(){hsm(1,0)};$g('hsl').onmouseout=function(){hsm(1,1)};$g('hsl').onmousedown=function(){hsfast=true};$g('hsl').onmouseup=function(){hsfast=false};$g('hsr').onmouseover=function(){hsm(0,0)};$g('hsr').onmouseout=function(){hsm(0,1)};$g('hsr').onmousedown=function(){hsfast=true};$g('hsr').onmouseup=function(){hsfast=false};window.setTimeout(function(){showhsgames()},5000)}

function hsm(f,s){if($g('hscontent').scrollLeft=="0"){if($g('hsl').className=="hsl_y")$g('hsl').className="hsl_n"}else{if($g('hsl').className=="hsl_n")$g('hsl').className="hsl_y"}if($g('hscontent').scrollLeft+$g('hscontent').offsetWidth>=$g('hscontent').scrollWidth){if($g('hsr').className=="hsr_y")$g('hsr').className="hsr_n"}else{if($g('hsr').className=="hsr_n")$g('hsr').className="hsr_y"}if(s){clearTimeout(hst)}else{$g('hscontent').scrollLeft+=hsfast?f?-10:10:f?-3:3;hst=window.setTimeout(function(){hsm(f,s)},20)}}

function hsClear(){
	if (confirm("确定清空‘我玩过的游戏’吗？")){
		setCookie('cookie_hs','','/',999999);
		$g('myhistory').style.display='none';
	}
}
/*横向滚动*/
var sina = {
	$: function(objName) {
		if (document.getElementById) {
			return eval('document.getElementById("' + objName + '")')
		} else {
			return eval('document.all.' + objName)
		}
	},
	isIE: navigator.appVersion.indexOf("MSIE") != -1 ? true: false,
	addEvent: function(l, i, I) {
		if (l.attachEvent) {
			l.attachEvent("on" + i, I)
		} else {
			l.addEventListener(i, I, false)
		}
	},
	delEvent: function(l, i, I) {
		if (l.detachEvent) {
			l.detachEvent("on" + i, I)
		} else {
			l.removeEventListener(i, I, false)
		}
	},
	readCookie: function(O) {
		var o = "",
		l = O + "=";
		if (document.cookie.length > 0) {
			var i = document.cookie.indexOf(l);
			if (i != -1) {
				i += l.length;
				var I = document.cookie.indexOf(";", i);
				if (I == -1) I = document.cookie.length;
				o = unescape(document.cookie.substring(i, I))
			}
		};
		return o
	},
	writeCookie: function(i, l, o, c) {
		var O = "",
		I = "";
		if (o != null) {
			O = new Date((new Date).getTime() + o * 3600000);
			O = "; expires=" + O.toGMTString()
		};
		if (c != null) {
			I = ";domain=" + c
		};
		document.cookie = i + "=" + escape(l) + O + I
	},
	readStyle: function(I, l) {
		if (I.style[l]) {
			return I.style[l]
		} else if (I.currentStyle) {
			return I.currentStyle[l]
		} else if (document.defaultView && document.defaultView.getComputedStyle) {
			var i = document.defaultView.getComputedStyle(I, null);
			return i.getPropertyValue(l)
		} else {
			return null
		}
	}
}; //滚动图片构造函数
//UI&UE Dept. mengjia
//080623
function ScrollPic(scrollContId, arrLeftId, arrRightId) {
	this.scrollContId = scrollContId;
	this.arrLeftId = arrLeftId;
	this.arrRightId = arrRightId;
	this.pageWidth = 0;
	this.frameWidth = 0;
	this.speed = 10;
	this.space = 10;
	this.autoPlay = true;
	this.autoPlayTime = 5;
	var _autoTimeObj, _scrollTimeObj, _state = "ready", _picDownload = false;
	this.stripDiv = document.createElement("div");
	this.listDiv01 = document.createElement("ul");
	this.listDiv02 = document.createElement("ul");
	if (!ScrollPic.childs) {
		ScrollPic.childs = []
	};
	this.ID = ScrollPic.childs.length;
	ScrollPic.childs.push(this);
	this.initialize = function() {
		if (!this.scrollContId) {
			throw new Error("必须指定scrollContId.");
			return
		};
		this.scrollContDiv = $g(this.scrollContId);
		if (!this.scrollContDiv) {
			throw new Error("scrollContId不是正确的对象.(scrollContId = \"" + this.scrollContId + "\")");
			return
		};
		this.scrollContDiv.style.width = this.frameWidth + "px";
		this.scrollContDiv.style.overflow = "hidden";
		this.listDiv01.innerHTML = this.listDiv02.innerHTML = this.scrollContDiv.innerHTML;
		this.scrollContDiv.innerHTML = "";
		this.scrollContDiv.appendChild(this.stripDiv);
		this.stripDiv.appendChild(this.listDiv01);
		this.stripDiv.appendChild(this.listDiv02);
		this.stripDiv.style.overflow = "hidden";
		this.stripDiv.style.zoom = "1";
		this.stripDiv.style.width = "32766px";
		this.listDiv01.style.cssFloat = "left";
		this.listDiv02.style.cssFloat = "left";
		sina.addEvent(this.scrollContDiv, "mouseover", Function("ScrollPic.childs[" + this.ID + "].stop()"));
		sina.addEvent(this.scrollContDiv, "mouseout", Function("ScrollPic.childs[" + this.ID + "].play()"));
		if (this.arrLeftId) {
			this.arrLeftObj = $g(this.arrLeftId);
			if (this.arrLeftObj) {
				sina.addEvent(this.arrLeftObj, "mousedown", Function("ScrollPic.childs[" + this.ID + "].rightMouseDown()"));
				sina.addEvent(this.arrLeftObj, "mouseup", Function("ScrollPic.childs[" + this.ID + "].rightEnd()"));
				sina.addEvent(this.arrLeftObj, "mouseout", Function("ScrollPic.childs[" + this.ID + "].rightEnd()"))
			}
		};
		if (this.arrRightId) {
			this.arrRightObj = $g(this.arrRightId);
			if (this.arrRightObj) {
				sina.addEvent(this.arrRightObj, "mousedown", Function("ScrollPic.childs[" + this.ID + "].leftMouseDown()"));
				sina.addEvent(this.arrRightObj, "mouseup", Function("ScrollPic.childs[" + this.ID + "].leftEnd()"));
				sina.addEvent(this.arrRightObj, "mouseout", Function("ScrollPic.childs[" + this.ID + "].leftEnd()"))
			}
		};
		if (this.autoPlay) {
			this.play()
		}
	};
	this.leftMouseDown = function() {
		if (_state != "ready") {
			return
		};
		_state = "floating";
		if (!_picDownload){
			var arrImg=this.scrollContDiv.getElementsByTagName("IMG");
			for (var j=11;j<arrImg.length;j++){
				if (arrImg[j].name!=""){
					arrImg[j].src = arrImg[j].name;
				}
			}
			_picDownload = true;
		}
		_scrollTimeObj = setInterval("ScrollPic.childs[" + this.ID + "].moveLeft()", this.speed)
	};
	this.rightMouseDown = function() {
		if (_state != "ready") {
			return
		};
		_state = "floating";
		if (!_picDownload){
			var arrImg=this.scrollContDiv.getElementsByTagName("IMG");
			for (var j=11;j<arrImg.length;j++){
				if (arrImg[j].name!=""){
					arrImg[j].src = arrImg[j].name;
				}
			}
			_picDownload = true;
		}
		_scrollTimeObj = setInterval("ScrollPic.childs[" + this.ID + "].moveRight()", this.speed)
	};
	this.moveLeft = function() {
		//alert(this.scrollContDiv.scrollLeft)
		if (this.scrollContDiv.scrollLeft + this.space >= this.listDiv01.scrollWidth) {
			this.scrollContDiv.scrollLeft = this.scrollContDiv.scrollLeft + this.space - this.listDiv01.scrollWidth
		} else {
			this.scrollContDiv.scrollLeft += this.space
		};
	};
	this.moveRight = function() {
		if (this.scrollContDiv.scrollLeft - this.space <= 0) {
			this.scrollContDiv.scrollLeft = this.listDiv01.scrollWidth + this.scrollContDiv.scrollLeft - this.space
		} else {
			this.scrollContDiv.scrollLeft -= this.space
		};
	};
	this.leftEnd = function() {
		if (_state != "floating") {
			return
		};
		_state = "stoping";
		clearInterval(_scrollTimeObj);
		var fill = this.pageWidth - this.scrollContDiv.scrollLeft % this.pageWidth;
		this.move(fill)
	};
	this.rightEnd = function() {
		if (_state != "floating") {
			return
		};
		_state = "stoping";
		clearInterval(_scrollTimeObj);
		var fill = -this.scrollContDiv.scrollLeft % this.pageWidth;
		this.move(fill)
	};
	this.move = function(num, quick) {
		var thisMove = num / 5;
		if (!quick) {
			if (thisMove > this.space) {
				thisMove = this.space
			};
			if (thisMove < -this.space) {
				thisMove = -this.space
			}
		};
		if (Math.abs(thisMove) < 1 && thisMove != 0) {
			thisMove = thisMove >= 0 ? 1 : -1
		} else {
			thisMove = Math.round(thisMove)
		};
		var temp = this.scrollContDiv.scrollLeft + thisMove;
		if (thisMove > 0) {
			if (this.scrollContDiv.scrollLeft + thisMove >= this.listDiv01.scrollWidth) {
				this.scrollContDiv.scrollLeft = this.scrollContDiv.scrollLeft + thisMove - this.listDiv01.scrollWidth
			} else {
				this.scrollContDiv.scrollLeft += thisMove
			}
		} else {
			if (this.scrollContDiv.scrollLeft - thisMove <= 0) {
				this.scrollContDiv.scrollLeft = this.listDiv01.scrollWidth + this.scrollContDiv.scrollLeft - thisMove
			} else {
				this.scrollContDiv.scrollLeft += thisMove
			}
		};
		num -= thisMove;
		if (Math.abs(num) == 0) {
			_state = "ready";
			if (this.autoPlay) {
				this.play()
			};
			return
		} else {
			setTimeout("ScrollPic.childs[" + this.ID + "].move(" + num + "," + quick + ")", this.speed)
		}
	};
	this.next = function() {
		if (_state != "ready") {
			return
		};
		_state = "stoping";
		this.move(this.pageWidth, true)
	};
	this.play = function() {
		if (!this.autoPlay) {
			return
		};
		clearInterval(_autoTimeObj);
		_autoTimeObj = setInterval("ScrollPic.childs[" + this.ID + "].next()", this.autoPlayTime * 1000)
	};
	this.stop = function() {
		clearInterval(_autoTimeObj)
	};
	this.pageTo = function(num) {
		if (_state != "ready") {
			return
		};
		_state = "stoping";
		var fill = num * this.frameWidth - this.scrollContDiv.scrollLeft;
		this.move(fill, true)
	};
};
