//tab
function setTab(name,cursel,n){
   for(var i=1;i<=n;i++){
	var menu=$('#'+name+i)[0],con=$("#con_"+name+"_"+i);
	menu.className=i==cursel?"curr":"";
	con[0].style.display=i==cursel?"block":"none";
	}
return false;
}
		
	
$(function(){
	//点击a添加curr/cur样式的操作
	var iclass=new Array("sosott","gclass","ags","letter","hotgame","games");
	var n=iclass.length;
	for(var i=0;i<n;i++){
	   $("."+iclass[i]).find("a").click(function(){
		  $(this).parents('ul').find("a").removeClass("cur curr");
		  $(this).addClass("curr");
	   });
	}
	
	 //折叠面板
	 //$(".foldTt a").click(function(){
	//	 $(this).toggleClass("curr");
	//	 $(this).parents(".fold").eq(0).toggleClass("f_open");
	 //});
     //config
	 $(".config").hover(
	    function(){$(".config p").css('display','block');},
		function(){$(".config p").css('display','none');}
	 );
	 //btnoga
	 $(".btnoga").click(function(){$(this).toggleClass("btnup");$(".btnogaCon").toggleClass("hide");});
	 
	 //发表评论表情
	 $(".faceimgs a").click(function(){
		var i=$(this).attr("rel"); 
	    insertFace(i,'commentTxt');
	 });
	 
	 //插入表情
	function insertFace(id,target){
		var faceText='[em:'+id+':]';
		if($('#'+target).length){
			insertContent(target,faceText);
		}
	}
	//插入内容
	function insertContent(target,text,movestart,moveend,noselect){
		var obj=$('#'+target)[0];
		var movestart=movestart||0;
		var moveend=moveend||0;
		var selection=document.selection;
		checkFocus(target);
		if(!isUndefined(obj.selectionStart)){
			var opn=obj.selectionStart+0;
			obj.value=obj.value.substr(0,obj.selectionStart)+text+obj.value.substr(obj.selectionEnd);
			obj.selectionStart=opn+movestart;
			obj.selectionEnd=opn+strlen(text)-moveend;
			if(movestart==0){
				obj.selectionStart+=strlen(text);
			}
		}else if(selection&&selection.createRange){
			var sel=selection.createRange();
			sel.text=text.replace(/\r?\n/g,'\r\n');
			sel.moveStart('character',-strlen(text)+movestart);
			sel.moveEnd('character',-moveend);
			if(movestart!=0&&noselect){
				sel.select();
			}
		}else{
			obj.value+=text;
	
		}
	}
	function checkFocus(target){
		var obj=typeof(target)=='object'?target:$('#'+target)[0];
		if(!obj.hasfocus){
			obj.focus();
		}
	}
	function isUndefined(variable){
		return typeof variable=='undefined'?true:false;
	
	}
	function strLen(str){
		var charset=document.charset;
		var len=0;
		for(var i=0;i<str.length;i++)
		{
			len+=str.charCodeAt(i)<0||str.charCodeAt(i)>255?(charset=="utf-8"?3:2):1;
	
		}
		return len;
	
	}
	function strlen(str){
		return ($.browser.msie&&str.indexOf('\n')!=-1)?str.replace(/\r?\n/g,'_').length:str.length;
	}
   
   //左右滚动表情按钮
   $(".btnright").click(function(){$(".faceimgs").append($(".faceimgs span").first())});
   $(".btnleft").click(function(){$(".faceimgs").prepend($(".faceimgs span").last())});

	 
});

