﻿/**
 * Author:Paul Mason
 * CreateDate:2009-11-9 11:07
 * Remarsk:MainPage File
 */

/**
 * 用户对象
 */
function MUserData(){
	this.uid = 0;
	this.nick = "";
	this.region = 0;
	this.sex = 0;
	this.photo = "";
	this.online = 0;
	this.sign = "";
	this.mode = 0;
	this.id = 0;
}
//从flash中转化为js中的用户对象
MUserData.prototype.parse = function(u){
	this.uid = u.uid;
	this.nick = u.nick;
	this.region = u.region;
	this.sex = u.sex;
	this.photo = u.photo;
	this.online = u.online;
	this.sign = u.sign;
	this.mode = u.mode;
	this.id = !u.id ? u.uid : u.id;
	if(this.photo == null) this.photo = "";
	if(this.sign == null) this.sign = "";
};

function MGroupData(){
	this.msuper();
	this.createId = 0;
	this.level = 1;
	this.chamber = 0;
}

MGroupData.prototype.msuper = MUserData;
MGroupData.prototype.parse = function(u){
	this.msuper.prototype.parse.apply(this, arguments);
	this.createId = u.createId;
	//this.level = u.level;
	this.level = u.level;
	this.chamber = u.chamber;
}


/**
 * 聊天记录对象
 */
function MChatData(){
	this.from = "";			//聊天类型 {'sys' : 系统消息, 'me' : 我发出的消息, 'ta' : 收到的消息}
	this.content = "";		//聊天内容
	this.uid = 0;			//uid
	this.nick = "";			//昵称
	this.date = null;		//日期
}
//从flash中转化为js中的聊天消息对象
MChatData.prototype.parse = function(c){
	this.from = c.from;
	this.content = c.content;
	this.uid = c.uid;
	this.nick = c.nick;
	this.date = c.date;
}


