//document.domain = 'woyo.com';
$(function(){
	clearBlurA();
	window.focus();
	eval(gExec);
	gExec=null;
	//除去 box 类下所有 button 元素的焦点
	$('.box button').clearBlur();
});

/*==================== 功能函数-fun ====================*/

/*
	window onresize 事件
	按添加callback顺序执行
*/
function resizeForWindow(){
	this.callback = {};
	this.num = 0;
	this.flag = true;
}

resizeForWindow.prototype = {
	add : function(name, callback){
		this.callback[name] = callback;
		this.num++;
		if(this.flag === true){
			this.bind();
		}
	},
	del : function(name){
		delete this.callback[name];
		this.num--;
		if(this.num <= 0 && this.flag === false){
			this.unbind();
		}
	},
	bind: function(){
		var self = this;
		$(window).resize(function(){
			if(self.num > 0){
				var tmp = null;
				for(tmp in self.callback){
					if(typeof self.callback[tmp] == 'function'){
						self.callback[tmp].apply(self);
					} else {
						eval(self.callback[tmp]);
					}
				}
			}
		});
		this.flag = false;
	},
	unbind: function(){
		$(window).unbind('resize');
		this.flag = true;
	}
}

var rfwObj = new resizeForWindow();

/*
	document 事件
	按添加callback顺序执行
*/
function bindDocumentEvent(){
	this._eventName = {};
	this.callback = {};
	this.num = {};
	this.flag = {};
}

bindDocumentEvent.prototype = {
	add : function(eName, name, callback){
		if(this._eventName[name] == undefined){
			this._eventName[name] = eName;
			if(this.callback[eName] == undefined){
				this.callback[eName] = {};
				this.callback[eName][name] = callback;
			} else {
				this.callback[eName][name] = callback;
			}
			if(this.num[eName] == undefined){
				this.num[eName] = 1;
			} else {
				this.num[eName] += 1;
			}
			if(this.flag[eName] == undefined){
				this.bind(eName, name);
			}
		}
		return this;
	},
	del : function(eName, name){
		if(this._eventName[name] != undefined){
			delete this.callback[eName][name];
			delete this._eventName[name];
			this.num[eName]--;
			if(this.num[eName] <= 0 && this.flag[eName] === false){
				this.unbind(eName);
			}
		}
		return this;
	},
	bind: function(eName, name){
		var self = this;
		$(document).bind(eName, function(e){
			if(self.num[eName] > 0){
				var tmp = null;
				for(tmp in self.callback[eName]){
					if(typeof self.callback[eName][tmp] == 'function'){
						self.callback[eName][tmp].apply(self,[e]);
					} else {
						eval(self.callback[eName][tmp]);
					}
				}
			}
		});
		this.flag[eName] = false;
	},
	unbind: function(eName){
		$(document).unbind(eName);
		delete this.flag[eName];
	}
}

var bindDomEventObj = new bindDocumentEvent();

//这个控制搜索的suggest
bindDomEventObj.add('click','search_suggest',function() {
	if($.id('autoWords') != null && $.id('autoWords').innerHTML !=''){
		$.id('autoWords').style.display = 'none';
	}
})

//清除A标签的焦点
function clearBlurA(){
	$("a[name!='no_blur']").each(function(){clearDrag(this);this.onfocus=function(){this.blur()}});
	clearBlurObject();
	clearImage();
}

/*
 * 除去目标对象的焦点
 * 使用示例： $('jQuery 选择器').clearBlur();
 * @Author: George Wing
 * @Created: 2010/01/28
 * 注意：如进行改动请添加修改时间和修改作者的注释
 */
(function($){
	$.fn.clearBlur = function(){
		return this.focus(function(){ $(this).blur(); });
	};
})(jQuery);

//清除Flash的焦点
function clearBlurObject(){
	//$("object").each(function(){clearDrag(this);this.onfocus=function(){this.blur()}});
}

//清除image的焦点
function clearImage(){
	$("img").each(function(){clearDrag(this);this.onfocus=function(){this.blur()}});
}

//多少毫秒后去做事
function delayExec(fun,time){
	time=(time==undefined)? 100:time;
	var timer=window.setInterval(function(){
		window.clearInterval(timer);
		if(typeof fun == 'function')fun.apply(this);
		else eval(fun);
	},time);
}

//注销选中事件
function clearDrag(obj){
	var tmp=null;
	// for IE 5 +
	if (window.ActiveXObject) {
		if(obj.length==undefined){
			obj.onselectstart = function(){return false;};
			obj.ondragstart = function(){return false;};
			obj.unselectable = "on";
		}
		else{
			for(tmp in obj){
				tmp.onselectstart = function(){return false;};
				tmp.ondragstart = function(){return false;};
				tmp.unselectable = "on";
			}
		}
	}
	// for non IE 5 +
	else{
		if(obj.length==undefined){
			if(obj.style==undefined)return;
			obj.style.mozUserSelect = 'none';
			obj.style.userSelect = 'none';
			obj.style.KhtmlUserSelect = 'none';
		}
		else{
			for(tmp in obj){
				if(tmp.style==undefined)continue;
				tmp.style.mozUserSelect = 'none';
				tmp.style.userSelect = 'none';
				tmp.style.KhtmlUserSelect = 'none';
			}
		}
	}
}

