﻿function getObj(obj){
	return document.getElementById(obj)
}
function addScript(url,id) {
    var g = document.createElement("script");
    g.type = "text/javascript";
    g.src = url;
	if (id) g.id=id;
    var headID = document.getElementsByTagName("head")[0];
	var oScript = getObj(id);
	if (oScript)
	{
		headID.removeChild(oScript);
	}
	headID.appendChild(g);
}

function addIframe(url,id) {
    var g = document.createElement("iframe");
    g.src = url;
	g.style.display='none';
	g.style.width='0px';
	g.style.height='0px';
	g.frameBorder='0px';
	if (id) g.id=id;
    var bd = document.getElementsByTagName("body")[0];
	var oScript = getObj(id);
	if (oScript)
	{
		bd.removeChild(oScript);
	}
	bd.appendChild(g);
}

String.prototype.trim = function(){
	return this.replace(/(^\s+)|(\s+$)/g, "");	
}
	
String.prototype.bytes = function(){
	return this.replace(/[^\x00-\xff]/g, "  ").length;
}

function SetCookie(name,value)
{
   var argv=SetCookie.arguments;
   var argc=SetCookie.arguments.length;
   var expires=(2<argc)?argv[2]:getExpDate(1000,0,0);
   var path=(3<argc)?argv[3]:'default.htm';
   var domain=(4<argc)?argv[4]:null;
   var secure=(5<argc)?argv[5]:false;
   document.cookie=name+"="+escape(value)+((expires==null)?"":("; expires="+expires))+((path==null)?"":("; path="+path))+((domain==null)?"":("; domain="+domain))+((secure==true)?"; secure":"");
}
function GetCookie(Name)
{
   var search = Name + "=";
   var returnvalue = "";
   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;
         returnvalue=unescape(document.cookie.substring(offset,end));
       }
    }
    return returnvalue;
}

function getExpDate(days, hours, minutes)
{
	var expDate = new Date();
	if(typeof(days) == "number" && typeof(hours) == "number" && typeof(hours) == "number")
	{
		expDate.setDate(expDate.getDate() + parseInt(days));
		expDate.setHours(expDate.getHours() + parseInt(hours));
		expDate.setMinutes(expDate.getMinutes() + parseInt(minutes));
		return expDate.toGMTString();
	}
}

function savePlayd(title, link) {
	var my_playd_arr = new Array();
	var playd = title+','+link;
	my_playd = GetCookie('my_play_history');
	my_playd_arr = my_playd.split('|');
	var len = my_playd_arr.length;
	for (i=0;i<len;i++) {
		var tmp = my_playd_arr[i].split(',');
		if (tmp[1] == link) {
			return;
		}
	}
	if (len>=10) my_playd_arr.shift(my_playd_arr);
	my_playd_arr.push(playd);
	my_playd = my_playd_arr.join('|');

	//my_play_history = GetCookie('my_play_history');
	SetCookie('my_play_history', my_playd);
}
function getPlaydLink() {
	my_playd = GetCookie('my_play_history');
	my_playd_arr = my_playd.split('|');
	var playd_html = '';
	for(i=(my_playd_arr.length-1);i>0;i--) {
		var game = my_playd_arr[i].split(',');
		playd_html += '<a href="'+game[1]+'" target="_blank">'+game[0]+'</a>&nbsp;&nbsp;&nbsp;';
	}
	return playd_html;
}


function tabSelect(tab_name, elm_name, len,j, tab_style_s, tab_style, elm_style_s, elm_style) {
	if (!tab_style_s) tab_style_s = 'selectTag';
	if (!tab_style) tab_style = '';
	if (!elm_style_s) elm_style_s = 'ttagContent selectTag';
	if (!elm_style) elm_style = 'ttagContent';
	for(i=0;i<len;i++){
		eval("getObj('"+tab_name+'_'+i+"').className='"+tab_style+"'");
		eval("getObj('"+elm_name+'_'+i+"').style.display='none'");
		if (elm_style_s) {
			eval("getObj('"+elm_name+'_'+i+"').className='"+elm_style+"'");
		}
	}
	eval("getObj('"+tab_name+'_'+j+"').className='"+tab_style_s+"'");
	eval("getObj('"+elm_name+'_'+j+"').style.display=''");
	eval("getObj('"+elm_name+'_'+j+"').className='"+elm_style_s+"'");
}


/*
 * FX
 * Copyright (c) 2009 Ryan Morr (ryanmorr.com)
 * Licensed under the MIT license.
 */
