(function(a){a.widget("ui.panel",{options:{event:"click",collapsible:true,collapseType:"default",collapsed:false,accordion:false,collapseSpeed:"fast",draggable:false,trueVerticalText:true,vHeight:"220px",stackable:true,width:"auto",controls:false,cookie:null,widgetClass:"ui-helper-reset ui-widget ui-panel",headerClass:"ui-helper-reset ui-widget-header ui-panel-header ui-corner-top",contentClass:"ui-helper-reset ui-widget-content ui-panel-content ui-corner-bottom",contentTextClass:"ui-panel-content-text",rightboxClass:"ui-panel-rightbox",controlsClass:"ui-panel-controls",titleClass:"ui-panel-title",titleTextClass:"ui-panel-title-text",iconClass:"ui-icon",hoverClass:"ui-state-hover",collapsePnlClass:"ui-panel-clps-pnl",headerIconClpsd:"ui-icon-triangle-1-e",headerIcon:"ui-icon-triangle-1-s",slideRIconClpsd:"ui-icon-arrowthickstop-1-w",slideRIcon:"ui-icon-arrowthickstop-1-e",slideLIconClpsd:"ui-icon-arrowthickstop-1-e",slideLIcon:"ui-icon-arrowthickstop-1-w"},_init:function(){this._panelize()},_panelize:function(){if(this.element.is("div")){var b=this,c=this.options;this.panelBox=this.element;if(c.width=="auto"){c.width=this.panelBox.css("width")}else{this.panelBox.css("width",c.width)}this.panelBox.attr("role","panel");c.id=this.panelBox.attr("id");this.headerBox=this.element.children(":first");this.contentBox=this.element.children().eq(1);c.content=this.contentBox.html();this.contentBox.wrapInner("
");this.contentTextBox=this.contentBox.children(":first").addClass(c.contentTextClass);this.headerBox.wrapInner("
");this.titleBox=this.headerBox.children(":first");this.titleTextBox=this.titleBox.children(":first");this.titleText=this.titleTextBox.html();this.headerBox.prepend("");this.rightBox=this.headerBox.children(":first").addClass(c.rightboxClass);if(c.controls!=false){this.rightBox.append("");this.controlsBox=this.rightBox.children(":first").addClass(c.controlsClass).html(c.controls)}else{this.controlsBox=null}this.panelBox.addClass(c.widgetClass);this.headerBox.addClass(c.headerClass);this.titleBox.addClass(c.titleClass);this.titleTextBox.addClass(c.titleTextClass);this.contentBox.addClass(c.contentClass);if(c.collapsible){switch(c.collapseType){case"slide-right":var d=0;if(c.controls){d=1}this.rightBox.append("");this.collapsePanel=this.rightBox.children().eq(d).addClass(c.collapsePnlClass);this.collapseButton=this.collapsePanel.children(":first").addClass(c.slideRIcon);this.iconBtnClpsd=c.slideRIconClpsd;this.iconBtn=c.slideRIcon;this.ctrlBox=this.controlsBox;break;case"slide-left":this.headerBox.prepend("");this.collapsePanel=this.headerBox.children(":first").addClass(c.collapsePnlClass);this.collapseButton=this.collapsePanel.children(":first").addClass(c.slideLIcon);this.iconBtnClpsd=c.slideLIconClpsd;this.iconBtn=c.slideLIcon;this.ctrlBox=this.rightBox;break;default:this.headerBox.prepend("");this.collapseButton=this.headerBox.children(":first").addClass(c.headerIcon);this.iconBtnClpsd=c.headerIconClpsd;this.iconBtn=c.headerIcon;this.ctrlBox=this.controlsBox;break}this._buttonHover(this.collapseButton);this.collapseButton.addClass(c.iconClass);if(c.event){this.collapseButton.bind((c.event)+".panel",function(e){return b._clickHandler.call(b,e,this)});this.titleTextBox.bind((c.event)+".panel",function(e){return b._clickHandler.call(b,e,this)})}if(c.accordion){c.collapsed=true;c.trueVerticalText=false}if(c.cookie){if(b._cookie()==0){c.collapsed=false}else{c.collapsed=true}}this.panelBox.data("collapsed",c.collapsed);if(c.stackable&&a.inArray(c.collapseType,["slide-right","slide-left"])>-1){this.panelDock=this.panelBox.siblings("div[role=panelDock]:first");this.panelFrame=this.panelBox.siblings("div[role=panelFrame]:first");if(this.panelDock.length==0){this.panelDock=this.panelBox.parent(0).prepend("
").children(":first");this.panelFrame=this.panelDock.after("
").next(":first");this.panelDock.attr("role","panelDock").css("float",c.collapseType=="slide-left"?"left":"right");this.panelFrame.attr("role","panelFrame").css({"float":c.collapseType=="slide-left"?"left":"right",overflow:"hidden"})}if(c.collapsed){this.panelDock.append(this.panelBox)}else{this.panelFrame.append(this.panelBox)}}if(c.collapsed){b.toggle(0,true)}}else{this.titleTextBox.css("cursor","default")}if(!c.accordion&&c.draggable&&a.fn.draggable){this._makeDraggable()}this.panelBox.show()}},_cookie:function(){var b=this.cookie||(this.cookie=this.options.cookie.name||"ui-panel-"+this.options.id);return a.cookie.apply(null,[b].concat(a.makeArray(arguments)))},_makeDraggable:function(){this.panelBox.draggable({containment:"document",handle:".ui-panel-header",cancel:".ui-panel-content",cursor:"move"});this.contentBox.css("position","absolute")},_clickHandler:function(b,c){var d=this.options;if(d.disabled){return false}this.toggle(d.collapseSpeed);return false},toggle:function(f,i){var m=this,d=this.options,l=this.panelBox,h=this.contentBox,b=this.headerBox,k=this.titleTextBox,n=this.titleText,j=this.ctrlBox,g=this.panelDock,c="";if(!jQuery.support.leadingWhitespace){c="-ie"}if(h.css("display")=="none"){this._trigger("unfold")}else{this._trigger("fold")}if(j){j.toggle(0)}if(d.collapseType=="default"){if(f==0){if(j){j.hide()}h.hide()}else{h.slideToggle(f)}}else{if(f==0){d.collapsed=false;if(j){j.hide()}h.hide()}else{h.toggle()}if(d.collapsed==false){if(d.trueVerticalText){b.toggleClass("ui-panel-vtitle").css("height",d.vHeight);if(c==""){var e="height:"+(parseInt(d.vHeight)-50)+"px;width:100%;position:absolute;bottom:0;left:0;";k.empty().append('
"+n+'">').css("height",d.vHeight)}k.toggleClass("ui-panel-vtext"+c)}else{b.attr("align","center");k.html(k.text().replace(/(.)/g,"$1
"))}l.animate({width:"2.4em"},f);if(d.stackable){if(i){g.append(l)}else{g.prepend(l)}}}else{if(d.stackable){this.panelFrame.append(l)}if(d.trueVerticalText){b.toggleClass("ui-panel-vtitle").css("height","auto");k.empty().append(n);k.toggleClass("ui-panel-vtext"+c)}else{b.attr("align","left");k.html(k.text().replace(/
/g," "))}l.animate({width:d.width},f)}}if(((f!=0||d.trueVerticalText)&&d.cookie==null)||(!i&&d.cookie!=null)){d.collapsed=!d.collapsed}this.panelBox.data("collapsed",d.collapsed);if(!i){if(d.cookie){m._cookie(Number(d.collapsed),d.cookie)}if(d.accordion){a("."+d.accordion+"[role='panel'][id!='"+(d.id)+"']:not(:data(collapsed))").panel("toggle",f,true)}}this.collapseButton.toggleClass(this.iconBtnClpsd).toggleClass(this.iconBtn);b.toggleClass("ui-corner-all")},content:function(b){this.contentTextBox.html(b)},destroy:function(){var b=this.options;this.headerBox.html(this.titleText).removeAttr("align").removeAttr("style").removeClass("ui-panel-vtitle ui-corner-all "+b.headerClass);this.contentBox.removeClass(b.contentClass).removeAttr("style").html(b.content);this.panelBox.removeAttr("role").removeAttr("style").removeData("collapsed").unbind(".panel").removeClass(b.widgetClass);if(b.stackable&&a.inArray(b.collapseType,["slide-right","slide-left"])>-1){this.panelDock.before(this.panelBox);if(this.panelDock.children("div[role=panel]").length==0&&this.panelFrame.children("div[role=panel]").length==0){this.panelDock.remove();this.panelFrame.remove()}}if(b.cookie){this._cookie(null,b.cookie)}return this},_buttonHover:function(b){var c=this.options;b.bind({mouseover:function(){a(this).addClass(c.hoverClass)},mouseout:function(){a(this).removeClass(c.hoverClass)}})}});a.extend(a.ui.panel,{version:"0.6"})})(jQuery);