//msgbar控制
/*
function magBarControl(mode){
	var objbody = document.getElementById('body');
	var objhtml= document.getElementById('html_frame');
	var objmsg= document.getElementById('msgbar');
	if((objhtml.clientHeight - objbody.clientHeight)>=16)objmsg.style.bottom = '16px';
	if(mode === true)objmsg.style.bottom = '0px';
	$(window).resize(function(){
		if ((objhtml.clientHeight - objbody.clientHeight)>=16){
			if(objmsg.style.bottom!='16px')objmsg.style.bottom = '16px';
		} else {
			if(objmsg.style.bottom!='0px')objmsg.style.bottom = '0px';
		}
	});
}
*/

function msgBarFlush() {
    var timer = null;
    $('#msgBarWrap').hide();
    clearTimeout(timer);
    timer=setTimeout(function(){
        $('#msgBarWrap').show();
        $('#msgBarWrap').css('bottom',0).show();
    },500);
}

//异步加载msgbar
function makeMsgBar () {
    if (getQueryString("chatdebug") == "true") { //yuyii add 调试选项
        $.getScript("http://image.woyo.com/js/common/chat_1.0.2.js",function(){
    		delayExec(function (){$('#msgBarWrap').data('flagChatLoadStatus',1)},50);
    	});
    }
    else if(getQueryString("woyotoo") == "true") { //woyotoo 测试用
	    $.getScript("http://image.woyo.com/js/common/chat_1.0.js",function(){
		    delayExec(function (){$('#msgBarWrap').data('flagChatLoadStatus',1)},500);
	    });
    }
    else {
	    //$.getScript("http://image.woyo.com/js/common/chat_1.0.2.js",function(){
        $.getScript("http://image.woyo.com/js/common/chat_1.0.2-min.js",function(){
		    delayExec(function (){$('#msgBarWrap').data('flagChatLoadStatus',1)},50);
	    });
    }
    
    /*
    //使用iframe 要做ajax请求
    var m_content=document.createElement("iframe");
    m_content.name = "msgbar";
    m_content.id = "msgbar";
    m_content.scrolling="no";
    m_content.width="100%";
    m_content.height = "25";
    m_content.setAttribute("frameborder", "0", 0);
    m_content.src="http://msgbar.woyo.com/showMsgbar.php";
    $("#msgBarWrap").get(0).appendChild(m_content); 
    */
    
	//下面是新的版本，ff考css就能搞定，ie6需要下面的事件监听
	if($.browser.msie) {
        
        if ($.browser.version == '6.0') {
          /*
            var timer=null;
            function resizeLocation() {
                $('#msgBarWrap').hide();
                clearTimeout(timer);
                timer=setTimeout(function(){
                    $('#msgBarWrap').show();
                    $('#msgBarWrap').css('bottom',0).show();
                },500);
            }
            */
            var resizeLocation=msgBarFlush;

            jQuery(window).scroll(resizeLocation);
            jQuery(window).resize(resizeLocation);
        }
	}
	$('#msgBarWrap').data('flagChatLoadStatus',0);
	ajaxE({'domain':'msgbar.woyo.com','page':'showMsg','fun':'showMsg'});
}



function showMsgbarNoticeNum (newsNum) {
	if ($.id("msgbarNoticeNum") != null || $.id("msgbarNoticeNum") != 'undefined') {
		$.id("msgbarNoticeNum").innerHTML = newsNum;
		$("#msgbarNoticeNum").show();
	}
}

// 初始化聊天
function initChat(userid,webimip,webimport,ticket){
	delayExec(function(){
		if($('#msgBarWrap').data('flagChatLoadStatus') == 1){
			// 聊天对象已经存在，js加载完毕
			if(chatObj_g != undefined && chatObj_g != null){
				if(userid != undefined){
					chatObj_g.createChat(userid, webimip, webimport,ticket);
                    if(getQueryString("woyotoo") == "true") {
                        getWoyoToo(userid);
                    }
				}
			}
		} else {
			initChat(userid, webimip, webimport,ticket);
		}
	},13);
}

//获得woyotoo
//function getWoyoToo(mode){
function getWoyoToo(userid,mode){
	try{
		var woyotoo_handle = new ActiveXObject("ICCARD.ICCardCtrl.1");
		window.location.href="woyotoo://uid="+userid;
		return false;
	}
	catch(e){
		if(mode=='flash')window.open('http://www.woyo.com/superdown.php','superdown','fullscreen=yes');
		return true;
	}
}

//传ticket给flash,如果已经登录，就不在iwoyo内登录
var fsAirWin;
function upFsAirInstall(ticket){
	var date = new Date();
	var installStr = $(document).createSwf({
        src         : 'http://image.woyo.com/swf/upfs/badge.swf?'+date.getTime(),
        id          : "fm_install_wftps",
        w           : 252,
        h           : 220,
        ver         : 9,
        mode        : 3,
        vars        : {
            appname: 'WOYOFtp上传工具',
            appurl: 'http://image.woyo.com/swf/upfs/woyoupload.air',
			ticket:ticket,
			airversion: '1.0'
        },
        params      : {menu:'false',wmode:'transparent',allowScriptAccess:'always'}
    });

	fsAirWin = function(){
		popObj.close(true);
	}

	alertFun(function(){
        return '<div class="pop_container" style="display:none;width:250px;"><div class="pop_title-nav"><h2>欢迎使用我友相册/视频上传</h2><a href="#" class="pop_close" title="关闭"  onclick="popObj.close(true);return false;">&nbsp;</a></div><div class="pop_content after" style="height:220px;">'+installStr+'</div></div>';
    },'woyoFtpInstall',2);
}

//--------------------------------数据替换时的遮照--------------------------------------------------------

