/*
 * jztoc UI Components
 *
 * Copyright 2010, Acatl Pacheco
 * Licensed under the MIT License.
 *
 */
 
 
 var FocusEvents={FOCUSIN:"focusin",FOCUSOUT:"focusout"},MouseEvents={CLICK:"click",DBCLICK:"dbclick",HOVER:"hover",MOUSEDOWN:"mousedown",MOUSEENTER:"mouseenter",MOUSELEAVE:"mouseleave",MOUSEMOVE:"mousemove",MOUSEOUT:"mouseout",MOUSEOVER:"mouseover",MOUSEUP:"mouseup"};$.extend(MouseEvents,FocusEvents);var KeyboardEvents={KEYDOWN:"keydown",KEYPRESS:"keypress",KEYUP:"keyup"};$.extend(KeyboardEvents,FocusEvents);
var FormEvents={BLUR:"blur",CHANGE:"change",FOCUS:"focus",SELECT:"select",SUBMIT:"submit"},StateEvents={EXITSTATE:"exitstate",ENTERSTATE:"enterstate",ENDSTATE:"endstate"},UIComponentEvents={STARTRENDERING:"startrendering",FINISHRENDERING:"finishrendering"};jQuery.extend({jztocSetup:function(a){return jQuery.extend(true,jQuery.jztocSettings,a)},jztocSettings:{autoLoadApp:true,widgetDefinition:"data-widget"}});
$.ui.widget.subclass("ui.uicomponent",{options:{data:{},getChildren:true,renderHtmlTemplate:false,htmlTemplate:""},_helpers:[],elements:{},states:{_enterState:null,_exitState:null},_properties:{__currentState:null},_create:function(){this.element.addClass("ui-component");if(this._helpers!=null)for(var a=0;a<this._helpers.length;a++)$.extend(this,this._helpers[a]);this.__createProperties();this.options.renderHtmlTemplate==true&&this._renderHtmlTemplate();this._elements=$.extend({},this._elements);
this.options.getChildren==true&&this._getChildren()},__createProperties:function(){this._properties=$.extend({},this._properties);var a=[],b;for(b in this._properties)this._properties.hasOwnProperty(b)&&b.indexOf("__")!=0&&a.push({key:b,value:this._properties[b]});for(b=0;b<a.length;b++){var c=a[b];this[c.key]=this.__createProperty(c)}},__createProperty:function(a){this._properties[a.key+"Changed"]=false;return function(){if(arguments.length==0)return this._properties[a.key];else{this._properties[a.key+
"Changed"]=true;this._properties[a.key]=arguments[0];this.invalidateProperties();return true}}},_getChildren:function(){var a=[];$("[id]",this.element).each(function(){$(this).attr("id")!=null&&a.push({id:$(this).attr("id"),instance:$(this)})});this.elements={};for(var b=0;b<a.length;b++){var c=a[b];this.elements[c.id]=c.instance}},_renderHtmlTemplate:function(a){if(!(this.options.htmlTemplate==null||this.options.htmlTemplate=="")){$(b).trigger(UIComponentEvents.STARTRENDERING);var b=this.element;
if(a!=null)b=typeof a!=="string"?a:$(a);b.html(this.options.htmlTemplate);$(b).trigger(UIComponentEvents.FINISHRENDERING)}},addChild:function(a){a=$(a).appendTo(this.element);var b=a.attr("id");if(b!=null)this.elements.push[b]=a;return a},currentState:function(a){if(arguments.length==0)return this._properties.__currentState;for(var b=this._properties.__currentState,c=a.split(" "),e=[],d=1;d<arguments.length;d++)e.push(arguments[d]);this.__executePredefinedSatates(a);if(this.states!=null){this._properties.__currentState=
c[c.length-1];this.states._exitState!=null?this.states._exitState.apply(this,[a]):$(this.element).trigger("exitstate");this.states._enterState!=null?this.states._enterState.apply(this,[a]):$(this.element).trigger("enterstate");for(d=0;d<c.length;d++){var f=c[d];if(b==null)b="";else this.element.removeClass("state-"+b);this.element.addClass("state-"+f);e.splice(0,0,b);this.states[f].apply(this,e);b=f;e.splice(0,1)}this.states._endState!=null?this.states._endState.apply(this,[a]):$(this.element).trigger("endstate")}return false},
__executePredefinedSatates:function(a){var b="data-state-"+a,c,e;$("["+b+"]",this.element).each(function(){c=$(this).attr(b);if(c!=null){e=$.parseJSON(c);if(e!=null)for(var d in e)e.hasOwnProperty(d)&&$(this)[d](e[d])}})},_commitProperties:function(){},invalidateProperties:function(){this._commitProperties()},_updateView:function(){},invalidateView:function(){this._updateView()},destroy:function(){this.element.removeClass("ui-component");this._properties.__currentState!=null&&this.element.removeClass("state-"+
this._properties.__currentState);for(var a in this.elements)this.elements.hasOwnProperty(a)&&this.elements[a].remove();$.Widget.prototype.destroy.apply(this,arguments)}});$.ui.uicomponent.subclass("ui.document",{pageTitle:function(a){$("title").text(a)},destroy:function(){$.Widget.prototype.destroy.apply(this,arguments)}});
$.ui.uicomponent.subclass("ui.itemrenderer",{options:{listData:{owner:null,data:null,column:null,index:null,td:null,tr:null}},_create:function(){this.element.addClass("ui-itemrenderer")},_dispatchEvent:function(a,b){var c=jQuery.Event(a);c.listData=this.options.listData;$(this.options.listData.owner.element).trigger(c,b)},destroy:function(){$.Widget.prototype.destroy.apply(this,arguments)}});
(function(a){a.fn.addEventListener=function(b,c,e,d){if(!(arguments.length<2)){var f=c;if(arguments.length>2)f=a.proxy(c,e);return this.each(function(){a(this).bind(b,d,f)})}}})(jQuery);(function(a){a.fn.getChild=function(b){if(jQuery.type(b)=="number")return a(this).children().eq(b);return a(b,this)}})(jQuery);$(document).ready(function(){var a=jQuery.jztocSettings;if(a.autoLoadApp==true){a=$("body").attr(a.widgetDefinition);a!=null&&jQuery.type($(document)[a])=="function"&&$("body")[a]()}});

