
/*!
 * jQuery UI 1.8.2
 *
 * Copyright (c) 2010 AUTHORS.txt (http://jqueryui.com/about)
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 *
 * http://docs.jquery.com/UI
 */
(function(c){c.ui=c.ui||{};if(!c.ui.version){c.extend(c.ui,{version:"1.8.2",plugin:{add:function(a,b,d){a=c.ui[a].prototype;for(var e in d){a.plugins[e]=a.plugins[e]||[];a.plugins[e].push([b,d[e]])}},call:function(a,b,d){if((b=a.plugins[b])&&a.element[0].parentNode)for(var e=0;e<b.length;e++)a.options[b[e][0]]&&b[e][1].apply(a.element,d)}},contains:function(a,b){return document.compareDocumentPosition?a.compareDocumentPosition(b)&16:a!==b&&a.contains(b)},hasScroll:function(a,b){if(c(a).css("overflow")==
"hidden")return false;b=b&&b=="left"?"scrollLeft":"scrollTop";var d=false;if(a[b]>0)return true;a[b]=1;d=a[b]>0;a[b]=0;return d},isOverAxis:function(a,b,d){return a>b&&a<b+d},isOver:function(a,b,d,e,f,g){return c.ui.isOverAxis(a,d,f)&&c.ui.isOverAxis(b,e,g)},keyCode:{ALT:18,BACKSPACE:8,CAPS_LOCK:20,COMMA:188,COMMAND:91,COMMAND_LEFT:91,COMMAND_RIGHT:93,CONTROL:17,DELETE:46,DOWN:40,END:35,ENTER:13,ESCAPE:27,HOME:36,INSERT:45,LEFT:37,MENU:93,NUMPAD_ADD:107,NUMPAD_DECIMAL:110,NUMPAD_DIVIDE:111,NUMPAD_ENTER:108,
NUMPAD_MULTIPLY:106,NUMPAD_SUBTRACT:109,PAGE_DOWN:34,PAGE_UP:33,PERIOD:190,RIGHT:39,SHIFT:16,SPACE:32,TAB:9,UP:38,WINDOWS:91}});c.fn.extend({_focus:c.fn.focus,focus:function(a,b){return typeof a==="number"?this.each(function(){var d=this;setTimeout(function(){c(d).focus();b&&b.call(d)},a)}):this._focus.apply(this,arguments)},enableSelection:function(){return this.attr("unselectable","off").css("MozUserSelect","")},disableSelection:function(){return this.attr("unselectable","on").css("MozUserSelect",
"none")},scrollParent:function(){var a;a=c.browser.msie&&/(static|relative)/.test(this.css("position"))||/absolute/.test(this.css("position"))?this.parents().filter(function(){return/(relative|absolute|fixed)/.test(c.curCSS(this,"position",1))&&/(auto|scroll)/.test(c.curCSS(this,"overflow",1)+c.curCSS(this,"overflow-y",1)+c.curCSS(this,"overflow-x",1))}).eq(0):this.parents().filter(function(){return/(auto|scroll)/.test(c.curCSS(this,"overflow",1)+c.curCSS(this,"overflow-y",1)+c.curCSS(this,"overflow-x",
1))}).eq(0);return/fixed/.test(this.css("position"))||!a.length?c(document):a},zIndex:function(a){if(a!==undefined)return this.css("zIndex",a);if(this.length){a=c(this[0]);for(var b;a.length&&a[0]!==document;){b=a.css("position");if(b=="absolute"||b=="relative"||b=="fixed"){b=parseInt(a.css("zIndex"));if(!isNaN(b)&&b!=0)return b}a=a.parent()}}return 0}});c.extend(c.expr[":"],{data:function(a,b,d){return!!c.data(a,d[3])},focusable:function(a){var b=a.nodeName.toLowerCase(),d=c.attr(a,"tabindex");return(/input|select|textarea|button|object/.test(b)?
!a.disabled:"a"==b||"area"==b?a.href||!isNaN(d):!isNaN(d))&&!c(a)["area"==b?"parents":"closest"](":hidden").length},tabbable:function(a){var b=c.attr(a,"tabindex");return(isNaN(b)||b>=0)&&c(a).is(":focusable")}})}})(jQuery);
;/*!
 * jQuery UI Widget 1.8.2
 *
 * Copyright (c) 2010 AUTHORS.txt (http://jqueryui.com/about)
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 *
 * http://docs.jquery.com/UI/Widget
 */
