if(typeof(show8) != "object") {var show8 = {version: "1.00"};}
String.prototype.substr2=function(a,b){var s = this.replace(/([^\x00-\xff])/g,"\x00$1");return(s.length<b)?this:s.substring(a,b).replace(/\x00/g,'');}
$.extend(show8, {
	uid: null,
	nick: null,
    sid:null,
	path: "http://8.show.sina.com.cn/",
    saveVisted: function(){
        var sids = show8.getCookie("vistedSpace");
        var newSids = new Array();
        if (show8.sid){
            newSids[0] = show8.sid;
            if (sids){
                sids = decodeURIComponent(sids);
                sids=sids.split(',');
                for (i=0;i<sids.length;i++){
                    if (sids[i] != show8.sid){
                        newSids[newSids.length] = sids[i]
                    }
                }
            }
            newSids = newSids.slice(0,6);
            show8.setCookie("vistedSpace", newSids.join(','),{hoursToLive : 24*30,domain:'8.show.sina.com.cn'});
        }
    },
    getVisted:function(){
        var sids = show8.getCookie("vistedSpace");
        if (sids.length){
            sids = decodeURIComponent(sids);
            $("#visted").load(show8.path+"room/visited.php",{'sids':sids});
        }
    },
    spaceClick: function (sid,obj,act){
        new $.ajax({
            url: show8.path+"room/click.php",
            type: "post",
            data: "sid=" + sid + "&act=" + act,
            error: function() {
                alert("数据库忙，请你稍后再试！");
            },
            success: function(t) {
                t = eval("(" + t + ')');
                alert(t.info);
                if (t.result == "succ") {
                    obj.html(1+parseInt(obj.html()));
                }
            }
        });
    },
    checkLogin: function (){
        new $.ajax({
            url: show8.path+"checkLogin.php",
            type: "get",
            success: function(t) {
                show8.login.loginStatus();
            }
        });
    },
    cookieOptions: function(options){
        var defaultOptions={hoursToLive:null,path:'/',domain:null,secure:false};
        var curOptions;
        var ret = '';
        if (typeof options !=='object' || options === null){
            curOptions = defaultOptions;
        }else{
            curOptions = options;
        }
        if (typeof curOptions.hoursToLive==='number'){
            var dateObject=new Date()
            dateObject.setTime(dateObject.getTime()+(curOptions.hoursToLive*60*60*1000));
            ret += 'expires='+dateObject.toGMTString()+';';
        }
        cookiePath = curOptions.path?curOptions.path:"/";
        ret  += 'path='+cookiePath+';';
        if (typeof curOptions.domain==='string'){
            ret += 'domain='+curOptions.domain+';';
        }
        if (curOptions.secure===true){
            ret += 'secure;';
        }
        return ret;
    },
    setCookie:function(cookieKey,cookieValue,options) {
        var cookieOptions = show8.cookieOptions(options);
        document.cookie = cookieKey + "=" + encodeURIComponent(cookieValue) + ";" + cookieOptions;
    },
    getCookie:function(a) {
        var b;
        b = a + "=";
        offset = document.cookie.indexOf(b);
        if (offset != -1) {
            offset += b.length;
            end = document.cookie.indexOf(";", offset);
            if (end == -1) {
                end = document.cookie.length;
            }
            var ret = document.cookie.substring(offset, end);
            try {
               ret = decodeURIComponent(ret);
            }catch(e){}
            return ret;
        } else {
            return '';
        }
    },
    delCookie:function(cookieKey,options) {
        var curOptions = options;
        if (curOptions.hoursToLive) curOptions.hoursToLive = 0;
        var cookieOptions = show8.cookieOptions(options);
        document.cookie = cookieKey + "=; "+ cookieOptions;
    }
});