var IdoMain = {
	/**
	 * 常量
	 */
	_USER_QUIT_CONFIRM : "您确认要退出游戏吗",
	_FLASH_REQUIRE_VER : "9.0.124",		//flash最低版本号
	_SW_REQUIRE_VER : 11.5,				//SHOCKWAVE最低版本号
	window : window,
	
	/**
	 * 检测用
	 */
	
	_bHasFlash : false,		//是否有flash插件
	_bHasSW : false,		//是否有shockwave插件
	
    /**
     * 对象
     */
	$oCont : null,			//container
    $oMainCont : null,		//主框架
    $oGameCont : null,		//游戏框架
	$oWebCont : null,		//网页框架
	$oGameUseCont : null,	//游戏内网页框架

	_sCurLoadType : "",		//当前加载框架类型 flash,noflash
   

    
    //主框加载时初始化
    init : function(isLogin){
		this.$oCont = $('#Container');
		this.$oMainCont = $('#MainCont');
		this.$oGameCont = $('#GameCont');
		this.$oWebCont = $('#WebCont');
		this.$oGameUseCont = $('#GameUseCont');
		this.setContainer();
		$(window).resize(function(){
			IdoMain.setContainer(isLogin);
		});
		$(window).focus(function(){
			IdoMain.proxy.W2SActiveWindow();
		});
    },
    
    setContainer : function(isLogin){
		var w = parseInt(($(window).width() - 990) / 2);
		$('#Container').css("left", w < 0 ? 0 : w);
		if(isLogin == undefined) return;
		//登陆前后窗体
		var p = this.client.getWinPos(isLogin);
		var tab = p.tab, m = p.mid;
		this.$oMainCont.height(p.height);
		if(isLogin){
			this.$oMainCont.find("#ChatFlashCont").height(m);
			//this.$oGameCont.css("top", ((m - 452) / 2) + p.top);
			//this.$oGameCont.height(452);
			this.$oGameCont.height(m);
			/*var f = document.getElementById("FlashChat");
			if(f != null){
				f.style.height = m;
			}*/
			$("#FlashChat").height(m);

			//ie6 100%时不会自动拉高
			$(".frame").height(m - p.tab);

			//游戏退出按钮
			$("#QuitGame").css("top", this.chat.$oTask.position().top + 1);
		}
		this.$oMainCont.find(".mleft, .mright, .middle").height(m);
		this.$oWebCont.css("top", p.top).find("#TabBody").height(m - tab);
		$("#MainBottom").css("top", p.height + 2);
		
	},
    
	//加载基础页 或 Flash框
	//type:flash,noflash
	loadMainPage : function(type, url, chatserver, token, server, site, area, uid, nick, picurl){
		this._sCurLoadType = type;
		this.client._sCliIsLogin = token ? true : false;
		this.client._sCliNick = nick;
		this.client._sCliUid = uid;
		this.client._sCliPicUrl = picurl;
		this.client._sCliChatServer = chatserver;

		//init tab
		this.tab.init();

		//test flash
		//type = $('#selMode').val() == '1' ? 'flash' : '';

		if (type != 'flash'){
			this._setMainContHtml();
			this.client.clearCliParam();
		}else{
			this.client._sCliServer = server;
			this.client._sCliSite = site;
			this.client._sCliArea = area;
			this.client._sCliToken = token;
			//检测flash
			this._bHasFlash = swfobject.hasFlashPlayerVersion(this._FLASH_REQUIRE_VER);
			/*if(this._bHasFlash){
				this.chat.loadMainChat();
			}else{
				alert('你没有安装flash，无法使用部分功能');
				//this.$oMainCont.html(this._getMainContHtml());
			}*/
			this.chat.loadMainChat();
			this.music.init();
		}
		
		if(url){
			//在这里打开Url
			this.tab.open(url);
		}
		this.setContainer(uid > 0);

		//this.include.get(document, "http://img1.ido360.com/css/main.css");
		//this.include.get(document, "http://img1.ido360.com/css/main.css");
		//this.include.get($("#Chat8002").contents()[0], "http://img1.ido360.com/css/chat.css");

		//IdoMain.client.dyn.recv(200, 1506, 8051);

		//IdoMain.client.dyn.recv(9, 1478, 18087);

		//for(var i = 0;i<30;i++){
		//	IdoMain.client.dyn.recv(0, 1470 + i, 0);
		//}

		//IdoMain.client.dyn.recv(9, 1422, 8001);

		
	},
	
	/**
	 * 音乐部分 ^_^MUSIC^_^
	 */
	music : {
		_bIsInit : false,	//是否加载了音乐播放器
		init : function(){
			var flashvars = {};
			var params = {"allowScriptAccess" : "always", "allowFullScreen" : "false", "wmode" : "transparent"};
			var attributes = {};
			swfobject.embedSWF(IdoMain.chat.lChatVer["music"], "FlashMusic", "630", "45", IdoMain._FLASH_REQUIRE_VER,"", flashvars, params, attributes);
			this._bIsInit = true;
		},

		//由音乐flash在初始化完成时回调
		onFinishProxy : function(){
			
			//添加圣诞歌
			/*try{
				var proxy = this.getProxy();
				proxy.addOne({mid:1000000,uid:0,mname:"silent night",murl:"http://www.51share.net/upfiles/200312161558172997.mp3",singer:"mariah carey"});
				proxy.addOne({mid:1000001,uid:0,mname:"圣诞歌2",murl:"http://www.brodkaster.com/communities/5/004/006/154/505/audio/4529666718.mp3",singer:""});
				proxy.addOne({mid:1000002,uid:0,mname:"圣诞歌3",murl:"http://faculty.bush.edu/mark.francis/rudolph.mp3",singer:""});
				proxy.addOne({mid:1000003,uid:0,mname:"圣诞歌4",murl:"http://cdn1-24.projectplaylist.com/e1/static12/mp3/2714189.mp3",singer:""});
				proxy.addOne({mid:1000004,uid:0,mname:"圣诞歌5",murl:"http://content.12530.com/upload/rings/20081202/600597979813600902000004236033/000026617355_000019.mp3",singer:""});
				proxy.addOne({mid:1000005,uid:0,mname:"圣诞歌6",murl:"http://english116.com/admin/annex/20091218074342541.mp3",singer:""});
				//proxy.playOne(1000000);
			}catch(e){}*/

			//setTimeout(function(){
			
				//if(IdoMain.client._sCliUid != "8002"){
				//	for(var i=0;i<1;i++){
				//		var data = "{\"uid\":8001,\"time\":\"2010-06-03 16:06\",\"nick\":\"Karas\",\"pic\":\"http://pic1.ido360.com/head/00/05/m_8001_1000586.jpg\",\"content\":\"不许动，我是黑猫警长！(" + (i+1) + "/5)\",\"first\":true}";
				//		IdoMain.client.msg.recv(3, data, 1);
				//	}
				//}else{
				//	IdoMain.client.msg.recv(4, "208|0|18087|三多的大爷", 1);
				//}
				//IdoMain.client.msg.recv(7, "8001", 1);
			//}, 1000);
			
			
			//addMusicList
			setTimeout(function(){
				$.ajax({
					type: "POST",
					url: "/web/app/music/fl_music.aspx",
					data: {uid : IdoMain.client._sCliUid},
					dataType : "json",
					success: function(msg){
						IdoMain.music.onLoadList(msg["Table"]);
					},
					
					error : function(msg, t2, t3){
					   //alert("读取音乐列表失败");
					}
				})
			}, 1000);
		},

		onLoadList : function(list){
			try{
				var proxy = this.getProxy();
				for(var i=0;i<list.length;i++){
					proxy.addOne(list[i]);
				}
			}catch(e){/*alert(e);*/}
		},
		
		playOne : function(mid){
			try{
				this.getProxy().playOne(mid);
			}catch(e){/*alert(e);*/};
		},
		
		addOne : function(obj){
			try{
				this.getProxy().addOne(obj);
			}catch(e){/*alert(e);*/};
		},
		
		delOne : function(mid){
			try{
				this.getProxy().delOne(mid);
			}catch(e){/*alert(e);*/};
		},

		getProxy : function(){
			return document.getElementById('FlashMusic');
		}

		
	},

	/**
	 * 聊天部分 ^_^CHAT^_^
	 */
	chat : {
		_bIsRun : false,	//是否已经加载了主框
		nSkinId : 10,		//皮肤ID
		
		//窗口列表
		$oChat : null,
		$oTop : null,
		$oBottom : null,
		$oTask : null,
		$oFlashCont : null,
		
		lSkin : {
			1 : {skinId : 1, back : "#FFE1EA", border : "#C75D67", chatBack : "#E992A9", chatDisBack : "#FBE2EA", chatDisBorder : "#E99FB6", word : "#000"},
			2 : {skinId : 2, back : "#FFDFC5", border : "#C15C0A", chatBack : "#FFA66B", chatDisBack : "#FFE6D6", chatDisBorder : "#F3BF9C", word : "#000"},
			3 : {skinId : 3, back : "#F9F7AD", border : "#B37F2B", chatBack : "#F4E99A", chatDisBack : "#FFFAE0", chatDisBorder : "#ECE3AF", word : "#000"},
			4 : {skinId : 4, back : "#D5FCB1", border : "#1D5F44", chatBack : "#90B96B", chatDisBack : "#D9F1C1", chatDisBorder : "#90B96B", word : "#FFF"},
			5 : {skinId : 5, back : "#C4E7EB", border : "#1BA7B8", chatBack : "#65CCED", chatDisBack : "#C4EEF8", chatDisBorder : "#65CCED", word : "#000"},
			6 : {skinId : 6, back : "#D2E4FF", border : "#2287FF", chatBack : "#ADCEFF", chatDisBack : "#CFDFF3", chatDisBorder : "#ADCEFF", word : "#2C2C2C"},
			7 : {skinId : 7, back : "#B7D0EE", border : "#5266AD", chatBack : "#78A6D7", chatDisBack : "#BED0E1", chatDisBorder : "#78A6D7", word : "#FFF"},
			8 : {skinId : 8, back : "#F4EFE4", border : "#BAB19B", chatBack : "#EAE6DB", chatDisBack : "#EEEDE9", chatDisBorder : "#EAE6DB", word : "#2C2C2C"},
			9 : {skinId : 9, back : "#FFFFCC", border : "#212121", chatBack : "#5F5F5F", chatDisBack : "#CBCBCB", chatDisBorder : "#A4A4A4", word : "#FFF"},
			10 : {skinId : 10, back : "#EEF2F9", border : "#9E9E9E", chatBack : "#D1D6E1", chatDisBack : "#F1F1F1", chatDisBorder : "#CBCBCB", word : "#000"}
		},
		
		lChatVer : {},		//聊天flash版本属性列表

		mTabUsers : new MMap(),				//下面列表中的用户
		lAllUsers : {},					//有聊天记录的用户(个人或圈子)	{user, type, record, topWin, visible} type={'user', 'group'} record = ArrayList
		
		_lastWinPos : {x : -1, y : -1},	//最后一次窗口的打开位置
		_nMaxZIndex : 100,				//当前最大的zIndex
		_sCurTopUid : 0,				//当前最大zIndex的uid
		_timerMsgShine : 0,				//消息来标题栏闪烁的timer
		sShineType : "",				//消息来闪烁内型
		_bIsOpenWining : false,			//是否正在打开聊天窗口，下在打开聊天窗口时不能再打开下一个聊天窗口
		nSendKeyId : 0,					//发送快捷键的ID，1为Enter发送，2为Ctrl+Enter发送，3为两者都可发送
		
		stranger : {
			uid : -1,
			nick : "陌生人",
			sign : "随缘对对碰",
			photo : "http://img1.ido360.com/img/app/stranger/appHead.png",
			isJoin : false
		},

		
		//主框登陆后加载聊天场景界面
		loadMainChat : function(){
			this._bIsRun = true;
			if(this.nSkinId < 1 || this.nSkinId > 10){
				this.nSkinId = 10;
			}
			IdoMain._setChatContHtml();
			//inittabs要在resetSkin之前
			IdoMain.client._initTabs();
			this.resetSkin();	//初始化皮肤

			//IdoMain.client._sCliChatServer = '61.129.50.157'; //218.78.209.75 //192.168.18.39
			var flashvars = {ver:this.lChatVer["ver"], token:IdoMain.client._sCliToken, serverName:IdoMain.client._sCliChatServer, serverPort:5001, fmsServerName:"sh.ido360.com", session:IdoMain.client.getLocalSession(), skinId:this.nSkinId};
			var params = {"allowScriptAccess" : "always", "allowFullScreen" : "false", "scale" : "noScale", "align" : "LT"};
			var attributes = {};
			//alert($.param(flashvars));
			var height = IdoMain.client.getWinPos().mid;
			swfobject.embedSWF(this.lChatVer["init"], "FlashChat", "220", height, IdoMain._FLASH_REQUIRE_VER,"", flashvars, params, attributes);
		},
		
		initConfig : function(o){
			this.nSkinId = o.chatSkin;
			this.nSendKeyId = o.chatKey;
		},

		getSkin : function(){
			return this.lSkin[this.nSkinId];
		},

		getNewZIndex : function(){
			return ++ this._nMaxZIndex;
		},

		getCurZIndex : function(){
			return this._nMaxZIndex;
		},

		//重新设置皮肤
		resetSkin : function(){
			//set skin
			if(!this._bIsRun) return;
			var n = this.nSkinId;
			var skin = this.getSkin();
			var p = "url(http://img1.ido360.com/img/chat/back" + n + ".png)";
			var b = "1px solid " + skin.border;
			var $oMiddle = $('#ChatCont .mleft');
			this.$oTop.css("background-image", p);
			this.$oBottom.css("background-image", p);
			$oMiddle.css({"border-left" : b, "border-right" : b});
			//this.$oTask.css({"background-color" : skin.back, "border-top" : b});
			this.$oTask.find(".mtasktips").css({"color" : skin.word});
			
			//选项卡
			for(var i in IdoMain.client.lTabs){
				IdoMain.client.lTabs[i].btn.css("background-image", p);
			}

			//聊天框
			//alert($("iframe.chatFrame").size());
			var b1 = "1px solid " + skin.chatDisBorder;
			for(var i in this.lAllUsers){
				var o = this.lAllUsers[i];
				if(o.frm == null) continue;
				var id = o.user.id;
				var con = o.frm.find("#Main" + id);
				con.css({"background-color" : skin.chatDisBack, "border" : b1});
				con.find("#TxtOut" + id).css({"border" : b1});
				//con.find("#Head").css({"background-image" : "url(http://img1.ido360.com/img/chat/topback" + n + ".png)"});
				con.find("#Head" + id).css({"background-image" : "none"});
				con.find("#HeadInfo" + id).css({"color" : skin.word});
				con.find("#HeadInfo" + id + " a").css({"color" : skin.word});
				con.find("#GroupTitle" + id).css({"color" : skin.word, "border-left" : b1, "border-right" : b1});
				con.find("#FuncBtns" + id).css({"color" : skin.word, "border-left" : b1, "border-right" : b1});
				con.find("#TxtIn" + id).css({"border" : b1});
				con.find("#GroupNotice" + id).css({"border" : b1});
				con.find("#GroupList" + id).css({"border" : b1});
			}

			this.resetChatSkin();

			//更改网站皮肤
			IdoMain.tab.changeSkin(n);
			
		},
		
		//修改皮肤api
		changeSkin : function(skinId){
			this.nSkinId = skinId;
			this.resetSkin();
		},

		saveSkin : function(){
			$.post("/web/app/user/config.aspx", {type : "chatSkin", value : this.nSkinId});
		},
		
		saveSendKey : function(){
			$.post("/web/app/user/config.aspx", {type : "chatKey", value : this.nSendKeyId});
		},
		
		//标题栏闪烁
		setMsgShine : function(type, msg){
			if(type == '_shine_'){
				document.title = document.title.indexOf('_') != -1 ? msg + " - 爱度网" : "______ - 爱度网";
				return;
			}

			try{
				clearInterval(this._timerMsgShine);
			}catch(e){}

			this.sShineType = "";

			if(type != 'msg' && type != 'dyn' && type != 'chat') {
				document.title = "爱度--中国首创都市游戏社区";
				return;
			}
			
			var msg = "";
			if(type == 'msg'){
				msg = '新消息';
			}else if(type == 'dyn'){
				msg = '新动态';
			}else{
				msg = '悄悄话';
			}
			this.sShineType = type;
			this._timerMsgShine = setInterval("IdoMain.chat.setMsgShine('_shine_', '"+msg+"')", 800);
		},
		
		

		//修改TopWin z-index
		changeTopWin : function(id){
			if(!this.isAddUser(id)) return;
			$('#Chat' + id).css("display", "block");
			if(this._sCurTopUid == id){
				return;
			}
			var u;
			if(this.isAddUser(this._sCurTopUid)){
				//第一个窗口
				u = this.lAllUsers[this._sCurTopUid];
				u.topWin = false;
				this.resetChatSkin(this._sCurTopUid);
				$('#Chat' + this._sCurTopUid).css("display", "block");
			}
			u = this.lAllUsers[id];
			u.topWin = true;
			if(u.frm){
				u.frm.css("z-index", this.getNewZIndex());
			}
			
			this._sCurTopUid = id;
			this.resetChatSkin(id);
			

		},

		resetTopWin : function(){
			var maxIndex = -1;
			var maxId = 0;
			var u;
			var tmpIndex = 0;
			for(var i in this.lAllUsers){
				u = this.lAllUsers[i];
				if(u.frm != null){
					tmpIndex = u.frm.css("z-index");
					if(tmpIndex > maxIndex){
						maxIndex = tmpIndex;
						maxId = u.user.id;
					}
				}
				u.topWin = false;
			}
			if(maxIndex < 0 || this._sCurTopUid == maxId) return;

			if(this._sCurTopUid != 0){
				this.resetChatSkin(this._sCurTopUid);
			}
			
			this.lAllUsers[maxId].topWin = true;
			this._sCurTopUid = maxId;
			this.resetChatSkin(maxId);
			
		},

		resetChatSkin : function(id){
			if(id == undefined){
				id = this._sCurTopUid;
			}
			//alert(uid);
			//if(!this.isTabUser(uid)) return;
			//alert('yes');
			if(!this.isAddUser(id)) return;
			var u = this.lAllUsers[id];
			if(u.frm == null) return;
			var con = u.frm.find("#Main" + id)
			var skin = this.getSkin();
			var b = "1px solid " + (u.topWin ? skin.border : skin.chatDisBorder);
			var p = u.topWin ? "url(http://img1.ido360.com/img/chat/topback" + skin.skinId + ".png)" : "none";
			
			con.css({"background-color" : (u.topWin ? skin.chatBack : skin.chatDisBack), "border" : b});
			con.find("#Head" + id).css({"background-image" : p});
			con.find("#GroupTitle" + id).css({"background-image" : p, "border-left" : b, "border-right" : b});
			con.find("#FuncBtns" + id).css({"background-image" : p, "border-left" : b, "border-right" : b});
			con.find("#TxtOut" + id).css({"border" : b});
			con.find("#TxtIn" + id).css({"border" : b});
			con.find("#GroupNotice" + id).css({"border" : b});
			con.find("#GroupList" + id).css({"border" : b});

		},

		parseContent : function(s){
			if (s.length == 0) return "";
			s = s.replace(/&/g, "&gt;");
			s = s.replace(/</g, "&lt;");
			s = s.replace(/>/g, "&gt;");
			s = s.replace(/ /g, "&nbsp;");
			s = s.replace(/\'/g,"&#39;");
			s = s.replace(/\"/g,"&quot;");
			s = s.replace(/\n/g,"<br/>");
			s = s.replace(/\r/g,"");
			s = s.replace(/:em([1-9][0-9]?);/g, "<img src='http://img1.ido360.com/img/face1/$1.gif' height='19' width='19'/>");
			return s;
		},


		getChatOneHtml : function(chat/*MChatData*/){
			if(chat.from == 'sys') chat.nick = '系统';
			return "<div class='cont'><div class='" + chat.from + "'>" + chat.nick + " " + chat.date.format() + "</div><div class='con'>" + chat.content + "</div></div>";
		},

		getChatHtml : function(id){
			if(!this.isAddUser(id)) return "";
			var u = this.lAllUsers[id];
			if(!u.frm) return "";
			var len = u.record.size();
			var s = "";
			for(var i=0;i<len;i++){
				s += this.getChatOneHtml(u.record.get(i));
			}
			return s;
		},

		closeChatWin : function(id, _isNotConfirm){
			var o = this.lAllUsers[id];
			//if(!o) return;
			if(o && o.type == "stranger"){
				//陌生人聊天退出
				if(_isNotConfirm || !this.stranger.isJoin){
					this.setStrangerJoin(false);
					IdoMain.proxy.W2FStranger("quit");
				}else{
					$.idoConfirm("关闭窗口将退出随缘对对碰，确定要退出吗？", function(){
						IdoMain.chat.closeChatWin(id, true);
					}, null, {showMask:false});
					return;
				}
			}
			
			if(o && o.type == "sysnotice"){
				//系统消息关闭时清空
				o.record.clear();
			}
			
			if(this.isTabUser(id)){
				this.mTabUsers.remove(id);
			}
			
			this.$oTask.find("div[uid=" + id + "]").remove();
			if(!o || !o.topWin) return;
			if(o){
				if(o.frm) o.frm.remove();
				o.frm = null;
				o.visible = false;
				o.topWin = false;
			}

			this._sCurTopUid = 0;
			this.resetTopWin();

			
		},

		//最小化所有聊天窗口
		minAllChatWin : function(){
			//$("iframe.chatFrame").remove();
			for(var i in this.lAllUsers){
				var o = this.lAllUsers[i];
				o.topWin = false;
				o.visible = false;
				if(o.frm != null){
					o.frm.remove();
				}
				o.frm = null;
			}
			this._sCurTopUid = 0;
		},

		minChatWin : function(id){
			var o = this.lAllUsers[id];
			if(!o) return;
			o.frm.remove();
			o.frm = null;
			o.visible = false;
			if(!o.topWin) return;
			o.topWin = false;
			this._sCurTopUid = 0;
			this.resetTopWin();

			
		},

		//是否已经添加了用户
		isAddUser : function(id){
			return this.lAllUsers[id] != undefined;
		},

		isTabUser : function(id){
			return this.mTabUsers.containsKey(id);
		},
		
		setTabUserWave : function(id){
			if(!this.mTabUsers.containsKey(id)) return;
			var u = this.mTabUsers.get(id);
			if(!u.waveTimer){
				u.waveTimer = {};
			}else{
				if(u.waveTimer.timer > 0){
					//this.delTabUserWave(id);
					return;
				}
			}
			u.waveTimer.level = 1;
			u.waveTimer.timer = 0;
			//start wave
			u.waveTimer.timer = setInterval(function(){
				var ox = 0, oy = 0;
				var level = u.waveTimer.level;
				if(level == 1) {
					//right
					ox = 1; oy = 1;
				}else if(level == 2) {
					//middle
					ox = 0; oy = -1;
				}else if(level == 3) {
					//left
					ox = -1; oy = 1;
				}else{
					//middle
					ox = 0; oy = -1;
				}
				u.waveTimer.level ++;
				if(u.waveTimer.level >= 4) {
					u.waveTimer.level = 0;
				}
				var $o = IdoMain.chat.$oTask.find("#ChatTaskImg" + id);
				if($o.length < 1){
					IdoMain.chat.delTabUserWave(id);
				}
				$o.css({"margin-top" : (3 + ox), "margin-left" : (3 + oy)});

			}, 300);
		},

		delTabUserWave : function(id){
			if(!this.mTabUsers.containsKey(id)) return;
			var u = this.mTabUsers.get(id);
			if(u.waveTimer && u.waveTimer.timer > 0){
				try{
					clearInterval(u.waveTimer.timer);
				}catch(e){}
				u.waveTimer.timer = 0;
			}
			this.$oTask.find("#ChatTaskImg" + id).css({"margin-top" : 3, "margin-left" : 3});
		},

		addUpdateAllUser : function(type, user, isAdd, isLeave){
			var id = user.id; //不同于uid
			var o = null;
			var isAddTask = false;
			if(!this.isAddUser(id)){
				o = {user : user, type : type, record : new ArrayList(), drag : {}, topWin : false, visible : false, frm : null, lastSend : 0, ext : {}};
				if(isLeave) o.isLeave = true;
				this.lAllUsers[id] = o;
				this.mTabUsers.put(id, o);
				isAddTask = true;
				
			}else{
				
				o = this.lAllUsers[id];
				//存在的话如果isAdd则不更新
				if(!isAdd){
					o.user = user;
				}
				if(isLeave) o.isLeave = true;
				if(!this.isTabUser(id)){
					this.mTabUsers.put(id, o);
					isAddTask = true;
				}
			}
			//添加到task栏
			if(isAddTask){
				var photo = user.photo ? user.photo : "http://img1.ido360.com/img/s_defhead.jpg";
				this.$oTask.find(".mtasktips").remove();
				$("<div class='headbox' title='" + user.nick + "' uid='"+id+"'><img src='" + photo + "' id='ChatTaskImg"+id+"'/></div>")
					.click(function(){
						if(!IdoMain.chat._bIsOpenWining){
							IdoMain.chat._bIsOpenWining = true;
							//正在打开聊天窗口时不能再打开下一个聊天窗口
							var id = $(this).attr("uid");
							IdoMain.chat.delTabUserWave(id);
							IdoMain.chat._openChatWin(id);
							if(IdoMain.chat.sShineType == "chat"){
								IdoMain.chat.setMsgShine("");//停止title闪烁
							}
						}
					}).prependTo(this.$oTask);
			}
			return o;
		},

		//发聊天消息
		sendMsg : function(id){
			var o = this.lAllUsers[id];
			if(!o) return;
			if(o.type == "stranger" && !this.stranger.isJoin){
				//$.idoAlert("随缘对对碰没有连接，不能聊天");
				this.recvStrangerMsg("没有连接成功或对方已退出！<a href='javascript:void(0)' onclick='IdoMain.chat.openStrangerWin()'>点击碰碰下一个</a>", true)
				return;
			}
			if(o.type == "sysnotice") return;//系统消息不能回复
			if(!o.lastSend) o.lastSend = 0;
			var newTime = new Date().getTime();
			if(newTime - o.lastSend < 1000){
				//1秒内禁止发送
				return;
			}
			o.lastSend = newTime;
			var con = o.frm.find("#Main" + id);
			var in1 = con.find("#TxtIn" + id);
			var out = con.find("#TxtOut" + id);
			var incon = in1.val();
			if(incon == '' || incon == '^_^ 说点什么吧') return;
			var chatData = new MChatData();
			chatData.uid = IdoMain.client._sCliUid;
			chatData.nick = IdoMain.client._sCliNick;
			chatData.date = new Date();
			chatData.from = "me";
			chatData.content = this.parseContent(incon);
			out.append(this.getChatOneHtml(chatData));
			
			//out.append("<div><p class='me'>" + IdoMain.client._sCliNick + " " + new Date().format() + "</p><p class='con'>" + Ido.htmlEncode(incon).replace(/\n/g, "<br/>") + "</p></div>");
			out.scrollTop(100000);
			in1.val("");
			in1.focus();

			this.lAllUsers[id].record.add(chatData);
			
			if(o.type == "stranger"){
				IdoMain.proxy.W2FStranger("chat", incon);
			}else{
				//因为聊天消息有type,故可以直接用uid
				IdoMain.proxy.W2FSendMsg(o.type, o.user.uid, incon);
			}
		},

		//由flash框调用，故为uid
		setUserOffline : function(uid){
			var o = this.lAllUsers[uid];
			if(!o) return;
			var chat = new MChatData();
			chat.from = 'sys';
			chat.uid = 0;
			chat.nick = '';
			chat.date = new Date();
			chat.content = o.user.nick + '已下线，Ta在下次登陆后可以收到你的消息!';
			o.record.add(chat);
			if(o.frm != null && o.visible){
				o.frm.find("#TxtOut" + uid).append(this.getChatOneHtml(chat))
					.scrollTop(100000);
			}
			IdoMain.proxy.W2FSetUserOnline(uid, 0);
			if(!o.topWin || !o.visible){
				this.setTabUserWave(uid);
				IdoMain.chat.setMsgShine("chat");
			}
		},
	
		parseUser : function(userf){
			var user;
			if(userf.mode == 1){
				user = new MGroupData();
			}else{
				user = new MUserData();
			}
			user.parse(userf);
			return user;
		},

		//收聊天消息
		recvMsg : function(type, isAdd, userf, chatf){
			//type is no user current
			//trace("type=" + type + " isAdd" + isAdd + " userf=" + userf);

			var user = this.parseUser(userf);
			var chat = new MChatData();
			chat.parse(chatf);

			var o =this.addUpdateAllUser(type, user, isAdd);
				
			chat.content = this.parseContent(chat.content);
			o.record.add(chat);
			if(o.frm != null && o.visible){
				o.frm.find("#TxtOut" + user.id).append(this.getChatOneHtml(chat))
					.scrollTop(100000);
			}
			if(!o.topWin || !o.visible){
				this.setTabUserWave(user.id);
			}
			IdoMain.chat.setMsgShine("chat");
		},


		//收离开聊天消息通知
		recvLeaveMsg : function(type, isAdd, userf){
			//type is no user current
			//trace("type=" + type + " isAdd" + isAdd + " userf=" + userf);
			var user = this.parseUser(userf);

			var o =this.addUpdateAllUser(type, user, isAdd, true);
			if(o.frm != null && o.visible){
				o.frm.find("#TxtOut" + user.id).scrollTop(100000);
				o.frm.find("#LeaveNotice" + user.id).show();
				//如果窗口存在就直接取数据
				//离线留言暂时不支持圈子消息
				IdoMain.proxy.W2FGetLeaveMsg("user", user.uid);
			}
			if(!o.topWin || !o.visible){
				this.setTabUserWave(user.id);
			}
			IdoMain.chat.setMsgShine("chat");
		},

		//收离线聊天消息
		recvLeaveData : function(type, isAdd, userf, msgList){
			var user = this.parseUser(userf);

			var o =this.addUpdateAllUser(type, user, isAdd);
			o.isLeave = false;
			var sCon = "";
			if(msgList != null){
				try{
					for(var i=0;i<msgList.length;i++){
						var oData = msgList[i];
						var chat = new MChatData();
						chat.from = 'ta';
						chat.uid = user.uid;
						chat.nick = user.nick;
						chat.date = oData.date;
						chat.content = this.parseContent(oData.content);
						o.record.add(chat);
						sCon += this.getChatOneHtml(chat);
					}
				}catch(e){}
			}
			
			if(o.frm != null && o.visible){
				o.frm.find("#TxtOut" + user.id).append(sCon).scrollTop(100000);
				o.frm.find("#LeaveNotice" + user.id).hide();
			}
		},
		
		recvStrangerJoin : function(isOther, success){
			var user = new MUserData();
			user.uid = this.stranger.uid;
			user.nick = this.stranger.nick;
			user.sign = this.stranger.sign;
			user.photo = this.stranger.photo;
			user.id = user.uid;
			
			var o = this.addUpdateAllUser("stranger", user, true);
			o.record.clear();
			if(o.frm != null){
				o.frm.find("#TxtOut" + user.id).empty();
			}
			if(isOther){
				this.setStrangerJoin(true);
				this.recvStrangerMsg("<img src='http://img1.ido360.com/img/face1/48.gif' height='19' width='19'/> 一个陌生人想和你随缘对对碰，现在你们可以开始对话了！你和对方都无法知道对方的个人信息！<br/><span style='color:blue;'>希望你们可以借此了解对方，成为互相投缘的人！</span>提倡文明聊天，拒绝恶性骚扰！", true);
			}else{
				if(success){
					this.setStrangerJoin(true);
					this.recvStrangerMsg("<img src='http://img1.ido360.com/img/face1/1.gif' height='19' width='19'/> 随缘对对碰成功，你们可以开始对话了！希望你们可以借此成为互相投缘的人！<br/><span style='color:blue;'>提倡文明聊天，拒绝恶性骚扰！</span>", true)
				}else{
					this.setStrangerJoin(false);
					this.recvStrangerMsg("<img src='http://img1.ido360.com/img/face1/53.gif' height='19' width='19'/> 很遗憾，谁都没碰到，<a href='javascript:void(0)' onclick='IdoMain.chat.openStrangerWin()'>再碰一次</a>", true)
				}
			}
		},
		
		recvStrangerQuit : function(isOther){
			this.setStrangerJoin(false);
			if(isOther){
				this.recvStrangerMsg("<img src='http://img1.ido360.com/img/face1/53.gif' height='19' width='19'/> 对方已退出！<a href='javascript:void(0)' onclick='IdoMain.chat.openStrangerWin()'>点击碰碰下一个</a>", true)
			}
		},
		
		recvStrangerMsg : function(msg, isSys){
			var id = this.stranger.uid;
			var o = this.lAllUsers[id];
			if(!o) return;//没有这个人，丢弃
			var chat = new MChatData();
			chat.from = isSys ? "sys" : "ta";
			chat.uid = this.stranger.uid;
			chat.nick = this.stranger.nick;
			chat.date = new Date();
			chat.content = isSys ? msg : this.parseContent(msg);
			o.record.add(chat);
			if(o.frm != null && o.visible){
				o.frm.find("#TxtOut" + id).append(this.getChatOneHtml(chat))
					.scrollTop(100000);
			}
			if(!o.topWin || !o.visible){
				this.setTabUserWave(id);
			}
			IdoMain.chat.setMsgShine("chat");
		},
		
		openStrangerWin : function(){
			var id = this.stranger.uid;
			var o = this.lAllUsers[id];
			//有o的话说明之前正在聊天，只要更新状态就可以了。
			if(!o){
				$.idoConfirm("系统将在当前在线用户中随机抽出一个人和你聊天，<br/>你无法看到对方任何信息，<br/>对方也无法看到你的任何信息，<br/><span style='color:blue;'>希望你们可以借此了解对方，成为互相投缘的人！</span><br/>确定要使用随缘对对碰吗？", function(){
					IdoMain.chat._openStrangerWin();
				}, null, {showMask:false});
			}else{
				this.setStrangerJoin(this.stranger.isJoin);
				if(!this.stranger.isJoin){
					IdoMain.proxy.W2FStranger("join");
				}
				this._openChatWin(id);
			}
		},
		
		_openStrangerWin : function(){
			var id = this.stranger.uid;
			var user = new MUserData();
			user.uid = this.stranger.uid;
			user.nick = this.stranger.nick;
			user.photo = this.stranger.photo;
			user.id = user.uid;
			this._bIsOpenWining = true;
			//正在打开聊天窗口时不能再打开下一个聊天窗口
			var o = this.addUpdateAllUser("stranger", user);
			this._openChatWin(id);
			this.setStrangerJoin(false);
			IdoMain.proxy.W2FStranger("join");
		},
		
		setStrangerJoin : function(isJoin){
			this.stranger.isJoin = isJoin;
			var o = this.lAllUsers[this.stranger.uid];
			if(!o) return;
			o.user.sign = this.stranger.sign + (isJoin ? " 【已连接】" : " 【未连接】");
			if(o.frm != null){
				o.frm.find("#InfoSign" + o.user.id).html(Ido.htmlEncode(o.user.sign));
			}
		},
		
		//添加聊天窗口
		openChatWin : function(type, userf, isord){
			//type == user,group
			var user = isord ? userf : this.parseUser(userf);
			if(!user.id) user.id = user.uid;
			var id = user.id;
			if(!id) return;
			if(this._bIsOpenWining) return;
			this._bIsOpenWining = true;
			//正在打开聊天窗口时不能再打开下一个聊天窗口

			this.addUpdateAllUser(type, user);
			this._openChatWin(id);

		},

		_openChatWin : function(id){
			
			var o = this.lAllUsers[id];
			if(o.frm != null){
				//已经存在窗口
				if(o.isLeave){
					o.frm.find("#LeaveNotice" + id).show();
				}else{
					o.frm.find("#LeaveNotice" + id).hide();
				}
				IdoMain.chat.changeTopWin(id);
				this._bIsOpenWining = false;
				return;
			}

			var pos = this._lastWinPos;
			if(pos.x < 0){
				pos.x = 248 / 2;
				pos.y = 62 / 2;
			}else{
				pos.x = pos.x + 20 > 248 ? pos.x + 20 - 248 : pos.x + 20;
				pos.y = pos.y + 6 > 62 ? pos.y + 6 - 62 : pos.y + 6;
			}
			
			//var frm = $("<iframe class='chatFrame' frameborder='0' scrolling='no'></iframe>");
			var frm = $("<div>");
			o.frm = frm;
			o.topWin = true;
			o.visible = true;
			
			frm.attr({name : "Chat" + id, id : "Chat" + id})
				.addClass("ChatFrame")
				.css({left : (IdoMain.$oCont.position().left + 1 + pos.x), top : (pos.y + 45), "z-index":this.getCurZIndex()})
				.html(IdoMain._getChatFrameHtml(o.user))
				.appendTo(document.body);
			
			//var w = this.contentWindow;
			//w.chat = IdoMain.chat.lAllUsers[uid];
			//var con = frm1.contents();
			var con = frm.find("#Main" + id);
			if(o.user.photo != null && o.user.photo != ""){
				con.find("#HeadImg" + id).attr("src", o.user.photo).click(function(){
					if(o.type == "group"){
						Ido.openGroupZone(o.user.uid);
					}
					if(o.type == "user"){
						Ido.openUserZone(o.user.uid);
					}
				});
			}
			
			//圈子增加宽度
			if(o.type == "group"){
				frm.width(442).height(402);
				con.width(440).height(400);
				con.find("#HeadInfo" + id).width(240);
				con.find("#TxtOut" + id).height(212 + 50);
			}
			
			IdoMain.chat.changeTopWin(id);
			con.mousedown(function(e){
				
				//如果已经在最上层则忽略
				//alert(w.chat.topWin + " - " + w.chat.user.uid);
				
				if(!o.topWin){
					IdoMain.chat.changeTopWin(id);
				}

				$("#ChatDivSendKey").remove();
				$("#ChatDivSendKeyFrame").remove();
				$("#ChatDivTopMenu").remove();

				if(IdoMain.chat.sShineType == "chat"){
					IdoMain.chat.setMsgShine("");//停止title闪烁
				}
				IdoMain.chat.delTabUserWave(id);

				return true;
			});
			
			frm.easydrag(false);
			//frm.setHandler("Head");
			
			con.keydown(function(e){
				if(e.which == 27){
					//esc quit
					IdoMain.chat.minChatWin(id);
					return false;
				}
				
				if(e.altKey || e.originalEvent.altKey){
					if(e.which == 67){	//ALT + C
						IdoMain.chat.closeChatWin(id);
					}else if(e.which == 83){	//ALT + S
						IdoMain.chat.sendMsg(id);
					}
					e.preventDefault();
					return false;
				}
			});
			
			var infoNick = Ido.htmlEncode(o.user.nick);
			var infoSign = Ido.htmlEncode(o.user.sign);
			if(o.type == "stranger" || o.type == "sysnotice"){
				//def
			}else if(o.type == "group"){
				infoNick = "<span style='font-weight:normal;line-height:15px;'>[" + o.user.level + "级] " + infoNick + "</span>";
				o.user.sign = "一起去PK"
				infoSign = "<a href='javascript:void(0);' class='gpzone m' title='打开圈子面板'></a><a href='javascript:void(0);' class='gphome m' title='进入圈子会所'></a>" + Ido.htmlEncode(o.user.sign);
			}else{
				//这里为个人，故为uid
				infoNick = "<a itab='" + o.user.uid + "'>" + o.user.nick + "</a>";
				//sign def
			}
			con.find("#InfoNick" + id).html(infoNick)
				.find("a[itab]").click(function(){
					IdoMain.proxy.openUserZone($(this).attr("itab"));
				}).attr({"href" : "javascript:void(0)", title : "打开" + o.user.nick + "的空间"})
				.css("color", this.getSkin().word);

			con.find("#InfoSign" + id).html(infoSign)
				.find("a.gpzone").click(function(){
					IdoMain.proxy.openGroupZone(o.user.uid, o.user.nick);
				}).end()
				.find("a.gphome").click(function(){
					if(o.user.chamber > 0){
						IdoMain.proxy.SWVisitGroup(o.user.uid);
					}else{
						$.idoAlert("该圈子暂时没有会所！<br/>圈子会所在游戏中创建产生！");
					}
				});

			con.find("#HeadBtn" + id + " .close").click(function(){
				IdoMain.chat.closeChatWin(id);
				return false;	//防止冒泡
			}).hover(function(){
				$(this).removeClass().addClass("closehover m");
			},function(){
				$(this).removeClass().addClass("close m");
			});
			con.find("#HeadBtn" + id + " .min").click(function(){
				IdoMain.chat.minChatWin(id);
				return false;	//防止冒泡
			}).hover(function(){
				$(this).removeClass().addClass("minhover m");
			},function(){
				$(this).removeClass().addClass("min m");
			});

			con.find("#HeadBtn" + id + " .max").click(function(){
				IdoMain.chat.minChatWin(id);
				return false;	//防止冒泡
			}).hover(function(){
				$(this).removeClass().addClass("maxhover m");
			},function(){
				$(this).removeClass().addClass("max m");
			});

			if(o.type == "stranger" || o.type == "sysnotice" || o.type == "group"){
				//陌生人聊天不出现菜单
				con.find("#HeadBtn" + id + " .menu").hide();
			}else{
				con.find("#HeadBtn" + id + " .menu").click(function(){
					//添加菜单
					var l1= $(this).offset().left;
					var t1 = $(this).offset().top + 16;
					$("<div id='ChatDivTopMenu'><ul><li v='1'>去TA空间</li><li v='2'>去TA房间</li><li v='3'>去TA身边</li><li v='4'>去TA花园</li><li v='5'>邀请TA来身边</li><li v='6'>添加TA为好友</li></div>")
						.css({left : l1, top : t1})
						.appendTo(document.body)
						.find("li")
						.hover(function(){
							$(this).addClass("hover");
						},function(){
							$(this).removeClass("hover");
						}).click(function(){
							var key = parseInt($(this).attr("v"));
							if(key == 1){
								//这里只用个人用户，故为uid
								IdoMain.proxy.openUserZone(o.user.uid);
							}else if(key == 2){
								$.idoConfirm('你确定要拜访' + o.user.nick + '的家吗？', function(){
									IdoMain.proxy.SWVisitHome(o.user.uid, o.user.nick);
								});
							}else if(key == 3){
								$.idoConfirm('你确定要去' + o.user.nick + '身边吗？', function(){
									IdoMain.proxy.SWVisitBuddy(o.user.uid, o.user.nick);
								});
							}else if(key == 4){
								$.idoConfirm('你确定要去' + o.user.nick + '花园吗？', function(){
									IdoMain.proxy.SWVisitGarden(o.user.uid, o.user.nick);
								});
							}else if(key == 5){
								$.idoConfirm('你确定要邀请' + o.user.nick + '来身边吗？', function(){
									IdoMain.proxy.W2FInviteBuddy(o.user.uid, o.user.nick);
								});
							}else if(key == 6){
								Ido.friend.add(o.user.uid);
							}
							$("#ChatDivTopMenu").remove();
						});
	
					return false;	//防止冒泡
				}).hover(function(){
					$(this).removeClass().addClass("menuhover m");
				}, function(){
					$(this).removeClass().addClass("menu m");
				});
			};
			if(o.type == "sysnotice"){
				con.find("#TxtIn" + id).val("这是爱度的系统消息，不能回复").attr("disabled", true);
			}else{
				con.find("#TxtIn" + id).keydown(function(e){
					
					var key = IdoMain.chat.nSendKeyId;
					var enter = e.which == 13 || e.which == 10;
					var shiftctrl = e.ctrlKey || e.shiftKey;
					var isSend = false;
					if(key == 0 || key == 1){
						isSend = !shiftctrl && enter;
						if(shiftctrl && enter){
							//$(this).val($(this).val() + "\n");
							this.value = this.value + "\r\n";
							return false;
						}
					}else if(key == 2){
						isSend = shiftctrl && enter;
					}else if(key == 3){
						isSend = enter;
					}
					if(isSend){
						IdoMain.chat.sendMsg(id);
						return false;
					}
					return true;
				}).setCaret();	//支持光标处插入文字
			}

			con.find("#FuncBtns" + id + " .face").click(function(){
				con.parent().find("#FaceCont" + id).remove();
				con.parent().append("<div id='FaceCont" + id + "' class='FaceCont'></div>");
				fc = con.parent().find("#FaceCont" + id);
				var s = "";
				for(var i=1;i<=78;i++){
					s += "<img src='http://img1.ido360.com/img/face1/" + i + ".gif' width='19' height='19' iem='" + i + "'/>";
				}
				s += "&nbsp;&nbsp;<a icmd='close'>关闭</a>";
				fc.html(s);
				fc.find("img").click(function(){
					var s = ":em" + $(this).attr("iem") + ";";
					var in1 = con.find("#TxtIn" + id);
					in1.insertAtCaret(s);
					con.parent().find("#FaceCont" + id).remove();
				});

				fc.find("a[icmd='close']").click(function(){
					con.parent().find("#FaceCont" + id).remove();
				}).attr("href", "javascript:void(0)");
			});

			con.find("#SendBtns" + id + " .send").click(function(){
				IdoMain.chat.sendMsg(id);
			});

			con.find("#SendBtns" + id + " .close").click(function(){
				IdoMain.chat.closeChatWin(id);
				return false;	//防止冒泡
			});
			con.find("#SendBtns" + id + " .arrow").click(function(){
				$("#ChatDivSendKey").remove();
				$("#ChatDivSendKeyFrame").remove();
				var l1= $(this).offset().left;
				var t1 = $(this).offset().top + 21;
				if(IdoMain.chat.nSendKeyId == 0) IdoMain.chat.nSendKeyId = 1;
				$("<div id='ChatDivSendKey'><ul><li v='1'>按Enter键发送消息</li><li v='2'>按Ctrl+Enter键发送消息</li><li v='3'>以上两者均可发送消息</li></div>")
					.css({left : l1, top : t1})
					.appendTo(document.body)
					.find("li")
					.each(function(){
						if($(this).attr("v") == IdoMain.chat.nSendKeyId){
							$(this).addClass("sel");
						}
					}).hover(function(){
						$(this).addClass("hover");
					},function(){
						$(this).removeClass("hover");
					}).click(function(){
						IdoMain.chat.nSendKeyId = parseInt($(this).attr("v"));
						//保存到服务器
						IdoMain.chat.saveSendKey();
						$("#ChatDivSendKey").remove();
						$("#ChatDivSendKeyFrame").remove();
					});
				var $o = $("#ChatDivSendKey");
				$("<iframe id='ChatDivSendKeyFrame' frameborder='0'></iframe>")
					.width($o.width())
					.height($o.height())
					.css({left : l1, top : t1})
					.appendTo(document.body);
				//停止冒泡
				return false;
			});
			
			con.find("#TxtOut" + id).html(IdoMain.chat.getChatHtml(id))
				.scrollTop(100000);

			if(o.isLeave){
				//取离线留言
				//离线留言暂时不支持圈子消息
				IdoMain.proxy.W2FGetLeaveMsg("user", o.user.uid);
				con.find("#LeaveNotice" + id).show();
			}else{
				con.find("#LeaveNotice" + id).hide();
			}
			if(o.type == "stranger"){
				con.find("#LeaveNotice" + id).html("你正在使用\"随缘对对碰\"插件和陌生人聊天..").show();
			}
			
			if(o.type == "group"){
				//con.find("#LeaveNotice" + id).html("圈子聊天目前只能发给在线成员").show();;

				//加载圈子信息
				this._loadGroupInfo(o);
			}
			
			IdoMain.chat._bIsOpenWining = false;
		},
		
		_loadGroupInfo : function(o){
			if(!o.ext.loadtime) o.ext.loadtime = 0;

			//5分钟更新一次
			if(o.ext.isload && new Date().getTime() - o.ext.loadtime <= 300*1000 ){
				this._fillGroupInfo(o);
			}else{
				$.post("/web/app/im/group.aspx", {type : "detail", gid : o.user.uid, uid : o.user.createId}, function(msg){
					try{
						var d = $.parseJSON(msg);
						if(!$.isArray(d.memList) || d.result != "success") throw "";
						o.ext.list = d.memList;
						o.ext.info = d.info;
						o.ext.isload = true;
						o.ext.loadtime = new Date().getTime();//加载的时间
						IdoMain.chat._fillGroupInfo(o);
					}catch(e){}
				});
			}
		},
		
		_fillGroupInfo : function(o){
			
			//填充圈子列表
			var $groupList = $("#GroupList" + o.user.id);
			var $notice = $("#GroupNotice" + o.user.id);
			var $title = $("#GroupTitle" + o.user.id);
			var ext = o.ext;
			$notice.html(ext.info.announce ? Ido.htmlEncode(ext.info.announce) : "本圈子暂无公告");
			var memCount = 0;
			var onlineCount = 0;
			if(ext.list.length == 0){
				$groupList.empty().html("此圈子无成员");
			}else{
				var s = "", m, ps, pstyle, istyle, astyle;
				//for(var j=0;j<10;j++){

				for(var i=0;i<ext.list.length;i++){
					m = ext.list[i];
					if(!m) continue;
					memCount ++;
					
					ps = m.position == 2 ? "圈主" : (m .position == 1 ? "管理员" : "普通成员");
					pstyle = m.position < 1 ? "background:none;" : "";
					if(m.online > 0){
						onlineCount ++;
						istyle = ""; astyle = "";
					}else{
						istyle = "filter:gray";
						astyle = "color:gray";
						pstyle += istyle;
					}
					s += "<div class='item'><div class='m admin"+m.position+"' title='"+ps+"' style='"+pstyle+"'>&nbsp;</div><div class='img'><img src='"+m.photo+"' width='16' height='16' style='"+istyle+"'/></div><div class='title'>&nbsp;<a title='"+m.nick+"' href='javascript:void(0);' i='"+i+"' style='"+astyle+"'>" + Ido.htmlEncode(m.nick) + "</a></span></div></div>";
				}//}
				$groupList.empty().html(s);
				//添加事件
				$groupList.find("a[i]").click(function(){
					var i = $(this).attr("i");
					if(!ext.list[i]) return;
					IdoMain.chat.openChatWin("user", ext.list[i], true);
				});
			}
			$title.html("圈子成员(" + onlineCount + "/" + memCount + ")");
		},

		setGroupMem : function(type, id, memUid){
			var o = this.lAllUsers[id];
			if(!o) return;
			if(type == 'del'){
				//删除成员, 直接删除
				if(o.ext.list && o.ext.list.length > 0){
					//o.ext.list.slice(0, n).concat(o.ext.list.slice(n + 1, o.ext.list.length));
					for(var i=0;i<o.ext.list.length;i++){
						if(o.ext.list[i].uid == memUid){
							delete o.ext.list[i];
							break;
						}
					}
					this._fillGroupInfo(o);
				}
			}else{
				//添加成员, 不直接添加
				o.ext.isload = false;
			}
		}
	},

	/**
	 * 客户端部分基本操作,如切换游戏网站动态,退出游戏等
	 */
	client : {

		/**
		 * 客户端参数
		 */
		_sCliChatServer : "",	//聊天服务器地址
		_sCliServer : "",		//服务器地址
		_sCliSite : "",			//服务器站点地址
		_sCliArea : "",			//所有区域
		_sCliToken : "",		//Token
		_sCliGameTarget : "",	//游戏目标，指明初始化游戏时进入哪个场景
		_sCliIsLogin : "",		//是否登陆
		_sCliUid : "",			//用户uid  
		_sCliNick : "",		//用户昵称 用在tab条上
		_sCliPicUrl	: "",		//用户头像 用在tab条上
		
		_sLocalSession : "",	//LocalSession

		_bGameUseOpen : false,	//GameUse是否打开
		
		//$oGame : null,			//游戏对象

		sCurTab : "web",		//当前选项卡
		lTabs : {},				//选项卡列表
		
		_noticeOnline : {timer : 0, sec : 0},		//XX上线了timer
		_userInfo : {isOpen : false, closeTimer : 0},
		_loginInfo : null,
		
		init : function(loginInfo){
			var c = null;
			var dtNow = new Date();
			if(!loginInfo){
				c = {firstTime : dtNow, lastTime : dtNow, countTime : 0, loginType : "logout", serverTime : dtNow, timer : 0};
			}else{
				c = loginInfo;
				c.firstTime = new Date(Date.parse(loginInfo.firstTime.replace(/-/g, '/').replace(/T/, ' ')));
				c.lastTime = new Date(Date.parse(loginInfo.lastTime.replace(/-/g, '/').replace(/T/, ' ')));
				c.loginType = loginInfo.loginType == "0" ? "logout" : "login";
				c.serverTime = new Date(Date.parse(loginInfo.serverTime.replace(/-/g, '/').replace(/T/, ' ')));
				c.timer = 0;
			}
			//本地时间应该加的时间
			c.serverAddTime = dtNow.getTime() - c.serverTime;
			this._loginInfo = c;
			//5分钟检测一次
			c.timer = window.setInterval(function(){
				var d = IdoMain.client._getIdoDot(false);
				var s = "";
				//if(d.needTime > 0 && d.needTime <= 30){
				if(d && d.needTime > 5 && d.needTime <= 10){
					s = "今日已获得<span style='color:#FF3333;'>" + d.dot + "</span>个爱点！<br/><span style='color:#0062C4;'>" + d.needTime + "</span>分钟后您将获得<span style='color:#FF3333;'>" + d.needDot + "</span>个爱点哦！<br/><span style='color:#BFBFBF;'>在线满半小时奖励翻倍，最高可达20倍奖励哦！</span><br/>&nbsp;<br/><div style='text-align:right'><a href='javascript:void(0)' onclick='Ido.showHelp(4)'>爱点是什么？</a><br/><a href='javascript:void(0)' onclick='Ido.showHelp(5)'>如何获得爱点？</a></div>";
					//$.idoAlert(s, null, {showMask : false, dispose : 5});
					$.idoAlert(s, null, {showMask : false});
				}
				
			}, 300000);
			//}, 10000);
		},
		
		logout : function(){
			var d = this._getIdoDot(false);
			var s = "";

			if(d && d.needTime > 0){
				s = "今日已获得<span style='color:#FF3333;'>" + d.dot + "</span>个爱点！<br/><span style='color:#0062C4;'>" + d.needTime + "</span>分钟之后你就能获得<span style='color:#FF3333;'>" + d.needDot + "</span>个爱点奖励了哦！<br/>";
				/*if(d.nextNeedTime > 0){
					s += "再坚持<span style='color:#0062C4;'>" + d.nextNeedTime + "</span>分钟可以多获得<span style='color:#FF3333;'>" + d.nextNeedDot + "</span>爱点哦！<br/>&nbsp;<br/>";
				}else{
					s += "&nbsp;<br/>";
				}*/
				s += "<span style='color:#BFBFBF;'>在线满半小时奖励翻倍，最高可达20倍奖励哦！</span><br/>&nbsp;<br/>";
			}
			$.idoConfirm(s + "要不要再呆一会儿？", null, null, {
				showMask:false, 
				buttonText:{ok:"再呆会儿", logout:"登出"},
				logoutEvent : function(){
					window.setTimeout(function(){
						$.idoProcess("logout", "正在安全登出，请稍候..");
						$.ajax({
							url : "/web/logout.aspx",
							type : "POST",
							data : {},
							complete : function(){
								$.hideIdoModal("logout");
								window.location.replace('/');
							}
						});
					}, 1);
				}
			});
		},

		anotherLogin : function(){
			window.setTimeout(function(){
				window.opener=null;  //IE6
				window.open('','_self');
				window.close();
			});

			//firefox可能无法关闭
		},
		
		//聊天服务器断开/连接成功时调用
		connect : function(isConnect){
			var c = this._loginInfo;
			var dtNow = new Date(new Date().getTime() + c.serverAddTime);
			if(isConnect && c.loginType == "logout"){
				//登陆过程
				//alert(c.firstTime.toLocaleString());
				c.loginType = "login";
				if(dtNow.getDate() != c.firstTime.getDate()){
					//今天第一次登陆
					c.firstTime = dtNow;
					c.countTime = 0;
				}
				c.lastTime = dtNow;
			}
			if(!isConnect && c.loginType == "login"){
				//断线过程
				c.loginType = "logout";
				this._getIdoDot(true);
				c.lastTime = dtNow;
			}
		},

		_getIdoDot : function(isRecord){

			var maxTime = 180;
			var everyTime = 30;
			var c = this._loginInfo;
			if(c.loginType != "login") return null;
			var countTimeAdd = 0;
			var firstTime = c.firstTime, lastTime = c.lastTime, countTime = c.countTime, stayTime = 0, dtNow = new Date(new Date().getTime() + c.serverAddTime);;
			if(dtNow.getDate() != lastTime.getDate()){
				//跨天登陆，从0点开始算
				lastTime = firstTime = new Date(dtNow.getFullYear(), dtNow.getMonth(), dtNow,getDate());
				countTime = 0;
			}else{
				//当天登陆
			}
			stayTime = parseInt((dtNow.getTime() - lastTime.getTime()) / 60000);
			if(stayTime < 1) stayTime = 0;

			if(countTime >= maxTime) return null;
			stayTime += countTime;
			var dot = 0;
			//if(stayTime <= 0) dot = 0;
			//else if(stayTime <= maxTime) dot = parseInt(stayTime / everyTime) * parseInt(stayTime / everyTime + 1);
			//else dot = (maxTime / everyTime) * (maxTime / everyTime + 1);
			/*if(countTime > 0){
				dot -= parseInt(countTime / everyTime) * parseInt(countTime / everyTime + 1);
			}*/
			//dot为今天已经获得的爱点
			
			countTime = stayTime;

			var needTime = 0;
			var needDot = 0;
			var nextNeedTime = 0;
			var nextNeedDot = 0;
			var countTime1 = countTime - 5; //延时5分钟，避免服务器来不及处理
			if(countTime1 < 0) countTime1 = 0;
			if(countTime1 < maxTime){
				var level = parseInt(countTime1 / everyTime);
				needTime = (level + 1) * everyTime - countTime1;
				needDot = 2 * (level + 1);
				if(needTime > everyTime) needTime = everyTime;
				if(level < (maxTime / everyTime) - 1){
					nextNeedTime = needTime + everyTime;
					nextNeedDot = 2 * (level + 2) + needDot;
				}
			}

			if(countTime1 <= 0) dot = 0;
			else if(countTime1 <= maxTime) dot = parseInt(countTime1 / everyTime) * parseInt(countTime1 / everyTime + 1);
			else dot = (maxTime / everyTime) * (maxTime / everyTime + 1);

			if(countTime > maxTime) countTime = maxTime;
			if(isRecord){
				c.firstTime = firstTime;
				c.countTime = countTime;
			}

			return {dot : dot, countTime : countTime, needTime : needTime, needDot : needDot, nextNeedTime : nextNeedTime, nextNeedDot : nextNeedDot};
		},
		
		//由this.chat在初始化时调用
		_initTabs : function(){
			var $oDyn = IdoMain.chat.$oTop.find(".dyn");
			var $oGame1 = IdoMain.chat.$oTop.find(".game");
			var $oWeb = IdoMain.chat.$oTop.find(".web");
			this.lTabs = {
				'dyn' : {isSel : false, btn : $oDyn, icon : $oDyn.find(".b1"), timer : 0, msgNum : {'game' : 0, 'zone' : 0}},
				'game' : {isSel : false, btn : $oGame1, icon : $oGame1.find(".b1"), timer : 0, msgNum : {'game' : 0}},
				'web' : {isSel : false, btn : $oWeb, icon : $oWeb.find(".b1"), timer : 0, msgNum : {'web' : 0}}
			};
			$oGame1.click(function(){
				IdoMain.client.showGame();
			});
			$oWeb.click(function(){
				IdoMain.client.showWeb();
			});

			this.gotoTab('web');
		},
		
		//跳转到选项卡  tab = web, dyn, game
		gotoTab : function(tab){
			
			if(tab != 'game' && tab != 'dyn') tab = 'web';
			var o;
			
			o = this.lTabs[tab];
			if(!o) return;		//在没有initTabs时有可能有调用gotoTab

			if(o.isSel) return;
			this.sCurTab = tab;
			o.btn.removeClass().addClass(tab + "sel");
			o.isSel = true;
			for(var i in this.lTabs){
				o = this.lTabs[i];
				if(tab == i || !o.isSel) continue;
				o.isSel = false;
				o.btn.removeClass().addClass(i);
			}
		},
		
		//显示网页
		//opentype为空或default或onlyone时显示有且仅有,为new时显示新的,为current时替换当前窗口
		showWeb : function(url, openType, tabType){
			IdoMain.$oGameUseCont.hide();
			IdoMain.$oWebCont.show();
			if (!url || url.length == 0){
				//清除动态网页
				IdoMain.tab._removeDyn();
				if(IdoMain.tab._nTabNum < 1){
					//没有网页就打开默认页
					IdoMain.tab.open(null);
				}
			}else{
				IdoMain.tab._openTab(url, openType);
			}

			/*if(!$.browser.msie){
				IdoMain.$oGameCont.css("visibility", "hidden");
			}else{
				this.moveShowGame(false);
			}*/
			this.moveShowGame(false);

			if(tabType && tabType == 'dyn'){
				IdoMain.client.gotoTab('dyn');
			}else{
				IdoMain.client.gotoTab('web');
			}
		},

		//显示游戏
		showGame : function(target){
			if(target == undefined){
				target = "";
			}
			IdoMain.client.gotoTab('game');

			//打开gameUse层就移出游戏
			this.moveShowGame(!this._bGameUseOpen);
			//this.moveShowGame(true);

			if(this._bGameUseOpen){
				IdoMain.$oGameUseCont.show();
			}else{
				IdoMain.$oGameUseCont.hide();
			}

			IdoMain.$oWebCont.hide();

			if (IdoMain.$oGameCont.html().length == 0){
				IdoMain.tool.checkShockwave();
				if (IdoMain._bHasSW){
					this._sCliGameTarget = target;
					//加载游戏
					//Ido.unloadConfirm.set(IdoMain._USER_QUIT_CONFIRM);

					//加载游戏时把所有聊天窗口关闭
					IdoMain.chat.minAllChatWin();
					IdoMain._setGameContHtml();
					IdoMain.$oGameCont.show();
					IdoMain.$oGameCont.css("visibility", "visible");
					
					IdoMain.$oGameUseCont.hide();
					document.getElementById('ido3d').style.display = 'block';
					IdoMain.$oGameCont.bind("mousewheel", function(e){
						IdoMain.proxy.W2SScroll(e.wheelDelta);
					});


				}else{
					this.moveShowGame(false);
					IdoMain.$oGameUseCont.show();
					this._bGameUseOpen = true;
					IdoMain._setGameNoSWHtml();
				}
			}else{
				/*if(this._bGameUseOpen){
					if(!$.browser.msie){
						IdoMain.$oGameCont.css("visibility", "visible");
					}
				}else{
					IdoMain.$oGameCont.css("visibility", "visible");
				}*/
				if(target != ""){
					IdoMain.proxy.W2SVisit(target);
				}
			}
		},
		

		//是否把游戏移出显示区域
		moveShowGame : function(flag){
			IdoMain.proxy.W2SActiveGame(flag);
			IdoMain.$oGameCont.css({top : (flag ? 45 : -1000), left : (flag ? 1 : -1000)});
		},
		
		//清除客户端参数
		clearCliParam : function(){
			this._sCliServer = "";
			this._sCliSite = "";
			this._sCliArea = "";
			this._sCliToken = "";
			//Ido.unloadConfirm.clear();
		},
		
		//退出游戏
		quitGame : function(){
			//删除标签
			$('#QuitGame').remove();

			this.showWeb();
			setTimeout(this._quitGameRun, 1000);
		},
		
		//退出游戏时先延时处理退出
		_quitGameRun : function(){
			
			IdoMain.$oGameUseCont.html("");
			IdoMain.$oGameUseCont.hide();

			IdoMain.$oGameCont.html("");
			//IdoMain.$oGameCont.hide();
			//IdoMain.$oGameCont.css("visibility", "hidden");
			IdoMain.client.moveShowGame(false);
			
			IdoMain.$oWebCont.show();
			//Ido.unloadConfirm.clear();

			IdoMain.client._bGameUseOpen = false;
		},
		
		//重新初始化游戏
		resetIntoGame : function(target){
			$.idoAlert("如果安装完毕点击这里仍然不能正常进入游戏，请按F5刷新当前网页", function(){
				IdoMain.client._quitGameRun();
				IdoMain.client.showGame(target);
			});
		},
		
		showGameUse : function(url){
			/*if(!$.browser.msie){
				IdoMain.$oGameCont.css("visibility", "hidden");
			}*/
			var s = "";
			s += '<div><iframe src="zgameuse.htm" border=0 width="768" height="22" frameborder=0 scrolling="no"></iframe></div>';
			s += '<div id="GUBody" class="cont" ><iframe src="' + url + '" border=0 width="768" height="426" frameborder=0 scrolling="no"></iframe></div>';		
			IdoMain.$oGameUseCont.html(s);
			IdoMain.$oGameUseCont.show();
			this.moveShowGame(false);
			this._bGameUseOpen = true;
		},

		hideGameUse : function(){
			/*if(this._bGameUseOpen){
				IdoMain.$oGameUseCont.show();
			}else{
				IdoMain.$oGameUseCont.hide();
			}*/
			/*if(!$.browser.msie){
				IdoMain.$oGameCont.css("visibility", "visible");
			}*/

			
			IdoMain.$oGameUseCont.html("");
			IdoMain.$oGameUseCont.hide();
			this.moveShowGame(true);
			this._bGameUseOpen = false;
		},

		//取窗口位置及大小
		getWinPos : function(isLogin){
			var p = {width : 990, height : $(window).height(), mid : 0, tab : 25, top : 45, bottom : 0};
			if(p.height < 591) p.height = 591;
			//debug
			//p.height = 591;
			//debug end
			p.height -= 23;
			if(isLogin == undefined) isLogin = this._sCliUid > 0;
			p.bottom = isLogin ? 29 : 14;
			p.mid = p.height - p.top - p.bottom;
			return p;
		},
		
		noticeUserOnline : function(userf){
			var user = new MUserData;
			user.parse(userf);
			if(!user.uid) return;
			var $o = $("#ChatBottomInfo");
			var $on;
			var $oh;
			this.showUserInfo("hh");
			try{
				this._noticeOnline.sec = 0;
				clearInterval(this._noticeOnline.timer);
				$on = $o.find(".infonick").empty();
				$oh = $o.find(".infohead").empty();
			}catch(e){}
			var color = IdoMain.chat.getSkin().word;
			
			$("<img/>").width(16).height(16).attr("src", user.photo).appendTo($oh);
			$on.html("&nbsp;<a href='javascript:void(0)' title='点击显示此人详细信息'></a> 上线了(<span class='infos' id='_notice_timer_sec_'>0</span>秒前)")
				.css("color", color)
				.find("a").html(user.nick)
				.css("color", color)
				.click(function(){
					IdoMain.proxy.W2FShowUserInfo(user.uid, user.nick, user.photo);
				});
			this._noticeOnline.timer = setInterval(function(){
				var n = IdoMain.client._noticeOnline;
				if(n.sec >= 60){
					clearInterval(n.timer);
					n.timer = 0;
					n.sec = 0;
					$("#ChatBottomInfo").children().empty();
				}else{
					n.sec ++;
					$("#_notice_timer_sec_").html(n.sec);
				}
			}, 1000);
		},
		
		showUserInfo : function(userf, postop, v){
			var $o = $("#ClientDivUserInfo");
			var $of = $("#ClientDivUserInfoFrame");
			var u = this._userInfo;
			clearTimeout(u.closeTimer);
			clearTimeout(u.openTimer);
			u.closeTimer = 0;
			u.openTimer = 0;
				
			if(!userf) {
				//CLOSE
				
				u.isOpen = false;
				if(!v) v = 500;
				u.closeTimer = setTimeout(function(){
					//到了要关闭时间，如果u.isOpen = false,刚关闭
					if(!IdoMain.client._userInfo.isOpen){
						$of.hide();
						$o.remove();
					}
				}, v);
				return;
			}else{
				$o.remove();
				//暂时不直接打开
				if(!userf.uid) return;
				if(!v){
					$of.hide();
					u.openTimer = setTimeout(function(){
						IdoMain.client.showUserInfo(userf, postop, true);
					}, 1000);
					return;
				}
				
			}
			u.isOpen = true;
			if($of.size() == 0){
				$of = $("<iframe id='ClientDivUserInfoFrame' frameBorder='0' src=''></iframe>").hide();
				$of.appendTo(document.body);
			}
			var user = new MUserData();
			user.parse(userf);
			var f = $("#FlashChat").offset();
			if(!user.photo){
				user.photo = "http://img1.ido360.com/img/b_" + (user.sex == 1? "sg" : "mm") + ".jpg";
			}
			user.photo = user.photo.replace(/s_/, "/b_");
			var s = "";
			s+="<div class='imgbox'><img src='"+user.photo+"' width='120' height='120' style='border:1px solid #ccc;margin:4px 0 4px 0;'/></div>";
			s+="<div class='infobox'>";
			s+="<div class='nick'><a href='javascript:void(0)' onclick='IdoMain.proxy.openUserZone("+user.uid+")' title='进入TA空间'>" + user.nick + "</a></div>";
			s+="<div class='info'>" + (user.sex == 1 ? "男" : "女") + " 上海区 " + (user.online>0?"<span class='online'>在线</span>":"<span class='offline'>离线</span>") + "</div>";
			s+="<div class='sign'>" + Ido.htmlEncode(user.sign) + "</div>";
			s+="</div>";
			s+="<div class='clear'>&nbsp;</div>";
			s+="<div class='btns_back' style='background-color:"+IdoMain.chat.getSkin().back+"'>";
			var arr = ["去TA空间", "去TA房间", "去TA身边", "去TA花园", "邀请TA来身边"];
			for(var i=0;i<arr.length;i++){
				s+="<a href='javascript:void(0)' i='"+i+"' class='btns' style='background-position:0 -"+(i*16)+"px' title='"+arr[i]+"'></a>";
			}
			s+="</div>";
			$o = $("<div id='ClientDivUserInfo'>" + s + "</div>");
			$(document.body).append($o);
			$o.css({left : f.left - 252 + 27, top : f.top + postop, "border" : "1px solid " + IdoMain.chat.getSkin().border});
			$of.css({left : f.left - 252 + 27, top : f.top + postop});
			//trace((f.left - 202) + "," + (f.top + postop));
			$of.height($o.height() + 2).show();
			$o.mousemove(function(){
				IdoMain.client._userInfo.isOpen = true;
			}).mouseover(function(){
				IdoMain.client._userInfo.isOpen = true;
			}).mouseout(function(){
				IdoMain.client.showUserInfo(null, 0, 200);
			});
			$o.find(".btns_back").find("a").click(function(){
				var i = $(this).attr("i");
				if(i == "0"){
					//去TA空间
					IdoMain.proxy.openUserZone(user.uid);
				}else if(i == "1"){
					//去TA房间
					IdoMain.proxy.SWVisitHome(user.uid, user.nick);
				}else if(i == "2"){
					//去TA身边
					IdoMain.proxy.SWVisitBuddy(user.uid, user.nick);
				}else if(i == "3"){
					//邀请来身边
					IdoMain.proxy.SWVisitGarden(user.uid, user.nick);
				}else if(i == "4"){
					//邀请来身边
					IdoMain.proxy.W2FInviteBuddy(user.uid, user.nick);
				}
			}).hover(function(){
				$(this).css("opacity", 0.7);
			}, function(){
				$(this).css("opacity", 1);
			});
		},

		//取LocalSession
		getLocalSession : function(){
			if(this._sLocalSession == ""){
				this._sLocalSession = Date.parse(new Date().toGMTString()) ;	
			}
			return this._sLocalSession;
		},

		//type = gameDyn, spaceDyn, web, game
		recvTabMsg : function(type, uid, msgType, msgData){
			trace("type = " + type + " uid = " + uid + " msgType = " + msgType + " msgData = " + msgData);
			if(type != "web" && type != "spaceDyn") return;	//暂时只处理个人消息中心的消息和动态
			if(type == "web"){
				IdoMain.client.msg.recv(msgType, msgData);
			}else if(type == "spaceDyn"){
				IdoMain.client.dyn.recv(msgType, msgData, uid);
			}
		},
		
		dyn : {
			recv : function(type, data, uid){
				$.idoModalFrame({
					title : "又有新鲜事啦！",
					initWidth: 470,
					showBottom: false,
					showMask : false,
					showOnLoad:false,
					content : {autoHeight : true, width: 470, height : 120, url : "/web/space/dyn.aspx", data : {type : "zoneDyn", pageFrom : "msg", uid : uid, cid : data}}
				}, "auto");
			}
		},
		
		msg : {
			_msgMap : new MMap(),	//消息队列
			_timer : 0,
			_msgIndex : 0,
			recv : function(type, data){
				this._msgMap.put(this._msgIndex++, {type : type, data : data});
				this.proNext(true);
			},
			
			proNext : function(isRecv){
				if(isRecv && this._timer > 0) return;

				if(this._msgMap.size() == 0){
					this._timer = 0;
					return;
				}
				var d = this._msgMap.getValue(0);
				this._msgMap.remove(this._msgMap.getKey(0));
				var pMsg = IdoMain.client.msg;
				this._timer = setTimeout(function(){
					var flag = false;
					//个人消息中心enum None, AddFriend, DoAddFriend, Msg},
					if(d.type == 1){
						//收到好友添加消息
						flag = pMsg.addFri(d.data);
					}else if(d.type == 2){
						//收到好友确认处理消息（通过/拒绝）
						flag = pMsg.doAddFri(d.data);
					}else if(d.type == 3){
						//收到新短消息
						try{
							flag = pMsg.sm(d.data);
						}catch(e){}
					}else if(d.type == 4){
						//收到评论或回复
						flag = pMsg.comment(d.data);
					}else if(d.type == 5){
						//收到礼物
						flag = pMsg.revGift(d.data);
					}else if(d.type == 6){
						//收到欣赏
						//$.idoAlert('收到欣赏' + d.data + '(UI未完成)');
					}else if(d.type == 7){
						flag = pMsg.findFri(d.data);
					}else if(d.type == 8){
						//收到消息，直接显示AlertMsg
						$.idoAlert(d.data, function(){
							IdoMain.client.msg.proNext(false);
						});
					}
					if(!flag){
						pMsg.proNext(false);
					}
				}, 1000);
			},
			
			revGift : function(data){
				var ds = data.split("|");
				if(ds.length != 3) return false;
				var id = parseInt(ds[0]);
				var uid = parseInt(ds[1]);
				var nick = ds[2];
				$.idoModalFrame({
					title : "收到礼物",
					buttonText : {ok : "去TA空间", cancel : "哈哈"},
					data : {id : id, uid : uid},
					indexId : "recvGift",
					initWidth:304,
					showMask:false,
					showOnLoad:true,
					okEvent: function(data, args, modal){
						Ido.openUserZone(data.uid);
						args.complete();
						IdoMain.client.msg.proNext(false);
					},
					cancelEvent : function(){
						IdoMain.client.msg.proNext(false);
					},
					contentCss : {"padding":"6px 10px 0 10px"},
					content : {width : 284, height : 240, url : "/web/space/win/recvgift.aspx?id=" + id + "&uid=" + uid + "&rnd=" + Math.random()}
				});
				return true;
			},
			
			addFri : function(data){
				var ds = data.split("|");
				if(ds.length != 3) return false;
				var uid = parseInt(ds[1]);
				var nick = ds[2];
				var reqid = parseInt(ds[0]);
				//$.idoAlert(nick + "想加您为好友" + reqid);
				$.idoModalFrame({
					title : nick + "想加您为好友",
					buttonText : {view : "查看", ok : "通过", reject : "拒绝"},
					data : {uid : uid},
					indexId : "addFriend1",
					initWidth:420,
					showMask:false,
					showOnLoad:true,
					okEvent: function(data, args, modal){
						IdoMain.client.msg.addFriPro("accept", reqid, uid, modal);
					},
					viewEvent : function(){
						Ido.openUserZone(uid);
					},
					rejectEvent : function(data, args, modal){
						IdoMain.client.msg.addFriPro("reject", reqid, uid, modal);
					},
					cancelEvent : function(){
						IdoMain.client.msg.proNext(false);
					},
					contentCss : {"padding":"20px 10px 0 10px"},
					content : {width : 400, height : 330, url : "/web/space/win/friendreq.aspx?type=act&uid=" + uid + "&reqid=" + reqid + "&rnd=" + Math.random()}
				});
				return true;
			},
			
			addFriPro : function(type, reqid, uid, modal){
				var $frm = modal.find("iframe").contents();
				if($frm.find("#tag_addfri").size() == 0) return false; //还没加载完

				$.idoProcess("doAddFriendPro", "正在处理..");
				var n = type == "accept" ? "通过" : "拒绝";
				$.ajax({
					url : "/web/space/ajax.aspx",
					type : "POST",
					data : {type : "doAddFriend", uid : uid, act : type, reqid : reqid},
					success : function(msg){
						var user = null;
						try{
							user = $.parseJSON(msg);
						}catch(e){
							user = null;
						}

						if(user != null){
							if(type == "accept"){
								$.idoAlert(n + "成功", function(){
									IdoMain.chat.openChatWin("user", user, true);
								});
							}
						}else{
							$.idoAlert(n + "失败");
						}
					},
					error : function(e){
						$.idoAlert(n + "失败");
					},
					
					complete : function(){
						$.hideIdoModal("doAddFriendPro");
						$.hideIdoModal("addFriend1");
						IdoMain.client.msg.proNext(false);
					}
				});
				return true;
			},

			doAddFri : function(data){
				var user = null;
				var act;
				try{
					var data = $.parseJSON(data);
					user = data.user;
					act = data.act;
				}catch(e){
					user = null;
				}
				if(user.uid == undefined || user.uid < 1) return false;
				
				//var ds = data.split("|");
				//if(ds.length != 3) return;
				//var act = ds[0];
				//var uid = parseInt(ds[1]);
				//var nick = ds[2];
				var n = (act == "accept") ? "通过" : "拒绝";
				$.idoModalFrame({
					title : user.nick + n + "了您的好友申请",
					buttonText : {ok : "确定"},
					data : {uid : user.uid},
					indexId : "addFriend2",
					initWidth:420,
					showMask:false,
					showOnLoad:true,
					okEvent: function(data, args){
						if(act == "accept"){
							IdoMain.chat.openChatWin("user", user, true);
						}
						IdoMain.client.msg.proNext(false);
						args.complete();
					},
					cancelEvent : function(){
						IdoMain.client.msg.proNext(false);
					},
					contentCss : {"padding":"20px 10px 0 10px"},
					content : {width : 400, height : 170, url : "/web/space/win/friendreq.aspx?type=result&uid=" + user.uid + "&act=" + act + "&rnd=" + Math.random()}
				});
				return true;
			},

			comment : function(data){
				var ds = data.split("|");
				if(ds.length != 6) return false;
				var uid = parseInt(ds[4]);
				var nick = ds[5];
				var cid = parseInt(ds[0]);
				var pid = parseInt(ds[1]);
				var classid = parseInt(ds[2]);
				var postid = parseInt(ds[3]);
				if(!(cid > 0)) return false;
				var key = Ido.key();
				var h = (pid > 0 ? 270 : 270 - 120);
				$.idoModalFrame({
					title : "您有新的评论" + (pid > 0 ? "回复" : "") + "消息 (来自：" + nick +")",
					buttonText : {ok : "回复", cancel : "以后再说"},
					data : {cid : cid, classid : classid, pid : pid, postid : postid},
					indexId : "recvComment" + key,
					initWidth:480,
					showMask:false,
					showOnLoad:true,
					okEvent: function(data, args, modal){
						IdoMain.client.msg._commentPro(data, args, modal);
					},
					cancelEvent : function(){
						IdoMain.client.msg.proNext(false);
					},
					contentCss : {"padding":"10px 20px 0px 20px"},
					content : {autoHeight : true, width : 440, height : h, url : "/web/space/win/comment.aspx?cid=" + cid + "&pid=" + pid + "&rnd=" + Math.random()}
				});

				return true;
			},
			
			_commentPro : function(data, args, modal){
				var key = data.key;
				var txt = modal.find("iframe").contents().find("#txtComment").val().trim();
				if (txt.length == 0 || txt == "请输入回复内容"){
					$.idoAlert("评论回复不能为空!");
					return false;
				}
				if (txt.length > 500 ){
					$.idoAlert("评论回复不能超过500个字符!");
					return false;
				}
				var pid = data.pid;
				if(pid < 1) pid = data.cid;
				$.idoProcess("addCommentPro" + key, "正在发表评论回复..");
				$.ajax({
					url : "/web/app/comment.aspx",
					type : "POST",
					data : {type : "add", classid : data.classid, postid : data.postid, content : txt, pid : pid},
					success : function(msg){
						if(msg == '1'){
							$.idoAlert("回复成功");
							args.complete();
							IdoMain.client.msg.proNext(false);
						}else if(msg == '-10000'){
							$.idoAlert('你没有登陆，不能回复');
						}else if(msg == '-101'){
							$.idoAlert('回复内容长度范围为1-500字');
						}else if(msg == '-2'){
							$.idoAlert('主题不存在或被删除');
						}else{
							$.idoAlert('回复失败');
						}
					},
					error : function(){
						$.idoAlert("回复失败，请稍候重试！");
					},
					
					complete : function(){
						$.hideIdoModal("addCommentPro" + key);
					}
				});
				return true;
			},

			sm : function(data1){
				var d = $.parseJSON(data1);
				if(!d.uid) return false;
				var s = "", title = "";
				var key = Ido.key();
				if(!d.first){
					title = d.nick + "回复了您的短消息";
				}else{
					title = "您有新短消息";
				}
				
				$.idoModalFrame({
					title : title,
					buttonText : {ok : "回复", cancel : "以后再说"},
					data : {mid : d.mid, uid : d.uid, key : key},
					indexId : "recvSM" + key,
					initWidth:480,
					showMask:false,
					okEvent: function(data, args, modal){
						IdoMain.client.msg._smPro(data, args, modal);
					},
					cancelEvent : function(){
						IdoMain.client.msg.proNext(false);
					},
					contentCss : {"padding":"10px 20px"},
					content : {autoHeight : true, width : 440, height : 270, url : "/web/space/win/sm.aspx?mid=" + d.mid + "&key=" + key + "&rnd=" + Math.random()}
				});
				return true;
			},

			_smPro : function(data, args, modal){
				var key = data.key;
				
				var txt = modal.find("iframe").contents().find("#txt_sm" + key).val().trim();
				if (txt.length == 0 ){
					$.idoAlert("短消息内容不能为空!");
					return false;
				}               
				if (txt.length > 300 ){
					$.idoAlert("短消息内容不能超过300个字符!");
					return false;
				}
				$.idoProcess("sendSmPro" + key, "正在发送短消息..");
				$.ajax({
					url : "/web/space/ajax.aspx",
					type : "POST",
					data : {type : "sendSm", mid : data.mid, uid : data.uid, content : txt},
					success : function(msg){
						if(msg == '1'){
							$.idoAlert("短消息已发送");
							$.hideIdoModal("recvSM" + key);
							IdoMain.client.msg.proNext(false);
						}else{
							$.idoAlert("发送失败，请稍候重试！");
						}
					},
					error : function(){
						$.idoAlert("发送失败，请稍候重试！");
					},
					
					complete : function(){
						$.hideIdoModal("sendSmPro" + key);
					}
				});
				return true;
			},
			
			findFri : function(data){
				var uid = parseInt(data);
				if(!(uid > 1)) return;

				var key = Ido.key();
				IdoMain.client.msg._findFriKey = key;

				$.idoModalFrame({
					title : "交友推荐",
					indexId : "recvFindFri" + key,
					initWidth:440,
					showBottom : false,
					showMask:false,
					showOnLoad:true,
					cancelEvent : function(){
						IdoMain.client.msg.proNext(false);
					},
					contentCss : {"padding":"10px 20px 0 20px"},
					content : {autoHeight : true, width : 400, height : 200, url : "/web/space/win/findfriend.aspx?uid=" + uid + "&rnd=" + Math.random()}
				});
				return true;
			},
			
			//供findfriend.aspx调用添加好友
			findFriAdd : function(uid){
				Ido.friend.add(uid);
				IdoMain.client.msg.proNext(false);
				$.hideIdoModal("recvFindFri" + IdoMain.client.msg._findFriKey);
			},

			findFriHome : function(uid){
				Ido.openUserZone(uid);
				IdoMain.client.msg.proNext(false);
				$.hideIdoModal("recvFindFri" + IdoMain.client.msg._findFriKey);
			},

			recvGiftHome : function(uid){
				Ido.openUserZone(uid);
				IdoMain.client.msg.proNext(false);
				$.hideIdoModal("recvGift");
			}
		}
	},
	
	/**
	 * 选项卡部分 ^_^TAB^_^
	 */
	tab : {
		 /**
		 * 选项卡参数
		 */
		_MAX_TAB_NUM : 20,		//最大页数
		_nCurId : 0,			//当前页
		_nTabNum : 0,			//当前页数
		_nNewId : 1,			//唯一值
		_lTabs : {},			//页面属性列表
		_$oTabHead : null,		//头部整体列表
		_$oTabBody : null,		//内容整体列表
		_$oTabHeadCont : null,	//头部标签容器
		_$oArrowLeft : null,	//左arrow
		_$oArrowRight : null,	//右arrow
		
		//初始化
		init : function(){
			this._nTabNum = 0;
			this._lTabs = {};
			this._nCurId = 0;
			IdoMain.$oWebCont.html(IdoMain._getWebContHtml());
			this._$oTabHead = $("#TabHead");
			this._$oTabBody = $("#TabBody");
			this._$oTabHeadCont = $("#TabHeadCont");
			this._$oArrowLeft = this._$oTabHead.find(".leftarr");
			this._$oArrowRight = this._$oTabHead.find(".rightarr");
			this._$oArrowLeft.click(function(){
				IdoMain.tab._gotoTab('pre');
			});
			this._$oArrowRight.click(function(){
				IdoMain.tab._gotoTab('next');
			});
			this._$oTabHead.find(".zone [user]").click(function(){
				Ido.openUserZone($(this).attr("user"));
			}).attr("href", "javascript:void(0)");
		},
		
		//如果当前有窗口存在就覆盖，没有新建
		open : function(url){
			this._openTab(url, "");
		},
		
		//总是打开新的选项窗口
		openNew : function(url){
			this._openTab(url, "new");
		},
		
		//在当前窗口中打开选项
		openCurrent : function(url){
			this._openTab(url, "current");
		},
		
		//打开新的窗口,由openTab调用
		_openNewTab : function(url){
			
			var curId = this._getNewId();
			this._nTabNum ++;
			
			
			//选项属性[index：索引号1-20，id:唯一标识，head：选项部分的jquery对象，body：内容部分的jquery对象，title：标题部分jquery对象]
			var obj = {index : this._nTabNum, id : curId, head : null, body : null, title : null, del : null};
			this._lTabs[curId] = obj;
			
			obj.head = $("<div/>");
			obj.body = $("<iframe frameborder='0' scrolling='yes'/>");
			obj.title = $("<div/>");
			obj.del = $("<div/>");
			
			//tab left 
			$("<div/>").addClass("bg l1")
				.appendTo(obj.head);

			//title
			obj.title.attr("id", "_tab_title_" + curId)
				.addClass("bg t")
				.html(IdoMain._getLoadingHtml("head"))
				.css("width", this._getWidth() - 26)
				.appendTo(obj.head)
				.click(function(){
					//选中一个
					IdoMain.tab._change(curId);
				});
			
			//tab right1
			$("<div/>").addClass("bg r1")
				.appendTo(obj.head);
			//del
			$("<div/>").addClass("bg d")
				.hover(function(){
					$(this).removeClass()
						.addClass("bg dover");
				}, function(){
					$(this).removeClass()
						.addClass("bg d");
				})
				.click(function(){
					//删除一个
					IdoMain.tab._remove(curId);
				})
				.appendTo(obj.head);

			//tab right3
			$("<div/>").addClass("bg r3")
				.appendTo(obj.head);

			//head
			obj.head.attr("id", "_tab_head_" + curId)
				.addClass("open")
				.appendTo(this._$oTabHeadCont);
			
			//body
			obj.body.attr({id : "_tab_body_" + curId, name : "_tab_body_" + curId})
				.addClass("frame")
				.css({"display" : "block", "overflow-x" : "hidden"})
				.appendTo(this._$oTabBody);

			obj.body.load(function(){
				try{
					var title = obj.body.contents()[0].title;
					obj.title.html(title ? title : "无标题");
					obj.title.attr("title", title);
					//var turl = obj.body.contents()[0].location.href;
					//IdoMain.tab._suitWebFrame(turl, obj.body, false);
				}catch(e){
					//alert(e);
				}
			});
			
			this._showOne(curId, url);
			obj.body.attr("src", url);
			this._setWidth();
		},

		_change : function(tabId){
			//若点中当前项则没有操作
			if(this._lTabs[tabId] && tabId != this._nCurId){
				this._showOne(tabId);
			}
		}, 
		
		_gotoTab : function(type){
			var obj = null;
			if(type == 'pre'){
				obj = this._getPreObj();
			}else if(type == 'next'){
				obj = this._getNextObj();
			}
			if(obj){
				this._showOne(obj.id);
			}

		},

		//删除页签并把相应的iframe删除，同时要把其他iframe显示出来
		_remove : function(tabId){
			//最后一个不能删除
			if(this._nTabNum <= 1) return;
			var obj = this._lTabs[tabId];
			if(!obj) return;
			
			//if dynamic then gotoTab web
			if(this._isDynUrl(obj.body.attr("src"))){
				IdoMain.client.gotoTab("web");
			}

			var index = obj.index;
			obj.head.remove();
			obj.body.remove();
			delete this._lTabs[tabId];
			this._nTabNum --;

			var curId = 0;
			if(index >= this._nTabNum){
				curId = this._getLastObj().id;
			}else{
				//比index大的index递减
				for(var i in this._lTabs){
					obj = this._lTabs[i];
					if(obj.index > index){
						obj.index --;
					}
				}
				curId = tabId == this._nCurId ? this._getLastObj().id : tabId;
			}
			this._showOne(curId);
			this._setWidth();
		},
		//删除动态的层
		_removeDyn : function(){
			
			var obj = null;
			for(var i in this._lTabs){
				obj = this._lTabs[i];
				if(this._isDynUrl(obj.body.attr("src"))){
					this._remove(obj.id);
				}
			}
		},

		//取最后一个选项
		_getLastObj : function(){
			var max = 0;
			var objr = null;
			var obj = null;
			for(var i in this._lTabs){
				obj = this._lTabs[i];
				if(max < obj.index){
					max = obj.index;
					objr = obj;
				}
			}
			return objr;
		},

		//取第一个选项
		_getFirstObj : function(){
			var min = 10000;
			var objr = null;
			var obj = null;
			for(var i in this._lTabs){
				obj = this._lTabs[i];
				if(min > obj.index){
					min = obj.index;
					objr = obj;
				}
			}
			return objr;
		},
		
		_getPreObj : function(){
			if(this._nCurId < 1) return null;
			var objr = null;
			var obj = null;
			var index = this._lTabs[this._nCurId].index;
			if(index == 1) return null;
			for(var i in this._lTabs){
				obj = this._lTabs[i];
				if(obj.index == index - 1){
					objr = obj;
					break;
				}
			}
			return objr;
		},

		_getNextObj : function(){
			if(this._nCurId < 1) return null;
			var objr = null;
			var obj = null;
			var index = this._lTabs[this._nCurId].index;
			if(index == this._nTabNum) return null;
			for(var i in this._lTabs){
				obj = this._lTabs[i];
				if(obj.index == index + 1){
					objr = obj;
					break;
				}
			}
			return objr;
		},
		
		//只显示一个网页
		_showOne : function(tabId, url1){
			var obj = null;
			var obj1 = null;
			var url = null;
			obj = this._lTabs[tabId];
			//若指定显示当前页则忽略
			if(!obj || tabId == this._nCurId) return;
			this._nCurId = tabId;
			for(var i in this._lTabs){
				obj1 = this._lTabs[i];
				if(i == tabId){
					obj1.head.removeClass().addClass("open");
					//obj.body.show();
					obj1.body.css("display", "block");
					url = obj1.body.attr("src");
				}else{
					obj1.head.removeClass().addClass("close");
					//obj.body.hide();
					obj1.body.css("display", "none");
				}
				
			}

			if(url != null){
				if(this._isDynUrl(url)){
					IdoMain.client.gotoTab("dyn");
				}else{
					IdoMain.client.gotoTab("web");
				}
			}
			this._resetArrow();
			/*var isInit = url1 != undefined && url1 != null;
			try{
				if(!isInit)
					url1 = obj.body.contents()[0].location.href;
				this._suitWebFrame(url1, obj.body, isInit);
			}catch(e){
				this._suitWebFrame("null", obj.body, isInit);
			}*/
		},
		
		//设置选项卡宽度
		_setWidth : function(){
			//if(_lastSetWidthNum == nPageNum) return;
			//_lastSetWidthNum = nPageNum;
			var w = this._getWidth();
			for(var i in this._lTabs){
				this._lTabs[i].title.width(w - 26);
			}
		},
		//取选项卡宽度
		_getWidth : function(){
			var w = 106;
			if(this._nTabNum > 5){
				w = Math.floor((106*5) / (this._nTabNum));
			}
			return w;
		},

		//是否为动态网址
		_isDynUrl : function(url){
			return /iuser\/user_spacedynamic.aspx/i.test(url) || /iuser\/user_gamedynamic.aspx/i.test(url);
		},
		
		_getNewId : function(){
			return this._nNewId++;
		},
		
		//重置快捷arrow
		_resetArrow : function(){
			var obj = this._lTabs[this._nCurId];
			if(!obj) return;
			this._$oArrowLeft.removeClass().addClass("bg leftarr" + (obj.index > 1 ? "" : "d"));
			this._$oArrowRight.removeClass().addClass("bg rightarr" + (obj.index < this._nTabNum ? "" : "d"));
		},

		changeSkin : function(skinid){
			var w;
			for(var i in this._lTabs){
				try{
					w = this._lTabs[i].body[0].contentWindow;
					if(w && w._idoChangeSkin){
						w._idoChangeSkin(skinid);
					}
				}catch(e){}
			}
		},

		_openTab : function(url, openType){
			if(url == undefined || url == null || url == ""){
				url = "/web/index.aspx";
			}
			//若为相对路径，补成根路径
			if(!/^\//.test(url) &&  !/^http:\/\//.test(url)){
				url = "/web/" + url;
			}
			//默认为onlyone类型
			if(openType != "current" && openType != "new"){
				openType = "onlyone";
			}
			//是否要打开新的窗口
			var isAddNew = true;
			var curTab = null;
			if(openType == "current"){
				isAddNew = false;
			}else if(openType == "onlyone"){
				var turl = null;
				var obj;
				
				for(var i in this._lTabs){
					obj = this._lTabs[i];
					try{
						turl = obj.body.contents()[0].location.href;
					}catch(e){
						turl = obj.body.attr("src");
					}
					//search.aspx特殊
					if(/search.aspx/i.test(turl) && /search.aspx/i.test(url)){
						curTab = obj;
						break;
					}
					var turl1 = url.replace(/(rnd=[^&]+[&]?)/i, "")
					if(new RegExp(turl1.replace(/\?/g, "\\?"), "i").test(turl)){
						curTab = obj;
						break;
					}
				}
				isAddNew = curTab == null;
			}
			
			if(isAddNew){
				if(this._nTabNum >= this._MAX_TAB_NUM){
					$.idoAlert('最多可同时打开' + this._MAX_TAB_NUM + '个页面，请关闭后重新打开！');
					return;
				}
				this._openNewTab(url);
			}else{
				if(curTab == null) curTab = this._lTabs[this._curId];
					
				this._showOne(curTab.id);
				//obj = this._lTabs
				var obj = curTab;
				obj.title.html(IdoMain._getLoadingHtml("head"));
				obj.title.attr("title", "");
				//obj.body.contents().html(_getLoadingStr("body"));

				var turl = url.toLowerCase();
				if(!turl.startWith("http") && !turl.startWith("/")){
					url = '/web/' + url;
				}
				obj.body[0].contentWindow.location.replace(url);
				return;
			}
		}
	},


	/**
	 * web 对 flash接口
	 */
	proxy : {

		_SP : String.fromCharCode(3),
		//显示个人空间的封面
		openUserZone : function(uid){
			uid = parseInt(uid);
			if(isNaN(uid)){
				uid = 0;
			}
			if(uid <= 0 || uid == IdoMain.client._sCliUid){
				IdoMain.client.showWeb("space/home.aspx?rnd=" + Math.random());
			}else{
				IdoMain.client.showWeb("space/cover.aspx?uid=" + uid + "&rnd=" + Math.random());
			}
		},
		
		openGroupZone : function(gid){
			if(parseInt(gid) > 0){
				IdoMain.client.showWeb("app/group/group.aspx?g=" + gid + "&rnd=" + Math.random());
			}
		},

		//打开搜索页面
		openSearch : function(region, sex, age, prov, city, online, photo){
			IdoMain.client.showWeb("search.aspx?type=simple&region=" + region + "&sex=" + sex + "&age=" + age + "&prov=" + prov + "&city=" + city + "&online=" + online + "&photo=" + photo + "&rnd=" + Math.random());
		},

		//打开高级搜索页面
		openAdvSearch : function(){
			IdoMain.client.showWeb("searchadv.aspx");
		},

		//打开精确搜索页面
		openAccuSearch : function(name, opt){
			IdoMain.client.showWeb("search.aspx?type=accu&name=" + encodeURI(name) + "&opt=" + opt + "&rnd=" + Math.random());
		},

		openCityGirl : function(){
			IdoMain.client.showWeb("app/ctg/ctg.aspx?rnd=" + Math.random());
		},

		openTruth : function(){
			IdoMain.client.showWeb("app/truth/friend.aspx?rnd=" + Math.random());
		},

		openRepaste : function(){
			IdoMain.client.showWeb("app/repaste/friend.aspx?rnd=" + Math.random());
		},

		openPoll : function(){
			IdoMain.client.showWeb("app/poll/friend.aspx?rnd=" + Math.random());
		},
		
		openMusic : function(){
			IdoMain.client.showWeb("app/music/music.aspx?rnd=" + Math.random());
		},

		openShow : function(){
			IdoMain.client.showWeb("app/rcm/rcmlist.aspx?rnd=" + Math.random());
		},

		openFlashGet : function(){
			IdoMain.client.showWeb("flashset.aspx");
		},

		openUserStatus : function(uid, type){
			//type == 'dynName', 'dynGame'
			/*if(type == 'dynGame'){
				IdoMain.client.showWeb("iuser/user_gamedynamic.aspx?uid=" + uid + "&rnd=" + Math.random());
			}else{
				IdoMain.client.showWeb("iuser/user_spacedynamic.aspx?uid=" + uid + "&rnd=" + Math.random());
			}*/
			IdoMain.proxy.openUserZone(uid);

		},

		openStranger : function(){
			IdoMain.chat.openStrangerWin();
		},
		
		W2SVisit : function(target){
			try{
				this.getFlashProxy().W2SVisit(target);
			}catch(e){}
		},

		//发送聊天信息
		W2FSendMsg : function(type, uid, content){
			try{
				this.getFlashProxy().W2FSendMsg(type, uid, content);
			}catch(e){}
		},

		W2SActiveGame : function(isActive){
			try{
				this.getFlashProxy().W2SActiveGame(isActive);
			}catch(e){}
		},
		
		W2SActiveWindow : function(){
			try{
				this.getFlashProxy().W2SActiveWindow();
			}catch(e){}
		},

		W2FShowUserInfo : function(uid, nick, photo){
			try{
				this.getFlashProxy().W2FShowUserInfo(uid, nick, photo);
			}catch(e){}
		},

		W2SScroll : function(delta){
			try{
				this.getFlashProxy().W2SScroll(delta);
			}catch(e){}
		},

		W2FSetUserOnline : function(uid, onlineStatus){
			try{
				this.getFlashProxy().W2FSetUserOnline(uid, onlineStatus);
			}catch(e){}
		},

		W2FGetLeaveMsg : function(wordType, uid){
			try{
				this.getFlashProxy().W2FGetLeaveMsg(wordType, uid);
			}catch(e){}
		},

		W2FInviteBuddy : function(uid, nick){
			try{
				this.getFlashProxy().W2FInviteBuddy(uid, nick);
			}catch(e){}
		},
		
		//type = 'join', 'quit', 'chat'
		W2FStranger : function(type, content){
			if(content == undefined) content = "";
			try{
				this.getFlashProxy().W2FStranger(type, content);
			}catch(e){}
		},

		SWVisitHome : function(uid, nick){
			if(uid < 1){
				uid = IdoMain.client._sCliUid;
			}
			IdoMain.client.showGame("1" + this._SP + uid + this._SP + nick + this._SP + this._SP);
		},

		SWVisitGarden : function(uid, nick){
			if(uid < 1){
				uid = IdoMain.client._sCliUid;
			}
			IdoMain.client.showGame("2"+ this._SP + uid + this._SP + nick + this._SP + this._SP);
		},

		SWVisitBuddy : function(uid, nick){
			if(uid < 1){
				uid = IdoMain.client._sCliUid;
			}
			IdoMain.client.showGame("3" + this._SP + uid + this._SP + nick + this._SP + "1" + this._SP + uid);
		},
		
		SWVisitRoom : function(roomid){
			IdoMain.client.showGame("4" + this._SP + roomid +  this._SP + this._SP + this._SP);
		},
		
		SWVisitGroup : function(gid){
			IdoMain.client.showGame("5" + this._SP + gid + this._SP + this._SP + this._SP);
		},
		
		SWVisitPet : function(uid, nick){
			IdoMain.client.showGame("1" + this._SP + uid + this._SP + nick + this._SP + "2" + this._SP + uid);
		},

		getFlashProxy : function(){
			return document.getElementById('FlashChat');
		}
	},
	/**
	 * 工具部分 ^_^tool^_^
	 */
	
	tool : {
		checkShockwave : function(){
			var ver = 0;
			try{
				ver = parseFloat(this._getSWVersion());
			}catch(e){ver = 0;}
			IdoMain._bHasSW = (ver >= IdoMain._SW_REQUIRE_VER);
			return IdoMain._bHasSW;
		},

		_getSWVersion : function(){
			
			var std = "application/x-director";
			var sts = "Shockwave for Director";
			if (navigator.mimeTypes && navigator.mimeTypes[std] && navigator.mimeTypes[std].enabledPlugin) {
				if (navigator.plugins && navigator.plugins[sts] && (tVersionIndex = navigator.plugins[sts].description.indexOf(".")) != - 1) {	
					return navigator.plugins[sts].description.substring(tVersionIndex-2, tVersionIndex+2);
				}
			} else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 && (navigator.userAgent.indexOf("Windows 95")>=0 || navigator.userAgent.indexOf("Windows 98")>=0 || navigator.userAgent.indexOf("Windows NT")>=0 )) {
				try{
					var o = new ActiveXObject("SWCtl.SWCtl");
					if(o){
						var ver = o.ShockwaveVersion("");
						var index1 = ver.indexOf(".");
						if(index1 > 0){
							var index2 = ver.substring(index1 + 1).indexOf(".");
							if(index2 > 0){
								return ver.substring(0, index1 + index2 + 1);
							}
						}
						o = null;
					}
				}catch(e){
					return "0.0";
				}
			}
			return "0.0";
		}
	},
	
	other : {
		
	},


	cache : {
		_obj : {},
		_timer : 0,

		_clear : function(){
			var count = 0;
			var t = parseInt(new Date().getTime() / 1000);
			for(var i in this._obj){
				if(!this._obj[i].time) continue;
				if(this._obj[i].time <= t){
					delete this._obj[i];
				}else{
					count ++;
				}
			}
			if(count < 1){
				window.clearInterval(this._timer);
				this._timer = 0;
			}
		},
		
		set : function(name, value, time, time_type){
			if(this._timer < 1){
				this._timer = window.setInterval(function(){
					IdoMain.cache._clear();
				}, 60000);
			}
			if(!time) time = null;
			var o = {value : value};
			if(time > 0){
				var curTime = parseInt(new Date().getTime() / 1000);
				if(time_type == 'day'){
					curTime += time * 86400;
				}else if(time_type == 'hour'){
					curTime += time * 3600;
				}else if(time_type == 'minute'){
					curTime += time * 60;
				}else{
					curTime += time;
				}
				o.time = curTime;
			}
			this._obj[name] = o;
		},

		get : function(name){
			var o = this._obj[name];
			if(!o) return null;
			if(o.time && o.time <= parseInt(new Date().getTime() / 1000)){
				delete this._obj[name];
				return null;
			}
			return o.value;
		},
		
		exist : function(name, time, time_type){
			var v = this.get(name);
			if(!v){
				this.set(name, true, time, time_type);
				return false;
			}else{
				return true;
			}
		}
	},
	/**
	 * 视图部分 ^_^VIEW^_^
	 */
	
	//主框未登陆界面
	_setMainContHtml : function(){
		var s= "";
		s+="<div class='m_main'>";
		s+="<div class='top'></div>";
		s+="<div class='middle'>";
		s+="	<div class='mleft'>";
		//s+="		<div class='m1'>&nbsp;</div>";
		s+="	</div>";
		s+="	<div class='mright'>";
		s+="	<div class='tb1'></div>";
		s+="	<div class='ido2010'><a itab='reg_1.aspx' title='注册'><img src='http://img1.ido360.com/img/main/ido2010.jpg' width='220' height='124'/></a></div>";
		s+="	<div class='box'>";
		s+="		<div class='clear'>&nbsp;</div>";
		s+="		<div class='login'>";
		s+="			<form id='frmLogin' name='frmLogin'>";
		s+="			<div class='alert' id='loginalert'></div>";
		s+="			<div class='w w_1'></div><div class='w w_2'></div>";
		s+="			<div class='txt_cont txtname'><input type='text' class='txt' id='txtUserName'/></div><div class='txt_cont txtpass '><input type='password' class='txt' id='txtPassWord'></div>";
		//s+="			<div class='txt_cont txtname'><input type='text' class='txt' id='txtUserName'/></div><div class='txt_cont txtpass '><input type='password' class='txt' id='txtPassWord'></div><div class='txt_cont txtpass' style='display:none'><input type='text' class='txt txtempty' id='txtPassInfo' value='输入您的密码'/></div>";

		s+="			<div class='rem'><input id='chkRemember' type='checkbox' name='chkRemember' />&nbsp;<label for='chkRemember' class='w'>&nbsp;</label></div>";
		s+="			<div class='login1'><input type='image' src='http://img1.ido360.com/img/main/login.gif' width='164' height='35'/></div>";

		s+="		<div class='acc'>";
		s+="			<img src='http://img1.ido360.com/img/main/arrow.gif'/>&nbsp;<a itab='space/getpass.aspx'>忘记密码？</a>&nbsp;&nbsp;";
		s+="			<img src='http://img1.ido360.com/img/main/arrow.gif'/>&nbsp;<a itab='reg_1.aspx'>注册新帐号</a>";
		s+="		</div>";
		
		s+="			</form>";
		s+="		</div>";
		
		s+="	</div>";

		s+="	</div>";
		s+= "	<div class='clear'>&nbsp;</div>";
		s+="</div>";
		s+="<div class='bottom'></div>";
		s+="</div>";
		this.$oMainCont.html(s);
		this.$oMainCont.find("a[itab]").click(function(){
			var t = $(this);
			Ido.openUrl(t.attr("itab"));
		}).attr("href", "javascript:void(0)");


		var $txtName = $('#txtUserName');
		$txtName.focus(function(){
			if(this.value == '邮箱/昵称/爱度号'){
				this.value = '';
				$(this).removeClass("txtempty");
			}
		}).blur(function(){
			if(this.value == ''){
				this.value = '邮箱/昵称/爱度号';
				$(this).addClass("txtempty");
			}
		});
		
		if(this.client.sLastLoginName){
			$txtName.val(this.client.sLastLoginName);
		}else{
			$txtName.blur();
		}

		/*$('#txtPassInfo').focus(function(){
			var $o = $('#txtPassWord');
			$(this).parent().hide();
			$o.parent().show();
			window.setTimeout(function(){
				$o.focus();
			}, 10);
			
		});*/

		/*$('#txtPassWord').blur(function(){
			if(this.value == ''){
				$(this).parent().hide();
				$('#txtPassInfo').parent().show();
			}
		}).blur();*/

		$('#txtUserName, #txtPassInfo, #txtPassWord, #chkRemember').focus(function(){
			IdoMain._loginAlert("");
		});

		var $frm = $('#frmLogin');
		$frm.bind("submit", function(){
			//正大登陆中，不重复登陆
			if(IdoMain._isLogining) return false;
			//只检测windows,老帐号排除（新老界限：2010-6-15前的帐号为老帐号，这里以玩家“忘不了”为界）
		    if (IdoMain.client._sCliUid >= 19114 && !IdoMain.tool.checkShockwave() && navigator.platform.toLowerCase() == "win32"){
		        $.idoAlert("<div>您还没有安装爱度客户端，<a href='/web/client/client.aspx' target='_blank'>请点击这里下载!</a></div>");
		        return false;
		        }		    
			var $user = $('#txtUserName');
			var $pass = $('#txtPassWord');
			var $rem = $("#chkRemember");
			if($user == null || $pass == null || $rem == null) return;
			if ($user.val() == null || $user.val() =='' || $user.val() == '邮箱/昵称/爱度号'){
				IdoMain._loginAlert("帐号不能为空！");
				return false;
			}
			if($pass.val() == null || $pass.val() == ''){ 
				IdoMain._loginAlert("密码不能为空！");
				return false;
			}
			var ps = $pass.val();
			if(!/^[A-Z]{32}$/.test(ps)){
				hexcase = 1;
				ps = hex_md5(hex_md5(ps));
			}
			if($rem[0].checked){
				if(!confirm("你选择了记住登陆状态\n登陆状态将保存20天\n你确定要记住密码登陆状态吗？")){
					$rem[0].checked = false;
					return false;
				}
			}
			var loginUrl = IdoMain.client.sLoginUrl;
			if(!loginUrl) loginUrl = "";
			var $frm = $(this);
			try{
				//$.idoProcess("login", "正在登陆中..");
				IdoMain._loginAlert("<img src='http://img1.ido360.com/img/loading1.gif' align='absmiddle'/>&nbsp;<span style='color:#1355B7;'>登陆中，请稍候..</span>", true);
				//return false;
				$.ajax({
					url : "/web/login.aspx",
					type : "POST",
					data : {type : "mlogin", txtUserName : $user.val(), txtPassWord : ps, chkRemember : ($rem[0].checked ? 1 : 0), url : loginUrl},
					success : function(msg){
						try{
							var d = $.parseJSON(msg);
							var msg = d.ret;
							var url = d.url;
							if(msg == '1'){
								if(url != ""){
									//IdoMain._loginAlert("注册过程未完成，无法登陆");
									//$.idoAlert("注册过程未完成，无法登陆<br/>请在左边页面完成注册过程后再重试！");
									window.location.replace("/web/ido.aspx?url=" + url);
									//Ido.openUrl(url);
								}else{
									window.location.reload();
								}
							}else if(msg=='-1'){
								IdoMain._loginAlert("帐号或密码错误");
							}else if(msg.length >= 2 && msg.charAt(0) == 'r'){
								IdoMain.client.showWeb("reg_"+msg.charAt(1)+".aspx?r="+Math.random());
							}else{
								IdoMain._loginAlert("登陆失败");
							}
						}catch(e1){
							IdoMain._loginAlert("登陆失败");
						}
					},
					error : function(e){
						IdoMain._loginAlert("登陆失败" + e.responseText);
					}
				});
			}catch(e){IdoMain._loginAlert("登陆失败");}
			 return false;
		});

	}, 
	_isLogining : false,
	_loginAlert : function(msg, isLock){
		var $t1 = $('#txtUserName, #chkRemember, #txtPassWord');
		this._isLogining = isLock;
		if(isLock) $t1.attr("disabled", "disabled")
		else $t1.removeAttr("disabled");
		$("#loginalert").hide().html(msg).show();
		//if(!isLock) $t1.focus();
	},

	_getLoadingHtml : function(type){
		if(type == "body"){
			return "<div style=\"margin-top:160px;text-align:center;font-size:14px;color:#333333;font-weight:bold;\"><img src='http://img1.ido360.com/img/loading1.gif' align='absmiddle'/>&nbsp;正在加载页面，请稍候..</div>";
		}else{
			return "<span class=\"loading\">loading..</span>";
		}
	}, 
	
	_getWebContHtml : function(){
		var s = "";
		s += "<div id='TabHead' unselectable='on'>";
		s += "	<div class='bg leftarr'></div><div class='bg rightarr'></div><div class='bg leftspace'></div>";
		s += "	<div id='TabHeadCont'></div>";
		s += "	<div class='bg rightspace'></div>";
		if(this.client._sCliIsLogin){

			s += "	<div class='bg zoneimg'><a user='" + this.client._sCliUid + "'><img src='" + this.client._sCliPicUrl + "' width='16' height='16'/></a></div>";
			s += "<div class='zone'>&nbsp;<a user='" + this.client._sCliUid + "'>我的空间</a></div>";
			s += "	<div class='bg login'><a href='javascript:void(0)' onclick='IdoMain.client.logout()'>登出</a></div>";
		}
		s += "</div>";
		s += "<div id='TabBody'></div>";
		return s;
	},

	_setGameNoSWHtml : function(){
		var s = "<div style='width:768px;height:300px;padding-top:132px;background-color:#000000;text-align:center;color:#FFFFFF;font-size:12px;text-align:center;line-height:30px;'><span style='color:#FF3300'>检测到你尚未安装游戏客户端，暂不能进入游戏</span><br/><a href='http://www.ido360.com/web/client/client.aspx' target='_blank'><img src='http://img1.ido360.com/img/downclient1.png' height='67' width='166'/></a><br/>如果已经安装完毕，请<a href='javascript:void(0)' onclick='IdoMain.client.resetIntoGame(\""+this.client._sCliGameTarget+"\");return false;'>点击这里进入游戏</a><!--请刷新(F5)当前页面即可进入游戏--></div>";
		this.$oGameUseCont.html(s);
	},

	//加载shockwave
	_setGameContHtml : function(){
		//加载游戏shockwave  游戏shockwave是分区的，所以参数sw1--sw5都要根据外部参数设定
		var s ="";
		//this.chat.lChatVer.game = "http://test/sw3d/ido3d.dcr";
		s +="<OBJECT classid='clsid:233C1507-6A77-46A4-9443-F871F945D258' codebase='http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=11,0,0,0' id='ido3d' WIDTH='768' HEIGHT='100%' VIEWASTEXT>";
		s +="<param name='src' value='" + this.chat.lChatVer.game + "'>";
		s +="<PARAM NAME='swStretchStyle' VALUE='stage'>";
		s +='<param name="swRemote" value="swSaveEnabled=\'true\' swVolume=\'true\' swRestart=\'true\' swPausePlay=\'true\' swFastForward=\'true\' swContextMenu=\'false\' ">';
		s +="<param name=PlayerVersion value=11>";
		s +="<param name='sw1' value='"+ this.client._sCliServer +"'>";
		s +="<param name='sw2' value='"+ this.client._sCliSite +"'>";
		s +="<param name='sw3' value='"+ this.client._sCliArea +"'>";
		s +="<param name='sw4' value='"+ this.client._sCliToken +"'>";
		s +="<param name='sw5' value='"+ this.client._sCliGameTarget +"'>";
		s +="<param name='sw6' value='"+ this.client.getLocalSession() +"'>";
		s +="<param name='sw7' value='"+ this.chat.lChatVer.gameVer +"'>";
		s +="<PARAM NAME='bgColor' VALUE='#ECE9D8'>";
		s +='<EMBED SRC="' + this.chat.lChatVer.game + '" bgColor=#ECE9D8 id="ido3d_f" WIDTH=768 HEIGHT=100% swRemote="swSaveEnabled=\'true\' swVolume=\'true\' swRestart=\'true\' swPausePlay=\'true\' swFastForward=\'true\' swContextMenu=\'false\'" sw1="'+ this.client._sCliServer +'" sw2="'+ this.client._sCliSite +'" sw3="'+ this.client._sCliArea +'" sw4="'+ this.client._sCliToken +'" sw5="'+ this.client._sCliGameTarget +'" sw6="'+ this.client.getLocalSession() +'" sw7="'+this.chat.lChatVer.gameVer+'" swStretchStyle=stage TYPE="application/x-director" PlayerVersion=11 PLUGINSPAGE="http://www.macromedia.com/shockwave/download/"></EMBED>';
		s +="</OBJECT>";
		document.getElementById('GameCont').innerHTML = s;
		

		$("<div style='position:absolute;' title='退出游戏' id='QuitGame'></div>")
			.css({width : 59, height : 19, top : this.chat.$oTask.position().top + 1, left : 710, cursor : "pointer"})
			.css("background", "url(http://img1.ido360.com/img/main/quitGame.gif) no-repeat")
			.appendTo(this.$oMainCont)
			.hover(function(){
				$(this).css("background-position", "0 -19px");
			}, function(){
				$(this).css("background-position", "0 0");
			}).click(function(){
				if(confirm("是否要退出游戏并返回网站?")){
					IdoMain.client.quitGame();
				}
			});
		
		$(window).resize();
		//this.$oGameCont.html(s);
	},
	
	_setChatContHtml : function(){
		var s = "";
		//firefox >= 3.6 时会有问题
		var sFFStyle = $.browser.mozilla && $.browser.version >= '1.9.2' ? "hidden" : "auto";
		s+="<div class='c_main' id='ChatCont'>";
		s+="	<div class='top' id='ChatTop'>";
		s+="		<div class='music'><div id='FlashMusic'>加载音乐中..</div></div>";
		//s+="		<div class='msg'></div>";
		//s+="		<div class='tab'><div class='dyn'><div class='b1 tab1'></div><div class='b2 tab2' id='ttt'>(0)</div></div><div class='game'><div class='b1 tab1'></div></div><div class='web'><div class='b1 tab1'></div></div></div>";
		s+="		<div class='tab'><div class='game'></div><div class='web'></div></div>";
		s+="		<div class='search'><div class='btn'></div><div class='i'><form><input type='text'/></form></div></div>";
		s+="	</div>";
		s+="	<div class='mmiddle'>";
		s+="		<div class='mleft'></div>";
		s+="		<div class='mright' id='ChatFlashCont' style='overflow:"+sFFStyle+"'><div id='FlashChat'>";
		s+="			<div style='padding:20px'><p style='font-size:16px;'>请下载最新的Flash插件，否则你无法体验聊天及交互功能！</p><p>&nbsp;</p><p><a href='http://www.adobe.com/go/getflashplayer' target='_blank' title='下载最新的Flash插件'><img src='http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif' alt='下载最新的Flash插件' border='0' /></a></p></div>";
		s+="		</div></div>";
		s+="	</div>";
		s+="	<div class='mbottom' id='ChatBottom'>";
		s+="		<div class='mtask' id='ChatTask'><div class='mtasktips'>小提示：双击右侧好友列表中对应的好友可以打开私聊窗口哦！</div></div>";
		s+="		<div class='bug'><a href='/web/bug.aspx' target='_blank' style='font-size:14px'>提交测试意见</a></div>";
		s+="		<div id='ChatBottomInfo' class='info'><div class='infohead'></div><div class='infonick'></div></div>";
		s+="	</div>";
		s+="</div>";
		IdoMain.$oMainCont.html(s);

		IdoMain.chat.$oFlashCont = $('#ChatFlashCont');
		IdoMain.chat.$oChat = $('#ChatCont');
		IdoMain.chat.$oTop = $('#ChatTop');
		IdoMain.chat.$oBottom = $('#ChatBottom');
		IdoMain.chat.$oTask = $('#ChatTask');
		
		IdoMain.chat.$oTop.find(".search form").submit(function(){
			var input = $(this).find("input");
			if(input.val().length > 0 && input.val() != '按昵称搜索'){
				//1为搜索昵称
				IdoMain.proxy.openAccuSearch(input.val(), 1);
			}
			input.val("");
			input.focus();
			return false;
		}).find("input").blur(function(){
			if(this.value == ''){
				this.value = '按昵称搜索';
				$(this).addClass('notice');
			}
		}).focus(function(){
			if(this.value == '按昵称搜索'){
				this.value = '';
				$(this).removeClass('notice');
			}
		}).blur();
		
	},
	
	_getChatFrameHtml : function(user){
		var id = user.id;
		var skin = this.chat.getSkin();
		var s = "";
		s += "<iframe id='MainFrame" + id + "' class='MainFrame' frameborder='0' scrolling='no'></iframe>";
		s += "<div id='Main" + id + "' class='Main' style='background-color:" + skin.chatBack + ";border:1px solid " + skin.border + ";'>";
		s += "	<div id='Head" + id + "' class='Head' drag='1' style='background:url(http://img1.ido360.com/img/chat/topback" + skin.skinId + ".png) repeat-x;'>";
		s += "		<div class='HeadImgCont'><img id='HeadImg" + id + "' class='HeadImg' src='http://img1.ido360.com/img/s_defHead.jpg'/></div>";
		s += "		<div id='HeadInfo" + id + "' class='HeadInfo' drag='1' style='color:" + skin.word + ";'>";
		s += "			<div id='InfoNick" + id + "' class='InfoNick' drag='1'></div>";
		s += "			<div id='InfoSign" + id + "' class='InfoSign' drag='1' unselectable='on' onselectstart='return false;'></div>";
		s += "		</div>";
		s += "		<div id='HeadBtn" + id + "' class='HeadBtn'><div class='menu m' title='操作菜单'></div><div class='min m' title='最小化'></div><div class='max m'></div><div class='close m' title='关闭 (ESC键快速关闭)'></div></div>";
		s += "	</div>";
		s += "	<div class='Body' drag='1'>";
		s += "		<div class='BodyMainPanel'>";
		s += "		<div id='TxtOut" + id + "' class='TxtOut' style='border:1px solid " + skin.border + ";'></div>";
		s += "		<div id='FuncBtns" + id + "' class='FuncBtns' drag='1' id='GroupTitle" + id + "' style='border-left:1px solid " + skin.border + ";border-right:1px solid " + skin.border + ";background:url(http://img1.ido360.com/img/chat/topback" + skin.skinId + ".png) repeat-x bottom center;'>";
		s += "			<div class='face m' title='表情'></div>";
		s += "			<div class='record m' title='历史记录'></div>";
		s += "			<div class='leaveNotice' id='LeaveNotice" + id + "' style='color:" + skin.word + ";'><img src='http://img1.ido360.com/img/loading2.gif'/> 您有离线留言，正在获取中..</div>";
		s += "		</div>";
		s += "		<div class='TxtInCont'>";
		s += "			<textarea type='text' id='TxtIn" + id + "' class='TxtIn' style='border:1px solid " + skin.border + ";'></textarea>";
		s += "		</div>";
		s += "		<div id='SendBtns" + id + "' class='SendBtns' drag='1'>";
		s += "			<div class='send btn m' unselectable='on' onselectstart='return false;' title='快捷键Alt+S'><div class='arrow m'> </div>发送(<span class='_line'>S</span>)</div>";
		s += "			<div class='close btn m' unselectable='on' onselectstart='return false;' title='快捷键Alt+C'>关闭(<span class='_line'>C</span>)</div>";
		s += "		</div>";
		s += "		</div>";
		if(user.mode == 1){
			//圈子
			s += "	<div class='GroupPanel'>";
			s += "		<div class='GroupNotice' id='GroupNotice" + id + "' style='border:1px solid " + skin.border + ";'></div>";
			s += " 		<div class='GroupTitle' id='GroupTitle" + id + "' style='color:" + skin.word + ";border-left:1px solid " + skin.border + ";border-right:1px solid " + skin.border + ";background:url(http://img1.ido360.com/img/chat/topback" + skin.skinId + ".png) repeat-x bottom center;'>圈子成员(0/0)</div>";
			s += "		<div class='GroupList' id='GroupList" + id + "' style='border:1px solid " + skin.border + ";'>";
			s += "			<div style='text-align:center;padding-top:50px;'><img src='http://img1.ido360.com/img/loading1.gif'/></div>";
			s += "		</div>";
			s += "	</div>";
		}
		s += "	</div>";
		s += "</div>";
		return s;
	}
};

$.extend({   
    /**  
     * 清除当前选择内容  
     */  
    unselectContents: function(){   
        if(window.getSelection)   
            window.getSelection().removeAllRanges();   
        else if(document.selection)   
	        document.selection.empty();   
    }   
});   
jQuery.fn.extend({   
    /**  
     * 选中内容  
     */  
    selectContents: function(){   
        $(this).each(function(i){   
            var node = this;   
            var selection, range, doc, win;   
            if ((doc = node.ownerDocument) &&   
                (win = doc.defaultView) &&   
                typeof win.getSelection != 'undefined' &&   
                typeof doc.createRange != 'undefined' &&   
                (selection = window.getSelection()) &&   
                typeof selection.removeAllRanges != 'undefined')   
            {   
                range = doc.createRange();   
                range.selectNode(node);   
                if(i == 0){   
                    selection.removeAllRanges();   
                }   
                selection.addRange(range);   
            }   
            else if (document.body &&   
                     typeof document.body.createTextRange != 'undefined' &&   
                     (range = document.body.createTextRange()))   
            {   
                range.moveToElementText(node);   
                range.select();   
            }   
        });   
    },   
    /**  
     * 初始化对象以支持光标处插入内容  
     */  
    setCaret: function(){   
        if(!$.browser.msie) return;   
        var initSetCaret = function(){   
            var textObj = $(this).get(0);   
            textObj.caretPos = document.selection.createRange().duplicate();   
        };   
        $(this)   
        .click(initSetCaret)   
        .select(initSetCaret)   
        .keyup(initSetCaret);   
    },   
    /**  
     * 在当前对象光标处插入指定的内容  
     */  
    insertAtCaret: function(textFeildValue){   
       var textObj = $(this).get(0);   
       if(document.all && textObj.createTextRange && textObj.caretPos){   
           var caretPos=textObj.caretPos;   
           caretPos.text = caretPos.text.charAt(caretPos.text.length-1) == '' ?   
                               textFeildValue+'' : textFeildValue;   
       }   
       else if(textObj.setSelectionRange){   
           var rangeStart=textObj.selectionStart;   
           var rangeEnd=textObj.selectionEnd;   
           var tempStr1=textObj.value.substring(0,rangeStart);   
           var tempStr2=textObj.value.substring(rangeEnd);   
           textObj.value=tempStr1+textFeildValue+tempStr2;   
           textObj.focus();   
           var len=textFeildValue.length;   
           textObj.setSelectionRange(rangeStart+len,rangeStart+len);   
           textObj.blur();   
       }   
       else {   
           textObj.value+=textFeildValue;   
       }   
    }
});


(function($){

	// to track if the mouse button is pressed
	var isMouseDown    = false;

	// to track the current element being dragged
	var currentElement = null;

	// callback holders
	var dropCallbacks = {};
	var dragCallbacks = {};
	
	// bubbling status
	var bubblings = {};

	// global position records
	var lastMouseX;
	var lastMouseY;
	var lastElemTop;
	var lastElemLeft;
	
	// track element dragStatus
	var dragStatus = {};	

	// if user is holding any handle or not
	var holdingHandler = false;

	// returns the mouse (cursor) current position
	$.getMousePosition = function(e){
		var posx = 0;
		var posy = 0;

		if (!e) var e = window.event;

		if (e.pageX || e.pageY) {
			posx = e.pageX;
			posy = e.pageY;
		}
		else if (e.clientX || e.clientY) {
			posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
			posy = e.clientY + document.body.scrollTop  + document.documentElement.scrollTop;
		}

		return { 'x': posx, 'y': posy };
	};

	// updates the position of the current element being dragged
	$.updatePosition = function(e) {
		var pos = $.getMousePosition(e);

		var spanX = (pos.x - lastMouseX);
		var spanY = (pos.y - lastMouseY);

		$(currentElement).css("top",  (lastElemTop + spanY));
		$(currentElement).css("left", (lastElemLeft + spanX));
	};

	// when the mouse is moved while the mouse button is pressed
	$(document).mousemove(function(e){
		if(isMouseDown && dragStatus[currentElement.id] != 'false'){
			// update the position and call the registered function
			$.updatePosition(e);
			if(dragCallbacks[currentElement.id] != undefined){
				dragCallbacks[currentElement.id](e, currentElement);
			}

			return false;
		}
	});

	// when the mouse button is released
	$(document).mouseup(function(e){
		if(isMouseDown && dragStatus[currentElement.id] != 'false'){
			isMouseDown = false;
			if(dropCallbacks[currentElement.id] != undefined){
				dropCallbacks[currentElement.id](e, currentElement);
			}

			return false;
		}
	});

	// register the function to be called while an element is being dragged
	$.fn.ondrag = function(callback){
		return this.each(function(){
			dragCallbacks[this.id] = callback;
		});
	};

	// register the function to be called when an element is dropped
	$.fn.ondrop = function(callback){
		return this.each(function(){
			dropCallbacks[this.id] = callback;
		});
	};
	
	// disable the dragging feature for the element
	$.fn.dragOff = function(){
		return this.each(function(){
			dragStatus[this.id] = 'off';
		});
	};
	
	// enable the dragging feature for the element
	$.fn.dragOn = function(){
		return this.each(function(){
			dragStatus[this.id] = 'on';
		});
	};
	
	// set a child element as a handler
	$.fn.setHandler = function(handlerId){
		return this.each(function(){
			var draggable = this;
			
			// enable event bubbling so the user can reach the handle
			bubblings[this.id] = true;
			
			// reset cursor style
			$(draggable).css("cursor", "");
			
			// set current drag status
			dragStatus[draggable.id] = "handler";

			// change handle cursor type
			$("#"+handlerId).css("cursor", "pointer");	
			
			// bind event handler
			$("#"+handlerId).mousedown(function(e){
				holdingHandler = true;
				$(draggable).trigger('mousedown', e);
			});
			
			// bind event handler
			$("#"+handlerId).mouseup(function(e){
				holdingHandler = false;
			});
		});
	}

	// set an element as draggable - allowBubbling enables/disables event bubbling
	$.fn.easydrag = function(allowBubbling){

		return this.each(function(){

			// if no id is defined assign a unique one
			if(undefined == this.id || !this.id.length) this.id = "easydrag"+(new Date().getTime());
			
			// save event bubbling status
			bubblings[this.id] = allowBubbling ? true : false;

			// set dragStatus 
			dragStatus[this.id] = "on";
			
			// change the mouse pointer
			//$(this).css("cursor", "move");
			//$(this).find("div[drag=1]").css("cursor", "move");
			//$(this).find("div[!drag=1]").css("cursor", "auto");
			
			// when an element receives a mouse press
			$(this).mousedown(function(e){
				if(e.target != this){
					if(!$(e.target).attr("drag")) return true;
				}
				// just when "on" or "handler"
				if((dragStatus[this.id] == "off") || (dragStatus[this.id] == "handler" && !holdingHandler))
					return bubblings[this.id];

				// set it as absolute positioned
				$(this).css("position", "absolute");

				// set z-index
				//$(this).css("z-index", parseInt( new Date().getTime()/1000 ));

				// update track variables
				isMouseDown    = true;
				currentElement = this;

				// retrieve positioning properties
				var pos    = $.getMousePosition(e);
				lastMouseX = pos.x;
				lastMouseY = pos.y;

				lastElemTop  = this.offsetTop;
				lastElemLeft = this.offsetLeft;

				$.updatePosition(e);

				return bubblings[this.id];
			});
		});
	};

})(jQuery);