/**
 *远角面板
 * @author obj
 * @version 0.1
 */
;(function($) {
	$.fn.roundPanel = function(settings) {
		var defaults = {
			content:undefined,
			padding:false,
			width:80,
			height:40,
			fixed:false,
			img:"/static/images/com/panel.png|713|635|16",
			animate:true,
			hasCloseButton:true,
			closeButtonStyle:false,
			onclose:function() {return true;}
		};
		var _Panel = this;
		/*
		 * extends the jquery chain
		 * Construct
		 */
		this.each(function(){
			var ext = $(this);
			/**
			 * Init 
			 * @method
			 * @param 
			 */
			this.init = function () {
				var _self=this;
				this.innerContents=ext.children();
				//加载样式
				var styles='.infoPanel{float:left;position:absolute;}.infoPanel .c{overflow:hidden;z-index: 1;position:absolute;overflow:hidden;}.infoPanel .c img{position:absolute;}.infoPanel .cc{z-index: 2;position:absolute; left:10px; top:10px;}.roundPanelClose{z-index:10; right:10px; top:10px;position:absolute;width:12px;height:12px;background:url(/static/images/com/close.gif) 2px 2px no-repeat; cursor:pointer;}';
				Utils.addCss(styles,"resizePanelStyle");
				//加载样式 over
				var _self=this;
				var info=this.options.img.split("|");
				var tpl='<div class="infoPanel" ><div class="c"><img src="{src}" style="" style="left:0px top:0px;"/></div><div class="c w"><img src="{src}" style="left:-{cr};top:0px;"/> </div><div class="c wp"><img src="{src}" style="left:-{vr};top:0px;"/></div><div class="c h"><img src="{src}" style="left:0px ;top:-{cr};"/></div><div class="c h w"><img src="{src}" style="left:-{cr};top:-{cr};"/></div><div class="c h wp"><img src="{src}" style="left:-{vr};top:-{cr};"/></div><div class="c hp"><img src="{src}" style="left:0px;top:-{hr};"/></div><div class="c hp w"><img src="{src}" style="left:-{cr};top:-{hr};"/></div><div class="c hp wp"><img src="{src}" style="left:-{vr};top:-{hr};"/></div><div class="cc"></div></div>';
				tpl=tpl.replace(/{src}/g,info[0]);
				tpl=tpl.replace(/{vr}/g,window.parseInt(info[1])-window.parseInt(info[3])+"px");
				tpl=tpl.replace(/{hr}/g,window.parseInt(info[2])-window.parseInt(info[3])+"px");
				tpl=tpl.replace(/{cr}/g,info[3]+"px");
				var obj=$(tpl);
				if($.browser.msie && $.browser.version=="6.0"){
					function FixPng(img,w,h) {
						if(img && img.src.match(/\.png$/i) !=null){
							var src = img.src;
							img.style.width = w + "px";
							img.style.height = h + "px";
							img.style.filter ="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+src+"', sizingMethod='crop')";
							img.src = "/static/images/blank.gif";
						}
					}
					var imgs=obj.find("img");
					for (var i=0; i < imgs.length; i++){
						FixPng(imgs[i],info[1],info[2]);
					};
				}
				obj.appendTo(ext);
				if(this.options.content!=undefined){
					obj.find(".cc").empty().append(this.options.content);
					
				}else{
					if(this.innerContents.length!=0){
						obj.find(".cc").empty().append(_self.innerContents);
					}
				}
				_Panel.innerContent=_self.innerContents;
				var cnt=ext.find(".cc>div");
				var w=cnt.width();
				var h=cnt.height();
				if(this.options.width!=undefined){
					w=this.options.width;
				}
				if(this.options.height!=undefined){
					h=this.options.height;
				}
				var cr=window.parseInt(info[3]);
				this._cr=cr;
				obj.find(".c").css({width:cr,height:cr});
				
				if(!this.options.padding){
					this.options.padding=cr;
				}
				
				obj.find(".cc").css({
						left:_self.options.padding,
						top:_self.options.padding
					});
				obj.find(".w").css({
					width:w,
					left:cr
				});
				obj.find(".wp").css({
					left:w+cr
				});
				obj.find(".h").css({
					height:h,
					top:cr
				});
				obj.find(".hp").css({
					top:h+cr
				});
				obj.find(".cc").css({
					width:w,
					height:h
				});
				ext.css({
					width:w+2*cr,
					height:h+2*cr
				});
				obj.css({
					width:w+2*cr,
					height:h+2*cr
				});
				if(_self.options.hasCloseButton){
					var close=$('<div class="roundPanelClose"></div>').appendTo(obj).click(function(e) {
						try{
							e.cancelBubble =true;
							e.stopPropagation();
						}catch(e){}
						
						if(!_self.options.onclose()){
							return false;
						}
						ext.hide();
					});
					var st=_self.options.closeButtonStyle;
					 typeof st=="string" && close.addClass(st);
					 typeof st=="object" && close.css(st);
				}
				this.obj=obj;
			};
			// 调整大小 o:只传入内容块{$}
			//传入 o{int}:宽度 height{int}:高度
			//void
			this._resize=function(o,height) {
				var _self=this;
				var cr=this._cr;
				if(height==undefined){
					o.css({margin:0});
					var w=o.width();
					var h=o.height();
				}else{
					var w=o;
					var h=height;
				}
				var obj=ext.find(">div");
				var has=false;
				if(_self.options.animate){
					obj.find(".cc").animate({width:w});
					obj.find(".w").animate({width:w,left:cr},function(){
						v();
					});
					obj.find(".wp").animate({left:w+cr});
					function v(){
						if(has) return ;
						obj.find(".hp").not(".oc").animate({top:h+cr},function() {
							if(height==undefined)
							ext.find(".cc").empty().append(o.show());
						});
						obj.find(".cc").animate({height:h});
						ext.css({width:w+2*cr,height:h+2*cr});
						ext.find(".infoPanel").css({width:w+2*cr,height:h+2*cr});
						obj.find(".h").animate({height:h,top:cr});
						has=true;
					};
				}else{
					obj.find(".cc").css({width:w});
					obj.find(".w").css({width:w,left:cr});
					obj.find(".wp").css({left:w+cr});
					obj.find(".hp").not(".oc").css({top:h+cr});
					ext.find(".cc").empty().append(o.show());
					obj.find(".cc").css({height:h});
					ext.css({width:w+2*cr,height:h+2*cr});
					ext.find(".infoPanel").css({width:w+2*cr,height:h+2*cr});
					obj.find(".h").css({height:h,top:cr});
				}
			};
			this._close=function() {
				this.options.onclose();
			};
			//调整内容大小
			//w{int}:宽 ,h{int}:高
			//void
			
			this._resizeTo=function(w,h) {
				this._resize(w,h);
			};
			//设置内容 o:{$} is{anyValue}:是否根据内容自动调整大小
			this._setContent=function(o,is) {
				//var o=oj.clone();
				_Panel.innerContent=o;
				o.hide().appendTo('body');
				if(is==undefined){
					this._autoFit(o);
					return ;
				}
				ext.find(".cc").empty().append(o.fadeIn());
			};
			//根据内容调整大小 o{$}:内容块
			this._autoFit=function(o) {
				this._resize(o);
			};
			//继承参数列表
			this.options = $.extend({}, defaults, settings);
			this.init();
			return ext;
		});
		/**
		* external functions - append to $
		*/
		_Panel.setContent = function(o,is){ _Panel.each(function () {this._setContent(o,is); });};
	 	_Panel.resizeTo = function(w,h){_Panel.each(function () {this._resizeTo(w,h);});}; 
	 	_Panel.close = function(){_Panel.each(function () {this._close();});}; 
		return this;
	};
})(jQuery);
/**
 * 提示用户操作
 * @author 
 * @version $Rev$
 * @requires OtherClassName
 */