/*
createShield:
	mode=选择遮照模式
	para=[	w/width:0,宽
			h/height:0,高
			l/left:0,距左
			t/top:0,距上
			a/action:(true|false),是否隐藏input=select
			m:(undefined|true=1|false=2|3),[undefined:滑动|true=直接遮照和滑动消失|false=直接遮照和消失|3=直接遮照和渐渐消失]
			d/date:([500|1000|fast|slow|normal])滑动遮照和消失时间
			c/css:shield_child
		]
	fn=遮照后执行函数
*/
jQuery.fn.extend({
	createShield: function(mode,para,fn){
		if ($("#shieldHandle",this).get(0)!=undefined)return;
		var so=document.createElement("div"),self=this;
		so.id = "shieldHandle";
		so.className =(mode=='p')? "shield_wait" : "shield";
		with(so.style){
			if(para.l!=undefined)left=para.l+"px";
			if(para.t!=undefined)top=para.t+"px";
			width=(para.w==undefined || para.w==0)? (this.css('width')=='auto')? this.get(0).offsetWidth+"px" : this.css('width') : para.w+"px";
			height=(para.h==undefined)? (this.css('height')=='auto')? this.get(0).offsetHeight+"px" : this.css('height') : (para.h==0)? '100%':para.h+"px";
		}
		var so_c=document.createElement("div");
		so_c.className=(para.c==undefined)? "shield_child":para.c;
		with(so_c.style){
			width=so.style.width;
			height=so.style.height;
		}
		$(so).append(so_c);
		this.append(so);
		if(para.a==true)$("select[name!='no_hide']").hide();
		if(para.m==3 && para.d==undefined || para.d==0)para.d='fast';
		if(para.d==undefined || para.d==0)para.d=500;
		if(para.m==undefined){
			var tmp=$.toJSON({id:self[0].id,action:para.a,mode:0,date:para.d});
			$(so).slideDown(para.d,function(){if(/function/i.test(fn+""))fn.apply(self,[tmp])});
		}
		else{
			$(so).show();
			var tmp_mode=(para.m===true)? 1:(para.m===false)? 2:para.m;
			var tmp=$.toJSON({id:self[0].id,action:para.a,mode:tmp_mode,date:para.d});
			if(/function/i.test(fn+""))fn.apply(self,[tmp]);
		}
	}
});
function removeShield(args,fun){
	args=$.parseJSON(args);
	switch(args.mode){
		case 0:
		case 1:
			delayExec(function(){
				$("#shieldHandle",$.id(args.id)).slideUp(parseInt(args.date),function(){
					$(this).remove();
					if(args.action)$("select[name!='no_hide']").show();
					if(fun!=undefined)fun.apply();
				});
			},50);
			break;
		case 2:
			$("#shieldHandle",$.id(args.id)).remove();
			if(args.action)$("select[name!='no_hide']").show();
			if(fun!=undefined)fun.apply();
			break;
		case 3:
			delayExec(function(){
				$("#shieldHandle",$.id(args.id)).fadeOut(args.date,function(){
					$(this).remove();
					if(args.action)$("select[name!='no_hide']").show();
					if(fun!=undefined)fun.apply();
				});
			},50);
			break;
	}
}
function amendShield(args){
	args=$.parseJSON(args);
	var tmp=$.id(args.id);
	var height=($(tmp).css('height')=='auto')? tmp.offsetHeight+"px" : $(tmp).css('height');
	if($("#shieldHandle",$.id(args.id)).get(0)!=null && $("#shieldHandle",$.id(args.id)).get(0)!=undefined){
		$("#shieldHandle",$.id(args.id)).children(0).get(0).style.height=height;
		$("#shieldHandle",$.id(args.id))[0].style.height=height;
	}
}

/*==================== 异步提交数据-ajax ====================*/

var ajaxResponseData = null;

