/**
  * Chico-UI
  * Packer-o-matic
  * Like the pizza delivery service: "Les than 100 milisecons delivery guarantee!"
  * @components: core, positioner, object, floats, navs, controllers, watcher, sliders, keyboard, preload, list, extend, carousel, calendar, dropdown, layer, modal, tabNavigator, tooltip, string, number, custom, required, helper, form, viewer, expando, menu, zoom
  * @version 0.4
  * @autor Chico Team <chico@mercadolibre.com>
  *
  * @based on:
  * JSMin
  * @author Ryan Grove <ryan@wonko.com> 
  * @copyright 2002 Douglas Crockford <douglas@crockford.com> (jsmin.c) 
  * @copyright 2008 Ryan Grove <ryan@wonko.com> (PHP port) 
  * @link http://code.google.com/p/jsmin-php/ 
  */


var ch=window.ch={version:"0.6.7",components:"carousel,calendar,dropdown,layer,modal,tabNavigator,tooltip,string,number,custom,required,helper,form,viewer,expando,menu,zoom",internals:"positioner,object,floats,navs,controllers,watcher,sliders,keyboard,preload,list,extend",instances:{},features:{},init:function(){$("html").removeClass("no-js");ch.features=ch.support();$(ch.components.split(",")).each(function(i,e){ch.factory({component:e});});ch.utils.document.bind("keydown",function(event){ch.keyboard(event);});},utils:{body:$("body"),html:$("html"),window:$(window),document:$(document),zIndex:1000,index:0,isSelector:function(string){if(typeof string!=="string")return false;for(var regex in $.expr.match){if($.expr.match[regex].test(string)&&$(string).length>0){return true;};};return false;},isArray:function(o){return Object.prototype.toString.apply(o)==="[object Array]";},isUrl:function(url){return((/^((https?|ftp|file):\/\/|((www|ftp)\.)|(\/|.*\/)*)[a-z0-9-]+((\.|\/)[a-z0-9-]+)+([/?].*)?$/).test(url));},avoidTextSelection:function(){$.each(arguments,function(i,e){if($.browser.msie){$(e).attr('unselectable','on');}else if($.browser.opera){$(e).bind("mousedown",function(){return false;});}else{$(e).addClass("ch-user-no-select");};});return;},hasOwn:function(o,property){return Object.prototype.hasOwnProperty.call(o,property);}},events:{LAYOUT:{CHANGE:"change"},KEY:{ENTER:"enter",ESC:"esc",LEFT_ARROW:"left_arrow",UP_ARROW:"up_arrow",RIGHT_ARROW:"right_arrow",DOWN_ARROW:"down_arrow"}}};ch.clon=function(o){obj={};for(x in o){obj[x]=o[x];};return obj;};ch.factory=function(o){if(!o){alert("Factory fatal error: Need and object {component:\"\"} to configure a component.");return;};if(!o.component){alert("Factory fatal error: No component defined.");return;};var x=o.component;var create=function(x){$.fn[x]=function(options){var results=[];var that=this;var _arguments=arguments;that.each(function(i,e){var conf=options||{};var context={};context.type=x;context.element=e;context.$element=$(e);context.uid=ch.utils.index+=1;switch(typeof conf){case"number":var num=conf;conf={};conf.value=num;if(_arguments[1]){conf.msg=_arguments[1];};break;case"string":var msg=conf;conf={};conf.msg=msg;break;case"function":var func=conf;conf={};conf.lambda=func;if(_arguments[1]){conf.msg=_arguments[1];};break;};var created=ch[x].call(context,conf);created=(ch.utils.hasOwn(created,"public"))?created["public"]:created;if(created.type){var type=created.type;if(!ch.instances[type]){ch.instances[type]=[];}
ch.instances[type].push(created);}
if(created.exists){created=created.object;}
results.push(created);});return(results.length>1)?results:results[0];};if(o.callback){o.callback();}}
if(ch[o.component]){create(o.component);}else{ch.get({"method":"component","component":o.component,"script":(o.script)?o.script:"src/js/"+o.component+".js","styles":(o.style)?o.style:"src/css/"+x+".css","callback":create});}}
ch.get=function(o){switch(o.method){case"content":var that=o.that;var conf=that.conf;var context=(ch.utils.hasOwn(that,"controller"))?that.controller:that["public"];setTimeout(function(){$.ajax({url:conf.ajaxUrl,type:conf.ajaxType||'GET',data:conf.ajaxParams,cache:true,async:true,beforeSend:function(jqXHR){jqXHR.setRequestHeader("X-Requested-With","XMLHttpRequest");},success:function(data,textStatus,jqXHR){that.$content.html(data);if(ch.utils.hasOwn(conf,"onContentLoad"))conf.onContentLoad.call(context,data,textStatus,jqXHR);if(ch.utils.hasOwn(conf,"position"))ch.positioner(conf.position);},error:function(jqXHR,textStatus,errorThrown){data=(ch.utils.hasOwn(conf,"onContentError"))?conf.onContentError.call(context,jqXHR,textStatus,errorThrown):"<p>Error on ajax call </p>";that.$content.html(data);if(ch.utils.hasOwn(conf,"position"))ch.positioner(conf.position);}});},0);break;case"component":if(o.style){var style=document.createElement('link');style.href=o.style;style.rel='stylesheet';style.type='text/css';}
if(o.script){var script=document.createElement("script");script.src=o.script;}
var head=document.getElementsByTagName("head")[0]||document.documentElement;var done=false;script.onload=script.onreadystatechange=function(){if(!done&&(!this.readyState||this.readyState==="loaded"||this.readyState==="complete")){done=true;if(o.callback){o.callback(o.component);}
script.onload=script.onreadystatechange=null;if(head&&script.parentNode){head.removeChild(script);}}};if(o.script){head.insertBefore(script,head.firstChild);}
if(o.style){head.appendChild(style);}
break;}}
ch.support=function(){var thisBody=document.body||document.documentElement;var transition=(function(){var thisStyle=thisBody.style;return thisStyle.WebkitTransition!==undefined||thisStyle.MozTransition!==undefined||thisStyle.OTransition!==undefined||thisStyle.transition!==undefined;})();var fixed=(function(){var isSupported=false;var e=document.createElement("div");e.style.position="fixed";e.style.top="10px";thisBody.appendChild(e);if(e.offsetTop===10){isSupported=true;};thisBody.removeChild(e);return isSupported;})();return{transition:transition,fixed:fixed};};ch.positioner=function(o){var initPosition=function(){viewport=getViewport();parentRelative=getParentRelative();context=getContext();setPosition();};var o=o||this.conf.position;o.points=o.points||"cm cm";o.offset=o.offset||"0 0";var element=$(o.element);element.css("position","absolute");var context;var viewport;var parentRelative;var _CLASS_REFERENCES={"lt lb":"ch-left ch-bottom","lb lt":"ch-left ch-top","rt rb":"ch-right ch-bottom","rb rt":"ch-right ch-top","lt rt":"ch-right","cm cm":"ch-center"};var splittedOffset=o.offset.split(" ");var offset_left=parseInt(splittedOffset[0]);var offset_top=parseInt(splittedOffset[1]);var getViewport=function(){var viewport,width,height,left,top,pageX,pageY,scrollBar=30;if(typeof window.innerWidth!="undefined"){viewport=window;width=viewport.innerWidth-scrollBar;height=viewport.innerHeight;pageX=viewport.pageXOffset;pageY=viewport.pageYOffset;return{element:viewport,left:0+offset_left+pageX-scrollBar,top:0+offset_top+pageY,bottom:height+pageY,right:width+pageX,width:width,height:height}}
else{viewport=document.documentElement;width=viewport.clientWidth-scrollBar;height=viewport.clientHeight;pageX=viewport.scrollLeft;pageY=viewport.scrollTop;return{element:viewport,left:0+offset_left+pageX,top:0+offset_top+pageY,bottom:height+pageY,right:width+pageX,width:width,height:height}}};var getPosition=function(unitPoints){var contextLeft=context.left;var contextTop=context.top;var contextWidth=context.width;var contextHeight=context.height;var elementWidth=element.outerWidth();var elementHeight=element.outerHeight();var xReferences={ll:contextLeft,lr:contextLeft+contextWidth,rr:contextLeft+contextWidth-elementWidth,cc:contextLeft+contextWidth/2-elementWidth/2}
var yReferences={tt:contextTop,tb:contextTop+contextHeight,bt:contextTop-elementHeight,mm:contextTop+contextHeight/2-elementHeight/2}
var axis={left:xReferences[unitPoints.my_x+unitPoints.at_x],top:yReferences[unitPoints.my_y+unitPoints.at_y]}
return axis;};var calculatePoints=function(points,unitPoints){var styles=getPosition(unitPoints);var classes=_CLASS_REFERENCES[points]||"";if(o.hold){styles.classes=classes;return styles;};var stylesCache;classes=classes.split(" ");if((points=="lt lb"||points=="rt rb")&&((styles.top+parentRelative.top+element.outerHeight())>viewport.bottom)){unitPoints.my_y="b";unitPoints.at_y="t";stylesCache=styles;styles=getPosition(unitPoints);if(styles.top+parentRelative.top<viewport.top){styles=stylesCache;}else{styles.top-=(2*offset_top);classes[1]="ch-top";};};if((styles.left+parentRelative.left+element.outerWidth())>viewport.right){unitPoints.my_x=unitPoints.at_x="r";stylesCache=styles;styles=getPosition(unitPoints);if(styles.left<viewport.left){styles=stylesCache;}else{styles.left-=(2*offset_left);classes[0]="ch-right";if(classes[1]=="ch-top"){styles.top-=(2*offset_top);};};};styles.classes=classes.join(" ");return styles;};var setPosition=function(){var splitted=o.points.split(" ");var unitPoints={my_x:splitted[0].charAt(0),my_y:splitted[0].charAt(1),at_x:splitted[1].charAt(0),at_y:splitted[1].charAt(1)}
var styles=calculatePoints(o.points,unitPoints);element.css({left:styles.left,top:styles.top}).removeClass("ch-top ch-left ch-bottom ch-right").addClass(styles.classes);if(ch.utils.hasOwn(context,"element")&&context.element!==ch.utils.window[0]){$(context.element).removeClass("ch-top ch-left ch-bottom ch-right").addClass(styles.classes);};};var getContext=function(){if(!o.context){return viewport;}
var contextOffset=o.context.offset();context={element:o.context,top:contextOffset.top+offset_top-parentRelative.top,left:contextOffset.left+offset_left-parentRelative.left,width:o.context.outerWidth(),height:o.context.outerHeight()};return context;};var getParentRelative=function(){var relative={};relative.left=0;relative.top=0;var parent=element.offsetParent();if(parent.css("position")=="relative"){var borderLeft=(parent.outerWidth()-parent.width()-(parseInt(parent.css("padding-left"))*2))/2;relative=parent.offset();relative.left-=offset_left-borderLeft;relative.top-=offset_top;};return{left:relative.left,top:relative.top};};var scrolled=false;ch.utils.window.bind("resize scroll",function(){scrolled=true;});setInterval(function(){if(!scrolled)return;scrolled=false;if(element.css("display")==="none")return;initPosition();},250);initPosition();return $(element);};ch.object=function(){var that=this;var conf=that.conf;that.prevent=function(event){if(event&&typeof event=="object"){event.preventDefault();event.stopPropagation();};return that;};that.content=function(content){if(content===undefined){var content=conf.content||conf.msg;return(content)?((ch.utils.isSelector(content))?$(content):content):((conf.ajax===true)?(that.$trigger.attr('href')||that.$trigger.parents('form').attr('action')):conf.ajax);}else{var cache=conf.cache;conf.cache=false;if(ch.utils.isUrl(content)){conf.content=undefined;conf.ajax=content;}else{conf.ajax=false;conf.content=content;};if(ch.utils.hasOwn(that,"$content")){that.$content.html(that.loadContent());that.position("refresh");};conf.cache=cache;return that["public"];};};that.loadContent=function(){if(conf.ajax===true){conf.ajaxUrl=that.$element.attr('href')||that.$element.parents('form').attr('action');conf.ajaxParams='x=x';if(that.$element.attr('type')=='submit'){conf.ajaxType=that.$element.parents('form').attr('method')||'GET';var serialized=that.$element.parents('form').serialize();conf.ajaxParams=conf.ajaxParams+((serialized!='')?'&'+serialized:'');};ch.get({method:"content",that:that});return'<div class="loading"></div>';}else if(conf.ajax||(conf.msg&&ch.utils.isUrl(conf.msg))){conf.ajaxUrl=conf.ajax||conf.msg;conf.ajaxParams='x=x';ch.get({method:"content",that:that});return'<div class="loading"></div>';}else{var content=conf.content||conf.msg;return(ch.utils.isSelector(content))?$(content).detach().clone().removeClass("ch-hide").show():content;};};that.callbacks=function(when){if(ch.utils.hasOwn(conf,when)){var context=(that.controller)?that.controller["public"]:that["public"];return conf[when].call(context);};};that.position=function(o){switch(typeof o){case"object":conf.position.context=o.context||conf.position.context;conf.position.points=o.points||conf.position.points;conf.position.offset=o.offset||conf.position.offset;conf.position.fixed=o.fixed||conf.position.fixed;ch.positioner(conf.position);return that["public"];break;case"string":if(o!="refresh"){alert("ChicoUI error: position() expected to find \"refresh\" parameter.");};ch.positioner(conf.position);return that["public"];break;case"undefined":return conf.position;break;};};that["public"]={};return that;};ch.floats=function(){var that=this;var conf=that.conf;that=ch.object.call(that);that.parent=ch.clon(that);var createCone=function(){$("<div>").addClass("ch-cone").prependTo(that.$container);return;};var createClose=function(){$("<div>").addClass("btn close").css("z-index",ch.utils.zIndex++).bind("click",function(event){that.hide(event);}).prependTo(that.$container);ch.utils.document.bind(ch.events.KEY.ESC,function(event){that.hide(event);});return;};var createLayout=function(){that.$content=$("<div>").addClass("ch-"+that.type+"-content").html(that.loadContent());that.$container=$("<div>").addClass("ch-"+that.type).css("z-index",ch.utils.zIndex++).append(that.$content).appendTo("body");if(ch.utils.hasOwn(conf,"classes"))that.$container.addClass(conf.classes);if(ch.utils.hasOwn(conf,"width"))that.$container.css("width",conf.width);if(ch.utils.hasOwn(conf,"height"))that.$container.css("height",conf.height);if(ch.utils.hasOwn(conf,"closeButton")&&conf.closeButton)createClose();if(ch.utils.hasOwn(conf,"cone"))createCone();if(ch.utils.hasOwn(conf,"fx"))conf.fx=conf.fx;else conf.fx=true;conf.cache=(ch.utils.hasOwn(conf,"cache"))?conf.cache:true;if(conf.fx){that.$container.fadeIn("fast",function(){that.callbacks("onShow");});}else{that.$container.show();that.callbacks("onShow");};conf.position=conf.position||{};conf.position.element=that.$container;conf.position.hold=conf.hold||false;ch.positioner.call(that);return;};that.active=false;that.show=function(event){if(event)that.prevent(event);if(that.active)return;that.active=true;if(that.$container){if(!conf.cache)that.$content.html(that.loadContent());var content=conf.content||conf.msg;if(ch.utils.isSelector(content))$(content).detach();that.$container.appendTo("body").css("z-index",ch.utils.zIndex++).fadeIn('fast',function(){that.active=true;that.callbacks('onShow');});that.position("refresh");return that;};createLayout();return that;};that.hide=function(event){if(event)that.prevent(event);if(!that.active)return;var afterHide=function(){that.active=false;var content=conf.content||conf.msg;if(ch.utils.isSelector(content)){if($("body "+content+".ch-hide").length>0)return false;that.$content.children().clone().addClass("ch-hide").appendTo("body");};that.callbacks('onHide');that.$container.detach();};if(conf.fx){that.$container.fadeOut("fast",afterHide);}else{that.$container.hide();afterHide();};return that;};return that;};ch.navs=function(){var that=this;var conf=that.conf;conf.icon=(ch.utils.hasOwn(conf,"icon"))?conf.icon:true;conf.open=conf.open||false;conf.fx=conf.fx||false;that=ch.object.call(that);that.parent=ch.clon(that);var createIcon=function(){$("<span>").addClass("ico").html("drop").appendTo(that.$trigger);return;};that.active=false;that.show=function(event){that.prevent(event);if(that.active){return that.hide(event);};that.active=true;that.$trigger.addClass("ch-"+that.type+"-trigger-on");if(conf.fx){that.$content.slideDown("fast",function(){that.callbacks("onShow");});}else{that.$content.removeClass("ch-hide");that.callbacks("onShow");};return that;};that.hide=function(event){that.prevent(event);if(!that.active)return;that.active=false;that.$trigger.removeClass("ch-"+that.type+"-trigger-on");if(conf.fx){that.$content.slideUp("fast",function(){that.callbacks("onHide");});}else{that.$content.addClass("ch-hide");that.callbacks("onHide");};return that;};that.configBehavior=function(){that.$trigger.addClass("ch-"+that.type+"-trigger").bind("click",function(event){that.show(event);});that.$content.addClass("ch-"+that.type+"-content ch-hide");if(conf.icon)createIcon();if(conf.open)that.show();return;};that.$element.addClass("ch-"+that.type);return that;}
ch.controllers=function(){var that=this;that=ch.object.call(that);that.parent=ch.clon(that);that.children=[];return that;};ch.watcher=function(conf){var that=this;conf=ch.clon(conf);that.conf=conf;that=ch.object.call(that);that.parent=ch.clon(that);var controller=(function(){if(ch.utils.hasOwn(ch.instances,"form")&&ch.instances.form.length>0){var i=0,j=ch.instances.form.length;for(i;i<j;i++){if(ch.instances.form[i].element===that.$element.parents("form")[0]){return ch.instances.form[i];};};}else{that.$element.parents("form").form();var last=(ch.instances.form.length-1);return ch.instances.form[last];};})();var checkInstance=function(){var instance=ch.instances.watcher;if(instance&&instance.length>0){for(var i=0,j=instance.length;i<j;i++){if(instance[i].element!==that.element)continue;$.merge(instance[i].conditions,that.conditions);return{exists:true,object:instance[i]};};};};var revalidate=function(){that.validate();controller.checkStatus();};that.active=false;that.enabled=true;that.reference=(function(){var reference;if(that.$element.hasClass("options")){if(that.$element.find('h4').length>0){var h4=that.$element.find('h4');h4.wrapInner('<span>');reference=h4.children();}else if(that.$element.prev().prop('tagName')=='LEGEND'){reference=that.$element.prev();}}else{reference=that.$element;}
return reference;})();that.conditions=(function(){var c=[];var i=0;var t=conf.conditions.length;for(i;i<t;i++){var condition=conf.conditions[i];if(conf[condition.name]){condition.value=conf[condition.name];if(conf.messages[condition.name]){condition.message=conf.messages[condition.name];}
c.push(condition);}}
return c;})();that.isRequired=function(){var t=that.conditions.length;while(t--){var condition=that.conditions[t];if(condition.name==="required"&&condition.value){return true;}}
return false;};var helper={};helper.uid=that.uid+"#0";helper.type="helper";helper.element=that.element;helper.$element=that.$element;that.helper=ch.helper.call(helper,that);that.validate=function(event){if(that.$element.attr('disabled')){return;}
var isRequired=that.isRequired()
if(!isRequired&&that.isEmpty()&&that.active===false){return;}
if(that.enabled&&(that.active===false||!that.isEmpty()||isRequired)){that.callbacks('beforeValidate');var i=0,t=that.conditions.length,value=that.$element.val(),gotError=false;for(i;i<t;i+=1){var condition=that.conditions[i];if(that.isRequired()){gotError=that.isEmpty();}
if(condition.patt){gotError=!condition.patt.test(value);}
if(condition.expr){gotError=!condition.expr(value,condition.value);}
if(condition.func){gotError=!condition.func.call(that["public"],value);}
if(gotError){that.callbacks('onError');that.$element.addClass("error");var text=(condition.message)?condition.message:(ch.utils.hasOwn(controller,"messages"))?controller.messages[condition.name]:undefined;that.helper.show(text);that.active=true;var validationEvent=(that.tag=='OPTIONS'||that.tag=='SELECT')?"change":"blur";that.$element.one(validationEvent,function(event){that.validate(event);});return;}}}
if(that.active||!that.enabled){that.$element.removeClass("error");that.helper.hide();that.active=false;if(event){var originalTarget=event.originalEvent.explicitOriginalTarget||document.activeElement;if(originalTarget.type=="submit"){controller.submit(event);};};};that.callbacks('afterValidate');return that;};that.reset=function(){that.active=false;that.$element.removeClass("error");that.helper.hide();that.$element.unbind("blur change",that.validate);that.callbacks("onReset");return that;};that.isEmpty=function(){that.tag=(that.$element.hasClass("options"))?"OPTIONS":that.element.tagName;switch(that.tag){case'OPTIONS':return that.$element.find('input:checked').length===0;break;case'SELECT':var val=that.$element.val();return parseInt(val)===-1||val===null;break;case'INPUT':case'TEXTAREA':return $.trim(that.$element.val()).length===0;break;};};that["public"].uid=that.uid;that["public"].element=that.element;that["public"].type="watcher";that["public"].reference=that.reference;that["public"].conditions=that.conditions;that["public"].helper=that.helper["public"];that["public"].active=function(){return that.active;};that["public"].and=function(){return that.$element;};that["public"].reset=function(){that.reset();return that["public"];};that["public"].validate=function(){that.validate();return that["public"];};that["public"].enable=function(){that.enabled=true;return that["public"];};that["public"].disable=function(){that.enabled=false;that.reset();return that["public"];};that["public"].refresh=function(){that.helper.position("refresh");return that["public"];};var check=checkInstance();if(check){var that={};that["public"]=check;}else{controller.children.push(that["public"]);};return that;};ch.keyboard=function(event){var keyCodes={"13":"ENTER","27":"ESC","37":"LEFT_ARROW","38":"UP_ARROW","39":"RIGHT_ARROW","40":"DOWN_ARROW"};if(!ch.utils.hasOwn(keyCodes,event.keyCode))return;ch.utils.document.trigger(ch.events.KEY[keyCodes[event.keyCode]],event);};ch.preload=function(arr){if(typeof arr==="string"){arr=(arr.indexOf(",")>0)?arr.split(","):[arr];}
for(var i=0;i<arr.length;i++){var o=document.createElement("object");o.data=arr[i];var h=document.getElementsByTagName("head")[0];h.appendChild(o);h.removeChild(o);}};ch.list=function(collection){var that=this;var _children=(collection&&ch.utils.isArray(collection))?collection:[];var _find=function(q,a){if(!q){return _children;}
var c=typeof q;if(c==="number"){q--;return(a)?a.call(that,q):_children[q];}
var t=size(),_prop,child;if(c==="string"||c==="object"){while(t--){child=_children[t];if(child===q){return(a)?a.call(that,t):child;}
for(_prop in child){if(_prop===q||child[_prop]===q){return(a)?a.call(that,t):child;}}}}};var add=function(child){if(ch.utils.isArray(child)){var i=0,t=child.length;for(i;i<t;i++){_children.push(child[i]);}
return _children;}
return _children.push(child);};var rem=function(q){if(!q){return that;}
var remove=function(t){return _children.splice(t,1)[0];}
return _find(q,remove);};var get=function(q){return _find(q);};var size=function(){return _children.length;};var that={children:_children,add:add,rem:rem,get:get,size:size};return that;};ch.extend=function(klass){"use strict";return{as:function(name,process){ch[name]=function(conf){conf=(process)?process(conf):conf||{};conf[name]=conf.value||true;conf.messages=conf.messages||{};if(ch.utils.hasOwn(conf,"msg")){conf.messages[name]=conf.msg;conf.msg=null;delete conf.msg;}
return ch[klass].call(this,conf);};ch.factory({component:name});}}};ch.carousel=function(conf){var that=this;conf=ch.clon(conf);conf.pagination=conf.pagination||false;conf.rolling=false;if(ch.utils.hasOwn(conf,"arrows")){conf.arrows=conf.arrows;}else{conf.arrows=true;};if(ch.utils.hasOwn(conf,"fx")){conf.fx=conf.fx;}else{conf.fx=true;};that.conf=conf;that=ch.object.call(that);that.parent=ch.clon(that);var _createLayout=function(){that.$content=$("<div>").addClass("ch-carousel-content").append(that.$collection);that.$container=$("<div>").addClass("ch-carousel-container").css("height",that.itemSize.height).append(that.$content).appendTo(that.$element);if(ch.utils.hasOwn(conf,"width")){that.$element.css("width",conf.width);};if(ch.utils.hasOwn(conf,"height")){that.$element.css("height",conf.height);};if(!conf.fx&&ch.features.transition){that.$content.addClass("ch-carousel-nofx");};return;},_createArrows=function(){that.prevArrow=$("<p>").addClass("ch-prev-arrow").append("<span>Previous</span>").bind("click",that.prev);that.nextArrow=$("<p>").addClass("ch-next-arrow").append("<span>Next</span>").bind("click",that.next);if(!conf.rolling){that.prevArrow.addClass("ch-hide")};that.$element.prepend(that.prevArrow).append(that.nextArrow);var arrowsPosition=(that.$element.outerHeight()-that.nextArrow.outerHeight())/2;$(that.prevArrow).css("top",arrowsPosition);$(that.nextArrow).css("top",arrowsPosition);return;},_toggleArrows=function(page){if(page>1&&page<that.pages){that.prevArrow.removeClass("ch-hide");that.nextArrow.removeClass("ch-hide");}else{if(page==1){that.prevArrow.addClass("ch-hide");that.nextArrow.removeClass("ch-hide");};if(page==that.pages){that.prevArrow.removeClass("ch-hide");that.nextArrow.addClass("ch-hide");};};return;},_createPagination=function(){that.$element.find(".ch-carousel-pages").remove();that.$pagination=$("<ul>").addClass("ch-carousel-pages");for(var i=1;i<=that.pages;i+=1){var thumb=$("<li>").html(i);if(i==that.currentPage){thumb.addClass("ch-carousel-pages-on");};that.$pagination.append(thumb);};$.each(that.$pagination.children(),function(i,e){$(e).bind("click",function(){that.goTo(i+1);});});that.$element.append(that.$pagination);that.$pagination.css("left",(that.$element.outerWidth()-that.$pagination.outerWidth())/2);_$itemsPagination=that.$pagination.children();return;},_getItemsPerPage=function(){var _widthDiff=that.$element.outerWidth()-that.itemSize.width;return(_widthDiff>that.itemSize.width)?~~(_widthDiff/that.itemSize.width):1;},_getPages=function(){return Math.ceil(that.items.children.length/that.itemsPerPage);},_draw=function(){_maskWidth=that.$container.outerWidth();that.itemsPerPage=_getItemsPerPage();that.pages=_getPages();var _itemMargin=((_maskWidth-(that.itemSize.width*that.itemsPerPage))/that.itemsPerPage)/2;if(_itemMargin<0)return;that.$content.detach();that.goTo(1);$.each(that.items.children,function(i,e){e.style.marginLeft=e.style.marginRight=_itemMargin+"px";});that.$content.css("width",((that.itemSize.width+(_itemMargin*2))*that.items.size()+_extraWidth)).appendTo(that.$container);if(conf.pagination&&that.pages>1){_createPagination();};return;},_maskWidth,_$itemsPagination,_extraWidth,_resize=false;that.$collection=that.$element.children();that.items=ch.list(that.$collection.children().toArray());that.itemSize={width:$(that.items.children[0]).outerWidth(),height:$(that.items.children[0]).outerHeight()};that.currentPage=1;that.goTo=function(page){if(page==that.currentPage||page>that.pages||page<1||isNaN(page)){return that;};var movement=-(_maskWidth*(page-1));if(conf.fx&&ch.features.transition){that.$content.css("left",movement);}else if(conf.fx){that.$content.animate({left:movement});}else{that.$content.css("left",movement);};if(!conf.rolling&&conf.arrows){_toggleArrows(page);};that.currentPage=page;if(conf.pagination){_$itemsPagination.removeClass("ch-carousel-pages-on").eq(page-1).addClass("ch-carousel-pages-on");};that.callbacks("onMove");return that;};that.prev=function(){that.goTo(that.currentPage-1);that.callbacks("onPrev");return that;};that.next=function(){that.goTo(that.currentPage+1);that.callbacks("onNext");return that;};that["public"].uid=that.uid;that["public"].element=that.element;that["public"].type=that.type;that["public"].getItemsPerPage=function(){return that.itemsPerPage;};that["public"].getPage=function(){return that.currentPage;};that["public"].goTo=function(page){that.goTo(page);return that["public"];};that["public"].next=function(){that.next();return that["public"];};that["public"].prev=function(){that.prev();return that["public"];};that["public"].redraw=function(){_draw();return that["public"];};that.$element.addClass("ch-carousel");that.$collection.detach().addClass("ch-carousel-list").children().addClass("ch-carousel-item");_createLayout();_extraWidth=(ch.utils.html.hasClass("ie6"))?that.itemSize.width:0;_draw();if(conf.arrows&&that.pages>1){_createArrows();};if(!conf.hasOwnProperty("width")){ch.utils.window.bind("resize",function(){_resize=true;});setInterval(function(){if(!_resize){return;};_resize=false;_draw();},250);};return that;}
ch.calendar=function(conf){var that=this;conf=ch.clon(conf);if(ch.utils.hasOwn(conf,"selected")){conf.selected=new Date(conf.selected);};that.conf=conf;that=ch.controllers.call(that);that.parent=ch.clon(that);var _monthsNames=conf.monthsNames||["Enero","Febero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre"];var _shortWeekdaysNames=conf.weekdays||["Dom","Lun","Mar","Mie","Jue","Vie","Sab"];var _today=new Date();var _selected=conf.selected;var _weekdays=(function(){var _weekdaysTitle="<thead>";for(var i=0;i<_shortWeekdaysNames.length;i+=1){_weekdaysTitle+="<th>"+_shortWeekdaysNames[i]+"</th>";};return _weekdaysTitle+="</thead>";}());var _templateMonth=$("<table>").addClass("ch-calendar-month").append(_weekdays);var _createMonth=function(date){var date=new Date(date);var _tableMonth=_templateMonth.clone();var _currentMonth={};_currentMonth.fullDate=new Date(date.getFullYear(),date.getMonth(),1);_currentMonth.date=_currentMonth.fullDate.getDate();_currentMonth.day=_currentMonth.fullDate.getDay();_currentMonth.month=_currentMonth.fullDate.getMonth();_currentMonth.year=_currentMonth.fullDate.getFullYear();var _currentDate={};_currentDate.fullDate=new Date(date.getFullYear(),date.getMonth(),1);_currentDate.date=_currentDate.fullDate.getDate();_currentDate.day=_currentDate.fullDate.getDay();_currentDate.month=_currentDate.fullDate.getMonth();_currentDate.year=_currentDate.fullDate.getFullYear();var first_weekday=_currentMonth.day;var _weeks,_classToday,_classSelected;_weeks="<tbody>";do{_weeks+="<tr class=\"week\">";for(var i=0;i<7;i+=1){if(_currentDate.date==1){for(var i=0;i<first_weekday;i+=1){_weeks+="<td class=\"disable\"></td>";};};_classToday=(_currentDate.date==_today.getDate()&&_currentDate.month==_today.getMonth()&&_currentDate.year==_today.getFullYear())?" today":"";_classSelected=(_selected&&_currentDate.date==_selected.getDate()&&_currentDate.month==_selected.getMonth()&&_currentDate.year==_selected.getFullYear())?" selected":"";_weeks+="<td class=\"day"+_classToday+_classSelected+"\">"+_currentDate.date+"</td>";_currentDate.fullDate.setDate(_currentDate.date+1);_currentDate.date=_currentDate.fullDate.getDate();_currentDate.day=_currentDate.fullDate.getDay();_currentDate.month=_currentDate.fullDate.getMonth();_currentDate.year=_currentDate.fullDate.getFullYear();if(_currentDate.month!=_currentMonth.month){break;};};_weeks+="</tr>";}while(_currentDate.month==_currentMonth.month);_weeks+="</tbody>";_tableMonth.prepend("<caption>"+_monthsNames[_currentMonth.month]+" - "+_currentMonth.year+"</caption>").append(_weeks);$.each(_tableMonth.find(".day"),function(i,e){$(e).bind("click",function(){_select(_currentDate.year+"/"+_currentDate.month+"/"+this.innerHTML);});});return _tableMonth;};var _arrows={$prev:$("<p>").addClass("ch-calendar-prev").bind("click",function(event){that.prevent(event);_prevMonth();}),$next:$("<p>").addClass("ch-calendar-next").bind("click",function(event){that.prevent(event);_nextMonth();})};var _createDropdown=function(){var _dropdownTrigger=$("<strong>").html("Calendar");that.$trigger.append(_dropdownTrigger).append(that.$container);that.children[0]=that.$trigger.dropdown({onShow:function(){that.callbacks.call(that,"onShow");},onHide:function(){that.callbacks.call(that,"onHide");}});return;};var _createLayout=function(){that.$trigger=$("<div>").addClass("secondary ch-calendar");that.$container=$("<div>").addClass("ch-calendar-container ch-hide");that.$content=$("<div>").addClass("ch-calendar-content");that.$element.after(that.$trigger);_createDropdown();return;};var _parseDate=function(date){if(typeof date=="undefined"){return;};return date.getFullYear()+"/"+(date.getMonth()<10?'0':'')+(parseInt(date.getMonth(),10)+1)+"/"+(date.getDate()<10?'0':'')+date.getDate();};var _select=function(date){_selected=new Date(date);that.currentDate=_selected;that.$content.html(_createMonth(_selected));that.$element.val(_parseDate(_selected));that.callbacks("onSelect");return that;};var _nextMonth=function(){that.currentDate=new Date(that.currentDate.getFullYear(),that.currentDate.getMonth()+1,1);that.$content.html(_createMonth(that.currentDate));that.callbacks("onNextMonth");return that;};var _prevMonth=function(){that.currentDate=new Date(that.currentDate.getFullYear(),that.currentDate.getMonth()-1,1);that.$content.html(_createMonth(that.currentDate));that.callbacks("onPrevMonth");return that;};var _nextYear=function(){that.currentDate=new Date(that.currentDate.getFullYear()+1,that.currentDate.getMonth(),1);that.$content.html(_createMonth(that.currentDate));return that;};var _prevYear=function(){that.currentDate=new Date(that.currentDate.getFullYear()-1,that.currentDate.getMonth(),1);that.$content.html(_createMonth(that.currentDate));return that;};var _reset=function(){_selected=conf.selected;that.currentDate=_selected||_today;that.$element.val("");that.$content.html(_createMonth(that.currentDate));that.callbacks("onReset");return that;};that.currentDate=_selected||_today;that["public"].uid=that.uid;that["public"].element=that.element;that["public"].type=that.type;that["public"].show=function(){that.children[0].show();return that["public"];};that["public"].hide=function(){that.children[0].hide();return that["public"];};that["public"].select=function(date){_select(date);return that["public"];};that["public"].getSelected=function(){return _parseDate(_selected);};that["public"].getToday=function(){return _parseDate(_today);};that["public"].next=function(){_nextMonth();return that["public"];};that["public"].prev=function(){_prevMonth();return that["public"];};that["public"].nextYear=function(){_nextYear();return that["public"];};that["public"].prevYear=function(){_prevYear();return that["public"];};that["public"].reset=function(){_reset();return that["public"];};that.$element.prop("type","text");_createLayout();that.$content.html(_createMonth(that.currentDate)).appendTo(that.$container);that.$container.prepend(_arrows.$prev).prepend(_arrows.$next);return that;};ch.dropdown=function(conf){var that=this;conf=ch.clon(conf);that.conf=conf;that=ch.navs.call(that);that.parent=ch.clon(that);var shortcuts=function(items){var selected=0;$.each(items,function(i,e){$(e).bind("mouseenter",function(){selected=i;items.eq(selected).focus();});});var selectItem=function(arrow,event){that.prevent(event);if(selected==((arrow=="bottom")?items.length-1:0))return;items.eq(selected).blur();if(arrow=="bottom")selected+=1;else selected-=1;items.eq(selected).focus();};ch.utils.document.bind(ch.events.KEY.UP_ARROW,function(x,event){selectItem("up",event);});ch.utils.document.bind(ch.events.KEY.DOWN_ARROW,function(x,event){selectItem("bottom",event);});};that.$trigger=that.$element.children().eq(0);that.$content=that.$trigger.next().detach();that.show=function(event){that.prevent(event);that.$content.css('z-index',ch.utils.zIndex++);if(that.$element.hasClass("secondary")){that.$trigger.css('z-index',ch.utils.zIndex++);};that.$element.addClass("ch-dropdown-on").css('z-index',ch.utils.zIndex++);that.parent.show(event);that.position("refresh");$.each(ch.instances.dropdown,function(i,e){if(e.uid!==that.uid)e.hide();});ch.utils.document.one("click "+ch.events.KEY.ESC,function(event){that.hide(event);});that.$content.find("a").one("click",function(){that.hide();});var items=that.$content.find("a");items.eq(0).focus();if(items.length>1){shortcuts(items);};return that;};that.hide=function(event){that.prevent(event);that.parent.hide(event);that.$element.removeClass("ch-dropdown-on");ch.utils.document.unbind(ch.events.KEY.ESC+" "+ch.events.KEY.UP_ARROW+" "+ch.events.KEY.DOWN_ARROW);return that;};that["public"].uid=that.uid;that["public"].element=that.element;that["public"].type=that.type;that["public"].show=function(){that.show();return that["public"];};that["public"].hide=function(){that.hide();return that["public"];};that["public"].position=that.position;that.configBehavior();that.$element.after(that.$content);ch.utils.avoidTextSelection(that.$trigger);if(that.$element.hasClass("secondary"))that.$content.addClass("secondary");that.$content.bind("click",function(event){event.stopPropagation();});that.conf.position={};that.conf.position.element=that.$content;that.conf.position.context=that.$trigger;that.conf.position.points=conf.points||"lt lb";that.conf.position.offset="0 -1";return that;};ch.layer=function(conf){var that=this;conf=ch.clon(conf);conf.cone=true;conf.classes="box";conf.position={};conf.position.context=that.$element;conf.position.offset=conf.offset||"0 10";conf.position.points=conf.points||"lt lb";that.conf=conf;that=ch.floats.call(that);that.parent=ch.clon(that);var showTime=conf.showTime||400;var hideTime=conf.hideTime||400;var st;var ht;var showTimer=function(){st=setTimeout(that.show,showTime)};var hideTimer=function(){ht=setTimeout(that.hide,hideTime)};var clearTimers=function(){clearTimeout(st);clearTimeout(ht);};that.$trigger=that.$element;that.show=function(event){$.each(ch.instances.layer,function(i,e){e.hide();});that.parent.show(event);that.$container.bind('click',function(event){event.stopPropagation()});if(conf.event=="click"){conf.close=true;$(document).one('click',that.hide);}else{clearTimers();that.$container.one("mouseenter",clearTimers).one("mouseleave",function(event){var target=event.srcElement||event.target;var relatedTarget=event.relatedTarget||event.toElement;var relatedParent=relatedTarget.parentNode;if(target===relatedTarget||relatedParent===null||target.nodeName==="SELECT")return;hideTimer();});};return that;};that["public"].uid=that.uid;that["public"].element=that.element;that["public"].type=that.type;that["public"].content=that.content;that["public"].show=function(){that.show();return that["public"];};that["public"].hide=function(){that.hide();return that["public"];};that["public"].position=that.position;if(conf.event==='click'){conf.closeButton=true;that.$trigger.css('cursor','pointer').bind('click',that.show);}else{that.$trigger.css('cursor','default').bind('mouseenter',that.show).bind('mouseleave',hideTimer);};$("body").bind(ch.events.LAYOUT.CHANGE,function(){that.position("refresh")});return that;};ch.modal=function(conf){var that=this;conf=ch.clon(conf);conf.ajax=(!ch.utils.hasOwn(conf,"ajax")&&!ch.utils.hasOwn(conf,"content")&&!ch.utils.hasOwn(conf,"msg"))?true:conf.ajax;conf.closeButton=(that.type=="modal")?true:false;conf.classes="box";that.conf=conf;that=ch.floats.call(that);that.parent=ch.clon(that);var $dimmer=$("<div>").addClass("ch-dimmer");if(ch.utils.html.hasClass("ie6")){$dimmer.height(parseInt(document.documentElement.clientHeight,10)*3)};var dimmer={on:function(){$dimmer.appendTo("body").css("z-index",ch.utils.zIndex++).fadeIn();if(that.type=="modal"){$dimmer.one("click",function(event){that.hide(event)});};if(!ch.features.fixed){ch.positioner({element:$dimmer});};if($("html").hasClass("ie6")){$("select, object").css("visibility","hidden");};},off:function(){$dimmer.fadeOut("normal",function(){$dimmer.detach();if($("html").hasClass("ie6")){$("select, object").css("visibility","visible");};});}};that.$trigger=that.$element;that.show=function(event){dimmer.on();that.parent.show(event);that.$trigger.blur();return that;};that.hide=function(event){dimmer.off();that.parent.hide(event);return that;};that["public"].uid=that.uid;that["public"].element=that.element;that["public"].type=that.type;that["public"].content=that.content;that["public"].show=function(){that.show();return that["public"];};that["public"].hide=function(){that.hide();return that["public"];};that["public"].position=that.position;that.$trigger.css("cursor","pointer").bind("click",function(event){that.show(event);});return that;};ch.extend("modal").as("transition",function(conf){conf.closeButton=false;conf.msg=conf.msg||conf.content||"Please wait...";conf.content=$("<div>").addClass("loading").after($("<p>").html(conf.msg));return conf;});ch.tabNavigator=function(conf){var that=this;conf=ch.clon(conf);that.conf=conf;that=ch.controllers.call(that);that.parent=ch.clon(that);var hash=window.location.hash.replace("#!","");var hashed=false;var selected=conf.selected-1||conf.value-1||0;var createTabs=function(){that.$element.children().eq(0).addClass("ch-tabNavigator-triggers").find("a").each(function(i,e){var tab={};tab.uid=that.uid+"#"+i;tab.type="tab";tab.element=e;tab.$element=$(e);tab.controller=that["public"];var conf={};conf.open=(selected==i);conf.onShow=function(){selected=i;};if(ch.utils.hasOwn(that.conf,"onContentLoad"))conf.onContentLoad=that.conf.onContentLoad;if(ch.utils.hasOwn(that.conf,"onContentError"))conf.onContentError=that.conf.onContentError;that.children.push(ch.tab.call(tab,conf));$(e).unbind("click").bind("click",function(event){that.prevent(event);select(i+1);});});return;};var select=function(tab){tab=that.children[tab-1];if(tab===that.children[selected])return;$.each(that.children,function(i,e){if(tab!==e)e.hide();});tab.show();window.location.hash="#!"+tab.$content.attr("id");that.callbacks("onSelect");return that;};that.$content=that.$element.children().eq(1).addClass("ch-tabNavigator-content box");that["public"].uid=that.uid;that["public"].element=that.element;that["public"].type=that.type;that["public"].children=that.children;that["public"].select=function(tab){select(tab);return that["public"];};that["public"].getSelected=function(){return(selected+1);};that.$element.addClass('ch-tabNavigator');createTabs();for(var i=that.children.length;i--;){if(that.children[i].$content.attr("id")===hash){select(i+1);hashed=true;break;};};return that;};ch.tab=function(conf){var that=this;conf=ch.clon(conf);conf.icon=false;that.conf=conf;that=ch.navs.call(that);that.parent=ch.clon(that);var createContent=function(){var href=that.element.href.split("#");var controller=that.$element.parents(".ch-tabNavigator");var content=controller.find("#"+href[1]);if(content.length>0){return content;}else{conf.ajax=true;return $("<div>").attr("id",(href.length==2)?href[1]:"ch-tab"+that.uid.replace("#","-")).addClass("ch-hide").appendTo(controller.children().eq(1));};};that.$trigger=that.$element;that.$content=createContent();that.show=function(event){that.prevent(event);if(that.$content.html()=="")that.$content.html(that.loadContent());that.parent.show(event);return that;};that.configBehavior();return that;}
ch.tooltip=function(conf){var that=this;conf=ch.clon(conf);conf.cone=true;conf.content=that.element.title;conf.position={};conf.position.context=$(that.element);conf.position.offset=conf.offset||"0 10";conf.position.points=conf.points||"lt lb";that.conf=conf;that=ch.floats.call(that);that.parent=ch.clon(that);that.$trigger=that.$element;that.show=function(event){that.$trigger.attr('title','');that.parent.show(event);return that;};that.hide=function(event){that.$trigger.attr('title',conf.content);that.parent.hide(event);return that;};that["public"].uid=that.uid;that["public"].element=that.element;that["public"].type=that.type;that["public"].content=that.content;that["public"].show=function(){that.show();return that["public"];};that["public"].hide=function(){that.hide();return that["public"];};that["public"].position=that.position;that.$trigger.bind('mouseenter',that.show).bind('mouseleave',that.hide);$("body").bind(ch.events.LAYOUT.CHANGE,function(){that.position("refresh")});return that;};ch.extend("watcher").as("string",function(conf){if(!conf.text&&!conf.email&&!conf.url&&!conf.maxLength&&!conf.minLength){conf.text=true;};conf.conditions=[{name:"text",patt:/^([a-zA-Z\s]+)$/},{name:"email",patt:/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/},{name:"url",patt:/^((https?|ftp|file):\/\/|((www|ftp)\.)|(\/|.*\/)*)[a-z0-9-]+((\.|\/)[a-z0-9-]+)+([/?].*)?$/},{name:"minLength",expr:function(a,b){return a.length>=b}},{name:"maxLength",expr:function(a,b){return a.length<=b}}];return conf;});ch.extend("string").as("email");ch.extend("string").as("url");ch.extend("string").as("minLength");ch.extend("string").as("maxLength");ch.extend("watcher").as("number",function(conf){if(!conf.number&&!conf.min&&!conf.max&&!conf.price){conf.number=true;};conf.conditions=[{name:"number",patt:/^([0-9\s]+)$/},{name:"min",expr:function(a,b){return a>=b}},{name:"max",expr:function(a,b){return a<=b}},{name:"price",patt:/^(\d+)[.,]?(\d?\d?)$/}];return conf;});ch.extend("number").as("min");ch.extend("number").as("max");ch.extend("number").as("price");ch.extend("watcher").as("custom",function(conf){if(!conf.lambda){alert("Custom Validation fatal error: Need a function to evaluate, try $().custom(function(){},\"Message\");");};conf.custom=true;conf.conditions=[{name:"custom",func:conf.lambda}];return conf;});ch.extend("watcher").as("required",function(conf){conf.required=true;conf.conditions=[{name:"required"}];return conf;});ch.helper=function(controller){var that=this;var conf={};conf.cone=true;conf.position={};conf.position.context=controller.reference;conf.position.offset="15 0";conf.position.points="lt rt";conf.cache=false;that.conf=conf;that=ch.floats.call(that);that.parent=ch.clon(that);that.$trigger=that.$element;that.show=function(text){if(!that.active){conf.content='<p><span class="ico error">Error: </span>'+text+'</p>';that.parent.show();}else{that.$content.html('<p><span class="ico error">Error: </span>'+text+'</p>');};return that;};that["public"].uid=that.uid;that["public"].element=that.element;that["public"].type=that.type;that["public"].content=that.content;that["public"].show=function(text){that.show(text);return that["public"];};that["public"].hide=function(){that.hide();return that["public"];};that["public"].position=that.position;$("body").bind(ch.events.LAYOUT.CHANGE,function(){that.position("refresh");});return that;};ch.form=function(conf){if(this.$element.find(":submit").length==0||this.$element.attr("action")==""){alert("Form fatal error: The <input type=submit> is missing, or need to define a action attribute on the form tag.");return;};if(ch.utils.hasOwn(ch.instances,"form")&&ch.instances.form.length>0){for(var i=0,j=ch.instances.form.length;i<j;i++){if(ch.instances.form[i].element===this.element){return{exists:true,object:ch.instances.form[i]};};};};var that=this;conf=ch.clon(conf);that.$element.attr("novalidate","novalidate");that.$submit=that.$element.find("input:submit");that.conf=conf;that=ch.controllers.call(that);that.parent=ch.clon(that);var status=true;var validate=function(){that.callbacks("beforeValidate");if(!status){status=true;};var i=0,j=that.children.length,toFocus,childrenError=[];for(i;i<j;i++){var child=that.children[i];child.validate();if(child.active()){childrenError.push(child);}};if(childrenError.length>0){status=false;if(childrenError[0].element.tagName==="DIV"){$(childrenError[0].element).find("input:first").focus();}else{childrenError[0].element.focus();}}else{status=true;}
status?that.callbacks("onValidate"):that.callbacks("onError");that.callbacks("afterValidate");return that;};var submit=function(event){that.callbacks("beforeSubmit");that.$element.one("submit",submit);validate();if(!status){that.prevent(event);}
if(status&&ch.utils.hasOwn(conf,"onSubmit")){that.prevent(event);that.callbacks("onSubmit");}
that.callbacks("afterSubmit");return that;};var clear=function(event){that.prevent(event);var i=0,j=that.children.length;for(i;i<j;i+=1){that.children[i].reset();}
that.callbacks("onClear");return that;};var reset=function(event){clear();that.element.reset();that.callbacks("onReset");return that;};that["public"].uid=that.uid;that["public"].element=that.element;that["public"].type=that.type;that["public"].children=that.children;that["public"].messages=conf.messages;that["public"].validate=function(){validate();return that["public"];};that["public"].submit=function(){submit();return that["public"];};that["public"].getStatus=function(){return status;};that["public"].clear=function(){clear();return that["public"];};that["public"].reset=function(){reset();return that["public"];};if(ch.utils.hasOwn(conf,"onSubmit")){that.$element.bind('submit',function(event){that.prevent(event);});that.$element.find(":submit").unbind('click');};that.$element.bind("submit",submit);that.$element.find(":reset, .resetForm").bind("click",function(event){reset(event);});return that;};ch.viewer=function(conf){var that=this;conf=ch.clon(conf);that.conf=conf;that=ch.controllers.call(that);that.parent=ch.clon(that);var $viewer=that.$element.addClass("ch-viewer");conf.width=$viewer.outerWidth();conf.height=$viewer.outerHeight();var $content=$viewer.children().addClass("ch-viewer-content");var $display=$("<div>").addClass("ch-viewer-display").append($content).appendTo($viewer).carousel({width:conf.width,arrows:false,onMove:function(){var carousel=this;var page=carousel.getPage();that.move(page);var currentHeight=$(itemsChildren[page-1]).height();$viewer.find(".ch-mask").eq(0).height(currentHeight);}})
var items=$content.children();var itemsAmount=items.length;var itemsAnchor=items.children("a");var itemsChildren=items.find("img, object");if(ch.utils.hasOwn(ch,"zoom")){var i=0;itemsChildren.filter("img").bind("load",function(){var _parentNode=this.parentNode;var component={uid:that.uid+"#"+i,type:"zoom",element:_parentNode,$element:$(_parentNode)};var config={context:$viewer,onShow:function(){var _rest=(ch.utils.body.outerWidth()-$viewer.outerWidth());var _zoomDisplayWidth=(conf.width<_rest)?conf.width:(_rest-65);this.width(_zoomDisplayWidth);this.height($viewer.height());}};that.children.push(ch.zoom.call(component,config));i+=1;});};var createThumbs=function(){var structure=$("<ul>").addClass("carousel");$.each(items,function(i,e){var thumb=$("<li>").bind("click",function(event){that.prevent(event);that.move(i+1);});if($(e).children("link[rel=thumb]").length>0){$("<img>").attr("src",$(e).children("link[rel=thumb]").attr("href")).appendTo(thumb);}else if($(e).children("object").length>0||$(e).children("embed").length>0){$("<span>").html("Video").appendTo(thumb.addClass("ch-viewer-video"));};structure.append(thumb);});var self={};self.children=structure.children();self.selected=1;self.carousel=that.children[0]=$("<div>").addClass("ch-viewer-triggers").append(structure).appendTo($viewer).carousel({width:conf.width});return self;};var move=function(item){if(item>itemsAmount||item<1||isNaN(item))return that;$(thumbnails.children[thumbnails.selected-1]).removeClass("ch-thumbnail-on");$(thumbnails.children[item-1]).addClass("ch-thumbnail-on");$display.goTo(item);var nextThumbsPage=Math.ceil(item/thumbnails.carousel.getItemsPerPage());if(thumbnails.carousel.getPage()!=nextThumbsPage)thumbnails.carousel.goTo(nextThumbsPage);if(item>1&&item<itemsAmount){arrows.prev.on();arrows.next.on();}else{if(item==1){arrows.prev.off();arrows.next.on();};if(item==itemsAmount){arrows.next.off();arrows.prev.on();};};thumbnails.selected=item;that.callbacks("onMove");return that;};var arrows={};arrows.prev={$element:$("<p>").addClass("ch-viewer-prev").bind("click",function(){that.prev();}),on:function(){arrows.prev.$element.addClass("ch-viewer-prev-on")},off:function(){arrows.prev.$element.removeClass("ch-viewer-prev-on")}};arrows.next={$element:$("<p>").addClass("ch-viewer-next").bind("click",function(){that.next();}),on:function(){arrows.next.$element.addClass("ch-viewer-next-on")},off:function(){arrows.next.$element.removeClass("ch-viewer-next-on")}};that.prev=function(){that.move(thumbnails.selected-1);return that;};that.next=function(){that.move(thumbnails.selected+1);return that;};that["public"].uid=that.uid;that["public"].element=that.element;that["public"].type=that.type;that["public"].children=that.children;if(itemsAmount>1){that["public"].moveTo=function(item){that.move(item);return that["public"];};that["public"].next=function(){that.next();return that["public"];};that["public"].prev=function(){that.prev();return that["public"];};that["public"].getSelected=function(){return thumbnails.selected;};var thumbnails=createThumbs();$viewer.append(arrows.prev.$element).append(arrows.next.$element);that.move=move;that.move(1);arrows.next.on();};$viewer.find(".ch-mask").eq(0).height($(itemsChildren[0]).height());ch.utils.avoidTextSelection(that.element);return that;};ch.expando=function(conf){var that=this;conf=ch.clon(conf);that.conf=conf;that=ch.navs.call(that);that.parent=ch.clon(that);that.$trigger=that.$element.children().eq(0).wrapInner("<span>").children();that.$content=that.$element.children().eq(1);that["public"].uid=that.uid;that["public"].element=that.element;that["public"].type=that.type;that["public"].show=function(){that.show();return that["public"];};that["public"].hide=function(){that.hide();return that["public"];};that.configBehavior();ch.utils.avoidTextSelection(that.$trigger);return that;};ch.menu=function(conf){var that=this;conf=ch.clon(conf);that.conf=conf;that=ch.controllers.call(that);that.parent=ch.clon(that);var selected=conf.selected-1;var createLayout=function(){var efects=(ch.utils.html.hasClass("ie6")||ch.utils.html.hasClass("ie7"))?false:true;that.$element.children().each(function(i,e){var $child=$(e).children();if($child.eq(0).prop("tagName")=="A"){$(e).addClass("ch-bellows").children().addClass("ch-bellows-trigger");that.children.push($child[0]);return;};var expando=$(e).expando({fx:efects,onShow:function(){selected=i;that.callbacks.call(that,"onSelect");}});that.children.push(expando);});};var select=function(item){var child,grandson;if(typeof item=="string"){var sliced=item.split("#");child=sliced[0]-1;grandson=sliced[1];}else{child=item-1;};var itemObject=that.children[child];if(ch.utils.hasOwn(itemObject,"uid")){itemObject.show();if(grandson)$(itemObject.element).find("a").eq(grandson-1).addClass("ch-menu-on");if(conf.accordion){$.each(that.children,function(i,e){if((e.tagName!="A")&&(ch.utils.hasOwn(e,"uid"))&&(that.children[child].uid!=that.children[i].uid)){e.hide();};});};}else{that.children[child].addClass("ch-menu-on");};return that;};var configureAccordion=function(){$.each(that.children,function(i,e){$(e.element).find(".ch-expando-trigger").unbind("click").bind("click",function(){select(i+1);});});return;};that["public"].uid=that.uid;that["public"].element=that.element;that["public"].type=that.type;that["public"].select=function(item){select(item);return that["public"];};that.$element.addClass('ch-menu');createLayout();if(conf.accordion)configureAccordion();if(ch.utils.hasOwn(conf,"selected"))select(conf.selected);return that;};ch.extend("menu").as("accordion");ch.zoom=function(conf){var that=this;conf=ch.clon(conf);conf.width=conf.width||300;conf.height=conf.height||300;conf.fx=false;conf.position={};conf.position.context=conf.context||that.$element;conf.position.offset=conf.offset||"20 0";conf.position.points=conf.points||"lt rt";conf.position.hold=true;that.conf=conf;that=ch.floats.call(that);that.parent=ch.clon(that);var original={};original.img=that.$element.children();original["width"]=original.img.prop("width");original["height"]=original.img.prop("height");var zoomed={};zoomed.img=conf.content=$("<img>");var seeker={};seeker.shape=$("<div>").addClass("ch-seeker ch-hide").bind("mousemove",function(event){move(event);}).css({width:conf.width/3,height:conf.height/3});var move=function(event){var offset=original.img.offset();var x=event.pageX-offset.left;var y=event.pageY-offset.top;zoomed.img.css({"left":-(((zoomed["width"]*x)/original["width"])-(conf.width/2)),"top":-(((zoomed["height"]*y)/original["height"])-(conf.height/2))});seeker.shape.css({"left":x-seeker["width"],"top":y-seeker["height"]});};that.$trigger=that.$element;that.show=function(event){that.prevent(event);zoomed.img.prop("src",that.element.href);that.parent.show();seeker.shape.removeClass("ch-hide");return that;};that.hide=function(event){that.prevent(event);seeker.shape.addClass("ch-hide");that.parent.hide();return that;};that.enlarge=function(event){that.prevent(event);};that.size=function(attr,data){if(!data)return conf[attr];that.conf[attr]=data;that.$container[attr](data);var size=(original[attr]*data)/zoomed[attr];seeker.shape[attr](size);seeker[attr]=size/2;return that["public"];};that["public"].uid=that.uid;that["public"].element=that.element;that["public"].type=that.type;that["public"].content=that.content;that["public"].show=function(){that.show();return that["public"];};that["public"].hide=function(){that.hide();return that["public"];};that["public"].position=that.position;that["public"].width=function(data){that.size("width",data);};that["public"].height=function(data){that.size("height",data)};setTimeout(function(){that.$element.addClass("ch-zoom-trigger").append(seeker.shape).css({"width":original["width"],"height":original["height"]}).bind("mouseenter",that.show).bind("mouseleave",that.hide).bind("mousemove",function(event){move(event);}).bind("click",function(event){that.enlarge(event);});},50);ch.utils.window.one("load",function(){zoomed.img.prop("src",that.element.href).one("load",function(){zoomed["width"]=zoomed.img.prop("width");zoomed["height"]=zoomed.img.prop("height");});});return that;};
ch.init();