function tipBox(){
	this.msg='';
	this.preTimer=0;
	this.warn=function(w,s){
		this.cla="TipBoxWarn";
		this._show(w,s);
	};
	this.error=function(w,s){
		this.cla="TipBoxError";
		this._show(w,s);
	};
	this.info=function(w,s){
		this.cla="TipBoxInfo";
		this._show(w,s);
	};
	this.log=function(w,s){
		this.cla="TipBoxLog";
		this._show(w,s);
	};
	this.hide=function(){
		$("#tmp_tipBox").fadeOut();
	};
	this._show=function(w,s){
	    this.box && this.box.remove();
	    this.box=$('<div id="tmp_tipBox"><div class="content"></div></div>').appendTo("body").roundPanel({
	        animate:false,
	        hasCloseButton:true,
	        width:200,
	        height:120
		});
		this.box.setContent($("<div>"+w+"</div>"),false);
		this.box.hide()
		clearTimeout(tipBox.preTimer);
		this.box.attr('class','TipBoxNormal').addClass(tipBox.cla);
		this.box.show();
		tipBox.preTimer= setTimeout("tipBox.hide()",s);
	};
}
var tipBox=new tipBox();

function jsTrace (s) {
    console.info(s);
}


/* utils package */
function Utils() {
    this.initFootprintPopMap=function(o /*jQuery set*/) {
        if ($.fn.footprintPopMap) {
            init();
        }else{
            loadJS("/static/js/ext/footprint_popmap.js",function(){
                init();
            });
        }
        function init() {
            o.footprintPopMap({
                trackId:o.eq(0).attr("tripId")
            });
        }
    };
    this.successCallbackProxy=function(fn) {
        return function (result) {
            var action = result.action;
            if (!action) {
                alert("Server Error:ActionNotDefined");
                throw new Error('Server Error:ActionNotDefined');
                return ;
            }
            var data = action.data;
            var actionName = action.name;
            if (actionName == 'redirect') {
                window.location.href=data.url;
                return ;
            };
            fn && $.isFunction(fn) && fn(actionName,data);
        }
    }
    
    this.initFootprintCard = function(o) {
        this._initCard(o,{
            width:320,
            height:135,
            onInit:function(card,area) {
            },
            getUrl:function(o) {
                return "/footprint/" + o.attr('fid') + "/get_simple_ajax/?iframe=false&t=" + Utils.unid();
            },
            iframe:false
        });
    };
    
    this._initCard = function (o,opt) {
        if ($.infoCard) {
            o.infoCard(opt);
        }else{
            loadJS("/static/js/ext/infocard.js",function(){
                o.infoCard(opt);
            });
        }
    };
    
    this.initInforCard=function(o /*jQuery set*/) {
        function initCardEvent(card,area) {
            var img = $('<img class="follow" src="/static/images/infocard/uploading.gif" />');
            var complete = function () {
                img.hide().remove();
            }
            card.find('.cancel_follow a').click(function() {
                var btn = $(this).parent();
                btn.hide();
                img.appendTo(btn.parent());
                $.ajax({
                    url: "/follow/_delete/",
                    type: "post",
                    dataType: "json",
                    data: {touserid: area.attr("uid")},
                    complete:complete,
                    success: function(data) {
                        if (data) {
                            $(card.group).each(function() {
                                if ($(this).find('infoCard').attr("uid")==card.attr('uid')) {
                                    $(this).find('.add_follow').show();
                                    $(this).find('.cancel_follow').hide();
                                };
                            });
                        };
                    },
                    error: function() {
                        btn.show();
                    }
                });
                return false;
            });
            card.find('.add_follow a').click(function() {
                var btn = $(this).parent();
                btn.hide();
                img.appendTo(btn.parent());
                $.ajax({
                    url: "/follow/create/?t="+Utils.unid(),
                    type: "get",
                    dataType: "json",
                    data: {userid: area.attr("uid")},
                    complete:complete,
                    success: Utils.successCallbackProxy(function(action,data) {
                        switch (action){
                            case 'successful':
                                $(card.group).each(function() {
                                    if ($(this).find('infoCard').attr("uid")==card.attr('uid')) {
                                        $(this).find('.cancel_follow').show();
                                        $(this).find('.add_follow').hide();
                                    };
                                });
                                break;
                        }
                    }),
                    error: function() {
                        btn.show();
                    }
                });
                return false;
            });
        }
        this._initCard(o,{
                showCloseBtn:true,
                width:420,
                height:210,
                onInit:initCardEvent,
                getUrl:function(o) {
                    return "/infocard/" + o.attr('uid') + "/?iframe=false&t=" + Utils.unid();
                }
            });
    };
    
    this.unid = function() {
        return (new Date().getTime() + Math.random())*10000;
    };
    this.initFlashCopyButton=function(id) {
        /**
         * @param {String} id  - the button's id attr
         * @requires    id:         find the element
         * @requires    content:    find content to copy || relInputId:    input id related to the button
         * @requires    callback:   global function name {String}
         * @example: <input class="copyToClipBoard" id="btn_copy_link_to_clicpboard" content="text string" callback="aaa" />
         * @example: <input class="copyToClipBoard" id="btn_copy_link_to_clicpboard" relInputId="input_id_1" callback="aaa" />
         */
        var button = $("#"+id);
        var container = button.parent().css({position:'relative'});
        var div = $("<div></div>").css({
            position:   'absolute',
            cursor:     'pointer',
            overflow:   'hidden',
            width:      button.outerWidth(),
            height:     button.outerHeight(),
            top:        button.offset().top - container.offset().top ,
            left:       button.offset().left - container.offset().left
        });
    
        var text = $.trim(button.attr("content"));
        var callback = $.trim(button.attr("callback"));
        if (!text.length) {
            if (button.attr("relInputId")) {
                var rel = $.trim(button.attr("relInputId"));
                text = $("#"+rel).val();
            }else{
                throw new Error("relInputId or text Attribute must be set.");
            }
        }
        if (!callback) {
            callback = "__globalCopyCallback__";
        }
        if (typeof(window[callback])!="function"){
            throw new Error("callback must be a function");
        }
        text = $.trim(text);
        var flashvars = '';
            flashvars += 'id=' + id;
            flashvars += '&content=' + text;
            flashvars += '&callback=' + callback;
        
        div.appendTo(container);
        var flashStr = getFlashStr("/static/images/flash/copy.swf?"+Utils.unid(), id, "#ffffff",flashvars ,"transparent", button.outerWidth(),button.outerHeight(),"", true,false);
        div.html(flashStr);
    };
	this.getFlash=function(movieName) {
		/**
		 * @get a ref for flash
		 */
		if (navigator.appName.indexOf("Microsoft") != -1){
			return document.getElementById(movieName);
		}else{
			return document[movieName];
		}
	};
	this.copyToClipboard=function (txt) {
    	if(window.clipboardData){
    		window.clipboardData.clearData();
    		window.clipboardData.setData("Text", txt);
    	}
    	else if(navigator.userAgent.indexOf("Opera") != -1)
    	{
    		window.location = txt;
    	}
    	else if (window.netscape)
    	{
    		try {
    			netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
    		} catch (e) {
    			alert("当前浏览器无法自动复制到剪贴板\n请使用Ctrl+c快捷键手动复制");
    		}
    		var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
    		if (!clip){
    			return;
    		}
    		var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
    		if (!trans)
    		return;
    		trans.addDataFlavor('text/unicode');
    		var str = new Object();
    		var len = new Object();
    		var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
    		var copytext = txt;
    		str.data = copytext;
    		trans.setTransferData("text/unicode",str,copytext.length*2);
    		var clipid = Components.interfaces.nsIClipboard;
    		if (!clip)
    		return false;
    		clip.setData(trans,null,clipid.kGlobalClipboard);
    	}
    	tipBox.info("已经将内容复制到您的剪切板中..",5000);
    };
	this.addCss=function(sty,id) {
		/**
		 * add inline Css to head part
		 */
		if($("#"+id)[0]!=undefined)
		{
			return;
		}
		var styles=$('<style type="text/css" media="screen">'+sty+'</style>');
		if(id!=undefined)
		{
			var o=$("#"+id);
			if(o.length==0)
			{
				styles.attr("id",id);
				styles.appendTo("head");
			}
		}
		else
		{
			styles.appendTo("head");
		}
	};
	this.getModalOption=function(onClose){
	    var o={
	            mask: {
                    color: '#333333',
                    loadSpeed: 200,
                    opacity: 0.7
                },
                top : 'center',
                left : 'center',
                closeOnEsc:true,
                top:'30%',
                closeOnClick: false,
                onClose:onClose
            };
	    return o;
	};
}
var Utils=new Utils();
window.__globalCopyCallback__ = function() {
    tipBox.info("已成功复制当前内容到您的剪切板，粘贴按Control + V键.",5000);
}
/**
 * loading
 * @author obj
 * @version $Rev$
 * make a Div to Loading State
 * @requires $
 */