/*
	ajax	执行函数
	options 使用,以下是选项：
	type			= post | get
	domain		= www.woyo.com 没有 http 的全域名
	url			= index.php?u=allen 没有 域名 的 地址
	dir 			= 目录名称，多级目录用 index/page 如果在根目录下 请传 false
	page			= 页面名称
	fun			= 函数名称
	args			= ajax参数
	shieldArgs	= 遮照参数
	callFun		= ajax执行完成后的可执行函数
	callFailFun	= ajax执行发生错误后的可执行函数
	argsEncode	= true | false 通常在跨域时使用，因为跨域时涉及到中文编码问题 true = 编码
*/
function ajaxE(options){
	var re=/.+/;

	if(options.type == undefined){
		options.type = 'post';
	}
	if(options.dir == undefined){
		options.dir = 0;
	}
	if(options.page == undefined){
		return alertTip('ajaxE 参数错误： page 不能为空！');
	}
	if(options.fun == undefined){
		options.fun = 0;
	}

  /*
   * 添加同步异步选项 by dong4138 2009-12-16
   */
  if (options.async==undefined) {
    options.async = true;
  }
  /******** end by dong4138 ********/

	if(options.args == undefined){
		options.args = 0;
	} else {
		options.args = $.toJSON(options.args);
		if(options.argsEncode != undefined && options.argsEncode === true){
			options.args = encodeURIComponent(options.args);
		}
	}
	if(options.shieldArgs == undefined){
		options.shieldArgs = 0;
	}
	if(options.callFun == undefined){
		options.callFun = 0;
	}
	if(options.callFailFun == undefined){
		options.callFailfun = 0;
	}
	if(options.domain == undefined){
		options.domain = '/';
	} else {
		options.domain = 'http://'+options.domain+'/';
	}
	if(options.url == undefined){
		options.url = 'ajax.php';
	}

	options.dataType = 'json';

	var para = {
		ajax	:1,
		dir		:options.dir,
		page	:options.page,
		fun		:options.fun,
		args	:options.args
	}

	var url=options.domain+options.url;

	var ajaxDisp = function(key,val){
		switch(key){
			case 'innerhtml':
				$('#'+val[1]).html(val[2]);
				if(options.shieldArgs != 0)amendShield(options.shieldArgs);
				break;
			case 'alert':
				alertTip(val[1]);
				break;
			case 'append':
				$(val[2]).appendTo($.id(val[1]));
				break;
			case 'prepend':
				$(val[2]).prependTo($.id(val[1]));
				break;
			case 'appendb':
				$(val[2]).insertBefore($("#"+val[1]).children().get(0));
				break;
			case 'url':
				(val[1] == undefined || val[1] == 0)? window.location.reload(false) : window.location.replace(val[1]);
				break;
			case 'exec':
				eval(val[1]);
				break;
		}
	}

	var success = function(data){
		try{
			//没有数据返回时
			if(data!==0){
				var key=null;
				for(key in data){
					ajaxDisp(data[key][0],data[key]);
				}
			} else {
				if(options.shieldArgs != 0)removeShield(options.shieldArgs);
			}
			delayExec(function(){
				clearBlurA();
				if(options.shieldArgs != 0){
					removeShield(options.shieldArgs);
				}
				if(options.callFun != 0){
					if(typeof options.callFun == 'function'){
						options.callFun.apply(this);
					} else if(options.callFun != undefined) {
						eval(options.callFun);
					}
				}
			},500);
		}
		catch(exception){
			//alert(exception.message);
			if(options.shieldArgs != 0){
				removeShield(options.shieldArgs);
			}
			if(options.callFailFun != 0){
				if(typeof options.callFailFun == 'function'){
					options.callFailFun.apply(this);
				} else if(options.callFailFun != undefined) {
					eval(options.callFailFun);
				}
			}
		}
	}


	//解决跨域
	if(options.domain != '/'){
		para = "?ajax=1&dir="+para.dir+"&page="+para.page+"&fun="+para.fun+"&args="+para.args;
		$.getScript(url+para,function(){
			if(ajaxResponseData != null){
				success(ajaxResponseData);
			}
			ajaxResponseData = null;
		});
	} else {
		$.ajax({
			type	: options.type,
			url		: url,
			data	: para,
			dataType: options.dataType,
      async: options.async,
			success	: function(data){
				success(data);
			},
			error	: function(event, XMLHttpRequest, ajaxOptions, thrownError){
				//alertTip("服务器请求处理失败 或 服务器端出现错误！");
				if(options.callFailFun != 0){
					if(typeof options.callFailFun == 'function'){
						options.callFailFun.apply(this);
					} else if(options.callFailFun != undefined) {
						eval(options.callFailFun);
					}
				}
			}
		});
	}
}

/*==================== 提示对话框-dialog ====================*/

function popUp(tName){
	this._name = tName;
	this.str = '<table class="pop_dialog_table"><tr><td class="pop_top_left">&nbsp;</td><td class="pop_border">&nbsp;</td><td class="pop_top_right">&nbsp;</td></tr><tr><td class="pop_border" >&nbsp;</td><td><div id="popUpConId" style="width:300px;"></div></td><td class="pop_border">&nbsp;</td></tr><tr><td class="pop_bottom_left">&nbsp;</td><td class="pop_border">&nbsp;</td><td class="pop_bottom_right">&nbsp;</td></tr></table>';
	this.doc = null;
	this.isCreate = {};
	this.obj = {};
	this.conObj = {};
	this.did = {};
	this.time = {};
	this.tipTime = null;
	this.nowUseObj = null;
}

