var _AVATAR_HOST = "avatar.17wow.com";
var _FROM_GBOX = document.location.host.indexOf("gbox")==-1?false:true;
document.domain="17wow.com";


kstatus();
function kstatus(){
	self.status="如果你喜欢本站,别忘了把本站的网址告诉给你身边的朋友哦!,谢谢你的支持";
	setTimeout("kstatus()",100);
}

function generateAvatarUrl(user, b) {
	var a1 = 0,a2 = 0,	i, rs;
	b = b ? b : 0;
	for (i = 0; i < user.length; i++) {
		a1 += user.charCodeAt(i) * i;
		a2 += user.charCodeAt(i) * (i * 2 + 1);
	}
	a1 %= 30;
	a2 %= 30;
	rs = 'http://'+_AVATAR_HOST+'/img/' + a1 + "/" + a2 + "/";
	if (b) {
		return rs + user + "_b.jpg";
	} else {
		return rs + user + "_s.jpg";
	}
}
function comm_read_cookie(name)
{
	var cookieValue = ""; 
	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; 
			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=17wow.com;path=/;";
};
function parse_str(string){
	var a = [];
	var oRs = {};
	var query = string.substr(string.indexOf('?')+1);
	var tmp = query.split('&');
	var k;
	for(var i=0;i<tmp.length;i++){
		a = tmp[i].split('=');
		oRs[a[0]] = a[1];
	}
	return oRs;
};

function showhistory(user_admin){
	var history = comm_read_cookie('minigame_history');
	var history_list = '';
	user_admin = user_admin || -1;
	if(history !='' && history != null){
		history = eval('('+ history +')');
		for(var i=0;i<history.length;i++){
			if(user_admin==-1) { //not user admin page
				history_list = history_list + '<a href="/game/'+ history[i].id +'.html" target="_blank">'+history[i].name+'</a> ';
			}else{
				history_list = history_list + '<li style="text-align:left;height:22px;line-height:22px;border-bottom:#CCC dashed 1px;"><span style="float:left;width:16px;margin-right:3px;color:#ddd;font-weight:bold;">'+ (i+1) +'</span><a href="/game/'+ history[i].id +'.html" target="_blank">'+ history[i].name +'</a></li>';
			}
		}
		if(history_list){
			$("#history").show();
			if(user_admin==-1) { //not user admin page, eq play page, etc.
				$("#history").html( '<label>我玩过的游戏：</label>' + history_list );
			}else{
				$("#history").html( history_list );
			}
		}
	}else{
		$("#history").html('<li style="text-align:left;height:20px;line-height:20px;border-bottom:#CCC dashed 1px;">无历史记录</li>');;
		
	}
};

function search_input_bkgd() {
	if (document.getElementById('search_input').value.length <= 0) {
		document.getElementById('search_input').style.cssText = 'background: url(http://www.17wow.com/static/img/bkgd-searchinput.png) left center no-repeat;';
		}
	else {
		document.getElementById('search_input').style.cssText = 'background: none;';
	}
}

function addBookmark(title) {
	var url=parent.location.href;
	if (window.sidebar) { 
		window.sidebar.addPanel(document.title, url,""); 
	} else if( document.all ) {
		window.external.AddFavorite( url, document.title);
	} else if( window.opera && window.print ) {
		return true;
	}
}
function SetHome(obj,vrl){
	try{
		obj.style.behavior='url(#default#homepage)';obj.setHomePage(vrl);
	}
	catch(e){
		if(window.netscape) {
			try {
				netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");  
			}  
			catch (e) 
			{ 
				alert("抱歉！您的浏览器不支持直接设为首页。请在浏览器地址栏输入“about:config”并回车然后将[signed.applets.codebase_principal_support]设置为“true”，点击“加入收藏”后忽略安全提示，即可设置成功。");  
			}
			var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
			prefs.setCharPref('browser.startup.homepage',vrl);
		}
	}
};

//固浮广告 Begin
var delta = 0.95;
var collection;
function floaters() {
	this.items = [];
	this.addItem = function(id, x, y, content) {
		document.write('<span id='+id+' style="Z-INDEX: 10; POSITION: absolute;  width:80px; height:60px;left:'+(typeof (x) == 'string' ? eval(x) : x)+';top:'+(typeof (y) == 'string' ? eval(y) : y)+'">'+content+'</span>');
		var newItem = {};
		newItem.object = document.getElementById(id);
		newItem.x = x;
		newItem.y = y;
		this.items[this.items.length] = newItem;
	};
	this.play = function() {
		collection = this.items;
		setInterval('play()', 10);
	};
}
function play() {
	for (var i = 0; i<collection.length; i++) {
		var followObj = collection[i].object;
		var followObj_x = (typeof (collection[i].x) == 'string' ? eval(collection[i].x) : collection[i].x);
		var followObj_y = (typeof (collection[i].y) == 'string' ? eval(collection[i].y) : collection[i].y);
		if (followObj.offsetLeft != (document.documentElement.scrollLeft+followObj_x)) {
			var dx = (document.documentElement.scrollLeft+followObj_x-followObj.offsetLeft)*delta;
			dx = (dx>0 ? 1 : -1)*Math.ceil(Math.abs(dx));
			followObj.style.left = followObj.offsetLeft+dx + 'px';
		}
		if (followObj.offsetTop != (document.documentElement.scrollTop+followObj_y)) {
			var dy = (document.documentElement.scrollTop+followObj_y-followObj.offsetTop)*delta;
			dy = (dy>0 ? 1 : -1)*Math.ceil(Math.abs(dy));
			followObj.style.top = followObj.offsetTop+dy + 'px';
		}
		//followObj.style.display	= ''; 
	}
}
var theFloaters = new floaters();
theFloaters.play();
//固浮广告 End 




////////////////// global ////////////////////
var __LOGIN = false;
var __USER = {};
(function(){
	var ck=comm_read_cookie("__wow_user");
	if(ck) {
		var u=parse_str(unescape(ck));
		__LOGIN = true;
		__USER = u;
	}
}
)();