jQuery.fn.extend({
	loading:function() {
		return this.each(function() {
			var ext=$(this);
			var _self=this;
			var tpl=$('<div style="position:relative;"><div style="position:absolute"><img src="/static/images/com/loading.gif"/></div></div>').appendTo("body").hide();
			tpl.children().each(function() {
				$(this).css({
					left:(ext.width()-20)/2,
					top:(ext.height()-20)/2
				});
			}).show();
			ext.children(":visible").addClass("loading_").hide();
			tpl.appendTo(ext.show()).addClass("loadingFlag").show();
		});
	},
	stopLoading:function() {
		return this.each(function() {
			var ext=$(this);
			var _self=this;
			ext.children(".loading_").removeClass("loading_").show();
			ext.find(".loadingFlag").remove();
		});
	}
});
/* 
    break long words
 */
$(function() {
    function breakWord(dEl){
        if (!dEl || dEl.nodeType !== 1 ){
            return false ;
        } else if (dEl.currentStyle && typeof dEl.currentStyle.wordBreak === 'string' ){
            breakWord = function (dEl){
                dEl.runtimeStyle.wordBreak = 'break-all' ;
                return true ;
            }
            return breakWord(dEl);
        }else if (document .createTreeWalker){
            var trim = function   (str) {
                str = str.replace(/^\s\s*/ , '');
                var ws = /\s/ ,
                i = str.length;
                while (ws.test(str.charAt(-- i)));
                return str.slice(0 , i + 1 );
            }
            breakWord = function (dEl){
                //For Opera, Safari, and Firefox
                var dWalker = document .createTreeWalker(dEl, NodeFilter.SHOW_TEXT, null , false );
                var node,s,c = String .fromCharCode('8203' );
                while (dWalker.nextNode()){
                    node = dWalker.currentNode;
                    //we need to trim String otherwise Firefox will display
                    //incorect text-indent with space characters
                    s = trim( node.nodeValue ) .split('' ).join(c);
                    node.nodeValue = s;
                }
                return true ;
            }
            return breakWord(dEl);
        }else {
            return false ;
        }
    }
    var el=$(".richTextContainer11");
    for (var i=0; i < el.length; i++) {
        breakWord(el.eq(0)[0]);
    };
    /**
     * listsection stylesheet fix
     */
    $(".listSection").each(function() {
        $(this).find("ul li:last").css({borderWidth:0});
    });
    
});
function loadJS(url,callback,charset){
	var script = document.createElement('script');
	script.onload = script.onreadystatechange = function (){
		if (script && script.readyState && /^(?!(?:loaded|complete)$)/.test(script.readyState)) return;
		script.onload = script.onreadystatechange = null;
		script.src = '';
		script.parentNode.removeChild(script);
		script = null;
		callback && callback();
	};
	script.charset=charset || document.charset || document.characterSet;
	script.src = url;
	try {
	    document.getElementsByTagName("head")[0].appendChild(script);
    } catch (e) {
        
	}
}
// Flash Write
function getFlashStr (url,id,bg,vars,win,w,h,base,isWheel,inline) {
    var inline = inline ? 'inlineIcon' : '';
    var flashStr =
	"<div id='"+id+"_layer' class='" + inline +"' style='width:"+w+";height:"+h+";'>"+
	"<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,124,0' width='"+w+"' height='"+h+"' id='"+id+"' align='middle'>"+
	"<param name='allowScriptAccess' value='always' />"+
	"<param name='movie' value='"+url+"' />"+
	"<param name='base' value='"+base+"' />"+
	"<param name='FlashVars' value='"+vars+"' />"+
	"<param name='wmode' value='"+win+"' />"+
	"<param name='salign' value='lt' />"+
	"<param name='allowfullscreen' value='true' />"+
	"<param name='scale' value='noscale' />"+
	"<param name='quality' value='high' />"+
	"<param name='bgcolor' value='"+bg+"' />"+
	"<embed src='"+url+"' allowfullscreen='true' base='"+base+"' FlashVars='"+vars+"' wmode='"+win+"' quality='high' bgcolor='"+bg+"' width='"+w+"' height='"+h+"' name='"+id+"' align='middle' allowScriptAccess='always' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />"+
	"</object></div>";
	return flashStr;
}
function flashWrite(url,id,bg,vars,win,w,h,base,isWheel,inline){
    
	var flashStr=getFlashStr(url,id,bg,vars,win,w,h,base,isWheel,inline);
	document.write(flashStr);

	if(isWheel){
		flashId=id;
	}
}
//fix thumbnail
function fixThumbnail(area_class,w,h,boolean_show_url,boolean_out_box_exist){
	$("."+area_class+" img").each(function(){
		var img = $(this);
		function scale() {
			simple_image_fix($(this),w,h,boolean_out_box_exist,boolean_show_url);
			img.unbind("load",scale);
		}
		img.bind("load",scale);
		img.attr("src",img.attr('src'));
	});
	return false;
}