/*
var curr = 0, next = 0, count = 0,f;
		$(document).ready(function() {	
			count = $('#img_list a').size();				
			t = setInterval('imgPlay()', 3000);			
			$('#imgs li, #img_list a').hover(function() {
				clearInterval(t);
			}, function() {
				t = setInterval('imgPlay()', 3000);
			});			
			$('#img_list a').bind('mouseover',doit);
			$('#img_list a').bind('mouseout',function(){
				var timestamp=(new Date()).getTime(),oldtimestamp=$(this).attr('reldate');
				if(timestamp-oldtimestamp<380){
					clearTimeout(xxxx);
				}
				
			});
		});	
		
function doit(){
	var index = $('#img_list a').index(this);
	$(this).attr('reldate',(new Date()).getTime());
	window.xxxx=setTimeout(function(){qiehuan(index);},380);
}
		


function qiehuan(index){	
	if(curr != index) {	
		play(index);
		curr = index;
	};
}

function imgPlay() {
	next = curr + 1;
	if(curr == count-1) {
		next=0;
	}
	play(next);
	curr++;
	if(curr > count-1) {
		curr=0;
		next = curr +1;
	}
};
		
function play(next) {
	$('#imgs li').eq(curr).animate({'left': '-755px'},"slow", function() {
		$(this).css({'left': '755px'});
		$('#img_list a').siblings('a').addClass('active');
	})
	$('#imgs li').eq(next).animate({'left': '0px'}, 'slow', function() {
		$('#img_list a').siblings('a').removeClass('active').end().eq(next).addClass('active');
	});
};*/
/* endof ----- play img*/

(function($){
	$(function(){
		var imgs=$('#imgs li'),as=$('#img_list a'),timer;
		function dd(){
			var index=as.removeClass("active").index(this);
			imgs.stop(false,true).filter(":visible").fadeOut(1000);
			imgs.eq(index).fadeIn(1000);
			$(this).addClass("active");
		}
		function dn(){
			var index =as.index(as.filter(".active"));
			index++;
			if(!index||index<0||index>=as.length)
			{
				index=0;
			}
			dd.call(as[index]);
			timer=setTimeout(dn,5000);
		}
		dn();
		
		$("#imgs").hover(function(){
			clearTimeout(timer);
		},function(){
			timer=setTimeout(dn,5000);	
		});
		as.click(function(){
			dd.call(this);
			return false;
		});
	});
}(jQuery));


/**/
	