popUp.prototype = {
	getConId: function(nid){
		return this.did[nid];
	},
	getFrmId: function(nid){
		return this.obj[nid];
	},
	create : function(nid){
		if(this.isCreate[nid] === undefined){
			this.doc =jQuery.doc();
			var dObj = document.createElement('DIV');
			dObj.id = nid+'_popUpObjId';
			dObj.className = 'pop_main_box';
			dObj.innerHTML = this.str;
			$(dObj).appendTo(document.body);
			this.obj[nid] = dObj.id;
			this.did[nid] = nid+'_popUpConId';
			$('#popUpConId',$(dObj)).attr('id',this.did[nid]);
			this.conObj[nid] = $('#'+this.did[nid],$(dObj)).get(0);
			this.isCreate[nid] = true;
			return true;
		}
		return false;
	},
	tip : function(msg, options){
		var nid = 'g_tip_9999';
		this.create(nid);
		if(options == undefined) options = {};
		if(options['title'] == undefined){
			options['title'] = '温馨提示';
		}
		//this.conObj[nid].innerHTML = '<div class="pop_container"><h2><strong>'+options['title']+'</strong><a href="#" class="pop_close" onclick="popObj.close(\''+nid+'\');return false;">&nbsp;</a></h2><div class="pop_con">'+msg+'</div></div>';
		if(msg == '礼物发送成功')
		{
			this.conObj[nid].innerHTML = '<div class="pop_container"><div class="pop_title-nav"><h2>'+options['title']+'</h2><a title="关闭" class="pop_close" href="##" onclick="popObj.close(\''+nid+'\');return false;"> </a></div><div class="pop_content after" style="padding:15px;">'+msg+'&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://gift.woyo.com/giftlist.php"><font color="#3980F4">继续赠送>></font></a>&nbsp;&nbsp;<a href="http://pay.woyo.com/"><font color="#3980F4">充值woyo币>></font></a></div></div>';
			this.center(nid);
		}else
		{
			this.conObj[nid].innerHTML = '<div class="pop_container"><div class="pop_title-nav"><h2>'+options['title']+'</h2><a title="关闭" class="pop_close" href="##" onclick="popObj.close(\''+nid+'\');return false;"> </a></div><div class="pop_content after" style="padding:15px;">'+msg+'</div></div>';
			this.center(nid);
		}
		if(options['w'] != undefined && !isNaN(parseInt(options['w']))){
			$('#'+this.did[nid]).css('width',options['w']+'px');
		}
		if(this.tipTime != null){
			window.clearInterval(this.tipTime);
			this.tipTime = null;
		}
		var self = this;
		this.hideSelect();
		if(options['time'] == undefined) options['time'] = 3000;
		if(isNaN(parseInt(options['time']))) options['time'] = 3000;
		if(msg == '礼物发送成功')
		{
			options['time'] = 100000;
		}
		this.tipTime = window.setInterval(function(){
			popObj.close(nid);
		},parseInt(options['time']));
	},
	fun : function(callback, nid, mode) {
		popObj.close('g_tip_9999');
		mode = parseInt(mode);
		if(mode === 1){ // 强制模式，强制刷新
			this.clear(nid);
		}
		var flag = this.create(nid);
		if(this.doc.clientHeight > this.doc.scrollHeight){
			this.createCover({height:this.doc.clientHeight});
		} else {
			this.createCover({height:this.doc.scrollHeight});
		}
		var self = this;
		this.nowUseObj = $('#'+this.obj[nid]);
		
		if(flag){
			this.conObj[nid].innerHTML = '<div id="'+nid+'_popUpLoadTipId" style="width:100%;height:100%;margin:0 auto;line-height:50px;text-align:center;">加载中...</div>';
			this.center(nid);
			this.time[nid] = window.setInterval(function(){
				if($.id(nid+"_popUpLoadTipId") == null){
					window.clearInterval(self.time[nid]);
					self.time[nid] = null;
					if(mode === 2 || mode === 3 || mode === 4){
						self.display(nid);
					} else {
						self.move(nid);
					}
				}
			},13);
			var con = callback.apply(this,[this.did[nid]]);
			if(con != undefined){
				$('#'+this.did[nid]).html(con);
			}
		} else {
			this.center(nid);
			$('#'+this.obj[nid]).show();
		}
		rfwObj.add('popup', function(){
			if(self.doc.clientHeight > self.doc.scrollHeight){
				self.createCover({height:self.doc.clientHeight});
			} else {
				self.createCover({height:self.doc.scrollHeight});
			}
		});
	},
	center : function(nid){
		$('#'+this.obj[nid]).show();
		with($.id(this.obj[nid]).style){
			left=((this.doc.clientWidth-$.id(this.obj[nid]).offsetWidth)/2)+"px";
			top=(this.doc.clientHeight/2-$.id(this.obj[nid]).offsetHeight/2)+this.doc.scrollTop+"px";
		}
	},
	getLTWH:function(nid){
		var childObj = $($(this.conObj[nid]).children(0));
		var h = childObj.outerHeight();
		var th = $('#'+this.obj[nid]).outerHeight();
		var w = childObj.outerWidth();
		var l = ((this.doc.clientWidth-w)/2);
		if(th < h)th = h;
		var t = (this.doc.clientHeight/2-th/2)+this.doc.scrollTop;
		if(t < 0) t = 45;
		return {w:w, h:h, l:l, t:t};
	},
	display : function(nid){
		var whlt = this.getLTWH(nid);
		with($.id(this.obj[nid]).style){
			left = whlt.l+'px';
			top = whlt.t+'px';
		}
		with(this.conObj[nid].style){
			width = whlt.w+'px';
			height= whlt.h+'px';
		}
		
		/*
		var self = this;
		//回调函数中动态调整高度 added by yuyii 09/12/14
		$($(this.conObj[nid]).children(0)).show(function(){
			$(self.conObj[nid]).get(0).style.height = "auto";
			$.id(self.obj[nid]).style.height = "auto";
		});
		*/
		$($(this.conObj[nid]).children(0)).show();
	},
	move : function(nid){
		var whlt = this.getLTWH(nid);
		var self = this;
		$('#'+this.obj[nid]).animate({ left : whlt.l}, "normal");
		$(this.conObj[nid]).animate({ width : whlt.w}, "normal");
		$('#'+this.obj[nid]).animate({ top : whlt.t}, "normal");
		$(this.conObj[nid]).animate({ height : whlt.h}, "normal");
        delayExec(function() {
            $($(self.conObj[nid]).children(0)).fadeIn('normal');
        },500);
		/*
			//动态调整高度 added by yuyii 09/12/14
			setTimeout(function(){
				$(self.conObj[nid]).get(0).style.height = "auto";
				$.id(self.obj[nid]).style.height = "auto";
			},1000);
		*/

	},
    execCallback: function(callback, nid, time){
        var self = this;
        if(time == undefined)time = 500;
        var fun = function() {
            if(callback!=undefined){
                if(typeof callback == 'function'){
                    callback.apply(self,[nid]);
                } else {
                    eval(callback);
                }
            }
        }
        if(time == 0){
            fun();
        } else {
            delayExec(fun, time);
        }
    },
    change:function(nid, execMode,callback,effect){
        if(execMode == 'before'){
			if(callback != undefined && callback != ''){
				this.execCallback(callback, nid, 0);
			}
        }

        this.conObj[nid].style.height = 'auto';
        var whlt = this.getLTWH(nid);
		if(effect == undefined){
			//yuyii on 2010-1-14 加动画会导致好友框伸缩
			/*
			$('#'+this.obj[nid]).animate({ left : whlt.l}, "normal");
			$(this.conObj[nid]).animate({ width : whlt.w}, "normal");
			$('#'+this.obj[nid]).animate({ top : whlt.t}, "normal");
			$(this.conObj[nid]).animate({ height : whlt.h}, "normal");
			*/
		} else {
			$.id(this.obj[nid]).style.left = whlt.l+'px';
			$.id(this.obj[nid]).style.top = whlt.t+'px';
			this.conObj[nid].style.width = whlt.w+'px';
			this.conObj[nid].style.height = whlt.h+'px';
		}
		
        if(execMode == 'after'){
			if(callback != undefined && callback != ''){
				this.execCallback(callback, nid);
			}
        }
    },
	changeMove:function(nid, w, h, callback){
		var nowLeft = ((this.doc.clientWidth-w)/2);
		var nowTop = (this.doc.clientHeight/2-h/2)+this.doc.scrollTop;
		if(nowTop < 0) nowTop = 45;
		$('#'+this.obj[nid]).animate({ left : nowLeft}, "normal");
		$('#'+this.obj[nid]).animate({ top : nowTop}, "normal");
        this.execCallback(callback, nid);
	},
	changeResize:function(nid, w, h, callback){
		var self = this;
		if(w != undefined && w != 0) {
			$(this.conObj[nid]).animate({ width : w}, "normal");
		}
		if(h != undefined && h != 0) {
			$(this.conObj[nid]).animate({ height : h}, "normal");
		}
        this.execCallback(callback, nid);
	},
	createCover: function(options){
		if ($.id('popUpCoverHandleId') == null){
			var shieldobj=document.createElement("div");
			shieldobj.id = "popUpCoverHandleId";
			shieldobj.className =(options['css']==undefined)? "cover":css;
			if(options['width'] != undefined && options['width'] > 0){
				shieldobj.style.width = options['width']+'px';
			}
			if(options['height'] != undefined && options['height'] > 0){
				shieldobj.style.height = options['height']+'px';
			}
			$(shieldobj).appendTo(document.body);
		} else {
			var shieldobj = $.id("popUpCoverHandleId");
			if(options['width'] != undefined && options['width'] > 0){
				shieldobj.style.width = options['width']+'px';
			}
			if(options['height'] != undefined && options['height'] > 0){
				shieldobj.style.height = options['height']+'px';
			}
			$(shieldobj).show();
		}
		this.hideSelect();
	},
	showSelect : function(){
		$('select').each(function(){
			this.style.visibility = 'visible';
		});
	},
	hideSelect : function(){
		$("select[name!='no_hide']").each(function(){
			this.style.visibility = 'hidden';
		});
	},
	close : function(nid){
		if(nid === undefined || nid === true){
			rfwObj.del('popup');
			if(this.nowUseObj != null){
				if(nid === true){
					var tmpid = this.nowUseObj.get(0).id;
					tmpid = tmpid.split('_');
					this.clear(tmpid[0]);
				} else {
					this.nowUseObj.hide();
				}
				this.nowUseObj = null;
			}
			if($.id('popUpCoverHandleId') != null){
				$('#popUpCoverHandleId').hide();
			}
			this.showSelect();
		} else {
			window.clearInterval(this.tipTime);
			this.tipTime = null;
			this.clear(nid);
			if(this.nowUseObj == null){
				this.showSelect();
			}
		}
	},
	clear : function(nid){
		if(this.obj[nid] != undefined){
			$('#'+this.obj[nid]).remove();
			delete this.isCreate[nid];
			delete this.conObj[nid];
			delete this.did[nid];
			delete this.time[nid];
			delete this.obj[nid];
		}
	}
}