//simple image fix
function simple_image_fix(img_obj,w,h,boolean_out_box_exist,boolean_show_url){
	var img = img_obj;
	var _width = img.width();
	var _height = img.height();
	var zoom_w = _width > w ? w / _width : 1;
	var zoom_h = _height > h ? h / _height : 1;
	var zoom = Math.min(zoom_w, zoom_h);
	img.width(_width * zoom).height(_height * zoom);
	_height*zoom<h&&boolean_out_box_exist?img.css({"padding-top":((h-_height * zoom)/2)+"px"}):null;
	if(zoom_w!=1||zoom_h!=1){
		boolean_show_url?img.after("<div style='padding-left:10px'>原图地址：<a target='_blank' href='"+img.attr("src")+"'>点击查看</a></div>"):null;
	}
}

//convert a string with url href to a link
function c2href(href) {
        return '<a style="color:red" href="' + href +'">' + $.trim(href.length > 20 ? href : href.substring(0,5)) + '</a>';
}
function href2link(str) {
    return str;
    var out = str;
    var r1 = /(href|src)\s*=\s*['"]\s*http:\/\/[^>"\s]+/;
    var r2 = /http:\/\/[^>"\s]+/;
    var spac1 = "{{||}}";
    var spac2 = "{{==}}";
    var list1 = [];
    var list2 = [];
    var list2n = [];
    
    
    function _store(spac,reg) {
        var rs=null;
        var list=[];
        while(1){
            rs = out.match(reg);
            if (rs) {
                list.push(rs[0]);
                out = out.replace(rs[0],spac);
            }else{
                break;
            }
        }
        return list;
    }
    function _restore(list,spac) {
        var str = null;
        while(1){
            str = list.shift();
            if (str) {
                out = out.replace(spac,str)
            }else{
                break;
            }
        }
        return out;
    }
    
    list1 = _store(spac1,r1);
    list2 = _store(spac2,r2);
    for (var i=0; i < list2.length; i++) {
        list2n.push(c2href(list2[i]));
    };
    _restore(list1,spac1);
    _restore(list2n,spac2);
    return out;
}
/**
 * disable mousewheel on flash
 */
function disableFlashMouseWheel (id) {
    return 0;
    var f = Utils.getFlash(id);
    if (!f)
        return ;
    var types = ['DOMMouseScroll', 'mousewheel'];
    var handler = function(e) {
        e.preventDefault();
	    e.stopPropagation();
        return false; 
    }
    if ( f.addEventListener ){
		for ( var i=types.length; i; )
			f.addEventListener( types[--i], handler, false );
    }else{
        f.onmousewheel = function() {
            return false;
        };
    }
}

function TitleTiper(){
    var _self = this;
    var _title = document.title;
    var _text,_speed;
    var isPlaying = false,showDefault =false;
    var timer = null;
    var fn = null;
    function start() {
        clearTimeout(timer);
        isPlaying=true;
        setTitle();
    };
    function getEmptyTitle(str) {
        var s = "【";
        for (var i=0; i < str.length; i++) {
            s+="　";
        };
        s += "】";
        return s
    }
    
    function setTitle(){
        if (isPlaying) {
            if (showDefault){
                document.title = "【"+_text+"】" + _title;
                showDefault=false;
            }else{
                document.title = getEmptyTitle(_text)+_title;
                showDefault=true;
            }
            fn && fn(showDefault);
            timer = setTimeout(function() {
                setTitle();
            },_speed);
        }
    }
    this.stop = function() {
        isPlaying=false;
        title.text(_title);
    };
    this.tip = function(text,callback,speed) {
        _text = text;
        fn = callback;
        _speed = speed || 1000;
        start();
    };
}
TitleTiper = new TitleTiper();


