// FlyTabs version 1.01 - 04/12/2009
// Copyright © Milan Adamovsky
// E-mail  : milan@adamovsky.com   
// Website : http://www.adamovsky.com/flytabs                                 
// License : Must give credit to use in any way (e.g. commercially, personally, academically).
// I kept the notice short so you will keep this notice in here. Thanks!

(function(f){var p=new Object();if(!p.tabs){p.tabs=new Object()}if(!p.core){p.core=new Object()}var t="";var i="";var r=f.prototype.init;f.prototype.init=function(w,x){var y=r.apply(this,arguments);if(w&&w.selector){y.context=w.context,y.selector=w.selector}if(typeof w=="string"){y.context=x||document,y.selector=w;i=y.selector}return y};f.prototype.init.prototype=f.prototype;f.fn.flyTabs={config:function(w){t=i;return h(w)},addTab:function(w){t=i;return d(w)},clearTabs:function(w){t=i;return c(w)},countTabs:function(w){t=i;return n(w)},getTab:function(w){t=i;return v(w)},pinTab:function(w){t=i;return q(w)},removeTab:function(w){t=i;return m(w)}};f.fn.flyTabs.delTab=f.fn.flyTabs.removeTab;f.fn.flyTabs.deleteTab=f.fn.flyTabs.removeTab;f.fn.flyTabs.remTab=f.fn.flyTabs.removeTab;function j(w){f(w).each(function(){var y="#"+this.id+" li a";x(this,y,w)});function x(B){if(document.getElementById(B.id+"_wrapper")){return(0)}var A=e();var z=B.id;if(!(document.getElementById(z+"_wrapper"))){f(B)["after"]('<div id="'+z+'_wrapper" class="fly_wrapper"><div id="'+z+'_content" class="fly_content" style="display:block"></div></div>')}var D=parseInt(f("#"+z+"_content").css("padding-top"))+parseInt(f("#"+z+"_content").css("padding-bottom"))+parseInt(f("#"+z+"_content").css("height"));var C=parseInt(f("#"+z+"_wrapper").css("height"));var y=parseInt(f("#"+z+"_wrapper").css("min-height"));p.core["initHeight"]=C==D?null:C;p.core["minHeight"]=y;if(A.html){if(!f.browser.msie){f("#"+z+"_wrapper").css({overflow:"auto"})}f("#"+z+"_content").html(A.html)}}return(w)}function h(x){var w=f(t).data("config");if(w){alert("Config has already been defined for "+t)}var y=f.extend({align:"top",effect:"yes",html:""},x);f(t).data("config",y);return(y)}function g(y,x){var w=e();switch(w.align){case ("left"):b({level:y,index:x});break;default:a({level:y,index:x});break}}function k(y){var x=e();var w=y.tabsId;if(x.html&&!f.browser.msie){if(!p.core["minHeight"]){f("#"+w+"_wrapper").css({"min-height":((p.core["initHeight"]||o("scrollHeight"))+(f.browser.msie?7:2))+"px","margin-left":f("#"+w).width()+parseInt(f("#"+w).css("padding-left"))+parseInt(f("#"+w).css("padding-right"))+"px"})}}else{f("#"+w+"_wrapper").css({height:((p.core["initHeight"]||o("scrollHeight"))+(f.browser.msie?7:2))+"px","margin-left":f("#"+w).width()+parseInt(f("#"+w).css("padding-left"))+parseInt(f("#"+w).css("padding-right"))+"px"})}if(f.browser.msie){f("#"+w+"_wrapper").css({left:"-3px"})}else{s(y)}}function s(x){var w=x.tabsId;var y=f("#"+w).width()-parseInt(f("#"+w).css("padding-left"));f("#"+w+" li").each(function(){var z=parseInt(f(this).css("padding-left"))+parseInt(f(this).css("padding-right"));var B=parseInt(f(this).css("left"));var A=(y-f(this).width()-z+1);if(A>0){f(this).css({left:B>A?B:A})}})}function b(z){var A=z.level;var y=z.index;var x=f(t);var w=p.tabs[t][y];x.each(function(){var F=new l({tabs:"#"+this.id});var H=this.id;var C;if(w){C=w.id;F.setTab("#"+w.id)}switch(A){case (1):default:k({tabsId:H});f("#"+H).css({margin:"0px","padding-left":"5px","float":"left",textAlign:"right"});f("#"+H+" li").css({"border-right":"0px","margin-top":"0px"});var G=parseInt(f("#"+H+" li").width());var J=parseInt(f("#"+H+" li").height());if(f.browser.msie){var D=parseInt(f("#"+H+" li").css("borderRight"))||0;var B=parseInt(f("#"+H+" li").css("borderLeft"))||0;var E=parseInt(f("#"+H+" li").css("paddingRight"))||0;var I=parseInt(f("#"+H+" li").css("paddingLeft"))||0;f("#"+H+" li").css({"border-top-width":"1px"});G=G+E+I+B+D}f("#"+H+" li").css({height:J+"px",width:G+"px"});f("#"+H+" li").css({"margin-bottom":(f.browser.msie?2:3)+"px"});f("#"+H+" li").css({display:"block","margin-bottom":(f.browser.msie?2:3)+"px"});f("#"+H+" .tabOn").css({left:"1px","padding-top":"0px",top:(f.browser.msie?1:1)+"px"});f("#"+H+" .tabOff").css({left:"0px",top:"1px"});f("#"+H+" .tabOff a").css({display:"block"});break;case (2):var G=parseInt(f("#"+C).width());var J=parseInt(f("#"+C).height());f("#"+C+"Img").load(function(){imgHeight=this.height;imgWidth=this.width;var K=parseInt((imgHeight/2)-(J/2));K=K<0?(J>0?(J/4):0):K;if(f.browser.msie){f("#"+C).css({height:(imgHeight+2)+"px",overflow:"hidden"})}f("#"+C).css({width:(G+(f.browser.msie?imgWidth:0))+"px",position:"relative","padding-top":K+"px","padding-bottom":K+"px","padding-left":imgWidth+"px"});k({tabsId:H})});f("#"+C+"Img").css({display:"none"});break;case (3):break;case (4):break;case (5):f("#"+C).css({left:(F.tab.css.left()+1)+"px"});break;case (6):f("#"+C).css({left:(F.tab.css.left()-1)+"px"});break;case (7):break}k({tabsId:H})})}function l(y){var w=y.tabs||"";var x=y.tab||"";this.setTabs=function(z,A){if(!z){return(0)}A=A||this;A.tabs=new Object();A.tabs.id=z;A.tabs.offset=new Object();A.tabs.offset.left=function(){return(f(A.tabs.id).offset().left)};A.tabs.top=function(){return(f(A.tabs.id).offset().top)};A.tabs.css=new Object();A.tabs.css.left=function(){return(parseInt(f(A.tabs.id).css("left"))||0)};A.tabs.css.top=function(){return(parseInt(f(A.tabs.id).css("top"))||0)};A.tabs.height=function(){return(f(A.tabs.id).height())};A.tabs.bottom=function(){return(A.tabs.top()+A.tabs.height())};A.tabs.wrapper=new Object();A.tabs.wrapper.id=A.tabs.id+"_wrapper";A.tabs.wrapper.original=new Object();A.tabs.wrapper.original.css=new Object();A.tabs.wrapper.original.css.borderTopWidth=function(){return(parseInt(f(A.tabs.wrapper.id).css("border-top-width")))};A.tabs.wrapper.original.offset=new Object();A.tabs.wrapper.original.offset.top=function(){return(f(A.tabs.wrapper.id).offset().top)};A.tabs.wrapper.original.top=function(){return(A.tabs.wrapper.original.offset.top()+A.tabs.wrapper.original.css.borderTopWidth())};A.tabs.wrapper.original.difference=function(){return(A.tabs.wrapper.original.top()-A.tabs.bottom())}};this.setTab=function(z,A){if(!z){return(0)}A=A||this;A.tab=new Object();A.tab.id=z;A.tab.height=function(){return(parseInt(f(A.tab.id).height()))};A.tab.offset=new Object();A.tab.offset.left=function(){return(f(A.tab.id).offset().left)};A.tab.offset.top=function(){return(f(A.tab.id).offset().top)};A.tab.original=new Object();A.tab.original.css=new Object();A.tab.original.css.left="";A.tab.css=new Object();A.tab.css.left=function(){var B=(parseInt(f(A.tab.id).css("left"))||0);A.tab.original.css.left=A.tab.original.css.left!=""?A.tab.original.css.left:B;return(B)};A.tab.css.top=function(){return(parseInt(f(A.tab.id).css("top"))||0)};A.tab.css.marginLeft=function(){return(parseInt(f(A.tab.id).css("margin-left"))||0)};A.tab.css.paddingLeft=function(){return(parseInt(f(A.tab.id).css("padding-left"))||0)};A.tab.css.paddingTop=function(){return(parseInt(f(A.tab.id).css("padding-top"))||0)};A.tab.css.paddingBottom=function(){return(parseInt(f(A.tab.id).css("padding-bottom"))||0)};A.tab.css.borderTopWidth=function(){return(parseInt(f(A.tab.id).css("border-top-width"))||0)};A.tab.css.borderBottomWidth=function(){return(parseInt(f(A.tab.id).css("border-bottom-width"))||0)};A.tab.full=new Object();A.tab.full.left=function(){return(A.tab.css.left())};A.tab.full.height=function(){return(A.tab.height()+A.tab.css.paddingTop()+A.tab.css.paddingBottom()+A.tab.css.borderTopWidth()+A.tab.css.borderBottomWidth())};A.tab.bottom=function(){return(A.tab.offset.top()+A.tab.full.height())}};if(w){this.setTabs(w,this)}if(x){this.setTab(x,this)}return(this)}function a(A){function z(){var E="";for(var C in p.tabs){if(f(C+"_wrapper").offset()!=undefined){var D=e(C);if(D.align=="top"||D.align==""){var G=new l({tabs:C});var F=G.tabs.wrapper.original.difference();if((E!="")&&(F!=E)){f(G.tabs.id).css({top:(G.tabs.css.top()+(F-E)+((f.browser.mozilla&&(f.browser.version.substr(0,3)=="1.9"))?-2:0))+"px"})}E=F}}}}var B=A.level;var y=A.index;var x=f(t);var w=p.tabs[t][y];z();x.each(function(){var I=new l({tabs:"#"+this.id});var J=I.tabs.bottom();var E,D;if(w){D=w.id;I.setTab("#"+w.id);E=I.tab.css.top()}switch(B){case (1):var F=I.tab.css.borderBottomWidth();f("#"+D).css({"border-bottom":"none"});f("#"+D).css({top:(E+F)+"px"});break;case (2):var G=I.tab.height();var C=f(this).find("img").height();var H=I.tab.bottom();f("#"+D+"Img").load(function(){C=this.height;imgWidth=this.width;var M=parseInt((C/2)-(G/2));M=M<0?(G>0?(G/4):0):M;f("#"+D).css({position:"relative","padding-top":M+"px","padding-bottom":M+"px"});if(f.browser.msie){var N=((C/2)-(f("#"+D+" a").height()/2));f(this).css({top:N+"px"});f(this).css({display:"none"});f("#"+D).css({height:(C+2)+"px",overflow:"hidden"});f("#"+D+" a").css({"padding-left":C+"px"});f("#"+D).css({top:(I.tab.css.top()-E)+"px"});f("#"+D).css({"border-bottom":"none"})}else{f("#"+D).css({"border-bottom":"none"});var L=I.tabs.bottom()-J;var K=H-I.tab.bottom()+E+L;f("#"+D).css({top:K+"px"})}});break;case (3):break;case (4):break;case (5):if(w.icon){f("#"+D).css({top:(I.tab.css.top()+1)+"px"});f("#"+D).addClass("tabOn")}else{f("#"+D).css({top:(I.tab.css.top()+1)+"px"})}break;case (6):f("#"+D).css({top:(I.tab.css.top()-1)+"px"});break;case (7):if(w.icon){f("#"+D+"Img").load(function(){f("#"+D).css({top:(I.tab.css.top()+1)+"px"})})}else{f("#"+D).css({top:(I.tab.css.top()+1)+"px"})}break;default:break}})}function o(x,z){var w=z||t;var y=0;f(w).each(function(){y+=this[x]});return(y)}function e(w){w=w||t;var x=f(w).data("config");if(!x){x=f(w).flyTabs.config()}return(x)}function d(x){j(t);var w=f(t);w.each(function(){var z=f(this).children();var C=x?(x.index||z.length):z.length;var B="#"+this.id+" li";var E=f.extend({caption:"tabName"+C,id:this.id+"-tabID"+C,html:"Tab "+C,index:C,status:"off",icon:null,code:function(){},url:"#"},x);if(!p.tabs[t]){p.tabs[t]=new Array()}p.tabs[t][C]=E;var y=z.get(E.index);var A=E.status=="on"?"On":"Off";var D=E.icon?'<img id="'+E.id+'Img" src="'+E.icon+'" />':"";if(y){f('<li id="'+E.id+'" class="tab'+A+'"><a href="javascript:return(false);" xhref="'+E.url+'">'+D+E.caption+"</a></li>").insertBefore(y);u(this,B,t)}else{f('<li id="'+E.id+'" class="tab'+A+'"><a onclick="return(false);" href="javascript:return(false);" xhref="'+E.url+'">'+D+E.caption+"</a></li>").appendTo(this);u(this,B,t)}if(D){f("#"+E.id).css({"background-image":"url('"+f("#"+E.id+"Img").attr("src")+"')","background-repeat":"no-repeat"});g(2,C)}else{g(1,C)}if(E.status=="pinned"){f(t).flyTabs.pinTab({index:C,defined:1})&&f(t).flyTabs.getTab(C)}});g();return(f(t))}function c(w){var x=t+" li";f(x).each(function(){var y=f(x).index(this);if(f(this).attr("defaultClass")){f(this).removeAttr("defaultClass")}if(f(this).hasClass("tabPinned")){g(6,y);f(this).removeClass("tabPinned");f(this).addClass("tabOff")}if(f(this).hasClass("tabOn")){f(this).addClass("tabOff");f(this).removeClass("tabOn");g(3,y)}});return(f(t))}function n(w){var x=t+" li";return f(x).length}function v(x){var y=e();function z(C){var E=C.data;var F=C["this"];var D=C.parentThis;var B=C.index;if(E.url=="#"){f(F).html(E.html);if(f.browser.msie){f(F).css({display:"block"})}f(F).show("slow",function(){f("#"+D.id+"_wrapper").removeClass("loading");E.code()})}else{if(f.browser.msie){f(F).css({display:"block"})}f(F).load(f(D).children().eq(B).find("a").attr("xhref"),{},function(){f(F).show("slow",function(){f("#"+D.id+"_wrapper").removeClass("loading");E.code()})})}}var w=f(t);var A=p.tabs[t][x];w.each(function(){var D=this;if(y.effect=="no"){z({"this":"#"+this.id+"_content",data:A,parentThis:D,index:x})}else{var B=f("#"+this.id+"_wrapper").css("overflow")||"auto";var C=f("#"+this.id+"_content").css("overflow")||"auto";if(f.browser.msie){f("#"+this.id+"_wrapper").css({overflow:"hidden"})&&f("#"+this.id+"_content").css({overflow:"hidden"})}f("#"+this.id+"_wrapper").addClass("loading");f("#"+this.id+"_content").hide("slow",function(){if(f.browser.msie){f("#"+D.id+"_wrapper").css({overflow:B})&&f("#"+this.id+"_content").css({overflow:C})}z({"this":this,data:A,parentThis:D,index:x})})}});return(f(t))}function q(y){var x=y.index;var z=y.defined;var w=f(t);var A=p.tabs[t][x];w.each(function(){var B=f(this).children().eq(x);if(B.attr("defaultClass")){B.removeAttr("defaultClass")}if(B.hasClass("tabOff")){B.removeClass("tabOff")}if(B.hasClass("tabOn")){B.removeClass("tabOn")}B.addClass("tabPinned");B.attr("defaultClass",B.attr("class"))});g(z?7:5,x);return(f(t))}function m(x){var w=f(t);w.each(function(){var y=f(this).children();var z=x?(x.index||y.length):y.length;var A=f.extend({index:z},x);if(y.get(A.index)){f(y.get(A.index)).remove();p.tabs[t]=f.grep(p.tabs[t],function(C,B){return(B!=A.index)})}else{alert("Could not find index "+A.index+" in "+t)}});return(f(t))}function u(x,w,y){if(!w){return -1}f(w).unbind("mouseenter");f(w).unbind("mouseleave");f(w).unbind("click");f(w).bind("mouseenter",function(A){if(f(this).hasClass("tabPinned")){return(0)}if(!f(this).attr("defaultClass")){f(this).attr("defaultClass",f(this).attr("class"))}f(this).addClass("tabOn");f(this).removeClass("tabOff");t=y;var z=f(w).index(this);g(3,z)});f(w).bind("mouseleave",function(A){if(f(this).hasClass("tabPinned")){return(0)}if(f(this).attr("defaultClass")!="tabOn"){f(this).addClass("tabOff");f(this).removeClass("tabOn")}t=y;var z=f(w).index(this);g(4,z)});f(w).click(function(){if(f(this).hasClass("tabPinned")){return(0)}f("#modalDiv").remove();f("#modalDivOverlay").remove();f(y).flyTabs.clearTabs();var z=f(w).index(this);f(y).flyTabs.pinTab({index:z});f(y).flyTabs.getTab(z)})}})(jQuery);