(function(b){var j=b.fn.remove;b.fn.remove=function(a,c){return this.each(function(){if(!c)if(!a||b.filter(a,[this]).length)b("*",this).add(this).each(function(){b(this).triggerHandler("remove")});return j.call(b(this),a,c)})};b.widget=function(a,c,d){var e=a.split(".")[0],f;a=a.split(".")[1];f=e+"-"+a;if(!d){d=c;c=b.Widget}b.expr[":"][f]=function(h){return!!b.data(h,a)};b[e]=b[e]||{};b[e][a]=function(h,g){arguments.length&&this._createWidget(h,g)};c=new c;c.options=b.extend({},c.options);b[e][a].prototype=
b.extend(true,c,{namespace:e,widgetName:a,widgetEventPrefix:b[e][a].prototype.widgetEventPrefix||a,widgetBaseClass:f},d);b.widget.bridge(a,b[e][a])};b.widget.bridge=function(a,c){b.fn[a]=function(d){var e=typeof d==="string",f=Array.prototype.slice.call(arguments,1),h=this;d=!e&&f.length?b.extend.apply(null,[true,d].concat(f)):d;if(e&&d.substring(0,1)==="_")return h;e?this.each(function(){var g=b.data(this,a),i=g&&b.isFunction(g[d])?g[d].apply(g,f):g;if(i!==g&&i!==undefined){h=i;return false}}):this.each(function(){var g=
b.data(this,a);if(g){d&&g.option(d);g._init()}else b.data(this,a,new c(d,this))});return h}};b.Widget=function(a,c){arguments.length&&this._createWidget(a,c)};b.Widget.prototype={widgetName:"widget",widgetEventPrefix:"",options:{disabled:false},_createWidget:function(a,c){this.element=b(c).data(this.widgetName,this);this.options=b.extend(true,{},this.options,b.metadata&&b.metadata.get(c)[this.widgetName],a);var d=this;this.element.bind("remove."+this.widgetName,function(){d.destroy()});this._create();
this._init()},_create:function(){},_init:function(){},destroy:function(){this.element.unbind("."+this.widgetName).removeData(this.widgetName);this.widget().unbind("."+this.widgetName).removeAttr("aria-disabled").removeClass(this.widgetBaseClass+"-disabled ui-state-disabled")},widget:function(){return this.element},option:function(a,c){var d=a,e=this;if(arguments.length===0)return b.extend({},e.options);if(typeof a==="string"){if(c===undefined)return this.options[a];d={};d[a]=c}b.each(d,function(f,
h){e._setOption(f,h)});return e},_setOption:function(a,c){this.options[a]=c;if(a==="disabled")this.widget()[c?"addClass":"removeClass"](this.widgetBaseClass+"-disabled ui-state-disabled").attr("aria-disabled",c);return this},enable:function(){return this._setOption("disabled",false)},disable:function(){return this._setOption("disabled",true)},_trigger:function(a,c,d){var e=this.options[a];c=b.Event(c);c.type=(a===this.widgetEventPrefix?a:this.widgetEventPrefix+a).toLowerCase();d=d||{};if(c.originalEvent){a=
b.event.props.length;for(var f;a;){f=b.event.props[--a];c[f]=c.originalEvent[f]}}this.element.trigger(c,d);return!(b.isFunction(e)&&e.call(this.element[0],c,d)===false||c.isDefaultPrevented())}}})(jQuery);
;/*!
 * jQuery UI Mouse 1.8.2
 *
 * Copyright (c) 2010 AUTHORS.txt (http://jqueryui.com/about)
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 *
 * http://docs.jquery.com/UI/Mouse
 *
 * Depends:
 *	jquery.ui.widget.js
 */
(function(c){c.widget("ui.mouse",{options:{cancel:":input,option",distance:1,delay:0},_mouseInit:function(){var a=this;this.element.bind("mousedown."+this.widgetName,function(b){return a._mouseDown(b)}).bind("click."+this.widgetName,function(b){if(a._preventClickEvent){a._preventClickEvent=false;b.stopImmediatePropagation();return false}});this.started=false},_mouseDestroy:function(){this.element.unbind("."+this.widgetName)},_mouseDown:function(a){a.originalEvent=a.originalEvent||{};if(!a.originalEvent.mouseHandled){this._mouseStarted&&
this._mouseUp(a);this._mouseDownEvent=a;var b=this,e=a.which==1,f=typeof this.options.cancel=="string"?c(a.target).parents().add(a.target).filter(this.options.cancel).length:false;if(!e||f||!this._mouseCapture(a))return true;this.mouseDelayMet=!this.options.delay;if(!this.mouseDelayMet)this._mouseDelayTimer=setTimeout(function(){b.mouseDelayMet=true},this.options.delay);if(this._mouseDistanceMet(a)&&this._mouseDelayMet(a)){this._mouseStarted=this._mouseStart(a)!==false;if(!this._mouseStarted){a.preventDefault();
return true}}this._mouseMoveDelegate=function(d){return b._mouseMove(d)};this._mouseUpDelegate=function(d){return b._mouseUp(d)};c(document).bind("mousemove."+this.widgetName,this._mouseMoveDelegate).bind("mouseup."+this.widgetName,this._mouseUpDelegate);c.browser.safari||a.preventDefault();return a.originalEvent.mouseHandled=true}},_mouseMove:function(a){if(c.browser.msie&&!a.button)return this._mouseUp(a);if(this._mouseStarted){this._mouseDrag(a);return a.preventDefault()}if(this._mouseDistanceMet(a)&&
this._mouseDelayMet(a))(this._mouseStarted=this._mouseStart(this._mouseDownEvent,a)!==false)?this._mouseDrag(a):this._mouseUp(a);return!this._mouseStarted},_mouseUp:function(a){c(document).unbind("mousemove."+this.widgetName,this._mouseMoveDelegate).unbind("mouseup."+this.widgetName,this._mouseUpDelegate);if(this._mouseStarted){this._mouseStarted=false;this._preventClickEvent=a.target==this._mouseDownEvent.target;this._mouseStop(a)}return false},_mouseDistanceMet:function(a){return Math.max(Math.abs(this._mouseDownEvent.pageX-
a.pageX),Math.abs(this._mouseDownEvent.pageY-a.pageY))>=this.options.distance},_mouseDelayMet:function(){return this.mouseDelayMet},_mouseStart:function(){},_mouseDrag:function(){},_mouseStop:function(){},_mouseCapture:function(){return true}})})(jQuery);
;/*
 * jQuery UI Resizable 1.8.2
 *
 * Copyright (c) 2010 AUTHORS.txt (http://jqueryui.com/about)
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 *
 * http://docs.jquery.com/UI/Resizables
 *
 * Depends:
 *	jquery.ui.core.js
 *	jquery.ui.mouse.js
 *	jquery.ui.widget.js
 */