var popObj = new popUp('myWoyoPopUp');

function alertTip(msg, options){
	popObj.tip(msg, options);
}

function alertCommonTip(msg, options){
	popObj.tip(msg, options);
}

/*
	弹出层
	callback = 函数
	idPrefix = ID
	mode	 = 使用模式 undefined | 0 = 正常 1 = 正常+强制刷新 2 = 直接弹出 3 = 直接弹出+强制刷新
*/
function alertFun(callback, idPrefix, mode){
	popObj.fun(callback, idPrefix, mode);
}

//--------------------------------COOKIE--------------------------------------------------------

function setCookie(name,value,expire,domain,issecure){
		if(domain==undefined || domain==null || domain=="")domain=".woyo.com";
		var secure=(issecure==undefined || issecure==null || issecure=="")? true : false;
		if(expire!=undefined && expire!=null && expire!=""){
			var date = new Date ();
			if(expire<=0)date.setTime(date.getTime()-(1*1000*3600*24));
			else date.setTime(date.getTime()+(expire*1000*3600*24));
			expire=";expires="+date.toGMTString();
		}
		else expire="";
		document.cookie=name+"="+escape(value)+expire+";path=/;domain="+domain+";"+secure;

}
function getCookie(name,mode){
	var CookieFound = false;
	var start = 0;
	var end = 0;
	var CookieString = document.cookie;
	var i = 0;
	while (i <= CookieString.length) {
		start = i ;
		end = start + name.length;
		if (CookieString.substring(start, end) == name){
			if(CookieString.substring(start+name.length,end+1)==';')break;
			CookieFound = true;
			break;
		}
		i++;
	}
	if (CookieFound){
		start = end + 1;
		end = CookieString.indexOf(";",start);
		if (end < start)
		end = CookieString.length;
		switch(mode){
			case 1:
				return unescape(decodeURIComponent(CookieString.substring(start,end)));
				break;
			default:
				return unescape(CookieString.substring(start,end));
				break;
		}
	}
	return "";
}


