/*


 Copyright (c) 2008 Paul Bakaus
 Dual licensed under the MIT (MIT-LICENSE.txt)
 and GPL (GPL-LICENSE.txt) licenses.

*/
(function(b){function j(a,c,e){a=b[a][c].getter||[];a=typeof a=="string"?a.split(/,?\s+/):a;return b.inArray(e,a)!=-1}b.ui={plugin:{add:function(a,c,e){a=b.ui[a].prototype;for(var d in e){a.plugins[d]=a.plugins[d]||[];a.plugins[d].push([c,e[d]])}},call:function(a,c,e){if(c=a.plugins[c])for(var d=0;d<c.length;d++)a.options[c[d][0]]&&c[d][1].apply(a.element,e)}},cssCache:{},css:function(a){if(b.ui.cssCache[a])return b.ui.cssCache[a];var c=b('<div class="ui-gen">').addClass(a).css({position:"absolute",
top:"-5000px",left:"-5000px",display:"block"}).appendTo("body");b.ui.cssCache[a]=!!(!/auto|default/.test(c.css("cursor"))||/^[1-9]/.test(c.css("height"))||/^[1-9]/.test(c.css("width"))||!/none/.test(c.css("backgroundImage"))||!/transparent|rgba\(0, 0, 0, 0\)/.test(c.css("backgroundColor")));try{b("body").get(0).removeChild(c.get(0))}catch(e){}return b.ui.cssCache[a]},disableSelection:function(a){a.unselectable="on";a.onselectstart=function(){return false};if(a.style)a.style.MozUserSelect="none"},
enableSelection:function(a){a.unselectable="off";a.onselectstart=function(){return true};if(a.style)a.style.MozUserSelect=""},hasScroll:function(a,c){var e=/top/.test(c||"top")?"scrollTop":"scrollLeft",d=false;if(a[e]>0)return true;a[e]=1;d=a[e]>0?true:false;a[e]=0;return d}};var k=b.fn.remove;b.fn.remove=function(){b("*",this).add(this).trigger("remove");return k.apply(this,arguments)};b.widget=function(a,c){var e=a.split(".")[0];a=a.split(".")[1];b.fn[a]=function(d){var f=typeof d=="string",h=Array.prototype.slice.call(arguments,
1);if(f&&j(e,a,d)){var i=b.data(this[0],a);return i?i[d].apply(i,h):undefined}return this.each(function(){var g=b.data(this,a);if(f&&g&&b.isFunction(g[d]))g[d].apply(g,h);else f||b.data(this,a,new b[e][a](this,d))})};b[e][a]=function(d,f){var h=this;this.widgetName=a;this.widgetBaseClass=e+"-"+a;this.options=b.extend({},b.widget.defaults,b[e][a].defaults,f);this.element=b(d).bind("setData."+a,function(i,g,l){return h.setData(g,l)}).bind("getData."+a,function(i,g){return h.getData(g)}).bind("remove",
function(){return h.destroy()});this.init()};b[e][a].prototype=b.extend({},b.widget.prototype,c)};b.widget.prototype={init:function(){},destroy:function(){this.element.removeData(this.widgetName)},getData:function(a){return this.options[a]},setData:function(a,c){this.options[a]=c;if(a=="disabled")this.element[c?"addClass":"removeClass"](this.widgetBaseClass+"-disabled")},enable:function(){this.setData("disabled",false)},disable:function(){this.setData("disabled",true)}};b.widget.defaults={disabled:false};
b.ui.mouse={mouseInit:function(){var a=this;this.element.bind("mousedown."+this.widgetName,function(c){return a.mouseDown(c)});if(b.browser.msie){this._mouseUnselectable=this.element.attr("unselectable");this.element.attr("unselectable","on")}this.started=false},mouseDestroy:function(){this.element.unbind("."+this.widgetName);b.browser.msie&&this.element.attr("unselectable",this._mouseUnselectable)},mouseDown:function(a){this._mouseStarted&&this.mouseUp(a);this._mouseDownEvent=a;var c=this,e=a.which==
1,d=typeof this.options.cancel=="string"?b(a.target).is(this.options.cancel):false;if(!e||d||!this.mouseCapture(a))return true;this._mouseDelayMet=!this.options.delay;if(!this._mouseDelayMet)this._mouseDelayTimer=setTimeout(function(){c._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(f){return c.mouseMove(f)};this._mouseUpDelegate=
function(f){return c.mouseUp(f)};b(document).bind("mousemove."+this.widgetName,this._mouseMoveDelegate).bind("mouseup."+this.widgetName,this._mouseUpDelegate);return false},mouseMove:function(a){if(b.browser.msie&&!a.button)return this.mouseUp(a);if(this._mouseStarted){this.mouseDrag(a);return false}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){b(document).unbind("mousemove."+
this.widgetName,this._mouseMoveDelegate).unbind("mouseup."+this.widgetName,this._mouseUpDelegate);if(this._mouseStarted){this._mouseStarted=false;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}};b.ui.mouse.defaults=
{cancel:null,distance:1,delay:0}})(jQuery);