show8.myDialog = {};
$.extend(show8.myDialog,{
    toggle : function (obj){
        if (obj.css("display") == 'block'){
            this.hide(obj);
        }else{
            this.show(obj);
        }
    },
    show:function(obj){
        if (!this.overlay){
            var overlay = $("#mask");
            if (overlay.length > 0){
                this.overlay = $(overlay[0]);
            }else{
                var overlayWidth = this.overlayWidth();
                var overlayHeight = this.overlayHeight();
                this.overlay = $('<div id="mask"></div>').appendTo(document.body)
                    .addClass('mask').css({
                        width: overlayWidth,
                        height: overlayHeight
                    });
                //this.overlay.bgiframe();
            }
        }
        var zIndex = this.overlay.css("zIndex");
        obj.css({"zIndex":zIndex+1,"position":"absolute"});
        obj.show();
        this._position(obj,'center');
        this.overlay.show();
        $(window).scroll(function () {
			show8.myDialog._position(obj,'center');
		});
        $(window).resize(function () {
			show8.myDialog._position(obj,'center');
            show8.myDialog.overlayResize();
		});
    },
    hide:function(obj){
        obj.hide();
        if (this.overlay) this.overlay.hide();
    },
    _position: function(obj,pos) {
		var wnd = $(window), doc = $(document),
			pTop = doc.scrollTop(), pLeft = doc.scrollLeft(),
			minTop = pTop;

		if ($.inArray(pos, ['center','top','right','bottom','left']) >= 0) {
			pos = [
				pos == 'right' || pos == 'left' ? pos : 'center',
				pos == 'top' || pos == 'bottom' ? pos : 'middle'
			];
		}
		if (pos.constructor != Array) {
			pos = ['center', 'middle'];
		}
		if (pos[0].constructor == Number) {
			pLeft += pos[0];
		} else {
			switch (pos[0]) {
				case 'left':
					pLeft += 0;
					break;
				case 'right':
					pLeft += wnd.width() - obj.outerWidth();
					break;
				default:
				case 'center':
					pLeft += (wnd.width() - obj.outerWidth()) / 2;
			}
		}
		if (pos[1].constructor == Number) {
			pTop += pos[1];
		} else {
			switch (pos[1]) {
				case 'top':
					pTop += 0;
					break;
				case 'bottom':
					pTop += wnd.height() - obj.outerHeight();
					break;
				default:
				case 'middle':
					pTop += (wnd.height() - obj.outerHeight()) / 2;
			}
		}

		// prevent the dialog from being too high (make sure the titlebar
		// is accessible)
		pTop = Math.max(pTop, minTop);
		obj.css({top: pTop, left: pLeft});
	},
    overlayHeight: function() {
		// handle IE 6
		if ($.browser.msie && $.browser.version < 7) {
			var scrollHeight = Math.max(
				document.documentElement.scrollHeight,
				document.body.scrollHeight
			);
			var offsetHeight = Math.max(
				document.documentElement.offsetHeight,
				document.body.offsetHeight
			);

			if (scrollHeight < offsetHeight) {
				return $(window).height() + 'px';
			} else {
				return scrollHeight + 'px';
			}
		// handle "good" browsers
		} else {
			return $(document).height() + 'px';
		}
	},

	overlayWidth: function() {
		// handle IE 6
		if ($.browser.msie && $.browser.version < 7) {
			var scrollWidth = Math.max(
				document.documentElement.scrollWidth,
				document.body.scrollWidth
			);
			var offsetWidth = Math.max(
				document.documentElement.offsetWidth,
				document.body.offsetWidth
			);

			if (scrollWidth < offsetWidth) {
				return $(window).width() + 'px';
			} else {
				return scrollWidth + 'px';
			}
		// handle "good" browsers
		} else {
			return $(document).width() + 'px';
		}
	},

	overlayResize: function() {
		/* If the dialog is draggable and the user drags it past the
		 * right edge of the window, the document becomes wider so we
		 * need to stretch the overlay. If the user then drags the
		 * dialog back to the left, the document will become narrower,
		 * so we need to shrink the overlay to the appropriate size.
		 * This is handled by shrinking the overlay before setting it
		 * to the full document size.
		 */
		this.overlay.css({
			width: 0,
			height: 0
		}).css({
			width: this.overlayWidth(),
			height: this.overlayHeight()
		});
	}
});
show8.login = {
	panel: null,
	title: null,
	ide: null,
	ideflag: false,
	iusername: null,
	ipsw: null,
	iide: null,
	ialert: null,
	remember: null,
    itext:'请输入VV号'
};
$.extend(show8.login, {
	login_check: function() {
		var username = $.trim(this.iusername.val());
        if (username.length == 0 || username == this.itext) {
			this.ialert.html("请输入用户名");
			this.iusername.val("");
			this.iusername.focus();
            //this.iblur();
			return false;
		}
		if ($.trim(this.ipsw.val()).length == 0) {
			this.ialert.html("请输入密码");
			this.ipsw.val("");
			this.ipsw.focus();
			return false;
		}
		if (this.ideflag) {
			if ($.trim(this.iide.val()).length == 0) {
				this.ialert.html("请输入验证码");
				this.iide.val("");
				this.iide.focus();
				return false;
			}
		}
		return true;
	},
	login_submit: function() {
		var self = this;
		if (this.login_check()) {
			var username = this.iusername.val();
			var psw = this.ipsw.val();
			var ide_code = "";
			if (this.ideflag) {
				ide_code = "&ide=" + this.iide.val();
			}
            self.ialert.html("登录中...");
			new $.ajax({
				url: show8.path+"ajaxLogin.php",
				type: "post",
				data: "uid=" + encodeURIComponent(username) + "&psw=" + encodeURIComponent(psw) + ide_code,
				error: function() {
					self.ialert.html("连接超时！");
				},
				success: function(t) {
					try{
                        t = eval("(" + t + ')');
                        if (t.type == "1") {
                            self.remember_me();
                            self.hide();
                            self.clear();
                            setTimeout(self.loginStatus,0);
                        }else if (t.type == "2") {
                            self.ialert.html(t.mess);
                            self.ipsw.val("");
                            self.iide.val("");
                            self.ipsw.focus();
                        }else if (t.type == "3") {
                            self.ialert.html(t.mess);
                            self.ide.show();
                            self.ideflag = true;
                            self.ipsw.val("");
                            self.iide.val("");
                            self.ipsw.focus();
                            try {
                                reGetImg();
                            }catch (e) {}
                        }
                    }catch (e){
                        self.ialert.html("登录失败！");
                    }
				}
			});
		}
	},
	remember_me: function() {
		if (this.remember[0].checked) {
			if (this.iusername.val() != "") show8.setCookie("SUID", $.trim(this.iusername.val()),{hoursToLive : 72,domain:'8.show.sina.com.cn'});
		}else {
			show8.delCookie("SUID",{domain:'8.show.sina.com.cn'});
		}
	},
    ifocus: function() {
        if (this.iusername.val() == this.itext) {
            this.iusername.val("");
            this.iusername.select();
        }
        this.iusername.css("color","#000000");
    },
	iblur: function() {
		if ($.trim(this.iusername.val()) == "") {
			this.ialert.html("请输入您的用户名");
            this.iusername.val(this.itext);
            this.iusername.css("color","#CCCCCC");
		}
	},
	clear: function() {
		this.iusername.val("");
		this.ipsw.val("");
		this.iide.val("");
	},
	hide: function() {
		this.ialert.html("");
		this.clear();
		show8.myDialog.hide(this.panel);
	},
	show: function(mess) {
		mess = mess || "登录";
		this.title.html(mess);
		show8.myDialog.show(this.panel);
        var username = show8.getCookie("SUID");
        if (username){
            this.iusername.val(username);
            this.remember[0].checked = true;
            this.ipsw.focus();
        }else{
            this.iusername.focus();
            this.remember[0].checked = false;
        }
	},
	toggle: function() {
		if (this.loginStatus()){
            this.hide();
        }else{
            if (this.panel.css('display') == 'block') {
                this.hide();
            }else {
                this.show();
            }
        }
	},
	init: function() {
        //alert("a");
		var self = this;
		this.panel = $("#login");
		this.title = $("#login_title");
		this.ide = $("#ide_box");
		this.iusername = $("#username");
		this.ipsw = $("#psw");
		this.iide = $("#ide");
		this.ialert = $("#ialert");
		this.remember = $("#remember");
        
		this.iusername.keydown(function(e) {
			e = e || window.event;
			if(e.keyCode == 13) self.login_submit();
		});
		this.ipsw.keydown(function(e) {
			e = e || window.event;
			if(e.keyCode == 13) self.login_submit();
		});
		this.iide.keydown(function(e) {
			e = e || window.event;
			if(e.keyCode == 13) self.login_submit();
		});
        this.iusername.focus(function() {
			self.ifocus();
		});
		this.iusername.blur(function() {
			self.iblur();
		});
        if (this.ideflag) {
            this.ide.show();
        }
	},
    loginStatus: function(){
        var a=show8.getCookie("SU");
        var b=a.split(":");
        if(b.length==1) b=a.split("%3A");
        var c;
        if(b.length>1){
            a=decodeURI(b[3]);
        }
        c = "";
        //alert(a);
        if(a!=""&&a!="null"&&a!=null&&a!="undefined"){
            if(a.length>8){
                c=a;
                a=a.substr2(0,6);
                a+=".."
                a = '<span title="'+c+'">'+a+'</span>';
            }
            
            $("#loginDiv").hide();
            $("#logoutDiv").show();
            $("#wellcome").show();
            $("#wellcome").html('欢迎，'+a);
            return true;
        }else{
            $("#loginDiv").show();
            $("#logoutDiv").hide();
            $("#wellcome").hide();
            return false;
        }
    },
    logout: function(){
        show8.login.clearCookie();
        //this.loginStatus();
        document.location.href = 'http://8.show.sina.com.cn';
    },
    clearCookie: function(){
        var options = {'path':'/','domain':'sina.com.cn'};
        show8.delCookie("SE",options);
        show8.delCookie("SU",options);
        show8.delCookie("SUP",options);
        show8.delCookie("SCT",options);
        show8.delCookie("SA",options);
        show8.delCookie("PS",options);
        if( show8.getCookie("SINAPRO") != "" && show8.getCookie("SINAPRO") != null){ //清查旧版Cookie
            show8.delCookie("SINAPRO",options);
            show8.delCookie("SINA-AVATAR",options);
            show8.delCookie("SINAPROC",options);
            show8.delCookie("nick",options);
            show8.delCookie("SINA_NU",options);
            show8.delCookie("SINA_OU",options);
            show8.delCookie("appmask",options);
            show8.delCookie("gender",options);
            show8.delCookie("UNIPROTM",options);
            show8.delCookie("UNIPROU",options);
            show8.delCookie("SINA_USER",options);
            show8.delCookie("SMS_COOKIE",options);
        }
    }
});

show8.subNav = {};
$.extend(show8.subNav,{
    select:function(sub) {
        $("#subnav li").removeClass('achor');
        $("#"+sub).addClass('achor');
    }
});