/*==================== 音乐试听-audition ====================*/

function musicTry(obj,url){
	var img=obj.firstChild;
	var imgsrc=img.src
	if(imgsrc.indexOf("music_off.gif")>=0){
		$("[@name='icon_music_try']").each(function(){
			this.src="http://image.woyo.com/m/image/music_off.gif";
		});
		img.src="http://image.woyo.com/m/image/music_on.gif";
		var emb=$.id('playbmusic');
		if(emb!=null)$(emb).remove();
		document.body.innerHTML+='<div id="playmobj"><object id="playbmusic" width="0" height="0" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6"><param name="url" value="'+url+'" /><embed id="playbmusic" width="0" height="0" type="application/x-mplayer2" src="'+url+'"></embed></object></div>';
	}
	else{
		img.src="http://image.woyo.com/m/image/music_off.gif";
		var emb=$.id('playbmusic');
		if($.browser.msie) try{emb.stop();}catch(e){emb.url='';}
		if(emb!=null){
			$('#playmobj').empty();
			$('#playmobj').remove();
		}
	}
}

/*==================== 上传前的提示-upload ====================*/

//提示
function TempTransfer(){
	fireUp();
	//myWoyoMsgBoxO.open("亲爱的WOYO用户：<br/>请在上传内容的同时严格遵守《互联网视听节目服务管理规定》和《互联网著作权行政保护办法》，遵守著作权法律、行政法规的规定，尊重著作权人的合法权益。<br/>如上传含有以下内容之一的文件，WOYO将采取封闭用户名并追究法律责任的行动\n（一）反对宪法确定的基本原则的；<br/>\t（二）危害国家统一、主权和领土完整的；<br/>\t（三）泄露国家秘密、危害国家安全或者损害国家荣誉和利益的；<br/>\t（四）煽动民族仇恨、民族歧视，破坏民族团结，或者侵害民族风俗、习惯的；<br/>\t（五）宣扬邪教、迷信的；\n\t（六）扰乱社会秩序，破坏社会稳定的；<br/>\t（七）诱导未成年人违法犯罪和渲染暴力、色情、赌博、恐怖活动的；<br/>\t（八）侮辱或者诽谤他人，侵害公民个人隐私等他人合法权益的；<br/>\t（九）危害社会公德，损害民族优秀文化传统的；<br/>\t（十）有关法律、行政法规和国家规定禁止的其他内容。<br/>如上传时政类视听新闻节目时，务必是地（市）级以上广播电台、电视台制作、播出的节目和中央新闻单位网站登载的时政类视听新闻节目。用户应对个人上传的视频、音乐、图片负全部法律责任。",4,'fireUp$$'+gWeb['my_up_op']+'',0);
}

//flash版本错误提示
function TempTransferError(){
	myWoyoMsgBoxO.open('如果想正常上传内容，请您使用"Flash Player 9.0"，下载请点击[确定]按钮。',3,['flashPlayerDownload'],0);
}

//flash播放器下载
function flashPlayerDownload() {
	window.location.href='http://www.woyo.com/download/Adobe.zip';
}

//确定提示后的调用flash操作
function fireUp(chn) {
	if(chn!=undefined && chn!="undefined"){
		$.id("fm_"+chn+"_upload").TempTransfer();
	}
	else $.id("fm_upload").TempTransfer();
}

function debug(o,mode,action) {
	var str='',s='',s1='';
	switch(mode){
		case 1:
			for(s in o){
				str+="   "+s+"="+o[s];
			}
			break;
		case 2:
			for(s in o){
				str+="   "+s+"=";
				if(typeof o[s] == 'object'){
					for(s1 in o[s]){
						str+=" "+s1+"="+o[s][s1];
					}
				} else {
					str+= o[s];
				}
			}
			break;
		case 3:
			for(s in o){
				str+="   "+s;
			}
			break;
	}
	if(str == '')str = o;
	switch(action){
		case 'i':
		case 'ia':
		case 'iar':
			var obj = $.id('debugs');
			if(obj == null) obj = document.body;
			obj.innerHTML = (action == 'i')? str:(action == 'ia')? obj.innerHTML+str:obj.innerHTML+"<br/>"+str;
			break;
		default:
			alert(str);
			break;
	}
}