(function(d){d.widget("ui.resizable",d.ui.mouse,{widgetEventPrefix:"resize",options:{alsoResize:false,animate:false,animateDuration:"slow",animateEasing:"swing",aspectRatio:false,autoHide:false,containment:false,ghost:false,grid:false,handles:"e,s,se",helper:false,maxHeight:null,maxWidth:null,minHeight:10,minWidth:10,zIndex:1E3},_create:function(){var b=this,a=this.options;this.element.addClass("ui-resizable");d.extend(this,{_aspectRatio:!!a.aspectRatio,aspectRatio:a.aspectRatio,originalElement:this.element,
_proportionallyResizeElements:[],_helper:a.helper||a.ghost||a.animate?a.helper||"ui-resizable-helper":null});if(this.element[0].nodeName.match(/canvas|textarea|input|select|button|img/i)){/relative/.test(this.element.css("position"))&&d.browser.opera&&this.element.css({position:"relative",top:"auto",left:"auto"});this.element.wrap(d('<div class="ui-wrapper" style="overflow: hidden;"></div>').css({position:this.element.css("position"),width:this.element.outerWidth(),height:this.element.outerHeight(),
top:this.element.css("top"),left:this.element.css("left")}));this.element=this.element.parent().data("resizable",this.element.data("resizable"));this.elementIsWrapper=true;this.element.css({marginLeft:this.originalElement.css("marginLeft"),marginTop:this.originalElement.css("marginTop"),marginRight:this.originalElement.css("marginRight"),marginBottom:this.originalElement.css("marginBottom")});this.originalElement.css({marginLeft:0,marginTop:0,marginRight:0,marginBottom:0});this.originalResizeStyle=
this.originalElement.css("resize");this.originalElement.css("resize","none");this._proportionallyResizeElements.push(this.originalElement.css({position:"static",zoom:1,display:"block"}));this.originalElement.css({margin:this.originalElement.css("margin")});this._proportionallyResize()}this.handles=a.handles||(!d(".ui-resizable-handle",this.element).length?"e,s,se":{n:".ui-resizable-n",e:".ui-resizable-e",s:".ui-resizable-s",w:".ui-resizable-w",se:".ui-resizable-se",sw:".ui-resizable-sw",ne:".ui-resizable-ne",
nw:".ui-resizable-nw"});if(this.handles.constructor==String){if(this.handles=="all")this.handles="n,e,s,w,se,sw,ne,nw";var c=this.handles.split(",");this.handles={};for(var e=0;e<c.length;e++){var g=d.trim(c[e]),f=d('<div class="ui-resizable-handle '+("ui-resizable-"+g)+'"></div>');/sw|se|ne|nw/.test(g)&&f.css({zIndex:++a.zIndex});"se"==g&&f.addClass("ui-icon ui-icon-gripsmall-diagonal-se");this.handles[g]=".ui-resizable-"+g;this.element.append(f)}}this._renderAxis=function(h){h=h||this.element;for(var i in this.handles){if(this.handles[i].constructor==
String)this.handles[i]=d(this.handles[i],this.element).show();if(this.elementIsWrapper&&this.originalElement[0].nodeName.match(/textarea|input|select|button/i)){var j=d(this.handles[i],this.element),l=0;l=/sw|ne|nw|se|n|s/.test(i)?j.outerHeight():j.outerWidth();j=["padding",/ne|nw|n/.test(i)?"Top":/se|sw|s/.test(i)?"Bottom":/^e$/.test(i)?"Right":"Left"].join("");h.css(j,l);this._proportionallyResize()}d(this.handles[i])}};this._renderAxis(this.element);this._handles=d(".ui-resizable-handle",this.element).disableSelection();
this._handles.mouseover(function(){if(!b.resizing){if(this.className)var h=this.className.match(/ui-resizable-(se|sw|ne|nw|n|e|s|w)/i);b.axis=h&&h[1]?h[1]:"se"}});if(a.autoHide){this._handles.hide();d(this.element).addClass("ui-resizable-autohide").hover(function(){d(this).removeClass("ui-resizable-autohide");b._handles.show()},function(){if(!b.resizing){d(this).addClass("ui-resizable-autohide");b._handles.hide()}})}this._mouseInit()},destroy:function(){this._mouseDestroy();var b=function(c){d(c).removeClass("ui-resizable ui-resizable-disabled ui-resizable-resizing").removeData("resizable").unbind(".resizable").find(".ui-resizable-handle").remove()};
if(this.elementIsWrapper){b(this.element);var a=this.element;a.after(this.originalElement.css({position:a.css("position"),width:a.outerWidth(),height:a.outerHeight(),top:a.css("top"),left:a.css("left")})).remove()}this.originalElement.css("resize",this.originalResizeStyle);b(this.originalElement);return this},_mouseCapture:function(b){var a=false;for(var c in this.handles)if(d(this.handles[c])[0]==b.target)a=true;return!this.options.disabled&&a},_mouseStart:function(b){var a=this.options,c=this.element.position(),
e=this.element;this.resizing=true;this.documentScroll={top:d(document).scrollTop(),left:d(document).scrollLeft()};if(e.is(".ui-draggable")||/absolute/.test(e.css("position")))e.css({position:"absolute",top:c.top,left:c.left});d.browser.opera&&/relative/.test(e.css("position"))&&e.css({position:"relative",top:"auto",left:"auto"});this._renderProxy();c=m(this.helper.css("left"));var g=m(this.helper.css("top"));if(a.containment){c+=d(a.containment).scrollLeft()||0;g+=d(a.containment).scrollTop()||0}this.offset=
this.helper.offset();this.position={left:c,top:g};this.size=this._helper?{width:e.outerWidth(),height:e.outerHeight()}:{width:e.width(),height:e.height()};this.originalSize=this._helper?{width:e.outerWidth(),height:e.outerHeight()}:{width:e.width(),height:e.height()};this.originalPosition={left:c,top:g};this.sizeDiff={width:e.outerWidth()-e.width(),height:e.outerHeight()-e.height()};this.originalMousePosition={left:b.pageX,top:b.pageY};this.aspectRatio=typeof a.aspectRatio=="number"?a.aspectRatio:
this.originalSize.width/this.originalSize.height||1;a=d(".ui-resizable-"+this.axis).css("cursor");d("body").css("cursor",a=="auto"?this.axis+"-resize":a);e.addClass("ui-resizable-resizing");this._propagate("start",b);return true},_mouseDrag:function(b){var a=this.helper,c=this.originalMousePosition,e=this._change[this.axis];if(!e)return false;c=e.apply(this,[b,b.pageX-c.left||0,b.pageY-c.top||0]);if(this._aspectRatio||b.shiftKey)c=this._updateRatio(c,b);c=this._respectSize(c,b);this._propagate("resize",
b);a.css({top:this.position.top+"px",left:this.position.left+"px",width:this.size.width+"px",height:this.size.height+"px"});!this._helper&&this._proportionallyResizeElements.length&&this._proportionallyResize();this._updateCache(c);this._trigger("resize",b,this.ui());return false},_mouseStop:function(b){this.resizing=false;var a=this.options,c=this;if(this._helper){var e=this._proportionallyResizeElements,g=e.length&&/textarea/i.test(e[0].nodeName);e=g&&d.ui.hasScroll(e[0],"left")?0:c.sizeDiff.height;
g={width:c.size.width-(g?0:c.sizeDiff.width),height:c.size.height-e};e=parseInt(c.element.css("left"),10)+(c.position.left-c.originalPosition.left)||null;var f=parseInt(c.element.css("top"),10)+(c.position.top-c.originalPosition.top)||null;a.animate||this.element.css(d.extend(g,{top:f,left:e}));c.helper.height(c.size.height);c.helper.width(c.size.width);this._helper&&!a.animate&&this._proportionallyResize()}d("body").css("cursor","auto");this.element.removeClass("ui-resizable-resizing");this._propagate("stop",
b);this._helper&&this.helper.remove();return false},_updateCache:function(b){this.offset=this.helper.offset();if(k(b.left))this.position.left=b.left;if(k(b.top))this.position.top=b.top;if(k(b.height))this.size.height=b.height;if(k(b.width))this.size.width=b.width},_updateRatio:function(b){var a=this.position,c=this.size,e=this.axis;if(b.height)b.width=c.height*this.aspectRatio;else if(b.width)b.height=c.width/this.aspectRatio;if(e=="sw"){b.left=a.left+(c.width-b.width);b.top=null}if(e=="nw"){b.top=
a.top+(c.height-b.height);b.left=a.left+(c.width-b.width)}return b},_respectSize:function(b){var a=this.options,c=this.axis,e=k(b.width)&&a.maxWidth&&a.maxWidth<b.width,g=k(b.height)&&a.maxHeight&&a.maxHeight<b.height,f=k(b.width)&&a.minWidth&&a.minWidth>b.width,h=k(b.height)&&a.minHeight&&a.minHeight>b.height;if(f)b.width=a.minWidth;if(h)b.height=a.minHeight;if(e)b.width=a.maxWidth;if(g)b.height=a.maxHeight;var i=this.originalPosition.left+this.originalSize.width,j=this.position.top+this.size.height,
l=/sw|nw|w/.test(c);c=/nw|ne|n/.test(c);if(f&&l)b.left=i-a.minWidth;if(e&&l)b.left=i-a.maxWidth;if(h&&c)b.top=j-a.minHeight;if(g&&c)b.top=j-a.maxHeight;if((a=!b.width&&!b.height)&&!b.left&&b.top)b.top=null;else if(a&&!b.top&&b.left)b.left=null;return b},_proportionallyResize:function(){if(this._proportionallyResizeElements.length)for(var b=this.helper||this.element,a=0;a<this._proportionallyResizeElements.length;a++){var c=this._proportionallyResizeElements[a];if(!this.borderDif){var e=[c.css("borderTopWidth"),
c.css("borderRightWidth"),c.css("borderBottomWidth"),c.css("borderLeftWidth")],g=[c.css("paddingTop"),c.css("paddingRight"),c.css("paddingBottom"),c.css("paddingLeft")];this.borderDif=d.map(e,function(f,h){f=parseInt(f,10)||0;h=parseInt(g[h],10)||0;return f+h})}d.browser.msie&&(d(b).is(":hidden")||d(b).parents(":hidden").length)||c.css({height:b.height()-this.borderDif[0]-this.borderDif[2]||0,width:b.width()-this.borderDif[1]-this.borderDif[3]||0})}},_renderProxy:function(){var b=this.options;this.elementOffset=
this.element.offset();if(this._helper){this.helper=this.helper||d('<div style="overflow:hidden;"></div>');var a=d.browser.msie&&d.browser.version<7,c=a?1:0;a=a?2:-1;this.helper.addClass(this._helper).css({width:this.element.outerWidth()+a,height:this.element.outerHeight()+a,position:"absolute",left:this.elementOffset.left-c+"px",top:this.elementOffset.top-c+"px",zIndex:++b.zIndex});this.helper.appendTo("body").disableSelection()}else this.helper=this.element},_change:{e:function(b,a){return{width:this.originalSize.width+
a}},w:function(b,a){return{left:this.originalPosition.left+a,width:this.originalSize.width-a}},n:function(b,a,c){return{top:this.originalPosition.top+c,height:this.originalSize.height-c}},s:function(b,a,c){return{height:this.originalSize.height+c}},se:function(b,a,c){return d.extend(this._change.s.apply(this,arguments),this._change.e.apply(this,[b,a,c]))},sw:function(b,a,c){return d.extend(this._change.s.apply(this,arguments),this._change.w.apply(this,[b,a,c]))},ne:function(b,a,c){return d.extend(this._change.n.apply(this,
arguments),this._change.e.apply(this,[b,a,c]))},nw:function(b,a,c){return d.extend(this._change.n.apply(this,arguments),this._change.w.apply(this,[b,a,c]))}},_propagate:function(b,a){d.ui.plugin.call(this,b,[a,this.ui()]);b!="resize"&&this._trigger(b,a,this.ui())},plugins:{},ui:function(){return{originalElement:this.originalElement,element:this.element,helper:this.helper,position:this.position,size:this.size,originalSize:this.originalSize,originalPosition:this.originalPosition}}});d.extend(d.ui.resizable,
{version:"1.8.2"});d.ui.plugin.add("resizable","alsoResize",{start:function(){var b=d(this).data("resizable").options,a=function(c){d(c).each(function(){d(this).data("resizable-alsoresize",{width:parseInt(d(this).width(),10),height:parseInt(d(this).height(),10),left:parseInt(d(this).css("left"),10),top:parseInt(d(this).css("top"),10)})})};if(typeof b.alsoResize=="object"&&!b.alsoResize.parentNode)if(b.alsoResize.length){b.alsoResize=b.alsoResize[0];a(b.alsoResize)}else d.each(b.alsoResize,function(c){a(c)});
else a(b.alsoResize)},resize:function(){var b=d(this).data("resizable"),a=b.options,c=b.originalSize,e=b.originalPosition,g={height:b.size.height-c.height||0,width:b.size.width-c.width||0,top:b.position.top-e.top||0,left:b.position.left-e.left||0},f=function(h,i){d(h).each(function(){var j=d(this),l=d(this).data("resizable-alsoresize"),p={};d.each((i&&i.length?i:["width","height","top","left"])||["width","height","top","left"],function(n,o){if((n=(l[o]||0)+(g[o]||0))&&n>=0)p[o]=n||null});if(/relative/.test(j.css("position"))&&
d.browser.opera){b._revertToRelativePosition=true;j.css({position:"absolute",top:"auto",left:"auto"})}j.css(p)})};typeof a.alsoResize=="object"&&!a.alsoResize.nodeType?d.each(a.alsoResize,function(h,i){f(h,i)}):f(a.alsoResize)},stop:function(){var b=d(this).data("resizable");if(b._revertToRelativePosition&&d.browser.opera){b._revertToRelativePosition=false;el.css({position:"relative"})}d(this).removeData("resizable-alsoresize-start")}});d.ui.plugin.add("resizable","animate",{stop:function(b){var a=
d(this).data("resizable"),c=a.options,e=a._proportionallyResizeElements,g=e.length&&/textarea/i.test(e[0].nodeName),f=g&&d.ui.hasScroll(e[0],"left")?0:a.sizeDiff.height;g={width:a.size.width-(g?0:a.sizeDiff.width),height:a.size.height-f};f=parseInt(a.element.css("left"),10)+(a.position.left-a.originalPosition.left)||null;var h=parseInt(a.element.css("top"),10)+(a.position.top-a.originalPosition.top)||null;a.element.animate(d.extend(g,h&&f?{top:h,left:f}:{}),{duration:c.animateDuration,easing:c.animateEasing,
step:function(){var i={width:parseInt(a.element.css("width"),10),height:parseInt(a.element.css("height"),10),top:parseInt(a.element.css("top"),10),left:parseInt(a.element.css("left"),10)};e&&e.length&&d(e[0]).css({width:i.width,height:i.height});a._updateCache(i);a._propagate("resize",b)}})}});d.ui.plugin.add("resizable","containment",{start:function(){var b=d(this).data("resizable"),a=b.element,c=b.options.containment;if(a=c instanceof d?c.get(0):/parent/.test(c)?a.parent().get(0):c){b.containerElement=
d(a);if(/document/.test(c)||c==document){b.containerOffset={left:0,top:0};b.containerPosition={left:0,top:0};b.parentData={element:d(document),left:0,top:0,width:d(document).width(),height:d(document).height()||document.body.parentNode.scrollHeight}}else{var e=d(a),g=[];d(["Top","Right","Left","Bottom"]).each(function(i,j){g[i]=m(e.css("padding"+j))});b.containerOffset=e.offset();b.containerPosition=e.position();b.containerSize={height:e.innerHeight()-g[3],width:e.innerWidth()-g[1]};c=b.containerOffset;
var f=b.containerSize.height,h=b.containerSize.width;h=d.ui.hasScroll(a,"left")?a.scrollWidth:h;f=d.ui.hasScroll(a)?a.scrollHeight:f;b.parentData={element:a,left:c.left,top:c.top,width:h,height:f}}}},resize:function(b){var a=d(this).data("resizable"),c=a.options,e=a.containerOffset,g=a.position;b=a._aspectRatio||b.shiftKey;var f={top:0,left:0},h=a.containerElement;if(h[0]!=document&&/static/.test(h.css("position")))f=e;if(g.left<(a._helper?e.left:0)){a.size.width+=a._helper?a.position.left-e.left:
a.position.left-f.left;if(b)a.size.height=a.size.width/c.aspectRatio;a.position.left=c.helper?e.left:0}if(g.top<(a._helper?e.top:0)){a.size.height+=a._helper?a.position.top-e.top:a.position.top;if(b)a.size.width=a.size.height*c.aspectRatio;a.position.top=a._helper?e.top:0}a.offset.left=a.parentData.left+a.position.left;a.offset.top=a.parentData.top+a.position.top;c=Math.abs((a._helper?a.offset.left-f.left:a.offset.left-f.left)+a.sizeDiff.width);e=Math.abs((a._helper?a.offset.top-f.top:a.offset.top-
e.top)+a.sizeDiff.height);g=a.containerElement.get(0)==a.element.parent().get(0);f=/relative|absolute/.test(a.containerElement.css("position"));if(g&&f)c-=a.parentData.left;if(c+a.size.width>=a.parentData.width){a.size.width=a.parentData.width-c;if(b)a.size.height=a.size.width/a.aspectRatio}if(e+a.size.height>=a.parentData.height){a.size.height=a.parentData.height-e;if(b)a.size.width=a.size.height*a.aspectRatio}},stop:function(){var b=d(this).data("resizable"),a=b.options,c=b.containerOffset,e=b.containerPosition,
g=b.containerElement,f=d(b.helper),h=f.offset(),i=f.outerWidth()-b.sizeDiff.width;f=f.outerHeight()-b.sizeDiff.height;b._helper&&!a.animate&&/relative/.test(g.css("position"))&&d(this).css({left:h.left-e.left-c.left,width:i,height:f});b._helper&&!a.animate&&/static/.test(g.css("position"))&&d(this).css({left:h.left-e.left-c.left,width:i,height:f})}});d.ui.plugin.add("resizable","ghost",{start:function(){var b=d(this).data("resizable"),a=b.options,c=b.size;b.ghost=b.originalElement.clone();b.ghost.css({opacity:0.25,
display:"block",position:"relative",height:c.height,width:c.width,margin:0,left:0,top:0}).addClass("ui-resizable-ghost").addClass(typeof a.ghost=="string"?a.ghost:"");b.ghost.appendTo(b.helper)},resize:function(){var b=d(this).data("resizable");b.ghost&&b.ghost.css({position:"relative",height:b.size.height,width:b.size.width})},stop:function(){var b=d(this).data("resizable");b.ghost&&b.helper&&b.helper.get(0).removeChild(b.ghost.get(0))}});d.ui.plugin.add("resizable","grid",{resize:function(){var b=
d(this).data("resizable"),a=b.options,c=b.size,e=b.originalSize,g=b.originalPosition,f=b.axis;a.grid=typeof a.grid=="number"?[a.grid,a.grid]:a.grid;var h=Math.round((c.width-e.width)/(a.grid[0]||1))*(a.grid[0]||1);a=Math.round((c.height-e.height)/(a.grid[1]||1))*(a.grid[1]||1);if(/^(se|s|e)$/.test(f)){b.size.width=e.width+h;b.size.height=e.height+a}else if(/^(ne)$/.test(f)){b.size.width=e.width+h;b.size.height=e.height+a;b.position.top=g.top-a}else{if(/^(sw)$/.test(f)){b.size.width=e.width+h;b.size.height=
e.height+a}else{b.size.width=e.width+h;b.size.height=e.height+a;b.position.top=g.top-a}b.position.left=g.left-h}}});var m=function(b){return parseInt(b,10)||0},k=function(b){return!isNaN(parseInt(b,10))}})(jQuery);
;





