//old
(function($){

    /*****************对jQuery的扩展*****************/
    //位置处理
    $.fn.extend({
        toolTipPosition: function(option) {
            return this.each(function() {
                var options = $.extend({
                    elem: null,               //tip对象
                    Horizontal: 0,           //水平偏移量
                    Vertical: 0,             //垂直偏移量
                    offsetHorizontal: true,  //水平偏移
                    offsetVertical: true,     //垂直偏移
                    conterHorizontal: true,
                    conterVertical: true
                }, option);
                var obj = options.elem;
                var $t = $(this);
                var offset = obj.offset();
                var size = { width: obj.outerWidth(), height: obj.outerHeight() };
                if (options.offsetHorizontal) {
                    // var t = (document.documentElement.clientHeight - temp.height()) / 2 + $(document).find("html")[0].scrollTop;
                    if (((offset.left - $(document).find("html")[0].scrollLeft) * 2 + size.width) > document.documentElement.clientWidth && options.conterHorizontal) {//过了中间线
                        offset.left -= ($t.outerWidth() + options.Horizontal);
                    } else {//没有过中线
                        offset.left += (size.width + options.Horizontal);
                    }
                } else {
                    offset.left += options.Horizontal;
                }
                if (options.offsetVertical) {
                    if (((offset.top - $(document).find("html")[0].scrollTop) * 2 + size.height) > document.documentElement.clientHeight && options.conterVertical) {//过了中间线
                        offset.top -= ($t.outerHeight() + options.Vertical);
                    } else {//没有过中线
                        offset.top += (size.height + options.Vertical);
                    }
                } else {
                    offset.top += options.Vertical;
                }
                $t.offset(offset);
            });
        },
        toolTipCenter: function(elem) {
            return this.each(function() {
                var obj = $(this).eq(0);
                var o = {};
                if (elem)
                    o = elem.offset();
                else
                    o = { left: 0, top: 0 };
                elem = elem || $(window);

                var options = {
                    left: (elem.width() - obj.width()) / 2 + o.left,
                    top: (elem.height() - obj.height()) / 2 + o.top
                };
                obj.css(options);
            });
        }
    });
	
	if(window.location.host.toLowerCase().indexOf("131.com")>=0)
	{
		document.domain="131.com";
	}else
	{
		document.domain="131wanwan.com"	;
	}
	
    var w=window["Wanwan"]=window["GamePage"]={};
    var urls={
		Grade:"/Ashx/GradeHandler.ashx",//评分
		Login:"/Ashx/LoginHandler.ashx",//登录
		GameDownload:"/Ashx/GameDownloadHandler.ashx",//获取游戏下载地址
		Feed:"/Ashx/Feed.ashx",//信息反馈入口
		GameRun:"/Ashx/GameRunHandler.ashx",//更新游戏运行次数
		Search:"/Ashx/SearchGameHandler.ashx"
	};	
	
	w.FeedUrl=urls.Feed;
	
	w.emptyFn=function(){}
	
	w.alert=function(msg,callback){
		alert(msg);
		(callback||w.emptyFn)();
	}
	
	//公共初始化
	$(function(){
		$("#loginBox").hide();
		$("#loginbox_close").click(function(){
			$("#loginBox").hide();			
		});
		
		$("#js_btn_down_wanwan,#js_btn_down_wanwan_canel,#js_btn_down_wanwan_close").click(function(){
			$("#js_wanwan_down_box,#js_wanwan_down_box_lock").hide();
		})
		
	});
	
    //复制内容到内存中
    w.copyToClipboard=function copyToClipboard(txt) {  
		try{
			if(window.clipboardData) {  
				window.clipboardData.clearData();  
				window.clipboardData.setData("Text", txt);  
			} else if(navigator.userAgent.indexOf("Opera") != -1) {  
				window.location = txt;  
			} else if (window.netscape) {  
				try {  
					netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");  
				} catch (e) {  
					alert("被浏览器拒绝！\n请在浏览器地址栏输入'about:config'并回车\n然后将 'signed.applets.codebase_principal_support'设置为'true'");  
					return false;
				}  
				var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);  
				if (!clip)  
					return false;  
				var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);  
				if (!trans)  
					return false;  
				trans.addDataFlavor('text/unicode');  
				var str = new Object();  
				var len = new Object();  
				var copytext = txt;  
				str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);  
				str.data = copytext;  
				trans.setTransferData("text/unicode",str,copytext.length*2);  
				var clipid = Components.interfaces.nsIClipboard;  
				clip.setData(trans,null,clipid.kGlobalClipboard);  
			}  
			return true;
		}catch(e){
			alert("环境不稳定，请勿过于频繁操作！")
			return false;	
		}
	} 
	
	//收藏玩玩官网
	w.AddCollection=function(title,url){
		url=url||"http://www.131wanwan.com";
			title=title||"131玩玩官网";
		try
        {
            window.external.addFavorite(url, title);
        }
        catch (e)
        {
            try
            {
                window.sidebar.addPanel(title, url, "");
            }
            catch (e)
            {
                alert("加入收藏失败，请使用Ctrl+D进行添加");
            }
        }	
	}	
	
	//替换{i}为指定参数
	w.formatString=function(str)
	{
		
		args = [].slice.call( arguments, 1 );
		for(var i=0,c=args.length;i<c;i++)	
		{
			str=str.replace("{"+i+"}",args[i]);
		}
		return str;
	}
	//初始化游戏详情页脚本
	w.initGameDetailPage=function(){
		$(function(){//评分处理
			var js_rank_msg=$("<div class='ww_tpkk' id='js_rank_msg'><p>2分</p><p>请选择您的评分</p></div>").appendTo($(document.body));
			function showMsg(obj){
				var of=obj.offset();
				of.top-=50;
				of.left-=64;
				js_rank_msg.show().offset(of).children().show().eq(0).html(obj.attr("msg"));
			}
			
			function setDefaultMsg(){
				showMsg($spans.eq(2));
				js_rank_msg.children().hide().eq(0).show().html("<span id='js_rank_grade_m'>"+PageHeadInfo.Grade+"</span>分值得一看！评分也会同步到你的");
			}
			
			var $tmp=$(".rank").not(".no_hover"),$max=$tmp.find(".max"),$spans=$(".rank").not(".no_hover").find("span").hover(function(e){
				var $t=$(this);
				$max.hide();
				$t.addClass("hover");
				if(e.target==this)
				{
					showMsg($t);
				}
			},function(e){
				$(this).removeClass("hover");
				var i=$spans.length-1,$s;
				while(!($s=$spans.eq(i)).is(".hover")&&i>0) i--;
				if($s.is(".hover")) showMsg($s);
				else {
						setDefaultMsg();
					//js_rank_msg.hide();
								$max.show();
				}
			}).click(function(){
				GamePage.GradeGame(($spans.index(this)+1)*2);
				return false;	
			});					
			setDefaultMsg();
		});
		
		$(function(){//硬件配置
			var hover=false;
			var panel=$("#js_hardwarerequire").hover(function(){
				var of=$(this).offset();
				of.top+=34;
				of.left-=120;
				panel.show().offset(of);
			},function(){
				setTimeout(function(){
					if(!hover)
						panel.hide();
				},1);
			}).parent().next().hover(function(){
				hover=true;
			},function(){
				hover=false;
				panel.hide();
			});
		});
		
		$(function(){//更多游戏
			$("#js_popul_more").click(function(){
				if($(this).blur().is(".zk"))
				{
					$("#js_popul_more_list").show();
					$(this).removeClass("zk").addClass("ss");
				}else
				{
					$("#js_popul_more_list").hide();
					$(this).removeClass("ss").addClass("zk");
				}
				return false;	        
			});
			$("#js_rel_more").click(function(){
				var $t=$(this),$p=$t.parent();
				if($t.blur().is(".zk"))
				{
					
					$p.next().show();
					$p.next().next().show();
					$p.next().next().next().show();					
					$t.removeClass("zk").addClass("ss");
				}else
				{
					$p.next().hide();
					$p.next().next().hide();
					$p.next().next().next().hide();					
					$t.removeClass("ss").addClass("zk");
				}
				return false;	  
			});
		})
		
		$(function(){//复制按钮
			$("#js_copy_url").click(function(){
				var text=$(this).prev().val();
				if(GamePage.copyToClipboard(text))
				{
					GamePage.alert("复制成功！");
				}else
				{
					GamePage.alert("复制失败！")
				}
				
				return false;
			});
		})		
	}
	//w.initGameDetailPage();
	//初始化功能介绍页面
	w.initFunctionPage=function(){
		$(function(){
			var img=$("<img style='display:none;position:absolute;' src='javascript:void(0);'/>") .appendTo($("body"));
			var list=$(".js_showDeomImage").hover(function(){
				img.attr("src",$(this).attr("href"));
				var w=img.stop(true).show().width(),h=img.height(),l=0,of=$(this).offset();
				of.top-=h/2-11;
				if(list.index(this)%2==0)
				{
					l=of.left+80;
					of.left=l+50;
					
				}else
				{
					l=of.left-w;
					of.left=l-50;
				}
				img.offset(of);
				img.css("opacity",0).animate({left:l,opacity:1});
			},function(){
				var w=img.stop(true).width(),h=img.height(),l=0,of=$(this).offset();
				of.top-=h/2-11;
				if(list.index(this)%2==0)
				{
					l=of.left+130;
					
				}else
				{
					l=of.left-w-50;
				}
				img.animate({left:l,opacity:0},function(){
					img.hide();	
				});
				
				//img.stop().hide();	
			}).each(function(){
				var i=new Image();
				i.src=$(this).attr("href");	
			});
			
		})		
		
	}
	
	//初始化新手教程
	w.initCoursePage=function(){
		$(function(){
			
			var list = $("#js_step_title").children().hover(function(){
				showSetp(list.index(this));
			},function(){}),
				listp=$("#js_step_content").children();
			function showSetp(i){
				list.children().removeClass("curr");
				list.eq(i).children().addClass("curr");
				listp.hide();
				listp.eq(i).show();	
			}
			showSetp(0);
		});
	}
	
	//初始化搜索功能
	w.InitSearch=function(){
		$(function(){//
			var urltemplate="",isgame,isactive=false;
			var cacheList={},currKey,search_content=$("#js_search_content"),input=$("#js_Search_Key"),ajax_timer=null,delay=200,show_hide_timer=null,ajax_doing=false,isnav=false;
			
			$("#js_Search_Type").find("a").click(function(){//更改搜索分类
				$("#js_Search_Type").find("a").removeClass("cur");
				urltemplate=$(this).addClass("cur").blur().attr("href");
				isgame=$(this).text()=="游戏";
				input.focus();
				return false;
			}).eq(0).click();
			$("#js_Search_Btn").click(function(){//搜索按钮事件
				var url=urltemplate.replace("{KeyWord}",encodeURIComponent(input.val()));
			   $(this).attr("href",url);
			   this.href=url;
			   if(isgame){ 
			   	window.location=url;
				return false;
			   }
			   else $(this).attr("target","_blank");
			});
			
			$(document).click(function(e){
				if(e.target!=input[0])
					search_content.hide();
				
			});
			

			function addToAjax(){
				if(ajax_timer!=null){
					return;	
				}
				if(ajax_doing){ 
					ajax_timer=setTimeout(function(){
						ajax_timer=null;
						addToAjax();
					},50)
					return ;
				}
				ajax_doing=true;
				var value=input.val();
				if(cacheList[value.toLowerCase()])//已经存在
				{
					checkValue(input);
					ajax_doing=false;
				}
				else if(value!=""){
					$.ajax({
						url:urls.Search,
						data:{key:value},
						dataType:"json",
						success:function(json){
							if(json.value)
							{
								cacheList[value.toLowerCase()]=json.data;
								checkValue(input);
								
							}
							ajax_doing=false;
						},
						error:function(){
							ajax_doing=false;								
						}
					});
				}else
				{
					ajax_doing=false;	
				}
			}

			function checkValue(input)
			{
				if(!isgame||!isactive) return;
				var value=(input.jquery?input:$(this)).val().toLowerCase();
				if(!input.jquery)
					addToAjax();
				
				var _cKey="";
				if(cacheList[value])
				{
					if(currKey!=value || search_content.is(":hidden"))
					{
						currKey=value;
						showSearchContent(cacheList[currKey],value);
					}
				}else
				{
					for(var k in cacheList)//找包含关键字的缓存
					{
						if(k.indexOf(value)&&k.length<_cKey)
						{
							_cKey=k;	
						}
					}
					if(_cKey=="")
					{
						for(var k in cacheList)//找关键字包含的缓存
						{
							if(value.indexOf(k)&&k.length>_cKey)
							{
								_cKey=k;	
							}
						}		
					}
					if(_cKey!="")//找到历史过滤项
					{
						if(currKey!=_cKey || search_content.is(":hidden"))
						{
							currKey=_cKey;
							showSearchContent(cacheList[currKey],value);
						}
					}else{//没有找到
						search_content.hide()
					}
						
				}
			}
			
			
			function showSearchContent(list,key){//显示搜索下拉框
				var da=[],d,reg=new RegExp(key,"ig");
				if(key=="")
				{
					search_content.hide()
					return ;
				}
				
				for(var i=0,c=list.length;i<c;i++)
				{
					d=list[i];
					//if(d.PinYin.indexOf(key)>-1||d.ResourceName.indexOf(key)>-1)	
					if(reg.test(d.PinYin)||reg.test(d.ResourceName))
					{
						da.push(d);
						if(da.length>=5)
							break;
					}
				}
				if(da.length>0)
				{				
					var of=input.offset();
					of.top+=input.height()-1;
					search_content.empty();
					search_content.show().offset(of);					
					for(var i=0,c=da.length;i<c;i++)
					{
						d=da[i];
						search_content.append($(w.formatString("<dd><a href='{0}'><strong>{1}</strong><span>人气：{2}</span></a></dd>",
							w.formatString(w.SearchJumpTemplate,d.TopCategoryID,d.ResourceID),d.ResourceName,d.RunCount
						)));
					}
					search_content.children().hover(function(){
						search_content.children().removeClass("active")	;
						$(this).addClass("active");
					},function(){}).click(function(){$(this).children().click();return false;}).children().click(function(){
						if(isnav) return false;
						location.href=$(this).attr("href");
						isnav=true;
						return false;
					})
					
				}else
				{
					search_content.hide();
				}
			}
			
			
			
			input.keydown(function(e){
				var i,l=search_content.children();
				i=search_content.children(".active");
				switch(e.keyCode){
					case 13:
						if(i.length>0)
						{
							i.children().click();
						}else{
							$("#js_Search_Btn").click();
						}
						return false;
					case 38://上
						i=i.prev();
						if(i.length==0)
							i=search_content.children(":last");
						l.removeClass("active");
						i.addClass("active");
					return false;
					case 40://下
						i=i.next();
						if(i.length==0)
							i=l.eq(0);
						l.removeClass("active");
						i.addClass("active");
					return false;
				}
			}).keyup(function(e){
				switch(e.keyCode)	
				{
					case 13:
					case 38:
					case 40:
					return false;	
				}				
				isactive=true;
				checkValue.call(this,e);
			}).change(function(e){
				isactive=true;
				checkValue.call(this,e);
	
			}).blur(function(){
				show_hide_timer=setTimeout(function(){
					search_content.hide();		
				},200);	
				isactive=false;
			}).focus(function(){
				clearTimeout(show_hide_timer);
				isactive=true;
				checkValue.call(input[0],{});
			});
			
			
		})			
	}
	
	//显示登录窗口
	w.ShowLogin=function(){
		$("#loginBox").show();
		var offset=$("#js_login").offset();
		offset.top+=26;
		offset.left-=79;
		$("#loginBox").offset(offset);
	}
	
	//登录操作
	w.Login=function(){
		var username=$("#username").val(),userpass=$("#password").val(),savecookie=$("#savecookie").is(":checked");
		if(username==""||userpass=="")
		{
			w.alert("用户名和密码均不能为空！");
			return;
		}
		$("#loginBox").hide();
		$.ajax({
			url:urls.Login, 
			data:{UserName:username,UserPass:userpass,SaveCookie:savecookie,action:"login"},
			dataType:"json",
			type:"POST",
			success:function(json){
				w.alert(json.msg);
				if(json.value)
				{
					var c=$("#js_login");
					c.before("<a href='http://i.131.com/'>"+username+"</a><a href='javascript:void(0);' onclick='Wanwan.Logout()'>[退出]</a>");
					c.add(c.next()).hide();
					$("#username,#password").val("");
					$("#savecookie").attr("checked",false);
					var iframe=$("#iframe_comment");
					if(iframe.length>0) iframe.attr("src",iframe.attr("src"));
				}
			},
			error:function(){
				w.alert("登录失败！")	;
			}
		});
	}
	
	//退出
	w.Logout=function(){
		var c=$("#js_login");
		c.prev().prev().remove();
		c.prev().remove();
		c.show();
		c.next().show();
		$.ajax({
			url:urls.Login, 
			data:{action:"logout"}
		});
	}
	
	w.GradeGame_IsGrade=false;
	w.GradeGame_IsDoing=false;
	//游戏评分
	w.GradeGame=function(grade)
	{
		if(w.GradeGame_IsDoing)
			return;
		w.GradeGame_IsDoing=true;
		
		if(w.GradeGame_IsGrade)
		{
			w.alert("该游戏你已经评过分了，请勿重复评分！");
			return;	
		}
		if(!w.TopCategoryID||!w.ResourceID)	{
			w.alert("分类ID或游戏ID不能为0！")	;
			return;
		}	
		$.ajax({
			url:urls.Grade,
			data:{TopCateID:w.TopCategoryID,ID:w.ResourceID,Grade:grade},
			dataType:"json",
			type:"GET",
			cache:false,
			complete:function(){
				w.GradeGame_IsDoing=false;	
			},
			success:function(json){
				alert(json.msg);
				if(json.value)
				{
					$("#js_rank_count").text(json.data.GradeCount);
					
					var ss = (json.data.Grade+'').split(".");
					PageHeadInfo.Grade=json.data.Grade;
					$("#js_rank_grade_m,#js_rank_grade").text(json.data.Grade);
					$("#js_rank_grade").html(ss[0]+".<em>"+ss[1]+"</em>");
					$("#js_rank_content").find(".curr").width((json.data.Grade*10)+"%");
				}
			},
			error:function(){
				w.alert("评分失败！")	;
			}
		});
		
	}
	
	w.UpdateGameRunCount=function(id,cateID){
		$.ajax({
			url:urls.GameRun,
			data:{ResID:id,TopCateID:cateID},
			type:"GET"
		});
	}
	
	w.IsRun=false;
	
	w.RunGame=function(){
		if(w.FlashUrl!=""&&swfobject&&!w.IsRun)
		{
			$("#js_Flash_Content").show();
			w.IsRun=true;			
			swfobject.embedSWF(w.FlashUrl,"js_FlashContent", "707", "600", "9.0.0","http://files.131wanwan.com/js/expressInstall.swf",null,{wmode:"transparent"});
			window.setTimeout(function(){
				document.documentElement.scrollTop=450;							
			},500);
			w.UpdateGameRunCount(w.ResourceID,w.TopCategoryID);
			
		}
	}
	
	//$(function(){
	//	$(document).keydown(function(e){
	//		if(e.keyCode>=37&&e.keyCode<=40)
	//		{
	//			return !w.IsRun;
	//		}
	//	});	
	//})
	
	//下载游戏
	w.DownLoadGame=function(topCateID,cateID,resourceID,wanwanID,resName,obj){
		//alert(""+topCateID+","+cateID+","+resourceID+","+wanwanID);
		if(topCateID==4||topCateID==3)
		{
			//网页游戏	flash游戏
			if(topCateID==3&&topCateID==w.TopCategoryID&&resourceID==w.ResourceID)
			{//当前游戏页面，直接打开flash游戏
				w.RunGame();
				return false;
			}
			$(obj).attr("href",w.formatString(w.RunGameTemplate,topCateID,resourceID))
				.attr("target","_blank");
			;
			if(topCateID==4)
				w.UpdateGameRunCount(resourceID,topCateID);
			return ;
		}
		DownloadGame(resourceID,wanwanID,resName);
		
		return false;		
	}
	
	w.ShowDownLoad=function(resName){
		$("#js_wanwan_down_box,#js_wanwan_down_box_lock").show();
		$("#js_wanwan_down_box").toolTipCenter();
		var of=$("#js_wanwan_down_box").offset();
		of.top+=document.documentElement.scrollTop;
		$("#js_wanwan_down_box").offset(of);
		$("#js_wanwan_down_box_lock").css({left:0,top:0,width:"100%",height:$("body").height()});
		$("#js_wanwan_down_gamename").text(resName);
	}
	
	/**************************** 玩玩相关 ******************************/
	var webobj = null;

	function CreateIEObject() {
		if (webobj == null) {
			try {
				webobj = new ActiveXObject("wwcom.WanWanCom");
				return true;
			}
			catch (e) {
				return false;
			}
		}
		return true;
	}

	function AddDownloadTask(id, oldid) {
		if (!CreateIEObject()) {
			return;
		}
		try {			
			$.ajax({
				url:urls.GameDownload,
				data:{ID:id,OldID:oldid},
				dataType:"json",
				type:"GET",	
				cache:false,
				success:function(json){
					if(json.value)
					{
						try{
							webobj.AddDownloadTask(id, json.data);						
							//AddDownStat();
						}catch(e){}
					}else
					{
						w.alert("获取游戏下载路径失败！");
					}
					
				},
				error:function(){
					w.alert(1)
					w.alert("获取游戏下载路径失败！");	
				}
			});
			
		}
		catch (e) {
		}
	}


	function GetLoginUserInfo() {
		if (!CreateIEObject()) {
			return '';
		}
		try {
			return webobj.GetLoginUserInfo();
		}
		catch (e) {
			return '';
		}
	}

	function DownloadFile(ed2kUrl, type) {
		if (!CreateIEObject()) {
			return;
		}
		try {
			webobj.DownloadFile(ed2kUrl, type);
		}
		catch (e) {
		}
	}

	function DownloadGame(id, oldWanwanID,resName) {
		if (!CreateIEObject()) {
			w.ShowDownLoad(resName);
		}
		else {
			if (GetVersion() == 0) {
				if (oldWanwanID == 0) {
					w.ShowDownLoad();
					return;
				}
				AddDownloadTask(oldWanwanID, true);
			}
			else {
				AddDownloadTask(id);
			}
		}
	}
	
	/*返回值     0-旧版玩玩 
			  1-新版玩玩 
			  null-没有安装客户端或非IE浏览器
	*/
	function GetVersion() {
		if (CreateIEObject()) {
			try {
				return webobj.GetVersion();
			}
			catch (e) {
				return 0;
			}
		} else {
			return null;
		}
	}
	
}(jQuery));