//------------------------------------这个用来看控制头部的弹出层  start
var hideSetTimeoutProcess = null;
function hideSetPop (status) {
	var divid = 'hideSet';
	if (status == 'block') {
		if(hideSetTimeoutProcess != null) clearTimeout(hideSetTimeoutProcess);
		$.id(divid).style.display = 'block';
	}
	if (status == 'none') {
		hideSetTimeoutProcess = setTimeout("$.id('"+divid+"').style.display = 'none';", 200);
	}
}
var searchSortTimeoutProcess = null;
function searchSortPop (status) {
	var divid = 'searchSort';
	if (status == 'block') {
		if(searchSortTimeoutProcess != null) clearTimeout(searchSortTimeoutProcess);
		$.id(divid).style.display = 'block';
	}
	if (status == 'none') {
		searchSortTimeoutProcess = setTimeout("$.id('"+divid+"').style.display = 'none';", 200);
	}
}
//------------------------------------这个用来看控制头部的弹出层  end
//------------------------------------这个用来看控制头部的搜索建议 start
function searchSuggest (e,value) {
	var e = e || window.event;

	if(e.keyCode==13)
	{
		$('#searchform').submit();
	}else{
		//这里需要判断下，要不服务器会挂
		ajaxE({domain:'search.woyo.com',type:'get',page:'searchSuggest',fun:'searchSuggestFun','argsEncode':true,args:{value:value}});
	}
}
function searchSuggestPop () {
	$.id('autoWords').style.display='block';
}
//------------------------------------这个用来看控制头部的搜索建议 end
function doSnsSearch () {
	var url='http://search.woyo.com/result.php?act=base&keyword='+encodeURI($.id('searchText').value);
	window.open(url);
}
function fnSearchKeyDownJelly(e){
	var url='http://search.woyo.com/result.php?act=base&keyword='+encodeURI($.id('searchText').value);
	if(jQuery.browser.msie){
		if(event.keyCode == 13){
			window.location.replace(url);
			return false;
		}
	}else{
		if(e.which == 13){
			window.location.replace(url);
			return false;
		}
	}
	return true;
}

//检查 字符串长度 ，obj有字符串的对象，msg字符串内容，len最大长度
function checkDataLen(obj,msg,len){
	//if($.trim(obj.value).length<=0)return alertTip(msg+"不能为空！");
	var tmp_value=$.trim(obj.value);
	var chineseR=/[\u0391-\uFFE5]/g;
	var re=/[\u4E00-\u9FA5\uF900-\uFA2D]+$/;
	var tmp_len=tmp_value.replace(chineseR,"***").length;
	if(tmp_len>len){
		var tmp=tmp_value;
		for(var i=tmp_value.length;i>0;i--){
			if(re.test(tmp.substr(i-1,1)))tmp_len-=3;
			else tmp_len--;
			tmp_value=tmp_value.substr(0,i-1);
			if(tmp_len<=len)break;
		}
		obj.value=tmp_value;
		alertTip(msg+"长度超过了最大限制("+(Math.round(len/3))+"个中文，"+len+"个英文)，我们将自动截取！");
		return false;
	}
	return true;
}

//根据给定的key,获取地址栏的指定querystring
//added by YuYii 09/10/14
function getQueryString(key) {
    var s = document.location.search;
    if (s == "") return false;
    s = s.substr(1);
    var b = s.split("&");
    var tmp;
    for(var i in b) {
        tmp = b[i].split("=");
        if (tmp[0] == key) {
            return tmp[1];
        }
    }
    return false;
}

//调试函数for webim
function myalert(s) {
    //if (console != undefined)
    //    console.log(s);
}

/**
 	wConfirm 确认框  added by YuYii 09/12/02
 	@param title string 标题
 	@param content string 内容
 	@param callback function 回调函数，绑定确定按钮
 	@param mode 打开方式，同alertFun的参数，默认为3，刷新且直接打开
**/
function wConfirm(title,content,callback,mode) {
	if (content == undefined) content = "";
	if (title == undefined || title == "") {
		title = "是否确定执行该操作";
	}
	if (mode == undefined)	mode = 3;

	alertFun(function(){
		var str ='<div class="pop_container">';
		str +='<div class="pop_title-nav">';
		str +='<h2>' + title + '</h2>';
		str +='<a href="#" class="pop_close" title="关闭" onclick="popObj.close();return false;">&nbsp;</a></div>';
		str +='<div class="pop_content after" style="padding:15px;">';
		str += content;
		str +='</div>';
		str +='<div class="pop_footer"> <a href="javascript:;" class="btnbg button1"><i>确定</i></a> &nbsp; <a href="#" class="btnbg button4" onclick="popObj.close();return false;"><i>取消</i></a> </div>';
		str +=' </div>';
		return str;
		},"wConfirm_id",mode
	);
	
	if (typeof callback == "function")
		$("#wConfirm_id_popUpConId .pop_footer a.button1").one("click",callback);
	$("#wConfirm_id_popUpConId .pop_footer a.button1").bind("click",function(){popObj.close()});
}


/*==================== 网站提示-tip ====================*/

function libTips(parent){
	if($('.i-item').length==0){	//增加道具标签
		$('.i-gift').parents('li').after('<li><a href="http://item.woyo.com/item_list.php"><span class="i i-item"></span>道具</a></li>');
	}
	var _b=null;
	if((_b=$.id('tipsBox'))==null){
		$("<div id='tipsBox' class='tips'></div>").appendTo(document.body);
		_b=$.id('tipsBox');
	}
	if(parent==undefined)parent=$(document.body);
	$('*[title]',parent).each(function(){
		var val=this.getAttribute('title'),tip=this;
		if (typeof val == "object") return;
		this.setAttribute('title','');
		if(val!="" && val!=null){
			$(tip).bind("mouseover",function(){
				_b.innerHTML='<span style="font-size: 11px;color: #333333;">'+val+'</span>';
				_b.style.visibility = "visible";
				$(tip).bind('mousemove',function(e){
					with(_b.style){
						left=$.pointerX(e)+"px";
						top=($.pointerY(e)+20)+"px";
					}
				});
			});
			$(tip).bind('mouseout',function(){_b.style.visibility="hidden"});
			$(tip).bind('mousedown',function(){_b.style.visibility="hidden"});
		}
	});
}
addLoadExec("libTips();");