WibiyaPlaceholderTypes =
{
	Above 		: "above",
	Bellow 		: "below",
	InsideTop	: "inside_top",
	InsideBottom: "inside_bottom"
}

WibiyaPlaceholders = [
   
];


//waiting for jquery to be ready (this is retrieved from wibiya toolbar)
_interval = setInterval(function(){
	if(jQuery)
	{
		jQuery(document).ready(function(){
			
			WibiyaLogger.init();
			WibiyaPlaceholderManager.init();
			
		});
		
		clearInterval(_interval);
		
	}	
},100);



WibiyaLogger = 
{
	init: function()
	{
		var container = jQuery("<div id = 'WibiyaPlaceholderManager_logger' style='font-size:10px;font-family:Verdana;width:300px;height:300px;overflow:scroll;overflow-x:hidden;background-color:#ffffff;border:1px solid #000000;position:fixed;top:10px;left:10px;text-align:center;padding-top:5px;z-index:9999999'><input type='button' value='start' onclick='WibiyaPlaceholderManager.start()'/><input type='button' value='stop' onclick='WibiyaPlaceholderManager.stop()'/><br><div id='WibiyaPlaceholderManager_logger_text' style='text-align:left;margin-top:10px'></div></div>");
		jQuery("body").prepend(container);
		
		this.dump();
	},
	
	dump: function()
	{
		jQuery("#WibiyaPlaceholderManager_logger_text").html("");
		var list = jQuery("<ul style='margin:0px;padding:0px'></ul>");
		for(var i=0;i<WibiyaPlaceholders.length;i++)
		{
			list.append("<li style='margin-bottom:10px'><b>XPath: </b>" + WibiyaPlaceholders[i].selector + "<br><b>Type: </b>" + WibiyaPlaceholders[i].type + "<br /><b>Width: </b>" + WibiyaPlaceholders[i].width + "&nbsp;&nbsp;<b>Height: </b>" + WibiyaPlaceholders[i].height);
		}
		jQuery("#WibiyaPlaceholderManager_logger_text").append(list);
	}
}

