(function(j){var O={saveSessUrl:"",saveRecentUrl:"",defaultTab:{url:"javascript:false",path:null},defaultTitle:"Untitled Tab",loaded:function(){},switched:function(){}},p={adder:"adder",closeOther:"close_other",leftbtn:"leftbtn",rightbtn:"rightbtn",tabList:"tab_list",iframeHolder:"iframe_div",hover:"hover",focus:"focus"},H=function(h,t){for(var m=0,u=0;u<h.length;u++){m+=h.charCodeAt(u)>255?2:1;if(m>t)break}if(m<=t)return h;for(t-=3;u--;){m-=h.charCodeAt(u)>255?2:1;if(m<=t)break}return h.substr(0,
u+1)+"..."},F=function(h){return h?h.indexOf("?")==0?location.protocol+"//"+location.host+location.pathname+h:h:location.protocol+"//"+location.host+location.pathname},S=j.browser.msie&&parseInt(j.browser.version)<8,x=function(){var h=document.createElement("div");return function(t){h.innerHTML=t;return j(h.firstChild)}}(),G=function(h,t,m){m=j.extend({},O,m||{});m.defaultTab.url=F(m.defaultTab.url);var u=t.empty(),k=x('<ul class="'+p.tabList+'"></ul>'),l=null,n={},r=[],T=this,B=x('<div class="'+
p.adder+'" title="&#x6DFB;&#x52A0;&#x65B0;&#x6807;&#x7B7E;"></div>').click(function(){var a=I(m.defaultTab.url,m.defaultTab.path);y(a,s)}),J=x('<div class="'+p.closeOther+'" title="&#x5173;&#x95ED;&#x5176;&#x5B83;&#x6807;&#x7B7E;&#x9875;"></div>').click(function(){confirm("\u786e\u5b9a\u5173\u95ed\u5176\u5b83\u6240\u6709\u6807\u7b7e\u9875\u5417\uff1f")&&U()}).dblclick(function(){return false}),C=0,P=function(a){var b=function(){if(!C){var c=a.pop();c===undefined||k.animate({left:c},"fast",b)}};b()},
v=x('<div class="'+p.leftbtn+'"></div>').hover(function(){k.stop(1);C=0;v.addClass(p.hover);var a=k.position().left,b=v.outerWidth();if(!(a>=b)){for(var c=k.children(),e=[],d=0,g=c.length;d<g;d++){var f=j(c[d]).position().left;if(f+a<b)e.push(b-f);else break}P(e)}},function(){C=1;v.removeClass(p.hover)}).dblclick(function(){return false}),w=x('<div class="'+p.rightbtn+'"></div>').hover(function(){k.stop(1);C=0;w.addClass(p.hover);var a=k.position().left,b=w.position().left;if(!(b>=k.outerWidth()+
a)){for(var c=k.children(),e=[],d=c.length;d-- >0;){var g=j(c[d]),f=g.position().left;g=g.outerWidth();if(f+g+a>b)e.push(b-f-g);else break}P(e)}},function(){C=1;w.removeClass(p.hover)}).dblclick(function(){return false}),D=0,E=function(a,b){b||(b=function(){});var c=a.position().left,e=k.position().left,d=D?v.outerWidth():0;if(c+e<d)k.animate({left:d-c},"fast",b);else{d=a.outerWidth();var g=D?w.position().left:h.innerWidth()-J.outerWidth();c+e+d>g?k.animate({left:g-c-d},"fast",b):b()}},z=function(){var a=
3;k.children().each(function(){a+=j.css(this,"width",false,"border")});k.css("width",a);a=k.outerWidth();var b=h.innerWidth()-J.outerWidth(),c=B.outerWidth();b-c>a?(w.hide(),v.hide(),B.css("left",a-3),D=0):(w.show(),v.show(),B.css("left",b-c),D=1)},s=function(){var a=k.outerWidth();if(D){var b=k.position().left,c=w.position().left,e;a+b<c?k.animate({left:c-a},"fast"):b>(e=v.outerWidth()-parseInt(k.css("padding-left")))&&k.animate({left:e},"fast")}else k.animate({left:0},"fast")};h.dblclick(function(){B.click()}).append(v).append(k).append(w).append(B).append(J);
var K=1,V=1,I=function(a,b,c){K++;var e=V++;c||(c=m.defaultTitle);a=F(a);var d=j("<li><span>"+H(c,19)+"</span></li>").hover(function(){j.className.add(this,p.hover)},function(){j.className.remove(this,p.hover)}).click(function(){T.switchTo(e)}).dblclick(function(i){i.preventDefault();i.stopPropagation();L(e)}).attr("url",a||"").attr("title",c||"").data("path",j.isArray(b)?[].concat(b):[]).data("tabguid",e);b=j(document.createElement("div")).hover(function(){j.className.add(this,p.hover)},function(){j.className.remove(this,
p.hover)}).click(function(i){i.stopPropagation();L(e)});d.append(b);var g=d.find("span");S?g.focus(function(){this.blur()}):g.css("outline","none");var f=x('<iframe src="'+a+'" width="100%" height="100%" frameborder="0"></iframe>');a=x('<div class="'+p.iframeHolder+'"></div>');var o={btn:d,iframe:f,holder:a};f.bind("load",function(){if(!f.data("toclose")){try{var i=f.doc()[0],q=f.win()[0];q&&(q.__ASSOC_TABID__=e);d.attr("url",q.location.href);if(i.title&&i.title.length){g.html(H(i.title,19));d.attr("title",
i.title)}else throw"no title";}catch(A){i=d.attr("url");g.html(H(i,19));d.attr("title",i)}z();e==l&&E(d);m.loaded(o)}});n[e]=o;r.unshift(e);k.append(d);u.append(a);z();return e},y=function(a,b){if(a==undefined||a=="last"){if(!r.length){z();return}a=r.pop()}else if(l&&a==l)return;else{var c=r.indexOf(a);if(c==-1)return;r.splice(c,1)}if(l){r.push(l);c=n[l];c.btn.removeClass(p.focus);c.holder.hide()}var e=n[a];e.btn.addClass(p.focus);z();E(e.btn,b);c=!e.init;e.init||setTimeout(function(){e.holder.append(e.iframe);
e.init=1},3);e.holder.show();l=a;m.switched(e);return c},Q=function(a,b,c){a.btn.data("path",j.isArray(c)?[].concat(c):[]).attr("url",b);a.iframe.attr("src",b)},L=function(a){if(a==undefined||a=="current"){if(!l)return;a=l}var b=n[a];if(b!=undefined){var c=b.btn.attr("title"),e=b.btn.attr("url"),d=function(){R(c,e);b.btn.remove();b.iframe.remove();b.holder.remove();delete b.btn;delete b.iframe;delete b.holder;delete b.init;delete n[a];K--;if(a==l){l=null;y(null,s)}else{z();l?E(n[l].btn,s):s();var i=
r.indexOf(a);i!=-1&&r.splice(i,1)}};if(b.init)try{var g=b.iframe,f=g[0].contentWindow;g.data("toclose",1);f.location="about:blank";f.tryclose||(g.bind("load",function(){g.data("toclose")&&setTimeout(d,0)}),f.tryclose=1)}catch(o){return d()}else d()}},M=1,U=function(){function a(g,f,o){R(f,o);g.btn.remove();g.iframe.remove();g.holder.remove();delete g.btn;delete g.iframe;delete g.holder;delete g.init;delete n[d];K--;if(--c==0){z();if(l){g=n[l];n={};n[l]=g;E(g.btn,s);r=[l]}else{n={};s();r=[]}M=1}}function b(g){var f=
n[g],o=f.btn.attr("title"),i=f.btn.attr("url");if(!f.init)return a(f,o,i);try{var q=f.iframe,A=q[0].contentWindow;q.data("toclose",1);A.location="about:blank";A.tryclose||(q.bind("load",function(){q.data("toclose")&&setTimeout(function(){a(f,o,i)},0)}),A.tryclose=1)}catch(W){return a(f,o,i)}}if(M){var c=0,e={};for(var d in n)d==l||(c++,e[d]=1);if(c){M=0;for(d in e)b(d)}}},N=function(a){a===undefined&&(a=l);return a&&n[a]},R=function(a,b){var c=m.defaultTab.url;b=F(b);b.substr(0,c.length)!=c&&j.post(m.saveRecentUrl,
{title:a,url:b})};this.initTabs=function(a){if(j.isArray(a)){for(var b={},c=0,e=0,d=0,g=a.length;d<g;d++){var f=a[d];if(!(!j.isArray(f)||f.length<4)){var o=parseInt(f[0]),i=j.trim(f[1]),q=f[2];f=f[3];o>c&&(c=o);o<e&&(e=o);i=i.length?i.split(","):[];b[o]=I(f,i,q)}}r=[];for(d=e;d<=c;d++)b[d]&&r.push(b[d]);y(null,s)}};window.onunload=function(){var a=[].concat(r);l&&a.push(l);for(var b=k.find("li"),c={},e=b.length,d=0,g=a.length;d<g;d++){var f=n[a[d]],o,i,q,A;f&&(q=f.btn)&&(i=b.index(q[0]))!=-1&&(o=
q.data("path")||"",A=q.attr("title")||"",c[i]=d+"#"+o+"#"+encodeURIComponent(A)+"#"+encodeURIComponent(f.iframe.attr("src")))}a=[];for(d=0;d<e;d++)c[d]&&a.push(c[d]);j.post(m.saveSessUrl,"data="+a.join("|"))};this.close=L;this.open=function(a,b,c){(a=j.trim(a)).length||(a="javascript:false");a=F(a);if(a!=m.defaultTab.url&&a!="javascript:false"){var e=k.find('li[url="'+a+'"]');if(e.length){b=e.data("tabguid");if(e=n[b]){y(b);return}}}if(b==undefined||b=="current")if(l){e=n[l];Q(e,a,c);return}if(typeof b==
"number")if(e=n[b]){y(b);Q(e,a,c);return}a=I(a,c);y(a,s)};this.get=N;this.reload=function(a){a=N(a);var b;a&&((b=a.iframe.win()[0])?b.location.reload():a.iframe.attr("src",a.btn.attr("url")))};this.switchTo=function(a){a!=l&&y(a)};this.adaptWidth=function(){z();k.stop(1);var a=N();a?E(a.btn,s):s()}};G.setClasses=function(h){h&&j.extend(p,h)};G.setConfigs=function(h){h&&j.extend(O,h)};j.tabview=G;j.fn.tabview=function(h){h||(h={});h=new G(this,j(this.attr("target")),h);this.data("tab",h);return h}})(jQuery);