(function(){this.FX=function(el,attributes,duration,callback,ctx){this.el=DOM.get(el);this.attributes=attributes;this.duration=duration||0.7;this.callback=callback||function(){};this.ctx=ctx||window};this.FX.prototype={frame:{},endAttr:{},startAttr:{},start:function(){var fx=this;this.getAttributes();this.duration=this.duration*1000;this.time=new Date().getTime();this.animating=true;this.timer=setInterval(function(){var time=new Date().getTime();if(time<(fx.time+fx.duration)){fx.elapsed=time-fx.time;fx.setCurrentFrame()}else{fx.frame=fx.endAttr;fx.complete()}fx.setAttributes()},1)},stop:function(finish){if(this.animating){if(finish){this.frame=this.endAttr;this.setAttributes()}this.complete()}},ease:function(start,end){return start+((1-Math.cos((this.elapsed/this.duration)*Math.PI))/2)*(end-start)},complete:function(){clearInterval(this.timer);this.timer=null;this.animating=false;this.callback.call(this.ctx)},setCurrentFrame:function(){for(attr in this.startAttr){if(this.startAttr[attr]instanceof Array){this.frame[attr]=[];for(var i=0;i<this.startAttr[attr].length;i++){this.frame[attr][i]=this.ease(this.startAttr[attr][i],this.endAttr[attr][i])}}else{this.frame[attr]=this.ease(this.startAttr[attr],this.endAttr[attr])}}},getAttributes:function(){for(var attr in this.attributes){switch(attr){case'color':case'background-color':this.startAttr[attr]=parseColor(this.attributes[attr].from||DOM.getStyle(this.el,attr));this.endAttr[attr]=parseColor(this.attributes[attr].to);break;case'scrollTop':case'scrollLeft':var el=(this.el==document.body)?(document.documentElement||document.body):this.el;this.startAttr[attr]=this.attributes[attr].from||el[attr];this.endAttr[attr]=this.attributes[attr].to;break;default:this.startAttr[attr]=this.attributes[attr].from||(parseFloat(DOM.getStyle(this.el,attr))||0);this.endAttr[attr]=this.attributes[attr].to;break}}},setAttributes:function(){for(var attr in this.frame){switch(attr){case'opacity':DOM.setStyle(this.el,attr,this.frame[attr]);break;case'scrollLeft':case'scrollTop':var el=(this.el==document.body)?(document.documentElement||document.body):this.el;el[attr]=this.frame[attr];break;case'color':case'background-color':var rgb='rgb('+Math.floor(this.frame[attr][0])+','+Math.floor(this.frame[attr][1])+','+Math.floor(this.frame[attr][2])+')';DOM.setStyle(this.el,attr,rgb);break;default:DOM.setStyle(this.el,attr,this.frame[attr]+'px');break}}}};var DOM={get:function(id){return(typeof id=="string")?document.getElementById(id):id},getStyle:function(el,prop){prop=toCamelCase(prop);var view=document.defaultView;if(view&&view.getComputedStyle){return el.style[prop]||view.getComputedStyle(el,"")[prop]||null}else{if(prop=='opacity'){var opacity=el.filters('alpha').opacity;return isNaN(opacity)?1:(opacity?opacity/100:0)}return el.style[prop]||el.currentStyle[prop]||null}},setStyle:function(el,prop,value){if(prop=='opacity'){el.style.filter="alpha(opacity="+value*100+")";el.style.opacity=value}else{prop=toCamelCase(prop);el.style[prop]=value}}};var toCamelCase=(function(){var cache={};return function(str){if(!cache[str]){return cache[str]=str.replace(/-([a-z])/g,function($0,$1){return $1.toUpperCase()})}else{return cache[str]}}})();var parseColor=function(str){var rgb=str.match(/^#?(\w{2})(\w{2})(\w{2})$/);if(rgb&&rgb.length==4){return[parseInt(rgb[1],16),parseInt(rgb[2],16),parseInt(rgb[3],16)]}rgb=str.match(/^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/);if(rgb&&rgb.length==4){return[parseInt(rgb[1],10),parseInt(rgb[2],10),parseInt(rgb[3],10)]}rgb=str.match(/^#?(\w{1})(\w{1})(\w{1})$/);if(rgb&&rgb.length==4){return[parseInt(rgb[1]+rgb[1],16),parseInt(rgb[2]+rgb[2],16),parseInt(rgb[3]+rgb[3],16)]}}})();

// search
var lastindex=-1;
var search_prompt_flag=false;
var listlength=0;
function StringBuffer(){this.data=[];} 
StringBuffer.prototype.append=function(){this.data.push(arguments[0]);return this;} 
StringBuffer.prototype.tostring=function(){return this.data.join("");} 

var XmlResultBuffer={
	data : {},
	append : function(key,value){this.data[key]=value},
	inBuffer : function(key){if(this.data[key]){return true}else{return false}},
	getBuffer : function(key){if(this.data[key]){return this.data[key]}else{return}}
	
}
var RequestDelayHandle=0;

function $(elm) {
	return getObj(elm);
}

function hiddensearch(){
	if(!$('search_prompt_list') || !$('search_prompt_frame') )return;
    $('search_prompt_list').style.display="none";
    $('search_prompt_frame').style.display="none";
}
function showsearch(num){
	if(!$('search_prompt_list') || !$('search_prompt_frame') )return;
    $('search_prompt_list').style.display='';
    $('search_prompt_frame').style.display='';
    $('search_prompt_list').style.height=num*20+num+'px';
    $('search_prompt_frame').style.height=num*20+num+2+'px';
}

function createlist(){
	//边框
	//var listDiv=document.createElement("div");
	//listDiv.id="search_prompt_list";
	var listDiv=$("search_prompt_list");        
	listDiv.style.zIndex="2";
	listDiv.style.position="absolute"; 
	listDiv.style.border="solid 1px #7D7D7D";
	listDiv.style.backgroundColor="#FFFFFF";
	listDiv.style.display="none";	
	listDiv.style.width=$('search_key').clientWidth+"px";
	
	//内容容器
	var listFrame=$("search_prompt_frame");
	listFrame.style.zIndex="1";
	listFrame.style.position="absolute";
	listFrame.style.border="0";
	listFrame.style.display="none";	
	listFrame.style.width=$('search_key').clientWidth+"px";
	
}
function setstyle(element,classname){
	switch (classname){
        case 'm':
            element.style.fontSize="12px";
		    element.style.fontFamily="arial,sans-serif";
		    element.style.backgroundColor="#3366cc";
		    element.style.color="black";
		    element.style.width=$('search_key').clientWidth-10+"px";
		    element.style.height="20px";
            element.style.padding="1px 5px 0px 5px";
            if(element.displayTitleSpan)element.displayTitleSpan.style.color="white";
            if(element.displayHitSpan)element.displayHitSpan.style.color="white";
		    break;
        case 'd':
	        element.style.fontSize="12px";
		    element.style.fontFamily="arial,sans-serif";
		    element.style.backgroundColor="white";
		    element.style.color="black";
		    element.style.width=$('search_key').clientWidth-10+"px";
		    element.style.height="20px";
            element.style.padding="1px 5px 0px 5px";
            if(element.displayTitleSpan)element.displayTitleSpan.style.color="black";
            if(element.displayHitSpan)element.displayHitSpan.style.color="#909090";
		    break;
	 case 't':
            element.style.width="60%";
            if(window.navigator.userAgent.toLowerCase().indexOf("firefox")!=-1)element.style.cssFloat="left";
            else element.style.styleFloat="left";
            element.style.whiteSpace="nowrap";
            element.style.overflow="hidden";
            element.style.textOverflow="ellipsis";
            element.style.fontSize="12px";
            element.style.textAlign="left";
            break;
	 case 'h':
            element.style.width="40%";
            if(window.navigator.userAgent.toLowerCase().indexOf("firefox")!=-1)element.style.cssFloat="right";
            else element.style.styleFloat="right";
            element.style.textAlign="right";
            element.style.color="#909090";
            break;
    }
}
function focusitem(index){
    if($('item'+lastindex)!=null)setstyle($('item'+lastindex),'d');
    if($('item'+index)!=null){
        setstyle($('item'+index), 'm');
        lastindex=index;
    }else{
        lastindex=-1;
        $("search_key").focus();
    }
}
function searchclick(index){
    if(index){
        $("search_key").value=$('title'+index).innerHTML;
        search_prompt_flag=true;
		search_index=index;
    }else{
        if($('title'+lastindex)!=null){
            $("search_key").value=$('title'+lastindex).innerHTML;
            search_prompt_flag=true;
			search_index=lastindex;
        }
    }
}
function searchformsubmit(url){
	start_search(url);	
}

function searchkeydown(e){
	if(!$('search_prompt_list') || !$('search_prompt_frame') )return;
    if($('search_prompt_list').innerHTML=='')return;
    var keycode=(window.navigator.appName=="Microsoft Internet Explorer")?event.keyCode:e.which;
    
    //down
    if(keycode==40){
	   if(lastindex==-1||lastindex==listlength-1){
	       focusitem(0);
	       searchclick(0);
	   }else{
	       focusitem(lastindex+1);
	       searchclick();
	   }
    }
    //up
    if(keycode==38){
	   if(lastindex==-1 && listlength>0){
	       //focusitem(0);
	       //searchclick(0);
	       focusitem(listlength-1);
	       searchclick(listlength-1);
	   }else{
	       focusitem(lastindex-1);
	       searchclick();
	   }
    }
    //enter
    if(keycode==13){
        if(lastindex!=-1){
            focusitem(lastindex);
            $("search_key").value=$('title'+lastindex).innerHTML;
        }
        hiddensearch();
    }
    //backspace || delete
    if(keycode==46||keycode==8){search_prompt_flag=false;ajaxsearch();}
}


function sendRequest(){
	var value=$('search_key').value.trim();
	var url="../my.210g.com/ajax_search.php@keyword="+encodeURIComponent(value);
	addScript(url);
}
function initPrompt(e){

	if($('search_key').value.trim()=='' || $('search_key').value.trim()=='搜索小游戏'){
		$('search_key').value='';
		$('search_key').className='col'

		hiddensearch();
	}else{
		var keycode=(window.navigator.appName=="Microsoft Internet Explorer")?event.keyCode:e.which;
        if(keycode!=40 && keycode!=38 && keycode!=13)search_prompt_flag=false;
		if($('search_key').value!=''&&search_prompt_flag==false)ajaxsearch();
        if(listlength!=0){
            $('search_key').onkeydown=searchkeydown;
        }else{
            hiddensearch();
        }
	}
}

var defaultSearchTextValue='';
var useDomain='www.210g.com';//只在www上显示默认词
var searchDomain='my.210g.com';
var headUserClicked=false;
var footUserClicked=false;

window.nova_init_hook_searchinputinit=function(){
	if ($('search_key'))
	{
		if($('search_key').onfocus!=null){
			var f1=function(e){focusSearchTxt($('search_key'));initPrompt(e)}
			$('search_key').onfocus=f1;
			var f2=function(){blurSearchTxt($('search_key'));hiddensearch()}
			$('search_key').onblur=f2;
		}else{
			$('search_key').onfocus=initPrompt;
			$('search_key').onblur=hiddensearch;
		}
		$('search_key').onkeyup=initPrompt;
		createlist();
		//window.onresize=reposition;
	}
}
nova_init_hook_searchinputinit();
//以下是默认显示词回调程序
function initsearch_keyValue(result){
	var txtArr=result.split("|");
	var pos=parseInt(Math.random()*txtArr.length);
	defaultSearchTextValue=txtArr[pos];
	if(!$("search_key").checked && $("search_key").value==''){
		$("search_key").style.color="#c6c6c6";
		$("search_key").value=defaultSearchTextValue;
	}else{
		headUserClicked=true;
	}
	
	if($('search_key').onfocus!=null){
		var f1=function(e){focusSearchTxt($('search_key'));initPrompt(e)}
		$('search_key').onfocus=f1;
		var f2=function(){blurSearchTxt($('search_key'));hiddensearch()}
		$('search_key').onblur=f2;
	}else{
		$("search_key").onfocus=function(){focusSearchTxt($("search_key"))};
		$("search_key").onblur=function(){blurSearchTxt($("search_key"))};
	}
	
	

	initFootqValue();
}
function initFootqValue(){
	if(!$("footq"))return;
	if(!$("footq").checked){
		$("footq").style.color="#c6c6c6";
		$("footq").value=defaultSearchTextValue;
	}else{
		footUserClicked=true;
	}
	$("footq").onfocus=function(){focusSearchTxt($("footq"))};
	$("footq").onblur=function(){blurSearchTxt($("footq"))};
	
}
function focusSearchTxt(objSearchTxt){
	if(location.href.indexOf(useDomain)==-1)return ;
	if(objSearchTxt.defaultValue!='')return;
	if(objSearchTxt.id=='search_key'){
		if(!headUserClicked){
			objSearchTxt.style.color="black";
			objSearchTxt.value="";
			headUserClicked=true;
		}
	}else{
		if(!footUserClicked){
			objSearchTxt.style.color="black";
			objSearchTxt.value="";
			footUserClicked=true;
		}
	}
}
function blurSearchTxt(objSearchTxt){
	if(location.href.indexOf(useDomain)==-1)return ;
	if(objSearchTxt.defaultValue!='')return;
	if(objSearchTxt.id=='search_key'){
		if(headUserClicked && objSearchTxt.value==''){
			objSearchTxt.style.color="#c6c6c6";
			objSearchTxt.value=defaultSearchTextValue;
			headUserClicked=false;
		}
	}else{
		if(footUserClicked && objSearchTxt.value==''){
			objSearchTxt.style.color="#c6c6c6";
			objSearchTxt.value=defaultSearchTextValue;
			footUserClicked=false;
		}
	}
}

//V3.01.A - http://www.openjs.com/scripts/jx/
jx={getHTTPObject:function(){var A=false;if(typeof ActiveXObject!="undefined"){try{A=new ActiveXObject("Msxml2.XMLHTTP")}catch(C){try{A=new ActiveXObject("Microsoft.XMLHTTP")}catch(B){A=false}}}else{if(window.XMLHttpRequest){try{A=new XMLHttpRequest()}catch(C){A=false}}}return A},load:function(url,callback,format,method,opt){var http=this.init();if(!http||!url){return }if(http.overrideMimeType){http.overrideMimeType("text/xml")}if(!method){method="GET"}if(!format){format="text"}if(!opt){opt={}}format=format.toLowerCase();method=method.toUpperCase();var now="uid="+new Date().getTime();if(method!="GET"){url+=(url.indexOf("?")+1)?"&":"?";url+=now;}var parameters=null;if(method=="POST"){var parts=url.split("?");url=parts[0];parameters=parts[1]}http.open(method,url,true);if(method=="POST"){http.setRequestHeader("Content-type","application/x-www-form-urlencoded");http.setRequestHeader("Content-length",parameters.length);http.setRequestHeader("Connection","close")}var ths=this;if(opt.handler){http.onreadystatechange=function(){opt.handler(http)}}else{http.onreadystatechange=function(){if(http.readyState==4){if(http.status==200){var result="";if(http.responseText){result=http.responseText}if(format.charAt(0)=="j"){result=result.replace(/[\n\r]/g,"");result=eval("("+result+")")}else{if(format.charAt(0)=="x"){result=http.responseXML}}if(callback){callback(result)}}else{if(opt.loadingIndicator){document.getElementsByTagName("body")[0].removeChild(opt.loadingIndicator)}if(opt.loading){document.getElementById(opt.loading).style.display="none"}if(error){error(http.status)}}}}}http.send(parameters)},bind:function(A){var C={"url":"","onSuccess":false,"onError":false,"format":"text","method":"GET","update":"","loading":"","loadingIndicator":""};for(var B in C){if(A[B]){C[B]=A[B]}}if(!C.url){return }var D=false;if(C.loadingIndicator){D=document.createElement("div");D.setAttribute("style","position:absolute;top:0px;left:0px;");D.setAttribute("class","loading-indicator");D.innerHTML=C.loadingIndicator;document.getElementsByTagName("body")[0].appendChild(D);this.opt.loadingIndicator=D}if(C.loading){document.getElementById(C.loading).style.display="block"}this.load(C.url,function(E){if(C.onSuccess){C.onSuccess(E)}if(C.update){document.getElementById(C.update).innerHTML=E}if(D){document.getElementsByTagName("body")[0].removeChild(D)}if(C.loading){document.getElementById(C.loading).style.display="none"}},C.format,C.method,C)},init:function(){return this.getHTTPObject()}}

// 我玩过游戏记录
if ($('my_play_history')) {
	var playd_link = getPlaydLink();
	$('my_play_history').innerHTML=playd_link;
}


/*通用浮动广告JS代码*/
var delta = 0.15;  //移动速度，数字越大越快，注意：值要小于等于1
var collection;
var closeFlag = false;
 
function ad_object()
{ 
 this.items = [];
 this.addItem = function(ad_id, ad_w, ad_h, ad_x, ad_y, ad_content)
 {
	html = '<div id="'+ad_id+'" style="z- index:10;position:absolute;width:'+ad_w+'px;height:'+ad_h+'px;left:'+ (typeof(ad_x)=='string'?eval(ad_x):ad_x)+'px;top:'+ (typeof(ad_y)=='string'?eval(ad_y):ad_y)+'px; border:0px #000000 solid;"&gt;';
  if (closeFlag) {
	html += '<div style="float:right;z-index:11;width:24px;height:12px; top:-15px;left:'+(ad_w-30)+'px;position:absolute;font- size:12px;cursor:pointer;" onclick="javascript:closeAd('+ad_id+');">关闭</div>';
  }
  html += '<div>'+ad_content+'</div></div>';
  document.write(html);
  var newItem = {};
  newItem.object = document.getElementById(ad_id);
  newItem.x = ad_x;
  newItem.y = ad_y;
  this.items[this.items.length] = newItem;
 }
 this.play = function()
 {
  collection = this.items
  setInterval('play()',30);
 }
}
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";
  }
 }
} 
  