WibiyaPlaceholderManager = {
	
	init:function()
	{
		//init the variables
		this._highlightedItem = null;
		
		this.blocked = false;
		
		//init the UI components
		this.menu = this.Menu.getInstance();
		this.border = this.Rectangle.getInstance();
		
		//bind the events that will happen only once
		jQuery(this.menu).bind("insert",null, this.insertEventHanlder);
		jQuery(this.menu).bind("close",null, function(){WibiyaPlaceholderManager.restart();});
		
		
		this.bindPlaceholders();
		
	}, 
	
	bindPlaceholders: function()
	{
		for(var i=0;i<WibiyaPlaceholders.length;i++)
		{
			this.insert(WibiyaPlaceholders[i]);
		}
	},
	
	start: function()
	{
		jQuery(document).mousemove(this.mouseMoveEventHandler); 
		jQuery(document).click(this.mouseClickEventHandler);
		
		//hide the rectangle 
		this.border.hide();
		this.menu.hide();
		
		this.blocked = false;
	},
	
	stop: function()
	{
		jQuery(document).unbind("mousemove", this.mouseMoveEventHandler);
		jQuery(document).unbind("click", this.mouseClickEventHandler);
		
		//hide the rectangle 
		this.border.hide();
		this.menu.hide();
		
		this.blocked = false;
		this._highlightedItem = null;
	},
	
	restart : function()
	{
		//stop the feature
		this.stop();
		
		//start the feature
		this.start();
	},
	
	mouseClickEventHandler: function(e)
	{
		var _this = WibiyaPlaceholderManager;
		
		if(_this._highlightedItem == null || _this.blocked == true)
			return;
		
		//apply the css
		_this.menu.follow(_this._highlightedItem);
		_this.menu.show();
		
		_this.blocked = true;
	},
	
	mouseMoveEventHandler: function(e)
	{
		var _this = WibiyaPlaceholderManager;
		
		if(_this.blocked == true)
			return;
		
		var elem = document.elementFromPoint ( e.clientX , e.clientY );
	    var item = _this.filter(jQuery(elem));
		
		if(item != null)
		{
			//show the border
			_this.border.follow(item);
			//show the border
			_this.border.show();
			
			//save the highlighted item 
			_this._highlightedItem = jQuery(elem);
		}
		else
		{
			//if the element which didn't succeed is not inside the highilighted element 
			//than close the highlight
			if(_this._highlightedItem != null && _this._highlightedItem != jQuery(elem))
			{
				var parents = jQuery(elem).parents();
				var bFound = false;
				for(var i=0;i<parents.length;i++)
				{
					if(_this.getElementXPath(parents[i]) == _this.getElementXPath(_this._highlightedItem[0]))
					{
						bFound = true;
						break;
					}
				}
				
				if(bFound == false)
				{
					_this._highlightedItem = null;
					_this.border.hide();
				}
			}
		}
	},
	
	insertEventHanlder: function(e,data)
	{
		var _this = WibiyaPlaceholderManager;
		
		if(_this._highlightedItem == null)
			return;
		
		//get the placeholder object 
		var placeholder = {
				"selector" 	: _this.getElementXPath(_this._highlightedItem[0]),
				"type" 		: data
		};
		
		//insert it in the UI
		var cont = _this.insert(placeholder);
		placeholder.width = cont.width();
		placeholder.height = cont.height();
		
		//insert in the placeholder config  
		WibiyaPlaceholders.push(placeholder);
		
		WibiyaLogger.dump();
		
		//restart the manager
		_this.restart();
	},
	
	insert: function(placeholder)
	{
		var item = jQuery(placeholder.selector);
		
		if(!item || item.length == 0)
			return; 
		
		var clearDiv = jQuery('<div></div>').css({
			"clear"		: "both",
			"float"		: "none"
		});
		
		var menuCont = WibiyaPlaceholderManager.Menu.getInstance();
		
		var container = jQuery("<div class='wibiyaplaceholder'><br/><br/>Placeholder</div>");
		container.css({
			"width"				: menuCont._menu.width() + "px",
			"height" 			: menuCont._menu.height() + "px",
			"background-color" 	: "#cccccc",
			"text-align" 		: "center",
			"overflow"  		: "hidden"
		});
		
		//adjust the placeholder height - not sure it will apply to all cases
		jQuery(placeholder.selector).css ("height", "auto");
		
		switch(placeholder.type)
		{
			//TODO: must be inserted as "previous child" for the placeholder
			//TODO: use jQuery(placeholder.selector).before(container) - nu prea da bine nici asa
			case WibiyaPlaceholderTypes.Above:
				jQuery(placeholder.selector).parent().prepend(container);
			break;
			case WibiyaPlaceholderTypes.Bellow:
				jQuery(placeholder.selector).parent().append(container);
			break;
			case WibiyaPlaceholderTypes.InsideTop:
				jQuery(placeholder.selector).prepend(container);
			break;
			case WibiyaPlaceholderTypes.InsideBottom:
				jQuery(placeholder.selector).append(container);
			break;
		}
		
		return container;
	},
	
	filter: function(item)
	{
		if(!item || item == null)
			return null;
		
		//restrict the width to 100 and height to 100
		if(item.height() < 100 || item.width() < 100)
			return null;
		
		//do not highlight the highlight elements
		if(item.attr("id").indexOf("WibiyaPlaceholderManager_") >= 0)
			return null;
		
		//get only some elements
		if(!(item.is("div") || item.is("table") || item.is("tr") || item.is("td") || item.is("html") || item.is("body") ))
			return null;
		
		return item;
	},
	
	getElementXPath : function(elm) 
	{
       
	   for (segs = []; elm && elm.nodeType == 1; elm = elm.parentNode) 
       {
           for (i = 1, sib = elm.previousSibling; sib; sib = sib.previousSibling)
             if (sib.localName == elm.localName) i++
           
           segs.unshift(elm.localName.toLowerCase() + ':eq(' + (i-1) + ')' );
       }
       
	   return segs.length ? segs.join(' > ') : null
	}
	
};






