var MooTools={'version':'1.2.1','build':'0d4845aab3d9a4fdee2f0d4a6dd59210e4b697cf'};var Native=function(options){options=options||{};var name=options.name;var legacy=options.legacy;var protect=options.protect;var methods=options.implement;var generics=options.generics;var initialize=options.initialize;var afterImplement=options.afterImplement||function(){};var object=initialize||legacy;generics=generics!==false;object.constructor=Native;object.$family={name:'native'};if(legacy&&initialize)object.prototype=legacy.prototype;object.prototype.constructor=object;if(name){var family=name.toLowerCase();object.prototype.$family={name:family};Native.typize(object,family);}
var add=function(obj,name,method,force){if(!protect||force||!obj.prototype[name])obj.prototype[name]=method;if(generics)Native.genericize(obj,name,protect);afterImplement.call(obj,name,method);return obj;};object.alias=function(a1,a2,a3){if(typeof a1=='string'){if((a1=this.prototype[a1]))return add(this,a2,a1,a3);}
for(var a in a1)this.alias(a,a1[a],a2);return this;};object.implement=function(a1,a2,a3){if(typeof a1=='string')return add(this,a1,a2,a3);for(var p in a1)add(this,p,a1[p],a2);return this;};if(methods)object.implement(methods);return object;};Native.genericize=function(object,property,check){if((!check||!object[property])&&typeof object.prototype[property]=='function')object[property]=function(){var args=Array.prototype.slice.call(arguments);return object.prototype[property].apply(args.shift(),args);};};Native.implement=function(objects,properties){for(var i=0,l=objects.length;i<l;i++)objects[i].implement(properties);};Native.typize=function(object,family){if(!object.type)object.type=function(item){return($type(item)===family);};};(function(){var natives={'Array':Array,'Date':Date,'Function':Function,'Number':Number,'RegExp':RegExp,'String':String};for(var n in natives)new Native({name:n,initialize:natives[n],protect:true});var types={'boolean':Boolean,'native':Native,'object':Object};for(var t in types)Native.typize(types[t],t);var generics={'Array':["concat","indexOf","join","lastIndexOf","pop","push","reverse","shift","slice","sort","splice","toString","unshift","valueOf"],'String':["charAt","charCodeAt","concat","indexOf","lastIndexOf","match","replace","search","slice","split","substr","substring","toLowerCase","toUpperCase","valueOf"]};for(var g in generics){for(var i=generics[g].length;i--;)Native.genericize(window[g],generics[g][i],true);};})();var Hash=new Native({name:'Hash',initialize:function(object){if($type(object)=='hash')object=$unlink(object.getClean());for(var key in object)this[key]=object[key];return this;}});Hash.implement({forEach:function(fn,bind){for(var key in this){if(this.hasOwnProperty(key))fn.call(bind,this[key],key,this);}},getClean:function(){var clean={};for(var key in this){if(this.hasOwnProperty(key))clean[key]=this[key];}
return clean;},getLength:function(){var length=0;for(var key in this){if(this.hasOwnProperty(key))length++;}
return length;}});Hash.alias('forEach','each');Array.implement({forEach:function(fn,bind){for(var i=0,l=this.length;i<l;i++)fn.call(bind,this[i],i,this);}});Array.alias('forEach','each');function $A(iterable){if(iterable.item){var array=[];for(var i=0,l=iterable.length;i<l;i++)array[i]=iterable[i];return array;}
return Array.prototype.slice.call(iterable);};function $arguments(i){return function(){return arguments[i];};};function $chk(obj){return!!(obj||obj===0);};function $clear(timer){clearTimeout(timer);clearInterval(timer);return null;};function $defined(obj){return(obj!=undefined);};function $each(iterable,fn,bind){var type=$type(iterable);((type=='arguments'||type=='collection'||type=='array')?Array:Hash).each(iterable,fn,bind);};function $empty(){};function $extend(original,extended){for(var key in(extended||{}))original[key]=extended[key];return original;};function $H(object){return new Hash(object);};function $lambda(value){return(typeof value=='function')?value:function(){return value;};};function $merge(){var mix={};for(var i=0,l=arguments.length;i<l;i++){var object=arguments[i];if($type(object)!='object')continue;for(var key in object){var op=object[key],mp=mix[key];mix[key]=(mp&&$type(op)=='object'&&$type(mp)=='object')?$merge(mp,op):$unlink(op);}}
return mix;};function $pick(){for(var i=0,l=arguments.length;i<l;i++){if(arguments[i]!=undefined)return arguments[i];}
return null;};function $random(min,max){return Math.floor(Math.random()*(max-min+1)+min);};function $splat(obj){var type=$type(obj);return(type)?((type!='array'&&type!='arguments')?[obj]:obj):[];};var $time=Date.now||function(){return+new Date;};function $try(){for(var i=0,l=arguments.length;i<l;i++){try{return arguments[i]();}catch(e){}}
return null;};function $type(obj){if(obj==undefined)return false;if(obj.$family)return(obj.$family.name=='number'&&!isFinite(obj))?false:obj.$family.name;if(obj.nodeName){switch(obj.nodeType){case 1:return'element';case 3:return(/\S/).test(obj.nodeValue)?'textnode':'whitespace';}}else if(typeof obj.length=='number'){if(obj.callee)return'arguments';else if(obj.item)return'collection';}
return typeof obj;};function $unlink(object){var unlinked;switch($type(object)){case'object':unlinked={};for(var p in object)unlinked[p]=$unlink(object[p]);break;case'hash':unlinked=new Hash(object);break;case'array':unlinked=[];for(var i=0,l=object.length;i<l;i++)unlinked[i]=$unlink(object[i]);break;default:return object;}
return unlinked;};var Browser=$merge({Engine:{name:'unknown',version:0},Platform:{name:(window.orientation!=undefined)?'ipod':(navigator.platform.match(/mac|win|linux/i)||['other'])[0].toLowerCase()},Features:{xpath:!!(document.evaluate),air:!!(window.runtime),query:!!(document.querySelector)},Plugins:{},Engines:{presto:function(){return(!window.opera)?false:((arguments.callee.caller)?960:((document.getElementsByClassName)?950:925));},trident:function(){return(!window.ActiveXObject)?false:((window.XMLHttpRequest)?5:4);},webkit:function(){return(navigator.taintEnabled)?false:((Browser.Features.xpath)?((Browser.Features.query)?525:420):419);},gecko:function(){return(document.getBoxObjectFor==undefined)?false:((document.getElementsByClassName)?19:18);}}},Browser||{});Browser.Platform[Browser.Platform.name]=true;Browser.detect=function(){for(var engine in this.Engines){var version=this.Engines[engine]();if(version){this.Engine={name:engine,version:version};this.Engine[engine]=this.Engine[engine+version]=true;break;}}
return{name:engine,version:version};};Browser.detect();Browser.Request=function(){return $try(function(){return new XMLHttpRequest();},function(){return new ActiveXObject('MSXML2.XMLHTTP');});};Browser.Features.xhr=!!(Browser.Request());Browser.Plugins.Flash=(function(){var version=($try(function(){return navigator.plugins['Shockwave Flash'].description;},function(){return new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version');})||'0 r0').match(/\d+/g);return{version:parseInt(version[0]||0+'.'+version[1]||0),build:parseInt(version[2]||0)};})();function $exec(text){if(!text)return text;if(window.execScript){window.execScript(text);}else{var script=document.createElement('script');script.setAttribute('type','text/javascript');script[(Browser.Engine.webkit&&Browser.Engine.version<420)?'innerText':'text']=text;document.head.appendChild(script);document.head.removeChild(script);}
return text;};Native.UID=1;var $uid=(Browser.Engine.trident)?function(item){return(item.uid||(item.uid=[Native.UID++]))[0];}:function(item){return item.uid||(item.uid=Native.UID++);};var Window=new Native({name:'Window',legacy:(Browser.Engine.trident)?null:window.Window,initialize:function(win){$uid(win);if(!win.Element){win.Element=$empty;if(Browser.Engine.webkit)win.document.createElement("iframe");win.Element.prototype=(Browser.Engine.webkit)?window["[[DOMElement.prototype]]"]:{};}
win.document.window=win;return $extend(win,Window.Prototype);},afterImplement:function(property,value){window[property]=Window.Prototype[property]=value;}});Window.Prototype={$family:{name:'window'}};new Window(window);var Document=new Native({name:'Document',legacy:(Browser.Engine.trident)?null:window.Document,initialize:function(doc){$uid(doc);doc.head=doc.getElementsByTagName('head')[0];doc.html=doc.getElementsByTagName('html')[0];if(Browser.Engine.trident&&Browser.Engine.version<=4)$try(function(){doc.execCommand("BackgroundImageCache",false,true);});if(Browser.Engine.trident)doc.window.attachEvent('onunload',function(){doc.window.detachEvent('onunload',arguments.callee);doc.head=doc.html=doc.window=null;});return $extend(doc,Document.Prototype);},afterImplement:function(property,value){document[property]=Document.Prototype[property]=value;}});Document.Prototype={$family:{name:'document'}};new Document(document);Array.implement({every:function(fn,bind){for(var i=0,l=this.length;i<l;i++){if(!fn.call(bind,this[i],i,this))return false;}
return true;},filter:function(fn,bind){var results=[];for(var i=0,l=this.length;i<l;i++){if(fn.call(bind,this[i],i,this))results.push(this[i]);}
return results;},clean:function(){return this.filter($defined);},indexOf:function(item,from){var len=this.length;for(var i=(from<0)?Math.max(0,len+from):from||0;i<len;i++){if(this[i]===item)return i;}
return-1;},map:function(fn,bind){var results=[];for(var i=0,l=this.length;i<l;i++)results[i]=fn.call(bind,this[i],i,this);return results;},some:function(fn,bind){for(var i=0,l=this.length;i<l;i++){if(fn.call(bind,this[i],i,this))return true;}
return false;},associate:function(keys){var obj={},length=Math.min(this.length,keys.length);for(var i=0;i<length;i++)obj[keys[i]]=this[i];return obj;},link:function(object){var result={};for(var i=0,l=this.length;i<l;i++){for(var key in object){if(object[key](this[i])){result[key]=this[i];delete object[key];break;}}}
return result;},contains:function(item,from){return this.indexOf(item,from)!=-1;},extend:function(array){for(var i=0,j=array.length;i<j;i++)this.push(array[i]);return this;},getLast:function(){return(this.length)?this[this.length-1]:null;},getRandom:function(){return(this.length)?this[$random(0,this.length-1)]:null;},include:function(item){if(!this.contains(item))this.push(item);return this;},combine:function(array){for(var i=0,l=array.length;i<l;i++)this.include(array[i]);return this;},erase:function(item){for(var i=this.length;i--;i){if(this[i]===item)this.splice(i,1);}
return this;},empty:function(){this.length=0;return this;},flatten:function(){var array=[];for(var i=0,l=this.length;i<l;i++){var type=$type(this[i]);if(!type)continue;array=array.concat((type=='array'||type=='collection'||type=='arguments')?Array.flatten(this[i]):this[i]);}
return array;},hexToRgb:function(array){if(this.length!=3)return null;var rgb=this.map(function(value){if(value.length==1)value+=value;return value.toInt(16);});return(array)?rgb:'rgb('+rgb+')';},rgbToHex:function(array){if(this.length<3)return null;if(this.length==4&&this[3]==0&&!array)return'transparent';var hex=[];for(var i=0;i<3;i++){var bit=(this[i]-0).toString(16);hex.push((bit.length==1)?'0'+bit:bit);}
return(array)?hex:'#'+hex.join('');}});Function.implement({extend:function(properties){for(var property in properties)this[property]=properties[property];return this;},create:function(options){var self=this;options=options||{};return function(event){var args=options.arguments;args=(args!=undefined)?$splat(args):Array.slice(arguments,(options.event)?1:0);if(options.event)args=[event||window.event].extend(args);var returns=function(){return self.apply(options.bind||null,args);};if(options.delay)return setTimeout(returns,options.delay);if(options.periodical)return setInterval(returns,options.periodical);if(options.attempt)return $try(returns);return returns();};},run:function(args,bind){return this.apply(bind,$splat(args));},pass:function(args,bind){return this.create({bind:bind,arguments:args});},bind:function(bind,args){return this.create({bind:bind,arguments:args});},bindWithEvent:function(bind,args){return this.create({bind:bind,arguments:args,event:true});},attempt:function(args,bind){return this.create({bind:bind,arguments:args,attempt:true})();},delay:function(delay,bind,args){return this.create({bind:bind,arguments:args,delay:delay})();},periodical:function(periodical,bind,args){return this.create({bind:bind,arguments:args,periodical:periodical})();}});Number.implement({limit:function(min,max){return Math.min(max,Math.max(min,this));},round:function(precision){precision=Math.pow(10,precision||0);return Math.round(this*precision)/precision;},times:function(fn,bind){for(var i=0;i<this;i++)fn.call(bind,i,this);},toFloat:function(){return parseFloat(this);},toInt:function(base){return parseInt(this,base||10);}});Number.alias('times','each');(function(math){var methods={};math.each(function(name){if(!Number[name])methods[name]=function(){return Math[name].apply(null,[this].concat($A(arguments)));};});Number.implement(methods);})(['abs','acos','asin','atan','atan2','ceil','cos','exp','floor','log','max','min','pow','sin','sqrt','tan']);String.implement({test:function(regex,params){return((typeof regex=='string')?new RegExp(regex,params):regex).test(this);},contains:function(string,separator){return(separator)?(separator+this+separator).indexOf(separator+string+separator)>-1:this.indexOf(string)>-1;},trim:function(){return this.replace(/^\s+|\s+$/g,'');},clean:function(){return this.replace(/\s+/g,' ').trim();},camelCase:function(){return this.replace(/-\D/g,function(match){return match.charAt(1).toUpperCase();});},hyphenate:function(){return this.replace(/[A-Z]/g,function(match){return('-'+match.charAt(0).toLowerCase());});},capitalize:function(){return this.replace(/\b[a-z]/g,function(match){return match.toUpperCase();});},escapeRegExp:function(){return this.replace(/([-.*+?^${}()|[\]\/\\])/g,'\\$1');},toInt:function(base){return parseInt(this,base||10);},toFloat:function(){return parseFloat(this);},hexToRgb:function(array){var hex=this.match(/^#?(\w{1,2})(\w{1,2})(\w{1,2})$/);return(hex)?hex.slice(1).hexToRgb(array):null;},rgbToHex:function(array){var rgb=this.match(/\d{1,3}/g);return(rgb)?rgb.rgbToHex(array):null;},stripScripts:function(option){var scripts='';var text=this.replace(/<script[^>]*>([\s\S]*?)<\/script>/gi,function(){scripts+=arguments[1]+'\n';return'';});if(option===true)$exec(scripts);else if($type(option)=='function')option(scripts,text);return text;},substitute:function(object,regexp){return this.replace(regexp||(/\\?\{([^{}]+)\}/g),function(match,name){if(match.charAt(0)=='\\')return match.slice(1);return(object[name]!=undefined)?object[name]:'';});}});Hash.implement({has:Object.prototype.hasOwnProperty,keyOf:function(value){for(var key in this){if(this.hasOwnProperty(key)&&this[key]===value)return key;}
return null;},hasValue:function(value){return(Hash.keyOf(this,value)!==null);},extend:function(properties){Hash.each(properties,function(value,key){Hash.set(this,key,value);},this);return this;},combine:function(properties){Hash.each(properties,function(value,key){Hash.include(this,key,value);},this);return this;},erase:function(key){if(this.hasOwnProperty(key))delete this[key];return this;},get:function(key){return(this.hasOwnProperty(key))?this[key]:null;},set:function(key,value){if(!this[key]||this.hasOwnProperty(key))this[key]=value;return this;},empty:function(){Hash.each(this,function(value,key){delete this[key];},this);return this;},include:function(key,value){var k=this[key];if(k==undefined)this[key]=value;return this;},map:function(fn,bind){var results=new Hash;Hash.each(this,function(value,key){results.set(key,fn.call(bind,value,key,this));},this);return results;},filter:function(fn,bind){var results=new Hash;Hash.each(this,function(value,key){if(fn.call(bind,value,key,this))results.set(key,value);},this);return results;},every:function(fn,bind){for(var key in this){if(this.hasOwnProperty(key)&&!fn.call(bind,this[key],key))return false;}
return true;},some:function(fn,bind){for(var key in this){if(this.hasOwnProperty(key)&&fn.call(bind,this[key],key))return true;}
return false;},getKeys:function(){var keys=[];Hash.each(this,function(value,key){keys.push(key);});return keys;},getValues:function(){var values=[];Hash.each(this,function(value){values.push(value);});return values;},toQueryString:function(base){var queryString=[];Hash.each(this,function(value,key){if(base)key=base+'['+key+']';var result;switch($type(value)){case'object':result=Hash.toQueryString(value,key);break;case'array':var qs={};value.each(function(val,i){qs[i]=val;});result=Hash.toQueryString(qs,key);break;default:result=key+'='+encodeURIComponent(value);}
if(value!=undefined)queryString.push(result);});return queryString.join('&');}});Hash.alias({keyOf:'indexOf',hasValue:'contains'});var Event=new Native({name:'Event',initialize:function(event,win){win=win||window;var doc=win.document;event=event||win.event;if(event.$extended)return event;this.$extended=true;var type=event.type;var target=event.target||event.srcElement;while(target&&target.nodeType==3)target=target.parentNode;if(type.test(/key/)){var code=event.which||event.keyCode;var key=Event.Keys.keyOf(code);if(type=='keydown'){var fKey=code-111;if(fKey>0&&fKey<13)key='f'+fKey;}
key=key||String.fromCharCode(code).toLowerCase();}else if(type.match(/(click|mouse|menu)/i)){doc=(!doc.compatMode||doc.compatMode=='CSS1Compat')?doc.html:doc.body;var page={x:event.pageX||event.clientX+doc.scrollLeft,y:event.pageY||event.clientY+doc.scrollTop};var client={x:(event.pageX)?event.pageX-win.pageXOffset:event.clientX,y:(event.pageY)?event.pageY-win.pageYOffset:event.clientY};if(type.match(/DOMMouseScroll|mousewheel/)){var wheel=(event.wheelDelta)?event.wheelDelta/120:-(event.detail||0)/3;}
var rightClick=(event.which==3)||(event.button==2);var related=null;if(type.match(/over|out/)){switch(type){case'mouseover':related=event.relatedTarget||event.fromElement;break;case'mouseout':related=event.relatedTarget||event.toElement;}
if(!(function(){while(related&&related.nodeType==3)related=related.parentNode;return true;}).create({attempt:Browser.Engine.gecko})())related=false;}}
return $extend(this,{event:event,type:type,page:page,client:client,rightClick:rightClick,wheel:wheel,relatedTarget:related,target:target,code:code,key:key,shift:event.shiftKey,control:event.ctrlKey,alt:event.altKey,meta:event.metaKey});}});Event.Keys=new Hash({'enter':13,'up':38,'down':40,'left':37,'right':39,'esc':27,'space':32,'backspace':8,'tab':9,'delete':46});Event.implement({stop:function(){return this.stopPropagation().preventDefault();},stopPropagation:function(){if(this.event.stopPropagation)this.event.stopPropagation();else this.event.cancelBubble=true;return this;},preventDefault:function(){if(this.event.preventDefault)this.event.preventDefault();else this.event.returnValue=false;return this;}});var Class=new Native({name:'Class',initialize:function(properties){properties=properties||{};var klass=function(){for(var key in this){if($type(this[key])!='function')this[key]=$unlink(this[key]);}
this.constructor=klass;if(Class.prototyping)return this;var instance=(this.initialize)?this.initialize.apply(this,arguments):this;if(this.options&&this.options.initialize)this.options.initialize.call(this);return instance;};for(var mutator in Class.Mutators){if(!properties[mutator])continue;properties=Class.Mutators[mutator](properties,properties[mutator]);delete properties[mutator];}
$extend(klass,this);klass.constructor=Class;klass.prototype=properties;return klass;}});Class.Mutators={Extends:function(self,klass){Class.prototyping=klass.prototype;var subclass=new klass;delete subclass.parent;subclass=Class.inherit(subclass,self);delete Class.prototyping;return subclass;},Implements:function(self,klasses){$splat(klasses).each(function(klass){Class.prototying=klass;$extend(self,($type(klass)=='class')?new klass:klass);delete Class.prototyping;});return self;}};Class.extend({inherit:function(object,properties){var caller=arguments.callee.caller;for(var key in properties){var override=properties[key];var previous=object[key];var type=$type(override);if(previous&&type=='function'){if(override!=previous){if(caller){override.__parent=previous;object[key]=override;}else{Class.override(object,key,override);}}}else if(type=='object'){object[key]=$merge(previous,override);}else{object[key]=override;}}
if(caller)object.parent=function(){return arguments.callee.caller.__parent.apply(this,arguments);};return object;},override:function(object,name,method){var parent=Class.prototyping;if(parent&&object[name]!=parent[name])parent=null;var override=function(){var previous=this.parent;this.parent=parent?parent[name]:object[name];var value=method.apply(this,arguments);this.parent=previous;return value;};object[name]=override;}});Class.implement({implement:function(){var proto=this.prototype;$each(arguments,function(properties){Class.inherit(proto,properties);});return this;}});var Chain=new Class({$chain:[],chain:function(){this.$chain.extend(Array.flatten(arguments));return this;},callChain:function(){return(this.$chain.length)?this.$chain.shift().apply(this,arguments):false;},clearChain:function(){this.$chain.empty();return this;}});var Events=new Class({$events:{},addEvent:function(type,fn,internal){type=Events.removeOn(type);if(fn!=$empty){this.$events[type]=this.$events[type]||[];this.$events[type].include(fn);if(internal)fn.internal=true;}
return this;},addEvents:function(events){for(var type in events)this.addEvent(type,events[type]);return this;},fireEvent:function(type,args,delay){type=Events.removeOn(type);if(!this.$events||!this.$events[type])return this;this.$events[type].each(function(fn){fn.create({'bind':this,'delay':delay,'arguments':args})();},this);return this;},removeEvent:function(type,fn){type=Events.removeOn(type);if(!this.$events[type])return this;if(!fn.internal)this.$events[type].erase(fn);return this;},removeEvents:function(events){if($type(events)=='object'){for(var type in events)this.removeEvent(type,events[type]);return this;}
if(events)events=Events.removeOn(events);for(var type in this.$events){if(events&&events!=type)continue;var fns=this.$events[type];for(var i=fns.length;i--;i)this.removeEvent(type,fns[i]);}
return this;}});Events.removeOn=function(string){return string.replace(/^on([A-Z])/,function(full,first){return first.toLowerCase();});};var Options=new Class({setOptions:function(){this.options=$merge.run([this.options].extend(arguments));if(!this.addEvent)return this;for(var option in this.options){if($type(this.options[option])!='function'||!(/^on[A-Z]/).test(option))continue;this.addEvent(option,this.options[option]);delete this.options[option];}
return this;}});var Element=new Native({name:'Element',legacy:window.Element,initialize:function(tag,props){var konstructor=Element.Constructors.get(tag);if(konstructor)return konstructor(props);if(typeof tag=='string')return document.newElement(tag,props);return $(tag).set(props);},afterImplement:function(key,value){Element.Prototype[key]=value;if(Array[key])return;Elements.implement(key,function(){var items=[],elements=true;for(var i=0,j=this.length;i<j;i++){var returns=this[i][key].apply(this[i],arguments);items.push(returns);if(elements)elements=($type(returns)=='element');}
return(elements)?new Elements(items):items;});}});Element.Prototype={$family:{name:'element'}};Element.Constructors=new Hash;var IFrame=new Native({name:'IFrame',generics:false,initialize:function(){var params=Array.link(arguments,{properties:Object.type,iframe:$defined});var props=params.properties||{};var iframe=$(params.iframe)||false;var onload=props.onload||$empty;delete props.onload;props.id=props.name=$pick(props.id,props.name,iframe.id,iframe.name,'IFrame_'+$time());iframe=new Element(iframe||'iframe',props);var onFrameLoad=function(){var host=$try(function(){return iframe.contentWindow.location.host;});if(host&&host==window.location.host){var win=new Window(iframe.contentWindow);new Document(iframe.contentWindow.document);$extend(win.Element.prototype,Element.Prototype);}
onload.call(iframe.contentWindow,iframe.contentWindow.document);};(window.frames[props.id])?onFrameLoad():iframe.addListener('load',onFrameLoad);return iframe;}});var Elements=new Native({initialize:function(elements,options){options=$extend({ddup:true,cash:true},options);elements=elements||[];if(options.ddup||options.cash){var uniques={},returned=[];for(var i=0,l=elements.length;i<l;i++){var el=$.element(elements[i],!options.cash);if(options.ddup){if(uniques[el.uid])continue;uniques[el.uid]=true;}
returned.push(el);}
elements=returned;}
return(options.cash)?$extend(elements,this):elements;}});Elements.implement({filter:function(filter,bind){if(!filter)return this;return new Elements(Array.filter(this,(typeof filter=='string')?function(item){return item.match(filter);}:filter,bind));}});Document.implement({newElement:function(tag,props){if(Browser.Engine.trident&&props){['name','type','checked'].each(function(attribute){if(!props[attribute])return;tag+=' '+attribute+'="'+props[attribute]+'"';if(attribute!='checked')delete props[attribute];});tag='<'+tag+'>';}
return $.element(this.createElement(tag)).set(props);},newTextNode:function(text){return this.createTextNode(text);},getDocument:function(){return this;},getWindow:function(){return this.window;}});Window.implement({$:function(el,nocash){if(el&&el.$family&&el.uid)return el;var type=$type(el);return($[type])?$[type](el,nocash,this.document):null;},$$:function(selector){if(arguments.length==1&&typeof selector=='string')return this.document.getElements(selector);var elements=[];var args=Array.flatten(arguments);for(var i=0,l=args.length;i<l;i++){var item=args[i];switch($type(item)){case'element':elements.push(item);break;case'string':elements.extend(this.document.getElements(item,true));}}
return new Elements(elements);},getDocument:function(){return this.document;},getWindow:function(){return this;}});$.string=function(id,nocash,doc){id=doc.getElementById(id);return(id)?$.element(id,nocash):null;};$.element=function(el,nocash){$uid(el);if(!nocash&&!el.$family&&!(/^object|embed$/i).test(el.tagName)){var proto=Element.Prototype;for(var p in proto)el[p]=proto[p];};return el;};$.object=function(obj,nocash,doc){if(obj.toElement)return $.element(obj.toElement(doc),nocash);return null;};$.textnode=$.whitespace=$.window=$.document=$arguments(0);Native.implement([Element,Document],{getElement:function(selector,nocash){return $(this.getElements(selector,true)[0]||null,nocash);},getElements:function(tags,nocash){tags=tags.split(',');var elements=[];var ddup=(tags.length>1);tags.each(function(tag){var partial=this.getElementsByTagName(tag.trim());(ddup)?elements.extend(partial):elements=partial;},this);return new Elements(elements,{ddup:ddup,cash:!nocash});}});(function(){var collected={},storage={};var props={input:'checked',option:'selected',textarea:(Browser.Engine.webkit&&Browser.Engine.version<420)?'innerHTML':'value'};var get=function(uid){return(storage[uid]||(storage[uid]={}));};var clean=function(item,retain){if(!item)return;var uid=item.uid;if(Browser.Engine.trident){if(item.clearAttributes){var clone=retain&&item.cloneNode(false);item.clearAttributes();if(clone)item.mergeAttributes(clone);}else if(item.removeEvents){item.removeEvents();}
if((/object/i).test(item.tagName)){for(var p in item){if(typeof item[p]=='function')item[p]=$empty;}
Element.dispose(item);}}
if(!uid)return;collected[uid]=storage[uid]=null;};var purge=function(){Hash.each(collected,clean);if(Browser.Engine.trident)$A(document.getElementsByTagName('object')).each(clean);if(window.CollectGarbage)CollectGarbage();collected=storage=null;};var walk=function(element,walk,start,match,all,nocash){var el=element[start||walk];var elements=[];while(el){if(el.nodeType==1&&(!match||Element.match(el,match))){if(!all)return $(el,nocash);elements.push(el);}
el=el[walk];}
return(all)?new Elements(elements,{ddup:false,cash:!nocash}):null;};var attributes={'html':'innerHTML','class':'className','for':'htmlFor','text':(Browser.Engine.trident||(Browser.Engine.webkit&&Browser.Engine.version<420))?'innerText':'textContent'};var bools=['compact','nowrap','ismap','declare','noshade','checked','disabled','readonly','multiple','selected','noresize','defer'];var camels=['value','accessKey','cellPadding','cellSpacing','colSpan','frameBorder','maxLength','readOnly','rowSpan','tabIndex','useMap'];Hash.extend(attributes,bools.associate(bools));Hash.extend(attributes,camels.associate(camels.map(String.toLowerCase)));var inserters={before:function(context,element){if(element.parentNode)element.parentNode.insertBefore(context,element);},after:function(context,element){if(!element.parentNode)return;var next=element.nextSibling;(next)?element.parentNode.insertBefore(context,next):element.parentNode.appendChild(context);},bottom:function(context,element){element.appendChild(context);},top:function(context,element){var first=element.firstChild;(first)?element.insertBefore(context,first):element.appendChild(context);}};inserters.inside=inserters.bottom;Hash.each(inserters,function(inserter,where){where=where.capitalize();Element.implement('inject'+where,function(el){inserter(this,$(el,true));return this;});Element.implement('grab'+where,function(el){inserter($(el,true),this);return this;});});Element.implement({set:function(prop,value){switch($type(prop)){case'object':for(var p in prop)this.set(p,prop[p]);break;case'string':var property=Element.Properties.get(prop);(property&&property.set)?property.set.apply(this,Array.slice(arguments,1)):this.setProperty(prop,value);}
return this;},get:function(prop){var property=Element.Properties.get(prop);return(property&&property.get)?property.get.apply(this,Array.slice(arguments,1)):this.getProperty(prop);},erase:function(prop){var property=Element.Properties.get(prop);(property&&property.erase)?property.erase.apply(this):this.removeProperty(prop);return this;},setProperty:function(attribute,value){var key=attributes[attribute];if(value==undefined)return this.removeProperty(attribute);if(key&&bools[attribute])value=!!value;(key)?this[key]=value:this.setAttribute(attribute,''+value);return this;},setProperties:function(attributes){for(var attribute in attributes)this.setProperty(attribute,attributes[attribute]);return this;},getProperty:function(attribute){var key=attributes[attribute];var value=(key)?this[key]:this.getAttribute(attribute,2);return(bools[attribute])?!!value:(key)?value:value||null;},getProperties:function(){var args=$A(arguments);return args.map(this.getProperty,this).associate(args);},removeProperty:function(attribute){var key=attributes[attribute];(key)?this[key]=(key&&bools[attribute])?false:'':this.removeAttribute(attribute);return this;},removeProperties:function(){Array.each(arguments,this.removeProperty,this);return this;},hasClass:function(className){return this.className.contains(className,' ');},addClass:function(className){if(!this.hasClass(className))this.className=(this.className+' '+className).clean();return this;},removeClass:function(className){this.className=this.className.replace(new RegExp('(^|\\s)'+className+'(?:\\s|$)'),'$1');return this;},toggleClass:function(className){return this.hasClass(className)?this.removeClass(className):this.addClass(className);},adopt:function(){Array.flatten(arguments).each(function(element){element=$(element,true);if(element)this.appendChild(element);},this);return this;},appendText:function(text,where){return this.grab(this.getDocument().newTextNode(text),where);},grab:function(el,where){inserters[where||'bottom']($(el,true),this);return this;},inject:function(el,where){inserters[where||'bottom'](this,$(el,true));return this;},replaces:function(el){el=$(el,true);el.parentNode.replaceChild(this,el);return this;},wraps:function(el,where){el=$(el,true);return this.replaces(el).grab(el,where);},getPrevious:function(match,nocash){return walk(this,'previousSibling',null,match,false,nocash);},getAllPrevious:function(match,nocash){return walk(this,'previousSibling',null,match,true,nocash);},getNext:function(match,nocash){return walk(this,'nextSibling',null,match,false,nocash);},getAllNext:function(match,nocash){return walk(this,'nextSibling',null,match,true,nocash);},getFirst:function(match,nocash){return walk(this,'nextSibling','firstChild',match,false,nocash);},getLast:function(match,nocash){return walk(this,'previousSibling','lastChild',match,false,nocash);},getParent:function(match,nocash){return walk(this,'parentNode',null,match,false,nocash);},getParents:function(match,nocash){return walk(this,'parentNode',null,match,true,nocash);},getChildren:function(match,nocash){return walk(this,'nextSibling','firstChild',match,true,nocash);},getWindow:function(){return this.ownerDocument.window;},getDocument:function(){return this.ownerDocument;},getElementById:function(id,nocash){var el=this.ownerDocument.getElementById(id);if(!el)return null;for(var parent=el.parentNode;parent!=this;parent=parent.parentNode){if(!parent)return null;}
return $.element(el,nocash);},getSelected:function(){return new Elements($A(this.options).filter(function(option){return option.selected;}));},getComputedStyle:function(property){if(this.currentStyle)return this.currentStyle[property.camelCase()];var computed=this.getDocument().defaultView.getComputedStyle(this,null);return(computed)?computed.getPropertyValue([property.hyphenate()]):null;},toQueryString:function(){var queryString=[];this.getElements('input, select, textarea',true).each(function(el){if(!el.name||el.disabled)return;var value=(el.tagName.toLowerCase()=='select')?Element.getSelected(el).map(function(opt){return opt.value;}):((el.type=='radio'||el.type=='checkbox')&&!el.checked)?null:el.value;$splat(value).each(function(val){if(typeof val!='undefined')queryString.push(el.name+'='+encodeURIComponent(val));});});return queryString.join('&');},clone:function(contents,keepid){contents=contents!==false;var clone=this.cloneNode(contents);var clean=function(node,element){if(!keepid)node.removeAttribute('id');if(Browser.Engine.trident){node.clearAttributes();node.mergeAttributes(element);node.removeAttribute('uid');if(node.options){var no=node.options,eo=element.options;for(var j=no.length;j--;)no[j].selected=eo[j].selected;}}
var prop=props[element.tagName.toLowerCase()];if(prop&&element[prop])node[prop]=element[prop];};if(contents){var ce=clone.getElementsByTagName('*'),te=this.getElementsByTagName('*');for(var i=ce.length;i--;)clean(ce[i],te[i]);}
clean(clone,this);return $(clone);},destroy:function(){Element.empty(this);Element.dispose(this);clean(this,true);return null;},empty:function(){$A(this.childNodes).each(function(node){Element.destroy(node);});return this;},dispose:function(){return(this.parentNode)?this.parentNode.removeChild(this):this;},hasChild:function(el){el=$(el,true);if(!el)return false;if(Browser.Engine.webkit&&Browser.Engine.version<420)return $A(this.getElementsByTagName(el.tagName)).contains(el);return(this.contains)?(this!=el&&this.contains(el)):!!(this.compareDocumentPosition(el)&16);},match:function(tag){return(!tag||(tag==this)||(Element.get(this,'tag')==tag));}});Native.implement([Element,Window,Document],{addListener:function(type,fn){if(type=='unload'){var old=fn,self=this;fn=function(){self.removeListener('unload',fn);old();};}else{collected[this.uid]=this;}
if(this.addEventListener)this.addEventListener(type,fn,false);else this.attachEvent('on'+type,fn);return this;},removeListener:function(type,fn){if(this.removeEventListener)this.removeEventListener(type,fn,false);else this.detachEvent('on'+type,fn);return this;},retrieve:function(property,dflt){var storage=get(this.uid),prop=storage[property];if(dflt!=undefined&&prop==undefined)prop=storage[property]=dflt;return $pick(prop);},store:function(property,value){var storage=get(this.uid);storage[property]=value;return this;},eliminate:function(property){var storage=get(this.uid);delete storage[property];return this;}});window.addListener('unload',purge);})();Element.Properties=new Hash;Element.Properties.style={set:function(style){this.style.cssText=style;},get:function(){return this.style.cssText;},erase:function(){this.style.cssText='';}};Element.Properties.tag={get:function(){return this.tagName.toLowerCase();}};Element.Properties.html=(function(){var wrapper=document.createElement('div');var translations={table:[1,'<table>','</table>'],select:[1,'<select>','</select>'],tbody:[2,'<table><tbody>','</tbody></table>'],tr:[3,'<table><tbody><tr>','</tr></tbody></table>']};translations.thead=translations.tfoot=translations.tbody;var html={set:function(){var html=Array.flatten(arguments).join('');var wrap=Browser.Engine.trident&&translations[this.get('tag')];if(wrap){var first=wrapper;first.innerHTML=wrap[1]+html+wrap[2];for(var i=wrap[0];i--;)first=first.firstChild;this.empty().adopt(first.childNodes);}else{this.innerHTML=html;}}};html.erase=html.set;return html;})();if(Browser.Engine.webkit&&Browser.Engine.version<420)Element.Properties.text={get:function(){if(this.innerText)return this.innerText;var temp=this.ownerDocument.newElement('div',{html:this.innerHTML}).inject(this.ownerDocument.body);var text=temp.innerText;temp.destroy();return text;}};Element.Properties.events={set:function(events){this.addEvents(events);}};Native.implement([Element,Window,Document],{addEvent:function(type,fn){var events=this.retrieve('events',{});events[type]=events[type]||{'keys':[],'values':[]};if(events[type].keys.contains(fn))return this;events[type].keys.push(fn);var realType=type,custom=Element.Events.get(type),condition=fn,self=this;if(custom){if(custom.onAdd)custom.onAdd.call(this,fn);if(custom.condition){condition=function(event){if(custom.condition.call(this,event))return fn.call(this,event);return true;};}
realType=custom.base||realType;}
var defn=function(){return fn.call(self);};var nativeEvent=Element.NativeEvents[realType];if(nativeEvent){if(nativeEvent==2){defn=function(event){event=new Event(event,self.getWindow());if(condition.call(self,event)===false)event.stop();};}
this.addListener(realType,defn);}
events[type].values.push(defn);return this;},removeEvent:function(type,fn){var events=this.retrieve('events');if(!events||!events[type])return this;var pos=events[type].keys.indexOf(fn);if(pos==-1)return this;events[type].keys.splice(pos,1);var value=events[type].values.splice(pos,1)[0];var custom=Element.Events.get(type);if(custom){if(custom.onRemove)custom.onRemove.call(this,fn);type=custom.base||type;}
return(Element.NativeEvents[type])?this.removeListener(type,value):this;},addEvents:function(events){for(var event in events)this.addEvent(event,events[event]);return this;},removeEvents:function(events){if($type(events)=='object'){for(var type in events)this.removeEvent(type,events[type]);return this;}
var attached=this.retrieve('events');if(!attached)return this;if(!events){for(var type in attached)this.removeEvents(type);this.eliminate('events');}else if(attached[events]){while(attached[events].keys[0])this.removeEvent(events,attached[events].keys[0]);attached[events]=null;}
return this;},fireEvent:function(type,args,delay){var events=this.retrieve('events');if(!events||!events[type])return this;events[type].keys.each(function(fn){fn.create({'bind':this,'delay':delay,'arguments':args})();},this);return this;},cloneEvents:function(from,type){from=$(from);var fevents=from.retrieve('events');if(!fevents)return this;if(!type){for(var evType in fevents)this.cloneEvents(from,evType);}else if(fevents[type]){fevents[type].keys.each(function(fn){this.addEvent(type,fn);},this);}
return this;}});Element.NativeEvents={click:2,dblclick:2,mouseup:2,mousedown:2,contextmenu:2,mousewheel:2,DOMMouseScroll:2,mouseover:2,mouseout:2,mousemove:2,selectstart:2,selectend:2,keydown:2,keypress:2,keyup:2,focus:2,blur:2,change:2,reset:2,select:2,submit:2,load:1,unload:1,beforeunload:2,resize:1,move:1,DOMContentLoaded:1,readystatechange:1,error:1,abort:1,scroll:1};(function(){var $check=function(event){var related=event.relatedTarget;if(related==undefined)return true;if(related===false)return false;return($type(this)!='document'&&related!=this&&related.prefix!='xul'&&!this.hasChild(related));};Element.Events=new Hash({mouseenter:{base:'mouseover',condition:$check},mouseleave:{base:'mouseout',condition:$check},mousewheel:{base:(Browser.Engine.gecko)?'DOMMouseScroll':'mousewheel'}});})();Element.Properties.styles={set:function(styles){this.setStyles(styles);}};Element.Properties.opacity={set:function(opacity,novisibility){if(!novisibility){if(opacity==0){if(this.style.visibility!='hidden')this.style.visibility='hidden';}else{if(this.style.visibility!='visible')this.style.visibility='visible';}}
if(!this.currentStyle||!this.currentStyle.hasLayout)this.style.zoom=1;if(Browser.Engine.trident)this.style.filter=(opacity==1)?'':'alpha(opacity='+opacity*100+')';this.style.opacity=opacity;this.store('opacity',opacity);},get:function(){return this.retrieve('opacity',1);}};Element.implement({setOpacity:function(value){return this.set('opacity',value,true);},getOpacity:function(){return this.get('opacity');},setStyle:function(property,value){switch(property){case'opacity':return this.set('opacity',parseFloat(value));case'float':property=(Browser.Engine.trident)?'styleFloat':'cssFloat';}
property=property.camelCase();if($type(value)!='string'){var map=(Element.Styles.get(property)||'@').split(' ');value=$splat(value).map(function(val,i){if(!map[i])return'';return($type(val)=='number')?map[i].replace('@',Math.round(val)):val;}).join(' ');}else if(value==String(Number(value))){value=Math.round(value);}
this.style[property]=value;return this;},getStyle:function(property){switch(property){case'opacity':return this.get('opacity');case'float':property=(Browser.Engine.trident)?'styleFloat':'cssFloat';}
property=property.camelCase();var result=this.style[property];if(!$chk(result)){result=[];for(var style in Element.ShortStyles){if(property!=style)continue;for(var s in Element.ShortStyles[style])result.push(this.getStyle(s));return result.join(' ');}
result=this.getComputedStyle(property);}
if(result){result=String(result);var color=result.match(/rgba?\([\d\s,]+\)/);if(color)result=result.replace(color[0],color[0].rgbToHex());}
if(Browser.Engine.presto||(Browser.Engine.trident&&!$chk(parseInt(result)))){if(property.test(/^(height|width)$/)){var values=(property=='width')?['left','right']:['top','bottom'],size=0;values.each(function(value){size+=this.getStyle('border-'+value+'-width').toInt()+this.getStyle('padding-'+value).toInt();},this);return this['offset'+property.capitalize()]-size+'px';}
if((Browser.Engine.presto)&&String(result).test('px'))return result;if(property.test(/(border(.+)Width|margin|padding)/))return'0px';}
return result;},setStyles:function(styles){for(var style in styles)this.setStyle(style,styles[style]);return this;},getStyles:function(){var result={};Array.each(arguments,function(key){result[key]=this.getStyle(key);},this);return result;}});Element.Styles=new Hash({left:'@px',top:'@px',bottom:'@px',right:'@px',width:'@px',height:'@px',maxWidth:'@px',maxHeight:'@px',minWidth:'@px',minHeight:'@px',backgroundColor:'rgb(@, @, @)',backgroundPosition:'@px @px',color:'rgb(@, @, @)',fontSize:'@px',letterSpacing:'@px',lineHeight:'@px',clip:'rect(@px @px @px @px)',margin:'@px @px @px @px',padding:'@px @px @px @px',border:'@px @ rgb(@, @, @) @px @ rgb(@, @, @) @px @ rgb(@, @, @)',borderWidth:'@px @px @px @px',borderStyle:'@ @ @ @',borderColor:'rgb(@, @, @) rgb(@, @, @) rgb(@, @, @) rgb(@, @, @)',zIndex:'@','zoom':'@',fontWeight:'@',textIndent:'@px',opacity:'@'});Element.ShortStyles={margin:{},padding:{},border:{},borderWidth:{},borderStyle:{},borderColor:{}};['Top','Right','Bottom','Left'].each(function(direction){var Short=Element.ShortStyles;var All=Element.Styles;['margin','padding'].each(function(style){var sd=style+direction;Short[style][sd]=All[sd]='@px';});var bd='border'+direction;Short.border[bd]=All[bd]='@px @ rgb(@, @, @)';var bdw=bd+'Width',bds=bd+'Style',bdc=bd+'Color';Short[bd]={};Short.borderWidth[bdw]=Short[bd][bdw]=All[bdw]='@px';Short.borderStyle[bds]=Short[bd][bds]=All[bds]='@';Short.borderColor[bdc]=Short[bd][bdc]=All[bdc]='rgb(@, @, @)';});(function(){Element.implement({scrollTo:function(x,y){if(isBody(this)){this.getWindow().scrollTo(x,y);}else{this.scrollLeft=x;this.scrollTop=y;}
return this;},getSize:function(){if(isBody(this))return this.getWindow().getSize();return{x:this.offsetWidth,y:this.offsetHeight};},getScrollSize:function(){if(isBody(this))return this.getWindow().getScrollSize();return{x:this.scrollWidth,y:this.scrollHeight};},getScroll:function(){if(isBody(this))return this.getWindow().getScroll();return{x:this.scrollLeft,y:this.scrollTop};},getScrolls:function(){var element=this,position={x:0,y:0};while(element&&!isBody(element)){position.x+=element.scrollLeft;position.y+=element.scrollTop;element=element.parentNode;}
return position;},getOffsetParent:function(){var element=this;if(isBody(element))return null;if(!Browser.Engine.trident)return element.offsetParent;while((element=element.parentNode)&&!isBody(element)){if(styleString(element,'position')!='static')return element;}
return null;},getOffsets:function(){if(Browser.Engine.trident){var bound=this.getBoundingClientRect(),html=this.getDocument().documentElement;return{x:bound.left+html.scrollLeft-html.clientLeft,y:bound.top+html.scrollTop-html.clientTop};}
var element=this,position={x:0,y:0};if(isBody(this))return position;while(element&&!isBody(element)){position.x+=element.offsetLeft;position.y+=element.offsetTop;if(Browser.Engine.gecko){if(!borderBox(element)){position.x+=leftBorder(element);position.y+=topBorder(element);}
var parent=element.parentNode;if(parent&&styleString(parent,'overflow')!='visible'){position.x+=leftBorder(parent);position.y+=topBorder(parent);}}else if(element!=this&&Browser.Engine.webkit){position.x+=leftBorder(element);position.y+=topBorder(element);}
element=element.offsetParent;}
if(Browser.Engine.gecko&&!borderBox(this)){position.x-=leftBorder(this);position.y-=topBorder(this);}
return position;},getPosition:function(relative){if(isBody(this))return{x:0,y:0};var offset=this.getOffsets(),scroll=this.getScrolls();var position={x:offset.x-scroll.x,y:offset.y-scroll.y};var relativePosition=(relative&&(relative=$(relative)))?relative.getPosition():{x:0,y:0};return{x:position.x-relativePosition.x,y:position.y-relativePosition.y};},getCoordinates:function(element){if(isBody(this))return this.getWindow().getCoordinates();var position=this.getPosition(element),size=this.getSize();var obj={left:position.x,top:position.y,width:size.x,height:size.y};obj.right=obj.left+obj.width;obj.bottom=obj.top+obj.height;return obj;},computePosition:function(obj){return{left:obj.x-styleNumber(this,'margin-left'),top:obj.y-styleNumber(this,'margin-top')};},position:function(obj){return this.setStyles(this.computePosition(obj));}});Native.implement([Document,Window],{getSize:function(){var win=this.getWindow();if(Browser.Engine.presto||Browser.Engine.webkit)return{x:win.innerWidth,y:win.innerHeight};var doc=getCompatElement(this);return{x:doc.clientWidth,y:doc.clientHeight};},getScroll:function(){var win=this.getWindow();var doc=getCompatElement(this);return{x:win.pageXOffset||doc.scrollLeft,y:win.pageYOffset||doc.scrollTop};},getScrollSize:function(){var doc=getCompatElement(this);var min=this.getSize();return{x:Math.max(doc.scrollWidth,min.x),y:Math.max(doc.scrollHeight,min.y)};},getPosition:function(){return{x:0,y:0};},getCoordinates:function(){var size=this.getSize();return{top:0,left:0,bottom:size.y,right:size.x,height:size.y,width:size.x};}});var styleString=Element.getComputedStyle;function styleNumber(element,style){return styleString(element,style).toInt()||0;};function borderBox(element){return styleString(element,'-moz-box-sizing')=='border-box';};function topBorder(element){return styleNumber(element,'border-top-width');};function leftBorder(element){return styleNumber(element,'border-left-width');};function isBody(element){return(/^(?:body|html)$/i).test(element.tagName);};function getCompatElement(element){var doc=element.getDocument();return(!doc.compatMode||doc.compatMode=='CSS1Compat')?doc.html:doc.body;};})();Native.implement([Window,Document,Element],{getHeight:function(){return this.getSize().y;},getWidth:function(){return this.getSize().x;},getScrollTop:function(){return this.getScroll().y;},getScrollLeft:function(){return this.getScroll().x;},getScrollHeight:function(){return this.getScrollSize().y;},getScrollWidth:function(){return this.getScrollSize().x;},getTop:function(){return this.getPosition().y;},getLeft:function(){return this.getPosition().x;}});Native.implement([Document,Element],{getElements:function(expression,nocash){expression=expression.split(',');var items,local={};for(var i=0,l=expression.length;i<l;i++){var selector=expression[i],elements=Selectors.Utils.search(this,selector,local);if(i!=0&&elements.item)elements=$A(elements);items=(i==0)?elements:(items.item)?$A(items).concat(elements):items.concat(elements);}
return new Elements(items,{ddup:(expression.length>1),cash:!nocash});}});Element.implement({match:function(selector){if(!selector||(selector==this))return true;var tagid=Selectors.Utils.parseTagAndID(selector);var tag=tagid[0],id=tagid[1];if(!Selectors.Filters.byID(this,id)||!Selectors.Filters.byTag(this,tag))return false;var parsed=Selectors.Utils.parseSelector(selector);return(parsed)?Selectors.Utils.filter(this,parsed,{}):true;}});var Selectors={Cache:{nth:{},parsed:{}}};Selectors.RegExps={id:(/#([\w-]+)/),tag:(/^(\w+|\*)/),quick:(/^(\w+|\*)$/),splitter:(/\s*([+>~\s])\s*([a-zA-Z#.*:\[])/g),combined:(/\.([\w-]+)|\[(\w+)(?:([!*^$~|]?=)(["']?)([^\4]*?)\4)?\]|:([\w-]+)(?:\(["']?(.*?)?["']?\)|$)/g)};Selectors.Utils={chk:function(item,uniques){if(!uniques)return true;var uid=$uid(item);if(!uniques[uid])return uniques[uid]=true;return false;},parseNthArgument:function(argument){if(Selectors.Cache.nth[argument])return Selectors.Cache.nth[argument];var parsed=argument.match(/^([+-]?\d*)?([a-z]+)?([+-]?\d*)?$/);if(!parsed)return false;var inta=parseInt(parsed[1]);var a=(inta||inta===0)?inta:1;var special=parsed[2]||false;var b=parseInt(parsed[3])||0;if(a!=0){b--;while(b<1)b+=a;while(b>=a)b-=a;}else{a=b;special='index';}
switch(special){case'n':parsed={a:a,b:b,special:'n'};break;case'odd':parsed={a:2,b:0,special:'n'};break;case'even':parsed={a:2,b:1,special:'n'};break;case'first':parsed={a:0,special:'index'};break;case'last':parsed={special:'last-child'};break;case'only':parsed={special:'only-child'};break;default:parsed={a:(a-1),special:'index'};}
return Selectors.Cache.nth[argument]=parsed;},parseSelector:function(selector){if(Selectors.Cache.parsed[selector])return Selectors.Cache.parsed[selector];var m,parsed={classes:[],pseudos:[],attributes:[]};while((m=Selectors.RegExps.combined.exec(selector))){var cn=m[1],an=m[2],ao=m[3],av=m[5],pn=m[6],pa=m[7];if(cn){parsed.classes.push(cn);}else if(pn){var parser=Selectors.Pseudo.get(pn);if(parser)parsed.pseudos.push({parser:parser,argument:pa});else parsed.attributes.push({name:pn,operator:'=',value:pa});}else if(an){parsed.attributes.push({name:an,operator:ao,value:av});}}
if(!parsed.classes.length)delete parsed.classes;if(!parsed.attributes.length)delete parsed.attributes;if(!parsed.pseudos.length)delete parsed.pseudos;if(!parsed.classes&&!parsed.attributes&&!parsed.pseudos)parsed=null;return Selectors.Cache.parsed[selector]=parsed;},parseTagAndID:function(selector){var tag=selector.match(Selectors.RegExps.tag);var id=selector.match(Selectors.RegExps.id);return[(tag)?tag[1]:'*',(id)?id[1]:false];},filter:function(item,parsed,local){var i;if(parsed.classes){for(i=parsed.classes.length;i--;i){var cn=parsed.classes[i];if(!Selectors.Filters.byClass(item,cn))return false;}}
if(parsed.attributes){for(i=parsed.attributes.length;i--;i){var att=parsed.attributes[i];if(!Selectors.Filters.byAttribute(item,att.name,att.operator,att.value))return false;}}
if(parsed.pseudos){for(i=parsed.pseudos.length;i--;i){var psd=parsed.pseudos[i];if(!Selectors.Filters.byPseudo(item,psd.parser,psd.argument,local))return false;}}
return true;},getByTagAndID:function(ctx,tag,id){if(id){var item=(ctx.getElementById)?ctx.getElementById(id,true):Element.getElementById(ctx,id,true);return(item&&Selectors.Filters.byTag(item,tag))?[item]:[];}else{return ctx.getElementsByTagName(tag);}},search:function(self,expression,local){var splitters=[];var selectors=expression.trim().replace(Selectors.RegExps.splitter,function(m0,m1,m2){splitters.push(m1);return':)'+m2;}).split(':)');var items,filtered,item;for(var i=0,l=selectors.length;i<l;i++){var selector=selectors[i];if(i==0&&Selectors.RegExps.quick.test(selector)){items=self.getElementsByTagName(selector);continue;}
var splitter=splitters[i-1];var tagid=Selectors.Utils.parseTagAndID(selector);var tag=tagid[0],id=tagid[1];if(i==0){items=Selectors.Utils.getByTagAndID(self,tag,id);}else{var uniques={},found=[];for(var j=0,k=items.length;j<k;j++)found=Selectors.Getters[splitter](found,items[j],tag,id,uniques);items=found;}
var parsed=Selectors.Utils.parseSelector(selector);if(parsed){filtered=[];for(var m=0,n=items.length;m<n;m++){item=items[m];if(Selectors.Utils.filter(item,parsed,local))filtered.push(item);}
items=filtered;}}
return items;}};Selectors.Getters={' ':function(found,self,tag,id,uniques){var items=Selectors.Utils.getByTagAndID(self,tag,id);for(var i=0,l=items.length;i<l;i++){var item=items[i];if(Selectors.Utils.chk(item,uniques))found.push(item);}
return found;},'>':function(found,self,tag,id,uniques){var children=Selectors.Utils.getByTagAndID(self,tag,id);for(var i=0,l=children.length;i<l;i++){var child=children[i];if(child.parentNode==self&&Selectors.Utils.chk(child,uniques))found.push(child);}
return found;},'+':function(found,self,tag,id,uniques){while((self=self.nextSibling)){if(self.nodeType==1){if(Selectors.Utils.chk(self,uniques)&&Selectors.Filters.byTag(self,tag)&&Selectors.Filters.byID(self,id))found.push(self);break;}}
return found;},'~':function(found,self,tag,id,uniques){while((self=self.nextSibling)){if(self.nodeType==1){if(!Selectors.Utils.chk(self,uniques))break;if(Selectors.Filters.byTag(self,tag)&&Selectors.Filters.byID(self,id))found.push(self);}}
return found;}};Selectors.Filters={byTag:function(self,tag){return(tag=='*'||(self.tagName&&self.tagName.toLowerCase()==tag));},byID:function(self,id){return(!id||(self.id&&self.id==id));},byClass:function(self,klass){return(self.className&&self.className.contains(klass,' '));},byPseudo:function(self,parser,argument,local){return parser.call(self,argument,local);},byAttribute:function(self,name,operator,value){var result=Element.prototype.getProperty.call(self,name);if(!result)return(operator=='!=');if(!operator||value==undefined)return true;switch(operator){case'=':return(result==value);case'*=':return(result.contains(value));case'^=':return(result.substr(0,value.length)==value);case'$=':return(result.substr(result.length-value.length)==value);case'!=':return(result!=value);case'~=':return result.contains(value,' ');case'|=':return result.contains(value,'-');}
return false;}};Selectors.Pseudo=new Hash({checked:function(){return this.checked;},empty:function(){return!(this.innerText||this.textContent||'').length;},not:function(selector){return!Element.match(this,selector);},contains:function(text){return(this.innerText||this.textContent||'').contains(text);},'first-child':function(){return Selectors.Pseudo.index.call(this,0);},'last-child':function(){var element=this;while((element=element.nextSibling)){if(element.nodeType==1)return false;}
return true;},'only-child':function(){var prev=this;while((prev=prev.previousSibling)){if(prev.nodeType==1)return false;}
var next=this;while((next=next.nextSibling)){if(next.nodeType==1)return false;}
return true;},'nth-child':function(argument,local){argument=(argument==undefined)?'n':argument;var parsed=Selectors.Utils.parseNthArgument(argument);if(parsed.special!='n')return Selectors.Pseudo[parsed.special].call(this,parsed.a,local);var count=0;local.positions=local.positions||{};var uid=$uid(this);if(!local.positions[uid]){var self=this;while((self=self.previousSibling)){if(self.nodeType!=1)continue;count++;var position=local.positions[$uid(self)];if(position!=undefined){count=position+count;break;}}
local.positions[uid]=count;}
return(local.positions[uid]%parsed.a==parsed.b);},index:function(index){var element=this,count=0;while((element=element.previousSibling)){if(element.nodeType==1&&++count>index)return false;}
return(count==index);},even:function(argument,local){return Selectors.Pseudo['nth-child'].call(this,'2n+1',local);},odd:function(argument,local){return Selectors.Pseudo['nth-child'].call(this,'2n',local);}});Element.Events.domready={onAdd:function(fn){if(Browser.loaded)fn.call(this);}};(function(){var domready=function(){if(Browser.loaded)return;Browser.loaded=true;window.fireEvent('domready');document.fireEvent('domready');};if(Browser.Engine.trident){var temp=document.createElement('div');(function(){($try(function(){temp.doScroll('left');return $(temp).inject(document.body).set('html','temp').dispose();}))?domready():arguments.callee.delay(50);})();}else if(Browser.Engine.webkit&&Browser.Engine.version<525){(function(){(['loaded','complete'].contains(document.readyState))?domready():arguments.callee.delay(50);})();}else{window.addEvent('load',domready);document.addEvent('DOMContentLoaded',domready);}})();var Fx=new Class({Implements:[Chain,Events,Options],options:{fps:50,unit:false,duration:500,link:'ignore'},initialize:function(options){this.subject=this.subject||this;this.setOptions(options);this.options.duration=Fx.Durations[this.options.duration]||this.options.duration.toInt();var wait=this.options.wait;if(wait===false)this.options.link='cancel';},getTransition:function(){return function(p){return-(Math.cos(Math.PI*p)-1)/2;};},step:function(){var time=$time();if(time<this.time+this.options.duration){var delta=this.transition((time-this.time)/this.options.duration);this.set(this.compute(this.from,this.to,delta));}else{this.set(this.compute(this.from,this.to,1));this.complete();}},set:function(now){return now;},compute:function(from,to,delta){return Fx.compute(from,to,delta);},check:function(caller){if(!this.timer)return true;switch(this.options.link){case'cancel':this.cancel();return true;case'chain':this.chain(caller.bind(this,Array.slice(arguments,1)));return false;}
return false;},start:function(from,to){if(!this.check(arguments.callee,from,to))return this;this.from=from;this.to=to;this.time=0;this.transition=this.getTransition();this.startTimer();this.onStart();return this;},complete:function(){if(this.stopTimer())this.onComplete();return this;},cancel:function(){if(this.stopTimer())this.onCancel();return this;},onStart:function(){this.fireEvent('start',this.subject);},onComplete:function(){this.fireEvent('complete',this.subject);if(!this.callChain())this.fireEvent('chainComplete',this.subject);},onCancel:function(){this.fireEvent('cancel',this.subject).clearChain();},pause:function(){this.stopTimer();return this;},resume:function(){this.startTimer();return this;},stopTimer:function(){if(!this.timer)return false;this.time=$time()-this.time;this.timer=$clear(this.timer);return true;},startTimer:function(){if(this.timer)return false;this.time=$time()-this.time;this.timer=this.step.periodical(Math.round(1000/this.options.fps),this);return true;}});Fx.compute=function(from,to,delta){return(to-from)*delta+from;};Fx.Durations={'short':250,'normal':500,'long':1000};Fx.CSS=new Class({Extends:Fx,prepare:function(element,property,values){values=$splat(values);var values1=values[1];if(!$chk(values1)){values[1]=values[0];values[0]=element.getStyle(property);}
var parsed=values.map(this.parse);return{from:parsed[0],to:parsed[1]};},parse:function(value){value=$lambda(value)();value=(typeof value=='string')?value.split(' '):$splat(value);return value.map(function(val){val=String(val);var found=false;Fx.CSS.Parsers.each(function(parser,key){if(found)return;var parsed=parser.parse(val);if($chk(parsed))found={value:parsed,parser:parser};});found=found||{value:val,parser:Fx.CSS.Parsers.String};return found;});},compute:function(from,to,delta){var computed=[];(Math.min(from.length,to.length)).times(function(i){computed.push({value:from[i].parser.compute(from[i].value,to[i].value,delta),parser:from[i].parser});});computed.$family={name:'fx:css:value'};return computed;},serve:function(value,unit){if($type(value)!='fx:css:value')value=this.parse(value);var returned=[];value.each(function(bit){returned=returned.concat(bit.parser.serve(bit.value,unit));});return returned;},render:function(element,property,value,unit){element.setStyle(property,this.serve(value,unit));},search:function(selector){if(Fx.CSS.Cache[selector])return Fx.CSS.Cache[selector];var to={};Array.each(document.styleSheets,function(sheet,j){var href=sheet.href;if(href&&href.contains('://')&&!href.contains(document.domain))return;var rules=sheet.rules||sheet.cssRules;Array.each(rules,function(rule,i){if(!rule.style)return;var selectorText=(rule.selectorText)?rule.selectorText.replace(/^\w+/,function(m){return m.toLowerCase();}):null;if(!selectorText||!selectorText.test('^'+selector+'$'))return;Element.Styles.each(function(value,style){if(!rule.style[style]||Element.ShortStyles[style])return;value=String(rule.style[style]);to[style]=(value.test(/^rgb/))?value.rgbToHex():value;});});});return Fx.CSS.Cache[selector]=to;}});Fx.CSS.Cache={};Fx.CSS.Parsers=new Hash({Color:{parse:function(value){if(value.match(/^#[0-9a-f]{3,6}$/i))return value.hexToRgb(true);return((value=value.match(/(\d+),\s*(\d+),\s*(\d+)/)))?[value[1],value[2],value[3]]:false;},compute:function(from,to,delta){return from.map(function(value,i){return Math.round(Fx.compute(from[i],to[i],delta));});},serve:function(value){return value.map(Number);}},Number:{parse:parseFloat,compute:Fx.compute,serve:function(value,unit){return(unit)?value+unit:value;}},String:{parse:$lambda(false),compute:$arguments(1),serve:$arguments(0)}});Fx.Morph=new Class({Extends:Fx.CSS,initialize:function(element,options){this.element=this.subject=$(element);this.parent(options);},set:function(now){if(typeof now=='string')now=this.search(now);for(var p in now)this.render(this.element,p,now[p],this.options.unit);return this;},compute:function(from,to,delta){var now={};for(var p in from)now[p]=this.parent(from[p],to[p],delta);return now;},start:function(properties){if(!this.check(arguments.callee,properties))return this;if(typeof properties=='string')properties=this.search(properties);var from={},to={};for(var p in properties){var parsed=this.prepare(this.element,p,properties[p]);from[p]=parsed.from;to[p]=parsed.to;}
return this.parent(from,to);}});Element.Properties.morph={set:function(options){var morph=this.retrieve('morph');if(morph)morph.cancel();return this.eliminate('morph').store('morph:options',$extend({link:'cancel'},options));},get:function(options){if(options||!this.retrieve('morph')){if(options||!this.retrieve('morph:options'))this.set('morph',options);this.store('morph',new Fx.Morph(this,this.retrieve('morph:options')));}
return this.retrieve('morph');}};Element.implement({morph:function(props){this.get('morph').start(props);return this;}});Fx.implement({getTransition:function(){var trans=this.options.transition||Fx.Transitions.Sine.easeInOut;if(typeof trans=='string'){var data=trans.split(':');trans=Fx.Transitions;trans=trans[data[0]]||trans[data[0].capitalize()];if(data[1])trans=trans['ease'+data[1].capitalize()+(data[2]?data[2].capitalize():'')];}
return trans;}});Fx.Transition=function(transition,params){params=$splat(params);return $extend(transition,{easeIn:function(pos){return transition(pos,params);},easeOut:function(pos){return 1-transition(1-pos,params);},easeInOut:function(pos){return(pos<=0.5)?transition(2*pos,params)/2:(2-transition(2*(1-pos),params))/2;}});};Fx.Transitions=new Hash({linear:$arguments(0)});Fx.Transitions.extend=function(transitions){for(var transition in transitions)Fx.Transitions[transition]=new Fx.Transition(transitions[transition]);};Fx.Transitions.extend({Pow:function(p,x){return Math.pow(p,x[0]||6);},Expo:function(p){return Math.pow(2,8*(p-1));},Circ:function(p){return 1-Math.sin(Math.acos(p));},Sine:function(p){return 1-Math.sin((1-p)*Math.PI/2);},Back:function(p,x){x=x[0]||1.618;return Math.pow(p,2)*((x+1)*p-x);},Bounce:function(p){var value;for(var a=0,b=1;1;a+=b,b/=2){if(p>=(7-4*a)/11){value=b*b-Math.pow((11-6*a-11*p)/4,2);break;}}
return value;},Elastic:function(p,x){return Math.pow(2,10*--p)*Math.cos(20*p*Math.PI*(x[0]||1)/3);}});['Quad','Cubic','Quart','Quint'].each(function(transition,i){Fx.Transitions[transition]=new Fx.Transition(function(p){return Math.pow(p,[i+2]);});});var Request=new Class({Implements:[Chain,Events,Options],options:{url:'',data:'',headers:{'X-Requested-With':'XMLHttpRequest','Accept':'text/javascript, text/html, application/xml, text/xml, */*'},async:true,format:false,method:'post',link:'ignore',isSuccess:null,emulation:true,urlEncoded:true,encoding:'utf-8',evalScripts:false,evalResponse:false},initialize:function(options){this.xhr=new Browser.Request();this.setOptions(options);this.options.isSuccess=this.options.isSuccess||this.isSuccess;this.headers=new Hash(this.options.headers);},onStateChange:function(){if(this.xhr.readyState!=4||!this.running)return;this.running=false;this.status=0;$try(function(){this.status=this.xhr.status;}.bind(this));if(this.options.isSuccess.call(this,this.status)){this.response={text:this.xhr.responseText,xml:this.xhr.responseXML};this.success(this.response.text,this.response.xml);}else{this.response={text:null,xml:null};this.failure();}
this.xhr.onreadystatechange=$empty;},isSuccess:function(){return((this.status>=200)&&(this.status<300));},processScripts:function(text){if(this.options.evalResponse||(/(ecma|java)script/).test(this.getHeader('Content-type')))return $exec(text);return text.stripScripts(this.options.evalScripts);},success:function(text,xml){this.onSuccess(this.processScripts(text),xml);},onSuccess:function(){this.fireEvent('complete',arguments).fireEvent('success',arguments).callChain();},failure:function(){this.onFailure();},onFailure:function(){this.fireEvent('complete').fireEvent('failure',this.xhr);},setHeader:function(name,value){this.headers.set(name,value);return this;},getHeader:function(name){return $try(function(){return this.xhr.getResponseHeader(name);}.bind(this));},check:function(caller){if(!this.running)return true;switch(this.options.link){case'cancel':this.cancel();return true;case'chain':this.chain(caller.bind(this,Array.slice(arguments,1)));return false;}
return false;},send:function(options){if(!this.check(arguments.callee,options))return this;this.running=true;var type=$type(options);if(type=='string'||type=='element')options={data:options};var old=this.options;options=$extend({data:old.data,url:old.url,method:old.method},options);var data=options.data,url=options.url,method=options.method;switch($type(data)){case'element':data=$(data).toQueryString();break;case'object':case'hash':data=Hash.toQueryString(data);}
if(this.options.format){var format='format='+this.options.format;data=(data)?format+'&'+data:format;}
if(this.options.emulation&&['put','delete'].contains(method)){var _method='_method='+method;data=(data)?_method+'&'+data:_method;method='post';}
if(this.options.urlEncoded&&method=='post'){var encoding=(this.options.encoding)?'; charset='+this.options.encoding:'';this.headers.set('Content-type','application/x-www-form-urlencoded'+encoding);}
if(data&&method=='get'){url=url+(url.contains('?')?'&':'?')+data;data=null;}
this.xhr.open(method.toUpperCase(),url,this.options.async);this.xhr.onreadystatechange=this.onStateChange.bind(this);this.headers.each(function(value,key){try{this.xhr.setRequestHeader(key,value);}catch(e){this.fireEvent('exception',[key,value]);}},this);this.fireEvent('request');this.xhr.send(data);if(!this.options.async)this.onStateChange();return this;},cancel:function(){if(!this.running)return this;this.running=false;this.xhr.abort();this.xhr.onreadystatechange=$empty;this.xhr=new Browser.Request();this.fireEvent('cancel');return this;}});(function(){var methods={};['get','post','put','delete','GET','POST','PUT','DELETE'].each(function(method){methods[method]=function(){var params=Array.link(arguments,{url:String.type,data:$defined});return this.send($extend(params,{method:method.toLowerCase()}));};});Request.implement(methods);})();Element.Properties.send={set:function(options){var send=this.retrieve('send');if(send)send.cancel();return this.eliminate('send').store('send:options',$extend({data:this,link:'cancel',method:this.get('method')||'post',url:this.get('action')},options));},get:function(options){if(options||!this.retrieve('send')){if(options||!this.retrieve('send:options'))this.set('send',options);this.store('send',new Request(this.retrieve('send:options')));}
return this.retrieve('send');}};Element.implement({send:function(url){var sender=this.get('send');sender.send({data:this,url:url||sender.options.url});return this;}});Request.HTML=new Class({Extends:Request,options:{update:false,evalScripts:true,filter:false},processHTML:function(text){var match=text.match(/<body[^>]*>([\s\S]*?)<\/body>/i);text=(match)?match[1]:text;var container=new Element('div');return $try(function(){var root='<root>'+text+'</root>',doc;if(Browser.Engine.trident){doc=new ActiveXObject('Microsoft.XMLDOM');doc.async=false;doc.loadXML(root);}else{doc=new DOMParser().parseFromString(root,'text/xml');}
root=doc.getElementsByTagName('root')[0];for(var i=0,k=root.childNodes.length;i<k;i++){var child=Element.clone(root.childNodes[i],true,true);if(child)container.grab(child);}
return container;})||container.set('html',text);},success:function(text){var options=this.options,response=this.response;response.html=text.stripScripts(function(script){response.javascript=script;});var temp=this.processHTML(response.html);response.tree=temp.childNodes;response.elements=temp.getElements('*');if(options.filter)response.tree=response.elements.filter(options.filter);if(options.update)$(options.update).empty().set('html',response.html);if(options.evalScripts)$exec(response.javascript);this.onSuccess(response.tree,response.elements,response.html,response.javascript);}});Element.Properties.load={set:function(options){var load=this.retrieve('load');if(load)load.cancel();return this.eliminate('load').store('load:options',$extend({data:this,link:'cancel',update:this,method:'get'},options));},get:function(options){if(options||!this.retrieve('load')){if(options||!this.retrieve('load:options'))this.set('load',options);this.store('load',new Request.HTML(this.retrieve('load:options')));}
return this.retrieve('load');}};Element.implement({load:function(){this.get('load').send(Array.link(arguments,{data:Object.type,url:String.type}));return this;}});Fx.Slide=new Class({Extends:Fx,options:{mode:"vertical"},initialize:function(B,A){this.addEvent("complete",function(){this.open=(this.wrapper["offset"+this.layout.capitalize()]!=0);if(this.open&&Browser.Engine.webkit419){this.element.dispose().inject(this.wrapper);}},true);this.element=this.subject=$(B);this.parent(A);var C=this.element.retrieve("wrapper");this.wrapper=C||new Element("div",{styles:$extend(this.element.getStyles("margin","position"),{overflow:"hidden"})}).wraps(this.element);this.element.store("wrapper",this.wrapper).setStyle("margin",0);this.now=[];this.open=true;},vertical:function(){this.margin="margin-top";this.layout="height";this.offset=this.element.offsetHeight;},horizontal:function(){this.margin="margin-left";this.layout="width";this.offset=this.element.offsetWidth;},set:function(A){this.element.setStyle(this.margin,A[0]);this.wrapper.setStyle(this.layout,A[1]);return this;},compute:function(E,D,C){var B=[];var A=2;A.times(function(F){B[F]=Fx.compute(E[F],D[F],C);});return B;},start:function(B,E){if(!this.check(arguments.callee,B,E)){return this;}this[E||this.options.mode]();var D=this.element.getStyle(this.margin).toInt();var C=this.wrapper.getStyle(this.layout).toInt();var A=[[D,C],[0,this.offset]];var G=[[D,C],[-this.offset,0]];var F;switch(B){case"in":F=A;break;case"out":F=G;break;case"toggle":F=(this.wrapper["offset"+this.layout.capitalize()]==0)?A:G;}return this.parent(F[0],F[1]);},slideIn:function(A){return this.start("in",A);},slideOut:function(A){return this.start("out",A);},hide:function(A){this[A||this.options.mode]();this.open=false;return this.set([-this.offset,0]);},show:function(A){this[A||this.options.mode]();this.open=true;return this.set([0,this.offset]);},toggle:function(A){return this.start("toggle",A);}});Element.Properties.slide={set:function(B){var A=this.retrieve("slide");if(A){A.cancel();}return this.eliminate("slide").store("slide:options",$extend({link:"cancel"},B));},get:function(A){if(A||!this.retrieve("slide")){if(A||!this.retrieve("slide:options")){this.set("slide",A);}this.store("slide",new Fx.Slide(this,this.retrieve("slide:options")));}return this.retrieve("slide");}};Element.implement({slide:function(D,E){D=D||"toggle";var B=this.get("slide"),A;switch(D){case"hide":B.hide(E);break;case"show":B.show(E);break;case"toggle":var C=this.retrieve("slide:flag",B.open);B[(C)?"slideOut":"slideIn"](E);this.store("slide:flag",!C);A=true;break;default:B.start(D,E);}if(!A){this.eliminate("slide:flag");}return this;}});Fx.Elements=new Class({Extends:Fx.CSS,initialize:function(B,A){this.elements=this.subject=$$(B);this.parent(A);},compute:function(G,H,I){var C={};for(var D in G){var A=G[D],E=H[D],F=C[D]={};for(var B in A){F[B]=this.parent(A[B],E[B],I);}}return C;},set:function(B){for(var C in B){var A=B[C];for(var D in A){this.render(this.elements[C],D,A[D],this.options.unit);}}return this;},start:function(C){if(!this.check(arguments.callee,C)){return this;}var H={},I={};for(var D in C){var F=C[D],A=H[D]={},G=I[D]={};for(var B in F){var E=this.prepare(this.elements[D],B,F[B]);A[B]=E.from;G[B]=E.to;}}return this.parent(H,I);}});var Tips=new Class({Implements:[Events,Options],options:{onShow:function(A){A.setStyle("visibility","visible");},onHide:function(A){A.setStyle("visibility","hidden");},showDelay:100,hideDelay:100,className:null,offsets:{x:16,y:16},fixed:false},initialize:function(){var C=Array.link(arguments,{options:Object.type,elements:$defined});this.setOptions(C.options||null);this.tip=new Element("div").inject(document.body);if(this.options.className){this.tip.addClass(this.options.className);}var B=new Element("div",{"class":"tip-top"}).inject(this.tip);this.container=new Element("div",{"class":"tip"}).inject(this.tip);var A=new Element("div",{"class":"tip-bottom"}).inject(this.tip);this.tip.setStyles({position:"absolute",top:0,left:0,visibility:"hidden"});if(C.elements){this.attach(C.elements);}},attach:function(A){$$(A).each(function(D){var G=D.retrieve("tip:title",D.get("title"));var F=D.retrieve("tip:text",D.get("rel")||D.get("href"));var E=D.retrieve("tip:enter",this.elementEnter.bindWithEvent(this,D));var C=D.retrieve("tip:leave",this.elementLeave.bindWithEvent(this,D));D.addEvents({mouseenter:E,mouseleave:C});if(!this.options.fixed){var B=D.retrieve("tip:move",this.elementMove.bindWithEvent(this,D));D.addEvent("mousemove",B);}D.store("tip:native",D.get("title"));D.erase("title");},this);return this;},detach:function(A){$$(A).each(function(C){C.removeEvent("mouseenter",C.retrieve("tip:enter")||$empty);C.removeEvent("mouseleave",C.retrieve("tip:leave")||$empty);C.removeEvent("mousemove",C.retrieve("tip:move")||$empty);C.eliminate("tip:enter").eliminate("tip:leave").eliminate("tip:move");var B=C.retrieve("tip:native");if(B){C.set("title",B);}});return this;},elementEnter:function(B,A){$A(this.container.childNodes).each(Element.dispose);var D=A.retrieve("tip:title");if(D){this.titleElement=new Element("div",{"class":"tip-title"}).inject(this.container);this.fill(this.titleElement,D);}var C=A.retrieve("tip:text");if(C){this.textElement=new Element("div",{"class":"tip-text"}).inject(this.container);this.fill(this.textElement,C);}this.timer=$clear(this.timer);this.timer=this.show.delay(this.options.showDelay,this);this.position((!this.options.fixed)?B:{page:A.getPosition()});},elementLeave:function(A){$clear(this.timer);this.timer=this.hide.delay(this.options.hideDelay,this);},elementMove:function(A){this.position(A);},position:function(D){var B=window.getSize(),A=window.getScroll();var E={x:this.tip.offsetWidth,y:this.tip.offsetHeight};var C={x:"left",y:"top"};for(var F in C){var G=D.page[F]+this.options.offsets[F];if((G+E[F]-A[F])>B[F]){G=D.page[F]-this.options.offsets[F]-E[F];}this.tip.setStyle(C[F],G);}},fill:function(A,B){(typeof B=="string")?A.set("html",B):A.adopt(B);},show:function(){this.fireEvent("show",this.tip);},hide:function(){this.fireEvent("hide",this.tip);}});(function(){if(window.google&&google.gears){return;}
var factory=null;if(typeof GearsFactory!='undefined'){factory=new GearsFactory();}else{try{factory=new ActiveXObject('Gears.Factory');if(factory.getBuildInfo().indexOf('ie_mobile')!=-1){factory.privateSetGlobalObject(this);}}catch(e){if((typeof navigator.mimeTypes!='undefined')&&navigator.mimeTypes["application/x-googlegears"]){factory=document.createElement("object");factory.style.display="none";factory.width=0;factory.height=0;factory.type="application/x-googlegears";document.documentElement.appendChild(factory);}}}
if(!factory){return;}
if(!window.google){google={};}
if(!google.gears){google.gears={factory:factory};}})();var JazzRecord={each:function(E,C,F){switch(JazzRecord.getType(E)){case"array":for(var B=0,A=E.length;B<A;B++){C.call(F,E[B],B)}break;case"object":for(var D in E){if(E.hasOwnProperty(D)){C.call(F,E[D],D)}}break}},isDefined:function(A){return!(typeof A==="undefined"||A===null)},getType:function(A){if(typeof A==="undefined"||A===null||(typeof A==="number"&&isNaN(A))){return false}else{if(A.constructor===Array){return"array"}else{return typeof A}}},debug:false,puts:function(A){if(JazzRecord.debug===false){return}if(typeof console!=="undefined"&&console.log){switch(JazzRecord.getType(A)){case"object":console.dir(A);break;default:console.log(A)}}if(typeof air!=="undefined"){if(air.Introspector&&air.Introspector.Console){switch(JazzRecord.getType(A)){case"string":air.Introspector.Console.log(A);break;case"object":air.Introspector.Console.dump(A);break}}else{air.trace(A)}}},merge:function(){var F={};for(var C=0,A=arguments.length;C<A;C++){var B=arguments[C];if(JazzRecord.getType(B)!=="object"){continue}for(var G in B){var E=B[G],D=F[G];if(D&&JazzRecord.getType(E)==="object"&&JazzRecord.getType(D)==="object"){F[G]=JazzRecord.merge(D,E)}else{F[G]=E}}}return F},shallowMerge:function(C,A){for(var B in A){C[B]=A[B]}return C},setOptions:function(A,C){if(!A){A={}}if(!this.options){this.options={}}mergedOptions=JazzRecord.merge(C,A);for(var B in C){this.options[B]=mergedOptions[B]}},replaceAndClean:function(B,A){for(opt in A){B=B.replace("{"+opt+"}",A[opt])}B=B.replace(/{\w+}/g,"");return B.replace(/\s+/g," ").replace(/^\s+|\s+$/g,"")},extend:function(C,A){if(!this.options){this.options={}}this.parent=new C(A);for(var D in this.parent){this[D]=this[D]||this.parent[D]}for(var B in this.parent.options){this.options[B]=this.options[B]||this.parent.options[B]}},indexOf:function(A,E){var C=-1;if(A.indexOf){C=A.indexOf(E)}else{for(var D=0,B=A.length;D<B;D++){if(A[D]===E){C=D;break}}}return C},arrayContainsVal:function(A,B){if(JazzRecord.indexOf(A,B)>-1){return true}else{return false}},removeFromArray:function(A,C){var B=JazzRecord.indexOf(A,C);A.splice(B,1)}};JazzRecord.Hash=function(A){this.data=A||{}};JazzRecord.Hash.toQueryString=function(B){var A=[];JazzRecord.each(this.data,function(E,D){if(B){D=B+"["+D+"]"}var C;switch(JazzRecord.getType(E)){case"object":C=JazzRecord.Hash.toQueryString(E,D);break;case"array":var F={};JazzRecord.each(E,function(G,H){F[H]=G});C=JazzRecord.Hash.toQueryString(F,D);break;default:C=D+"="+encodeURIComponent(E)}if(E){A.push(C)}});return A.join("&")};JazzRecord.Hash.prototype={has:function(A){if(this.data.hasOwnProperty(A)){return true}else{return false}},set:function(A,B){this.data[A]=B},get:function(A){return this.data[A]},getLength:function(){var A=0;for(i in this.data){if(this.data.hasOwnProperty(i)){A++}}return A},each:function(A,B){JazzRecord.each(this.data,A,B)},toQueryString:JazzRecord.Hash.toQueryString,getValues:function(){var A=[];this.each(function(B){A.push(B)});return A},getKeys:function(){var A=[];this.each(function(C,B){A.push(B)});return A}};JazzRecord.models=new JazzRecord.Hash();JazzRecord.depth=1;JazzRecord.run=function(A){return JazzRecord.adapter.run(A)};JazzRecord.count=function(A){return JazzRecord.adapter.count(A)};JazzRecord.save=function(A){return JazzRecord.adapter.save(A)};JazzRecord.runTransaction=function(A,C){JazzRecord.run("BEGIN");try{A.apply(C||this)}catch(B){JazzRecord.run("ROLLBACK");throw(B)}JazzRecord.run("END")};JazzRecord.Adapter=function(){this.run=this.count=this.save=function(A){JazzRecord.puts(A)}};JazzRecord.AirAdapter=function(A){var B={dbFile:"jazz_record.db"};JazzRecord.setOptions.call(this,A,B);JazzRecord.extend.call(this,JazzRecord.Adapter);this.connection=new air.SQLConnection();this.dbFile=air.File.applicationDirectory.resolvePath(this.options.dbFile);this.connection.open(this.dbFile,air.SQLMode.CREATE);this.statement=new air.SQLStatement();this.statement.sqlConnection=this.connection};JazzRecord.AirAdapter.prototype={run:function(B){this.parent.run(B);this.statement.text=B;this.statement.execute();var A=this.statement.getResult();return A.data},count:function(A){this.parent.count(A);A=A.toUpperCase();return this.run(A)[0]["COUNT(*)"]},save:function(A){this.parent.save(A);this.statement.text=A;this.statement.execute();return this.statement.getResult().lastInsertRowID}};JazzRecord.GearsAdapter=function(A){var B={dbFile:"jazz_record.db"};JazzRecord.setOptions.call(this,A,B);JazzRecord.extend.call(this,JazzRecord.Adapter);this.db=google.gears.factory.create("beta.database");this.db.open(this.options.dbFile);this.result=null};JazzRecord.GearsAdapter.prototype={run:function(D){this.parent.run(D);this.result=this.db.execute(D);var C=[];while(this.result.isValidRow()){var F={};for(var B=0,A=this.result.fieldCount();B<A;B++){var E=this.result.fieldName(B);F[E]=this.result.field(B)}C.push(F);this.result.next()}this.result.close();return C},count:function(B){this.parent.count(B);this.result=this.db.execute(B);var A=this.result.field(0);this.result.close();return A},save:function(A){this.parent.save(A);this.db.execute(A);return this.db.lastInsertRowId}};JazzRecord.TitaniumAdapter=function(A){JazzRecord.extend.call(this,JazzRecord.GearsAdapter,A);this.db=new ti.Database;this.db.open(this.options.dbFile);this.result=null};JazzRecord.Record=function(A){var B={model:null,columns:{},data:{},onCreate:function(){},onUpdate:function(){},onSave:function(){},onDestroy:function(){}};this.id=null;JazzRecord.setOptions.call(this,A,B);this.errors={};this.onCreate=this.options.onCreate;this.onUpdate=this.options.onUpdate;this.onSave=this.options.onSave;this.onDestroy=this.options.onDestroy;if(this.options.data.id){this.id=this.options.data.id;this.originalData={};this.isNew=function(){return false}}else{this.isNew=function(){return true}}JazzRecord.each(this.options.columns,function(D,C){this[C]=null;this[C]=this.options.data[C];if(this.originalData){this.originalData[C]=this.options.data[C]}if(D==="bool"){var E=(this[C]?true:false);if(this.originalData){this.originalData[C]=E}this[C]=E}},this);JazzRecord.each(this.options.model.options.recordMethods,function(D,C){this[C]=D},this)};JazzRecord.Record.prototype={destroy:function(){if(!this.id){throw("Unsaved record cannot be destroyed")}else{this.options.model.destroy(this.id);JazzRecord.each(this.options.model.options.hasMany,function(B,A){this.load(A);JazzRecord.each(this[A],function(C){C.updateAttribute(this.options.model.options.foreignKey,null)},this);this[A+"OriginalRecordIDs"]=[]},this);JazzRecord.each(this.options.model.options.hasAndBelongsToMany,function(C,B){var A=[this.options.model.table,C].sort().join("_");sql="DELETE FROM "+A+" WHERE "+this.options.model.options.foreignKey+"="+this.id+";";JazzRecord.adapter.run(sql)},this);JazzRecord.each(this.options.model.options.hasOne,function(B,A){this.load(A);if(!this[A]){return}this[A].updateAttribute(this.options.model.options.foreignKey,null);this[A+"OriginalRecordID"]=null},this);this.onDestroy();this.id=null;this.originalData=null;this.isNew=function(){return true}}},getData:function(){var A={};JazzRecord.each(this.options.columns,function(C,B){A[B]=this[B]},this);return A},revert:function(){JazzRecord.each(this.options.columns,function(B,A){this[A]=this.originalData[A]},this);JazzRecord.each(this.options.model.options.belongsTo,function(D,C){var B=JazzRecord.models.get(D);var A=B.options.foreignKey;if(this[C]&&!this[C].unloaded&&this[C].id!==this[A]){this[C]=B.find({id:this[A],depth:0})}},this)},reload:function(){if(!this.id){throw("Unsaved record cannot be reloaded")}else{var A=this.options.model.find(this.id);JazzRecord.shallowMerge(this,A)}},load:function(A,C){if(!C){C=0}if(this[A]&&this[A].unloaded){this[A]=this[A].loader(C);if(JazzRecord.getType(this[A])==="array"){var B=[];JazzRecord.each(this[A],function(D){B.push(D.id)});this[A+"OriginalRecordIDs"]=B}else{if(this[A]&&this[A].id){this[A+"OriginalRecordID"]=this[A].id}}}return this[A]},updateAttribute:function(A,B){this[A]=B;this.save()}};JazzRecord.Record.prototype.isChanged=function(){if(!this.id){return false}JazzRecord.each(this.options.model.options.belongsTo,function(F,E){var D=JazzRecord.models.get(F);var C=D.options.foreignKey;if(!this.originalData){return false}if(this[E]){if(this[E].unloaded){if(this[C]!==this.originalData[C]){return true}}else{if(this[E].isNew()){this[E].save()}if(this[E].id!==this.originalData[C]){this[C]=this[E].id;return true}if(this[C]!==this.originalData[C]){return true}}}else{if(this.originalData[C]){this[C]=null;return true}}},this);var B=new JazzRecord.Hash(this.getData());var A=new JazzRecord.Hash(this.originalData);if(this.id&&B.toQueryString()===A.toQueryString()){return false}else{return true}};JazzRecord.Record.prototype.save=function(){var A=this.options.model.options.foreignKey;if(!this.originalData){JazzRecord.each(this.options.model.options.belongsTo,function(F,E){var C=JazzRecord.models.get(F);var D=C.options.foreignKey;if(this[E]){if(this[E].unloaded){this.load(E)}}if(this[E]&&this[E].id){this[D]=this[E].id}},this)}JazzRecord.each(this.options.model.options.hasOne,function(F,E){if(this[E]){if(this[E].unloaded){this.load(E);if(!this[E]){return}}if(!JazzRecord.isDefined(this[E+"OriginalRecordID"])){this[E].updateAttribute(A,this.id)}else{if(this[E+"OriginalRecordID"]!==this[E].id){var D=JazzRecord.models.get(F);var C=D.first({id:this[E+"OriginalRecordID"],depth:0});C.updateAttribute(A,null);this[E].updateAttribute(A,this.id)}}this[E+"OriginalRecordID"]=this[E].id}else{if(this[E+"OriginalRecordID"]){var D=JazzRecord.models.get(F);var C=D.first({id:this[E+"OriginalRecordID"],depth:0});C.updateAttribute(A,null)}}},this);JazzRecord.each(this.options.model.options.hasMany,function(G,F){if(this[F]){if(this[F].length){var D=JazzRecord.models.get(G);var C=this[F+"OriginalRecordIDs"];JazzRecord.each(this[F],function(H,I){if(H){H[A]=this.id;H.save();if(JazzRecord.arrayContainsVal(C,H.id)){JazzRecord.removeFromArray(C,H.id)}}},this);JazzRecord.each(this[F],function(H,I){if(!JazzRecord.isDefined(H)){this[F].splice(I,1)}},this);JazzRecord.each(C,function(I){var H=D.find(I);if(H){H.updateAttribute(A,null)}});var E=[];JazzRecord.each(this[F],function(H){if(H){E.push(H.id)}});this[F+"OriginalRecordIDs"]=E}}else{this[F]=[];this[F+"OriginalRecordIDs"]=[]}},this);JazzRecord.each(this.options.model.options.hasAndBelongsToMany,function(I,H){if(this[H]){if(this[H].length){var C=[this.options.model.table,I].sort().join("_");var G=JazzRecord.models.get(I).options.foreignKey;var F="";var D=this[H+"OriginalRecordIDs"];JazzRecord.each(this[H],function(J){J.save();if(JazzRecord.arrayContainsVal(D,J.id)){JazzRecord.removeFromArray(D,J.id)}else{F="INSERT INTO "+C+" ("+A+", "+G+") VALUES("+this.id+", "+J.id+")";JazzRecord.adapter.run(F)}},this);JazzRecord.each(D,function(J){F="DELETE FROM "+C+" WHERE "+A+"="+this.id+" AND "+G+"="+J+";";JazzRecord.adapter.run(F)},this);var E=[];JazzRecord.each(this[H],function(J){E.push(J.id)});this[H+"OriginalRecordIDs"]=E}}else{this[H]=[];this[H+"OriginalRecordIDs"]=[]}},this);this.errors={};if(this.isNew()){if(this.isValid("create")){this.onCreate()}}else{if(this.isValid("update")&&this.isChanged()){this.onUpdate()}}if(this.isValid("save")){var B=this.getData();if(this.isChanged()){this.onSave();B.originalData=this.originalData?this.originalData:{id:this.id};this.options.model.save(B);this.reload()}else{if(this.isNew()){this.onSave();this.id=this.options.model.save(B)}}this.originalData={};JazzRecord.each(this.options.model.options.columns,function(D,C){this.originalData[C]=this[C]},this);this.isNew=function(){return false};return true}return false};JazzRecord.Model=function(A){var B={table:"",columns:{},foreignKey:"",hasOne:{},belongsTo:{},hasMany:{},hasAndBelongsToMany:{},events:{},modelMethods:{},recordMethods:{},validate:{atCreate:function(){},atUpdate:function(){},atSave:function(){}}};JazzRecord.setOptions.call(this,A,B);this.table=this.options.table;this.sql="";JazzRecord.each(this.options.modelMethods,function(D,C){this[C]=D},this);if(!JazzRecord.models.has(this.table)){JazzRecord.models.set(this.table,this)}};JazzRecord.Model.prototype={newRecord:function(B){if(!B){B={}}var C={};JazzRecord.each(this.options.columns,function(E,D){C[D]=B[D]||null});var A={model:this,columns:this.options.columns,data:C};JazzRecord.each(this.options.events,function(E,D){A[D]=E});return new JazzRecord.Record(A)},create:function(B){var A=this.newRecord(B);A.save();return A}};JazzRecord.AssociationLoader=function(A){this.loader=A;this.unloaded=true};JazzRecord.AssociationLoader.prototype={toString:function(){return"Not yet loaded"}};JazzRecord.columnNames=function(B){var A="(";JazzRecord.each(B,function(D,C){A+=C+", "});A=A.substr(0,A.length-2);return A+")"};JazzRecord.columnValues=function(C,B){var A=" VALUES(";JazzRecord.each(C,function(E,D){A+=JazzRecord.typeValue(C,D,B[D])+", "},this);A=A.substr(0,A.length-2);return A+")"};JazzRecord.typeValue=function(B,A,C){if(C===null){return"NULL"}else{switch(B[A]){case"string":case"text":return"'"+C+"'";case"int":C=parseInt(C,10);return JazzRecord.getType(C)==="number"?C:0;case"number":case"float":C=parseFloat(C);return JazzRecord.getType(C)==="number"?C:0;case"bool":if(C){return 1}else{return 0}}}};JazzRecord.Record.prototype.validatesAtCreate=function(){this.options.model.options.validate.atCreate.apply(this)};JazzRecord.Record.prototype.validatesAtUpdate=function(){this.options.model.options.validate.atUpdate.apply(this)};JazzRecord.Record.prototype.validatesAtSave=function(){this.options.model.options.validate.atSave.apply(this)};JazzRecord.Record.prototype.isValid=function(A){switch(A){case"create":this.validatesAtCreate();break;case"update":this.validatesAtUpdate();break;case"save":this.validatesAtSave();break;default:this.errors={};if(this.id){this.validatesAtUpdate();this.validatesAtSave()}else{this.validatesAtCreate();this.validatesAtSave()}}var B=0;for(prop in this.errors){B++}if(B===0){return true}else{return false}};JazzRecord.Record.prototype.pushError=function(A,B){if(!this.errors[A]){this.errors[A]=[]}this.errors[A].push(B)};JazzRecord.Record.prototype.validatesAcceptanceOf=function(A,B){var C=this[A];if(C&&JazzRecord.isDefined(C)&&JazzRecord.getType(C)==="boolean"){return}B=JazzRecord.isDefined(B)?B:(A+" must be accepted");this.pushError(A,B)};JazzRecord.Record.prototype.validatesConfirmationOf=function(A,B){var C=this[A];var D=this[A+"_confirmation"];if(C!==D||!JazzRecord.isDefined(D)||D==""){B=JazzRecord.isDefined(B)?B:A+" doesn't match confirmation";this.pushError(A,B)}};JazzRecord.Record.prototype.validatesExclusionOf=function(A,C,B){if(this[A]&&JazzRecord.indexOf(C,this[A])>-1){B=JazzRecord.isDefined(B)?B:(A+" is reserved");this.pushError(A,B)}};JazzRecord.Record.prototype.validatesInclusionOf=function(A,C,B){if(this[A]&&!(JazzRecord.indexOf(C,this[A])>-1)){B=JazzRecord.isDefined(B)?B:(A+" is not included in the list");this.pushError(A,B)}};JazzRecord.Record.prototype.validatesFormatOf=function(A,C,B){val=this[A];if(!val.match(C)){B=JazzRecord.isDefined(B)?B:(A+" does not match expected format: "+C.toString());this.pushError(A,B)}};JazzRecord.Record.prototype.validatesLengthOf=function(C,B,D){var A={minimum:0,maximum:Infinity,allowEmpty:true,tooShort:C+" is too short",tooLong:C+" is too long",wrongLength:C+" is not the correct length"};B=JazzRecord.shallowMerge(A,B);if(!JazzRecord.isDefined(this[C])||this[C]&&this[C].length&&this[C].length>=B.minimum&&this[C].length<=B.maximum){if(!JazzRecord.isDefined(B.is)||(B.is&&this[C].length===B.is)){return}}if(this[C].length<B.minimum){this.pushError(C,B.tooShort)}if(this[C].length>B.maximum){this.pushError(C,B.tooLong)}if(B.is&&this[C].length!==B.is){this.pushError(C,B.wrongLength)}};JazzRecord.Record.prototype.validatesNumericalityOf=function(A,B){var C=this[A];if(C&&JazzRecord.isDefined(C)&&JazzRecord.getType(C)!=="number"){B=JazzRecord.isDefined(B)?B:(A+" is not a number");this.pushError(A,B)}};JazzRecord.Record.prototype.validatesPresenceOf=function(A,B){var C=this[A];if(!JazzRecord.isDefined(C)||C===""){B=JazzRecord.isDefined(B)?B:(A+" can't be empty, null or blank");this.pushError(A,B)}};JazzRecord.Record.prototype.validatesUniquenessOf=function(B,C){var D=this[B];var A=this.id?1:0;if(this.options.model.findAllBy(B,D,0).length>A){C=JazzRecord.isDefined(C)?C:(B+" is not unique");this.pushError(B,C)}};JazzRecord.Record.prototype.validatesAssociated=function(C,B){if(!JazzRecord.isDefined(this[C])||(this[C]&&this[C].unloaded)){return}var A=[];if(JazzRecord.getType(this[C])==="array"){A=this[C]}else{A=[this[C]]}JazzRecord.each(A,function(D){if(D&&!D.isValid()){B=JazzRecord.isDefined(B)?B:C+" is not valid";this.pushError(C,B);return}},this)};JazzRecord.Record.prototype.validatesIsString=function(A,B){var C=this[A];if(JazzRecord.getType(C)&&JazzRecord.getType(C)!=="string"){B=JazzRecord.isDefined(B)?B:(A+" is not a string");this.pushError(A,B)}};JazzRecord.Record.prototype.validatesIsBool=function(A,B){var C=this[A];if(JazzRecord.getType(C)&&JazzRecord.getType(C)!=="boolean"){B=JazzRecord.isDefined(B)?B:(A+" is not a bool");this.pushError(A,B)}};JazzRecord.Record.prototype.validatesIsInt=function(A,B){var C=this[A];if(JazzRecord.getType(C)){if(JazzRecord.getType(C)!=="number"||parseInt(C,10)!==C){B=JazzRecord.isDefined(B)?B:(A+" is not an integer");this.pushError(A,B)}}};JazzRecord.Record.prototype.validatesIsFloat=function(A,B){var C=this[A];if(JazzRecord.getType(C)){if(JazzRecord.getType(C)!=="number"||parseFloat(C)!==C){B=JazzRecord.isDefined(B)?B:(A+" is not an float");this.pushError(A,B)}}};JazzRecord.Model.prototype.query=function(C){if(!JazzRecord.isDefined(C)){C={}}if(!JazzRecord.isDefined(C.depth)){C.depth=JazzRecord.depth}var E=C.depth-1;if(E<0){E=0}var A=this.sql;var D=JazzRecord.adapter.run(A);if(!D||D.length===0){if(this.sql.indexOf("LIMIT")>-1){return null}else{return[]}}var B=[];JazzRecord.each(D,function(H){var G={model:this,columns:this.options.columns,data:H};JazzRecord.each(this.options.events,function(J,I){G[I]=J});var F=new JazzRecord.Record(G);JazzRecord.each(this.options.hasOne,function(M,L){var K=JazzRecord.models.get(M);var I=this.options.foreignKey;var J=function(N){return K.findBy(I,H.id,N)};if(C.depth<1){F[L]=new JazzRecord.AssociationLoader(J)}else{F[L]=J(E);if(F[L]){F[L+"OriginalRecordID"]=F[L].id}}},this);JazzRecord.each(this.options.hasMany,function(N,M){var J=JazzRecord.models.get(N);var I=this.options.foreignKey;var L=function(O){return J.findAllBy(I,H.id,O)};if(C.depth<1){F[M]=new JazzRecord.AssociationLoader(L)}else{F[M]=L(E);var K=[];JazzRecord.each(F[M],function(O){K.push(O.id)});F[M+"OriginalRecordIDs"]=K}},this);JazzRecord.each(this.options.belongsTo,function(L,K){var J=JazzRecord.models.get(L);var I=J.options.foreignKey;if(F[I]){var M=function(N){return J.first({id:F[I],depth:N})};if(C.depth<1){F[K]=new JazzRecord.AssociationLoader(M)}else{F[K]=M(E)}}else{F[K]=null}});JazzRecord.each(this.options.hasAndBelongsToMany,function(P,O){var K=this;var I=[this.table,P].sort().toString().replace(",","_");var L=JazzRecord.models.get(P);var J=L.options.foreignKey;if(J){var N=function(T){var S="SELECT * FROM "+I+" WHERE "+K.options.foreignKey+"="+F.id;var R=JazzRecord.adapter.run(S);var Q=[];JazzRecord.each(R,function(U){Q.push(L.first({id:U[J],depth:T}))},K);return Q};if(C.depth<1){F[O]=new JazzRecord.AssociationLoader(N)}else{F[O]=N(E);var M=[];JazzRecord.each(F[O],function(Q){M.push(Q.id)});F[O+"OriginalRecordIDs"]=M}}},this);B.push(F)},this);if(A.indexOf("LIMIT 1")>-1){return B[0]}else{return B}};JazzRecord.save=function(D,E,B){this.sql="{saveMode} {table} {set} {data} {conditions}";var A={saveMode:"INSERT INTO",table:D,data:JazzRecord.columnNames(E)+JazzRecord.columnValues(E,B)};var C={};if(B.originalData){C.saveMode="UPDATE";C.set="SET";C.conditions="WHERE id="+B.originalData.id;C.data="";JazzRecord.each(E,function(G,F){C.data+=F+"="+JazzRecord.typeValue(E,F,B[F])+", "},this);C.data=C.data.slice(0,-2)}C=JazzRecord.shallowMerge(A,C);this.sql=JazzRecord.replaceAndClean(this.sql,C);return JazzRecord.adapter.save(this.sql)};JazzRecord.Model.prototype.save=function(A){return JazzRecord.save(this.table,this.options.columns,A)};JazzRecord.Model.prototype.destroy=function(B){var A="";if(JazzRecord.getType(B)==="number"){A="WHERE id="+B}else{if(JazzRecord.getType(B)==="array"){A="WHERE id IN ("+B+")"}}this.sql="DELETE FROM "+this.table+" "+A;this.query()};JazzRecord.Model.prototype.destroyAll=function(){this.sql="DELETE FROM "+this.table;this.query()};JazzRecord.Model.prototype.dropTable=function(){this.sql="DROP TABLE IF EXISTS "+this.table;this.query()};JazzRecord.Model.prototype.find=function(A){if(!JazzRecord.isDefined(A)){throw("Missing ID or Options")}else{switch(JazzRecord.getType(A)){case"array":A={id:A};break;case"number":A={id:A,limit:1};break;case"object":break;default:throw("Type Error. Model.find() expects Number, Array or Object")}}return this.select(A)};JazzRecord.Model.prototype.findBy=function(B,A,C){if(!this.options.columns[B]){throw("Column "+B+" Does Not Exist in Table "+this.table)}else{return this.select({conditions:B+"="+JazzRecord.typeValue(this.options.columns,B,A),limit:1,depth:C})}};JazzRecord.Model.prototype.findAllBy=function(B,A,C){if(!this.options.columns[B]){throw("Column "+B+" Does Not Exist in Table "+this.table)}else{return this.select({conditions:B+"="+JazzRecord.typeValue(this.options.columns,B,A),depth:C})}};JazzRecord.Model.prototype.all=function(A){return this.select(A)};JazzRecord.Model.prototype.first=function(A){A=JazzRecord.shallowMerge({limit:1},A);return this.select(A)};JazzRecord.Model.prototype.last=function(A){A=JazzRecord.shallowMerge({limit:1,order:"id"},A);A.order+=" DESC";return this.select(A)};JazzRecord.Model.prototype.count=function(A){this.sql="SELECT COUNT(*) FROM "+this.table;if(A){this.sql+=" WHERE "+A}return JazzRecord.adapter.count(this.sql)};JazzRecord.Model.prototype.select=function(B){if(!B){B={}}this.sql="SELECT {select} FROM "+this.table+" {conditions} {group} {order} {limit} {offset}";var A={select:"*"};B=JazzRecord.shallowMerge(A,B);if(!B.select=="*"&&!B.select.contains("id")){B.select="id, "+B.select}if(B.order){B.order="ORDER BY "+B.order}if(JazzRecord.getType(B.limit)=="number"){B.limit="LIMIT "+B.limit}if(JazzRecord.getType(B.offset)=="number"){B.offset="OFFSET "+B.offset}if(B.group){B.group="GROUP BY "+B.group}if(B.conditions){B.conditions="WHERE "+B.conditions;if(B.id){B.conditions+=" AND id="+B.id}}else{if(B.id){if(JazzRecord.getType(B.id)=="number"){B.conditions="WHERE id="+B.id;B.limit="LIMIT 1"}else{if(JazzRecord.getType(B.id)=="array"){B.conditions="WHERE id IN ("+B.id+")"}}}}this.sql=JazzRecord.replaceAndClean(this.sql,B);return this.query(B)};JazzRecord.schema=new JazzRecord.Model({table:"schema_definitions",columns:{id:"number",table_name:"text",column_names:"text",column_types:"text"}});JazzRecord.setupSchema=function(A){JazzRecord.createTable("schema_migrations",{version:"text"});if(JazzRecord.count("SELECT COUNT(*) FROM schema_migrations")===0){var B="INSERT INTO schema_migrations (version) VALUES(0)";JazzRecord.run(B)}if(A&&JazzRecord.count("SELECT COUNT(*) FROM schema_migrations")===1){var B="UPDATE schema_migrations set version = 0";JazzRecord.run(B)}JazzRecord.createTable("schema_definitions",{id:"number",table_name:"text",column_names:"text",column_types:"text"})};JazzRecord.writeSchema=function(A,G){if(A==="schema_definitions"||A==="schema_migrations"){return}var H="";var E=new JazzRecord.Hash(G);var F=E.getKeys().join();var C=E.getValues().join();var D=JazzRecord.schema.findBy("table_name",A);if(D){D.column_names=F;D.column_types=C;D.save()}else{JazzRecord.schema.create({table_name:A,column_names:F,column_types:C})}var B=JazzRecord.models.get(A);if(B){B.options.columns={};JazzRecord.each(G,function(J,I){B.options.columns[I]=J})}};JazzRecord.readSchema=function(B){if(B==="schema_definitions"||B==="schema_migrations"){return}var C=JazzRecord.schema.findBy("table_name",B);var A=C.column_names.split(",");var E=C.column_types.split(",");var D={};JazzRecord.each(A,function(F,G){D[F]=E[G]});return D};JazzRecord.currentSchemaVersion=function(){var A="SELECT version FROM schema_migrations LIMIT 1";return parseInt(JazzRecord.run(A)[0].version,10)};JazzRecord.updateSchemaVersion=function(A){var B="UPDATE schema_migrations SET version = "+A;JazzRecord.run(B)};JazzRecord.modifyColumn=function(B,A,C){if(!C){throw("MIGRATION_EXCEPTION: Not a valid column modification")}var E=JazzRecord.readSchema(B);var D={};JazzRecord.each(E,function(G,F){switch(C.modification){case"remove":if(F!==A){D[F]=G}break;case"rename":if(F!==A){D[F]=G}else{D[C.newName]=G}break;case"change":if(F!==A){D[F]=G}else{D[F]=C.newType}break;default:throw("MIGRATION_EXCEPTION: Not a valid column modification")}});JazzRecord.runTransaction(function(){var F=JazzRecord.run("SELECT * FROM "+B);JazzRecord.dropTable(B);JazzRecord.createTable(B,D);JazzRecord.each(F,function(G){switch(C.modification){case"remove":delete G[A];JazzRecord.save(B,D,G);break;case"rename":G[C.newName]=G[A];delete G[A];JazzRecord.save(B,D,G);break;case"change":JazzRecord.save(B,D,G);break;default:throw("MIGRATION_EXCEPTION: Not a valid column modification")}})})};JazzRecord.createTable=function(A,B){if(!(JazzRecord.isDefined(A)&&JazzRecord.isDefined(B))){return}var C="CREATE TABLE IF NOT EXISTS "+A;if(B){C+="(";JazzRecord.each(B,function(E,D){if(D==="id"){C+="id INTEGER PRIMARY KEY AUTOINCREMENT, "}else{C+=(D+" "+E.toString().toUpperCase()+", ")}});C=C.substr(0,C.length-2);C+=")";JazzRecord.run(C)}JazzRecord.writeSchema(A,B)};JazzRecord.dropTable=function(A){var C="DROP TABLE "+A;JazzRecord.run(C);var B=JazzRecord.schema.findBy("table_name",A);B.destroy()};JazzRecord.renameTable=function(B,A){var D="ALTER TABLE "+B+" RENAME TO "+A;JazzRecord.run(D);var C=JazzRecord.schema.findBy("table_name",B);C.updateAttribute("table_name",A)};JazzRecord.addColumn=function(C,B,A){var E="ALTER TABLE "+C+" ADD COLUMN "+B+" "+A.toUpperCase();JazzRecord.run(E);var D=JazzRecord.readSchema(C);D[B]=A;JazzRecord.writeSchema(C,D)};JazzRecord.removeColumn=function(B,A){JazzRecord.modifyColumn(B,A,{modification:"remove"})};JazzRecord.renameColumn=function(B,A,D){var C={modification:"rename",newName:D};JazzRecord.modifyColumn(B,A,C)};JazzRecord.changeColumn=function(B,A,D){var C={modification:"change",newType:D};JazzRecord.modifyColumn(B,A,C)};JazzRecord.migrate=function(C){if(JazzRecord.getType(C)==="object"){if(C.refresh){this.models.each(function(F){F.dropTable();JazzRecord.each(F.options.hasAndBelongsToMany,function(I){var G=[F.table,I].sort().toString().replace(",","_");var H="DROP TABLE IF EXISTS "+G;JazzRecord.run(H)})});JazzRecord.setupSchema(true)}}var E={};if(JazzRecord.migrations){E=JazzRecord.migrations}if(E[1]&&JazzRecord.getType(E[1])==="object"){JazzRecord.setupSchema();var B=JazzRecord.currentSchemaVersion();var A=Infinity;if(JazzRecord.getType(C)==="object"&&JazzRecord.isDefined(C.number)){A=C.number}else{if(JazzRecord.getType(C)==="number"){A=C}}var D=B;do{if(D===A){JazzRecord.puts("Up to date");return}else{if(D<A){D+=1;if(JazzRecord.isDefined(E[D])){E[D].up()}else{break}}else{E[D].down();D-=1}}JazzRecord.updateSchemaVersion(D)}while(E[D])}else{JazzRecord.models.each(function(F){var G="CREATE TABLE IF NOT EXISTS "+F.table+"(id INTEGER PRIMARY KEY AUTOINCREMENT";JazzRecord.each(F.options.columns,function(I,H){if(H!=="id"){G+=(", "+H+" "+I.toUpperCase())}});G+=")";JazzRecord.run(G);JazzRecord.each(F.options.hasAndBelongsToMany,function(N,I){var H=[F.table,N].sort().toString().replace(",","_");var J=F.options.foreignKey;var K=JazzRecord.models.get(N).options.foreignKey;var L=[J,K].sort();var M="CREATE TABLE IF NOT EXISTS "+H+"("+L[0]+" INTEGER, "+L[1]+" INTEGER)";JazzRecord.run(M)})})}if(C&&C.refresh&&JazzRecord.fixtures){JazzRecord.loadFixtures()}};JazzRecord.loadFixtures=function(){var A=JazzRecord.fixtures;JazzRecord.each(A.tables,function(C,B){JazzRecord.each(C,function(D){JazzRecord.models.get(B).create(D)})});if(!A.mappingTables){return}JazzRecord.each(A.mappingTables,function(C,B){JazzRecord.each(C,function(F){var D=new JazzRecord.Hash(F);var E="INSERT INTO "+B+" ("+D.getKeys().toString()+") VALUES("+D.getValues().toString()+")";JazzRecord.run(E)})})};JazzRecordOrg={initDemo:function(){JazzLegend=new JazzRecord.Model({table:"jazz_legends",foreignKey:"jazz_legend_id",hasMany:{albums:"albums"},columns:{id:"number",name:"text",primary_instrument:"text",years_active:"text"}});Album=new JazzRecord.Model({table:"albums",belongsTo:{artist:"jazz_legends"},columns:{id:"number",title:"text",year:"text",jazz_legend_id:"number"}});var legendaryData={tables:{jazz_legends:[{name:"Louis Armstrong",primary_instrument:"trumpet",years_active:"1914-1971"},{name:"Dizzy Gillespie",primary_instrument:"trumpet",years_active:"1935-1993"},{name:"Miles Davis",primary_instrument:"trumpet",years_active:"1944-1991"},{name:"Count Basie",primary_instrument:"piano",years_active:"1924-1984"},{name:"Thelonious Monk",primary_instrument:"piano",years_active:"1944-1971"},{name:"Charlie Parker",primary_instrument:"saxophone",years_active:"1937-1955"},{name:"John Coltrane",primary_instrument:"saxophone",years_active:"1946-1967"},{name:"Herbie Hancock",primary_instrument:"keyboard",years_active:"1961-Present"}],albums:[{title:"The Real Birth of the Cool",year:"1948",jazz_legend_id:3},{title:"Blue Period",year:"1951",jazz_legend_id:3},{title:"Blue Haze",year:"1953",jazz_legend_id:3}]}};JazzRecord.adapter=new JazzRecord.GearsAdapter();JazzRecord.fixtures=legendaryData;JazzRecord.migrate({refresh:true});},loggingOn:function(){console.log("Logging On");JazzRecord.debug=true;},loggingOff:function(){console.log("Logging Off");JazzRecord.debug=false;},moveMenu:function(){if($('share_button')&&$('share_list_item')){var button_coords=$('share_button').getCoordinates($$('.community')[0]);$("share_list_item").setStyles({top:button_coords.bottom+12,left:button_coords.left-63});}}};window.addEvent("domready",function(){JazzRecord.debug=true;if($("loggingOff")&&$("loggingOn")){$("loggingOff").addEvent("click",function(evt){JazzRecordOrg.loggingOff();evt.stop();});$("loggingOn").addEvent("click",function(evt){JazzRecordOrg.loggingOn();evt.stop();});}
if($("loadJazz")){$("loadJazz").addEvent("click",function(evt){JazzRecordOrg.initDemo();evt.stop();});}
if($("deity"))
$("deity").addEvent("click",function(evt){evt.stop();var deity=prompt('Who do you pray to?','Mammon');if(deity){$('deity').set('text',deity);}});if($('cache_sweep')&&$('output')){$('cache_sweep').addEvent('click',function(){$('output').load('admin/cache_sweep');return false;});}
if($('console')&&$('close')){$('close').addEvent('click',function(){$('console').className='inactive';return false;});}
if($$('.git')&&$('gitlink')){var gitlink=$('gitlink');$('gitlink').addEvent('contextmenu',function(){$('gitlink').dispose();$$('.git').adopt(new Element('input',{id:'gitbox',type:'text',value:'git://github.com/thynctank/jazzrecord.git'}));$('gitbox').select();$('gitbox').addEvent('blur',function(event){$('gitbox').dispose();$$('.git').adopt(gitlink);});return false;});}
if($('share_button')&&$('share_list_item')&&$('share_list')){JazzRecordOrg.moveMenu();$('share_list').setStyle('display','block');$('share_list').set('slide',{duration:500,transition:'bounce:out',mode:'vertical'});function shareActive(){if($("share_list_item").getStyle("overflow")=="hidden")
$("share_list_item").setStyle("overflow","visible");$('share_button').className='active';$('share_list').slide('in');}
function shareInactive(){$('share_list').slide('out');$('share_button').className='inactive';}
$('share_button').addEvents({'mouseover':function(){shareActive();$('share_list_item').addEvents({'mouseover':function(){shareActive();},'mouseout':function(){shareInactive();}});},'mouseout':function(){shareInactive();}});$("share_list_item").setStyles({height:0,overflow:"hidden"});$("share_list").slide("out");}
if($$('ul.community > li > a')){$$('ul.community > li > a').each(function(button){var highlightNav=new Fx.Morph(button,{duration:1500,transition:Fx.Transitions.Quint.easeOut});button.addEvents({'mouseover':function(){highlightNav.pause();highlightNav.start('.community_highlighted');},'focus':function(){highlightNav.pause();highlightNav.start('.community_highlighted');},'mouseout':function(){highlightNav.pause();highlightNav.start('.community_not_highlighted');},'blur':function(){highlightNav.pause();highlightNav.start('.community_not_highlighted');}});});}
if($$('ul.main > li > a')){$$('ul.main > li > a').each(function(button){var highlightNav=new Fx.Morph(button,{duration:250,transition:Fx.Transitions.Quint.easeOut});button.addEvents({'mouseover':function(){highlightNav.pause();highlightNav.start('.main_highlighted');},'focus':function(){highlightNav.pause();highlightNav.start('.main_highlighted');},'mouseout':function(){highlightNav.pause();(function(){highlightNav.start('.main_not_highlighted');}).delay(250);},'blur':function(){highlightNav.pause();highlightNav.start('.main_not_highlighted');}});});}
window.addEvent("resize",JazzRecordOrg.moveMenu);});