if(typeof(Prototype)=="undefined"){throw"Event.Behavior requires Prototype to be loaded."}if(typeof(Object.Event)=="undefined"){throw"Event.Behavior requires Object.Event to be loaded."}Event.Behavior={addVerbs:function(a){for(name in a){v=new Event.Behavior.Verb(a[name]);Event.Behavior.Verbs[name]=v;Event.Behavior[name.underscore()]=Event.Behavior[name]=v.getCallbackForStack.bind(v)}},addEvents:function(a){$H(a).each(function(b){Event.Behavior.Adjective.prototype[b.key.underscore()]=Event.Behavior.Adjective.prototype[b.key]=function(){this.nextConditionType="and";this.events.push(b.value);this.attachObserver(false);return this}})},invokeElementMethod:function(d,a,b){if(typeof(d)=="function"){return $A(d()).each(function(f){if(typeof(b[0])=="function"){return $A(b[0]).each(function(e){return $(f)[a].apply($(f),(e?[e]:[]))})}else{return $(f)[a].apply($(f),b||[])}})}else{return $(d)[a].apply($(d),b||[])}}};Event.Behavior.Verbs=$H({});Event.Behavior.Verb=Class.create();Object.extend(Event.Behavior.Verb.prototype,{originalAction:false,execute:false,executeOpposite:false,target:false,initialize:function(a){this.originalAction=a;this.execute=function(b,e,d){return(d)?b(e,d):b(e)}.bind(this,a)},setOpposite:function(a){opposite_action=a.originalAction;this.executeOpposite=function(b,e,d){return(d)?b(e,d):b(e)}.bind(this,opposite_action)},getCallbackForStack:function(a){return new Event.Behavior.Noun(this,a)}});Event.Behavior.addVerbs({call:function(a){a()},show:function(a){return Event.Behavior.invokeElementMethod(a,"show")},hide:function(a){return Event.Behavior.invokeElementMethod(a,"hide")},remove:function(a){return Event.Behavior.invokeElementMethod(a,"remove")},setStyle:function(b,a){return Event.Behavior.invokeElementMethod(b,"setStyle",[(typeof(a)=="function"?a():a)])},addClassName:function(b,a){return Event.Behavior.invokeElementMethod(b,"addClassName",[(typeof(a)=="function"?a():a)])},removeClassName:function(b,a){return Event.Behavior.invokeElementMethod(b,"removeClassName",[(typeof(a)=="function"?a():a)])},setClassName:function(b,a){c=(typeof(a)=="function")?a():a;if(typeof(b)=="function"){return $A(b()).each(function(d){$(d).className=c})}else{return $(b).className=c}},update:function(b,a){return Event.Behavior.invokeElementMethod(a,"update",[(typeof(b)=="function"?b():b)])},replace:function(b,a){return Event.Behavior.invokeElementMethod(a,"replace",[(typeof(b)=="function"?b():b)])}});Event.Behavior.Verbs.show.setOpposite(Event.Behavior.Verbs.hide);Event.Behavior.Verbs.hide.setOpposite(Event.Behavior.Verbs.show);Event.Behavior.Verbs.addClassName.setOpposite(Event.Behavior.Verbs.removeClassName);Event.Behavior.Verbs.removeClassName.setOpposite(Event.Behavior.Verbs.addClassName);Event.Behavior.Noun=Class.create();Object.extend(Event.Behavior.Noun.prototype,{verbs:false,verb:false,argument:false,subject:false,target:false,initialize:function(b,a){this.verb=b;this.argument=a},execute:function(){return(this.target)?this.verb.execute(this.target,this.argument):this.verb.execute(this.argument)},executeOpposite:function(){return(this.target)?this.verb.executeOpposite(this.target,this.argument):this.verb.executeOpposite(this.argument)},when:function(a){this.subject=a;return new Event.Behavior.Adjective(this)},getValue:function(){return Try.these(function(){return $(this.subject).getValue()}.bind(this),function(){return $(this.subject).options[$(this.subject).options.selectedIndex].value}.bind(this),function(){return $(this.subject).value}.bind(this),function(){return $(this.subject).innerHTML}.bind(this))},containsValue:function(a){value=this.getValue();if(typeof(a)=="function"){return $A(a()).include(value)}else{return value.match(a)}},setTarget:function(a){this.target=a;return this},and:function(){}});Event.Behavior.Noun.prototype._with=Event.Behavior.Noun.prototype.setTarget;Event.Behavior.Noun.prototype.on=Event.Behavior.Noun.prototype.setTarget;Event.Behavior.Noun.prototype.of=Event.Behavior.Noun.prototype.setTarget;Event.Behavior.Noun.prototype.to=Event.Behavior.Noun.prototype.setTarget;Event.Behavior.Noun.prototype.from=Event.Behavior.Noun.prototype.setTarget;Event.Behavior.Adjective=Class.create();Object.extend(Event.Behavior.Adjective.prototype,{noun:false,lastConditionName:"",nextConditionType:"and",conditions:$A([]),events:$A([]),attached:false,initialize:function(a){this.conditions=$A([]);this.events=$A([]);this.noun=a},attachObserver:function(a){if(this.attached){if(a){this.execute()}return}this.attached=true;if(typeof(this.noun.subject)=="function"){$A(this.noun.subject()).each(function(b){(this.events.length>0?this.events:$A(["change"])).each(function(d){(b.observe?b:$(b)).observe(d,function(){this.execute()}.bind(this))}.bind(this))}.bind(this))}else{(this.events.length>0?this.events:$A(["change"])).each(function(b){$(this.noun.subject).observe(b,function(){this.execute()}.bind(this))}.bind(this))}if(a){this.execute()}},execute:function(){if(this.match()){return this.noun.execute()}else{if(this.noun.verb.executeOpposite){this.noun.executeOpposite()}}},attachCondition:function(a){this.conditions.push([this.nextConditionType,a.bind(this)])},match:function(){if(this.conditions.length==0){return true}else{return this.conditions.inject(new Boolean(),function(a,b){return(b[0]=="and")?(a&&b[1]()):(a||b[1]())})}},is:function(a){this.lastConditionName="is";this.attachCondition(function(b){return(typeof(b)=="function"?b():b)==this.noun.getValue()}.bind(this,a));this.attachObserver(true);return this},isNot:function(a){this.lastConditionName="isNot";this.attachCondition(function(b){return(typeof(b)=="function"?b():b)!=this.noun.getValue()}.bind(this,a));this.attachObserver(true);return this},contains:function(a){this.lastConditionName="contains";this.attachCondition(function(b){return this.noun.containsValue(b)}.bind(this,a));this.attachObserver(true);return this},within:function(a){this.lastConditionName="within";this.attachCondition(function(b){}.bind(this,a));this.attachObserver(true);return this},change:function(){this.nextConditionType="and";this.attachObserver(true);return this},and:function(a){this.attached=false;this.nextConditionType="and";if(a){this[this.lastConditionName](a)}return this},or:function(a){this.attached=false;this.nextConditionType="or";if(a){this[this.lastConditionName](a)}return this}});Event.Behavior.addEvents({losesFocus:"blur",gainsFocus:"focus",isClicked:"click",isDoubleClicked:"dblclick",keyPressed:"keypress"});Event.Behavior.Adjective.prototype.is_not=Event.Behavior.Adjective.prototype.isNot;Event.Behavior.Adjective.prototype.include=Event.Behavior.Adjective.prototype.contains;Event.Behavior.Adjective.prototype.includes=Event.Behavior.Adjective.prototype.contains;Event.Behavior.Adjective.prototype.are=Event.Behavior.Adjective.prototype.is;Event.Behavior.Adjective.prototype.areNot=Event.Behavior.Adjective.prototype.isNot;Event.Behavior.Adjective.prototype.are_not=Event.Behavior.Adjective.prototype.isNot;Event.Behavior.Adjective.prototype.changes=Event.Behavior.Adjective.prototype.change;