//UI OBJECTS
WibiyaPlaceholderManager.Rectangle = 
{
	_object: 
	{
		left: null,
		right: null,
		top: null,
		bottom: null,
		
		follow: function(item)
		{
			if(!item)
				return;
			
			var border = 2;
			var zindex = 999999;

			//radu: width() replaced by outerWidth() - add the element padding to display the overlay border to border
			//height() -> outerHeight()
			jQuery(this.top).css({
				"width"   : item.outerWidth() + 2 * border,
				"top"     : item.offset().top - border,
				"left"	  : item.offset().left - border,
				"z-index" : zindex
			});
			
			jQuery(this.bottom).css({
				"width"   : item.outerWidth() + 2 * border,
				"top"     : item.offset().top + item.outerHeight(),
				"left"	  : item.offset().left - border,
				"z-index" : zindex
			});
			
			jQuery(this.left).css({
				"height"  : item.outerHeight(),
				"top"     : item.offset().top,
				"left"	  : item.offset().left - border,
				"z-index" : zindex
			});
			
			jQuery(this.right).css({
				"height"  : item.outerHeight(),
				"top"     : item.offset().top,
				"left"	  : item.offset().left + item.outerWidth(),
				"z-index" : zindex
			});
			this.show();
		}, 
		
		show: function()
		{
			this.top.show();
			this.bottom.show();
			this.left.show();
			this.right.show();
		},
		
		hide: function()
		{
			this.top.hide();
			this.bottom.hide();
			this.left.hide();
			this.right.hide();
		}
	},
	
	getInstance: function()
	{
		var border = 2;
		var pattern = "WibiyaPlaceholderManager_";
		
		//create left
		if(jQuery("#" + pattern + "left").length == 0)
		{
			this._object.left = jQuery("<div id='" + pattern + "left" + "' style='display:none'></div>");
			jQuery("body").append(this._object.left);
		}
		else
			this._object.left = jQuery("#" + pattern + "left");
		
		//create right
		if(jQuery("#" + pattern + "right").length == 0)
		{
			this._object.right = jQuery("<div id='" + pattern + "right" + "' style='display:none'></div>");
			jQuery("body").append(this._object.right);
		}
		else
			this._object.right = jQuery("#" + pattern + "right");
		
		//create top
		if(jQuery("#" + pattern + "top").length == 0)
		{
			this._object.top = jQuery("<div id='" + pattern + "top" + "' style='display:none'></div>");
			jQuery("body").append(this._object.top);
		}
		else
			this._object.top = jQuery("#" + pattern + "top");
		
		//create bottom
		if(jQuery("#" + pattern + "bottom").length == 0)
		{
			this._object.bottom = jQuery("<div id='" + pattern + "bottom" + "' style='display:none'></div>");
			jQuery("body").append(this._object.bottom);
		}
		else
			this._object.bottom = jQuery("#" + pattern + "bottom");
		
		
		//apply the css for left and right 
		var css = 
		{
			"border" 			: "none",
			"background-color" 	: "blue",
			"position"			: "absolute"
		}
		
		this._object.left.css(css).css({"width" : border + "px"});
		this._object.right.css(css).css({"width" : border + "px"});
		
		//apply the css for the top and bottom 
		this._object.top.css(css).css({"height" : border + "px"});
		this._object.bottom.css(css).css({"height" : border + "px"});
		
		
		return this._object;
	}
};

WibiyaPlaceholderManager.Menu =
{
	_object :
	{
		_background : null,
		_menu : null,
		
		follow: function(item)
		{
			//width() -> outerWidth()
			//height() -> outerHeight()
			jQuery(this._background).css({
				"top" 	: item.offset().top,
				"left" 	: item.offset().left,
				"width" : item.outerWidth(),
				"height": item.outerHeight()
			});
			
			
			jQuery(this._menu).css({
				"top"  : item.offset().top,
				"left" : item.offset().left,
				"width" : item.outerWidth(),
				"height" : item.outerHeight()
			});
			
			jQuery(this._menu).children("li").css({
				"border-bottom" : "1px solid #cccccc",
				"text-align" : "center",
				"cursor" : "pointer"
			});
			
			//adjust initial resize handler position
			jQuery("div.ui-resizable-e", this._menu).css ({
				"top"			: (this._menu.height() / 2) + "px"
			});
			
			jQuery("div.ui-resizable-s", this._menu).css ({
				"left"			: (this._menu.width() / 2) + "px"
			});
		},
		
		refreshBackground: function()
		{
			jQuery(this._background).css({
				"top" 	: this._menu.offset().top,
				"left" 	: this._menu.offset().left,
				"width" : this._menu.outerWidth(),
				"height": this._menu.outerHeight()
			});
		},
		
		show: function()
		{
			this._background.fadeIn();
			this._menu.fadeIn();
		},
		
		hide: function()
		{
			this._background.hide();
			this._menu.hide();
		}
	},
		
	getInstance: function()
	{
		var pattern = "WibiyaPlaceholderManager_";
		
		//init the background
		var background = null;
		if(jQuery("#" + pattern + "menu_background").length == 0)
		{
			background = jQuery("<div id='" + pattern + "menu_background" + "'></div>");
			jQuery("body").append(background);
		}
		else
			background = jQuery("#" + pattern + "menu_background");
		
		var css = {
			"background-color" : "#000000",
			"opacity" : 0.6,
			"filter" : "alpha(opacity=60)",
			"position" : "absolute",
			"top" : 0,
			"left" : 0,
			"display" : "none"
		}
		
		background.css(css);
		
		
		//init the menu list
		var menu = null;
		if(jQuery("#" + pattern + "menu").length == 0)
		{
			menu = jQuery("<div id='" + pattern + "menu'><a id='" + pattern + "close' style='margin: 4px 4px 0 0;cursor: pointer;background:url(http://gvs.ro/wibiya_img/btn_close.png) no-repeat;display: block; width: 21px; height: 21px;float:right'></a><ul id='" + pattern + "menu_list" + "'><li type='" + WibiyaPlaceholderTypes.Above + "'>Insert above</li><li type='" + WibiyaPlaceholderTypes.Bellow + "'>Insert below</li><li type='" + WibiyaPlaceholderTypes.InsideTop + "'>Insert inside top</li><li type='" + WibiyaPlaceholderTypes.InsideBottom + "'>Insert inside bottom</li></ul></div>");
			jQuery("body").append(menu);
			
			//bind the events for it
			menu.children("ul").children("li").hover(function(e){jQuery(this).css('background-color',"#aaaaaa");}, function (e) {jQuery(this).css('background',"none");});
			
			menu.children("ul").children("li").click(function(e){
				jQuery(WibiyaPlaceholderManager.Menu._object).trigger("insert", jQuery(this).attr("type"));
			});
			
			menu.children("a").click(function(e){
				jQuery(WibiyaPlaceholderManager.Menu._object).trigger("close");
			});
		
		}
		else
			menu = jQuery("#" + pattern + "menu");
		
		menu.css({
			"display" 			: "none",
			"position" 			: "absolute",
			"color" 			: "#ffffff",
			"margin" 			: "0px",
			"padding" 			: "0px",
			"z-index" 			: "1000",
			"font-family"		: "Arial, Verdana, sans-serif",
			"font-size"			: "12px",
			"font-weight"		: "bold",
			"min-width"			: "140px",
			"min-height"		: "150px"
		});
		menu.children("ul").css({
			"list-style" : "none",
			"margin" : "30px 0px",
			"padding" : "0px"
		});
		menu.children("ul").children("li").css({
			"padding" 	: "4px 0px 3px 10px",
			"cursor"	: "pointer"
		});
		
		menu.resizable({
			resize: function (event, ui) {
			
				jQuery("div.ui-resizable-e", menu).css ({
					"top"			: (menu.height() / 2 - 7) + "px"
				});
				jQuery("div.ui-resizable-s", menu).css ({
					"left"			: (menu.width() / 2 - 7) + "px"
				});
				
				var contRect = WibiyaPlaceholderManager.Rectangle.getInstance();
				var menuWidth = menu.width();
				var menuHeight = menu.height();
				var borderWidth = contRect.top.height();
				
				contRect.top.css({
					"width" : (borderWidth * 2 + menuWidth) + "px",
				});
				contRect.bottom.css({
					"width" : (borderWidth * 2 + menuWidth) + "px",
					"top"	: (menuHeight + menu.offset().top) + "px"
				});
				contRect.left.css({
					"height" : (borderWidth * 2 + menuHeight) + "px"
				});
				contRect.right.css({
					"height" 	: (borderWidth * 2 + menuHeight) + "px",
					"left"		: (menuWidth + menu.offset().left) + "px"
				});
				
				//refresh the background
				WibiyaPlaceholderManager.menu.refreshBackground();
			}
		});
		
		menu.children(".ui-resizable-handle").css({
			"width" : "15px",
			"height" : "15px",
			"position" : "absolute"
		})
		
		jQuery("div.ui-resizable-se", menu).css ({
			"background"	: "url(http://www.gvs.ro/wibiya_img/resize-se.png)",
			"bottom"		: "1px",
			"right"			: "1px",
			"cursor"		: "se-resize"
		});
		
		jQuery("div.ui-resizable-e", menu).css ({
			"background"	: "url(http://www.gvs.ro/wibiya_img/resize-e.png)",
			"right"			: "1px",
			"bottom"		: "px",
			"cursor"		: "e-resize",
		});
		
		jQuery("div.ui-resizable-s", menu).css ({
			"background"	: "url(http://www.gvs.ro/wibiya_img/resize-s.png)",
			"bottom"		: "1px",
			"cursor"		: "s-resize"
		});
		
		this._object._menu = menu;
		this._object._background = background;
		
		return this._object;
	}
}
