var Class={create:function(){return function(){if(this.destroy)Class.registerForDestruction(this);if(this.initialize)this.initialize.apply(this,arguments);}},extend:function(baseClassName){constructor=function(){var i;this[baseClassName]={}
for(i in window[baseClassName].prototype){if(!this[i])this[i]=window[baseClassName].prototype[i];if(typeof window[baseClassName].prototype[i]=='function'){this[baseClassName][i]=window[baseClassName].prototype[i].bind(this);}}
if(window[baseClassName].getInheritedStuff){window[baseClassName].getInheritedStuff.apply(this);}
if(this.destroy)Class.registerForDestruction(this);if(this.initialize)this.initialize.apply(this,arguments);}
constructor.getInheritedStuff=function(){var i;this[baseClassName]={}
for(i in window[baseClassName].prototype){if(!this[i])this[i]=window[baseClassName].prototype[i];if(typeof window[baseClassName].prototype[i]=='function'){this[baseClassName][i]=window[baseClassName].prototype[i].bind(this);}}
if(window[baseClassName].getInheritedStuff){window[baseClassName].getInheritedStuff.apply(this);}}
return constructor;},objectsToDestroy:[],registerForDestruction:function(obj){if(!Class.addedDestructionLoader){Event.observe(window,'unload',Class.destroyAllObjects);Class.addedDestructionLoader=true;}
Class.objectsToDestroy.push(obj);},destroyAllObjects:function(){var i,item;for(i=0;item=Class.objectsToDestroy[i];i++){if(item.destroy)item.destroy();}
Class.objectsToDestroy=null;}}
Function.prototype.extend=function(baseClassName){var parentFunc=this;var constructor=function(){this[baseClassName]={}
for(var i in window[baseClassName].prototype){if(!this[i])this[i]=window[baseClassName].prototype[i];this[baseClassName][i]=window[baseClassName].prototype[i].bind(this);}
if(window[baseClassName].getInheritedStuff){window[baseClassName].getInheritedStuff.apply(this);}
if(parentFunc.getInheritedStuff){parentFunc.getInheritedStuff.apply(this);}
parentFunc.apply(this,arguments);}
constructor.getInheritedStuff=function(){this[baseClassName]={}
var i;for(i in window[baseClassName].prototype){if(!this[i])this[i]=window[baseClassName].prototype[i];this[baseClassName][i]=window[baseClassName].prototype[i].bind(this);}
if(window[baseClassName].getInheritedStuff){window[baseClassName].getInheritedStuff.apply(this);}
if(parentFunc.getInheritedStuff){parentFunc.getInheritedStuff.apply(this);}}
return constructor;}
Function.prototype.bindAsEventListener=function(object){var __method=this;return function(event){return __method.call(object,event||window.event);}}
Function.prototype.applyTo=function(cssSelector,arg1,arg2,arg3,arg4,arg5,arg6){if(typeof cssSelector=='string'){var registration={}
var targetClass=this;registration[cssSelector]={initialise:function(){behaveAs(this,targetClass,arg1,arg2,arg3,arg4,arg5,arg6);}}
Behaviour.register(registration);}else{behaveAs(cssSelector,this);}}
var _APPLYTOCHILDREN_GENERATED_IDS=0;Function.prototype.applyToChildren=function(parentNode,cssSelector,arg1,arg2,arg3,arg4,arg5,arg6){if(!parentNode.id){_APPLYTOCHILDREN_GENERATED_IDS++;parentNode.id='atc-gen-id-'+_APPLYTOCHILDREN_GENERATED_IDS;}
this.applyTo('#'+parentNode.id+' '+cssSelector);}
if(typeof Behaviour=='undefined'){var Behaviour={isEventHandler:{onclick:true,onfocus:true,onblur:true,onmousedown:true,onmouseup:true,onmouseover:true,onmouseout:true,onclick:true},list:new Array,namedList:{},isDebugging:false,register:function(name,sheet){if(typeof name=='object'){Behaviour.list.push(name);if(Behaviour.alreadyApplied)Behaviour.process(name);}else{Behaviour.list.push(sheet);Behaviour.namedList[name]=sheet;if(Behaviour.alreadyApplied)Behaviour.process(sheet);}},start:function(){Behaviour.addLoader(function(){Behaviour.apply();});},debug:function(){Behaviour.isDebugging=true;},apply:function(parentNode,applyToParent){if(typeof(jQuery)!='undefined'&&typeof(jQuery.livequery)!='undefined')jQuery.livequery.run();if(Behaviour.isDebugging)console.time('Behaviour: apply took');if(typeof parentNode=='string')parentNode=document.getElementById(parentNode);var h;for(h=0;sheet=Behaviour.list[h];h++){Behaviour.process(sheet,parentNode,applyToParent);}
if(Behaviour.isDebugging)console.timeEnd('Behaviour: apply took');Behaviour.alreadyApplied=true;},reapply:function(name){if(typeof(jQuery)!='undefined'&&typeof(jQuery.livequery)!='undefined')jQuery.livequery.run();if(Behaviour.namedList[name])Behaviour.process(Behaviour.namedList[name]);},process:function(sheet,parentNode,applyToParent){var i;var selector;var list;var element;var debugText="";for(selector in sheet){if(!sheet[selector])continue;if(Behaviour.isDebugging)console.time('Behaviour: '+selector);list=document.getElementsBySelector(selector,parentNode);if(list&&list.length>0){if(Behaviour.isDebugging)console.log("Behaviour: %s: %d items, %o",selector,list.length,list);for(i=0;element=list[i];i++){if(parentNode==element&&applyToParent!=true)continue;if(element.lastSelectorApplied!=sheet[selector]){element.lastSelectorApplied=sheet[selector];if(sheet[selector].prototype){behaveAs(element,sheet[selector]);}else{var x;for(x in sheet[selector]){if(element[x]&&!element['old_'+x])element['old_'+x]=element[x];if(sheet[selector][x]){if(Behaviour.isEventHandler[x]){element[x]=sheet[selector][x].bindAsEventListener(element);}else{element[x]=sheet[selector][x];}}}
if(sheet[selector].initialise){element.initialise();}else if(sheet[selector].initialize){element.initialize();}
if(typeof sheet[selector]=='undefined')break;if(sheet[selector].destroy)Class.registerForDestruction(element);}}}}
if(Behaviour.isDebugging)console.timeEnd('Behaviour: '+selector);}},addLoader:function(func){Behaviour.addEvent(window,'load',func);},addEvent:function(obj,evType,fn,useCapture){if(obj.addEventListener){obj.addEventListener(evType,fn,useCapture);return true;}else if(obj.attachEvent){var r=obj.attachEvent("on"+evType,fn);return r;}else{alert("Handler could not be attached");}}}
Behaviour.start();}
function behaveAs(element,behaviourClass,arg1,arg2,arg3,arg4,arg5,arg6){if(!element)return;element.initialize=null;var x;for(x in behaviourClass.prototype){element[x]=behaviourClass.prototype[x];if(x=='onclick'&&element[x]){element[x]=element[x].bindAsEventListener(element);}}
behaviourClass.apply(element,[arg1,arg2,arg3,arg4,arg5,arg6]);return element;}
function getAllChildren(e){return e.all?e.all:e.getElementsByTagName('*');}
document.getElementsBySelector=function(selector,parentNode){if(!document.getElementsByTagName){return new Array();}
var tokens=selector.split(' ');var currentContext=new Array(document);for(var i=0;i<tokens.length;i++){token=tokens[i].replace(/^\s+/,'').replace(/\s+$/,'');;if(token.indexOf('#')>-1){var bits=token.split('#');var tagName=bits[0];var id=bits[1];var element=document.getElementById(id);if(!element||(tagName&&element.nodeName.toLowerCase()!=tagName)){return new Array();}
if(parentNode&&!hasAncestor(element,parentNode)&&!hasAncestor(parentNode,element)){return new Array();}
currentContext=new Array(element);continue;}
if(token.indexOf('.')>-1){var bits=token.split('.');var tagName=bits[0];var className=bits[1];if(!tagName){tagName='*';}
var found=new Array;var foundCount=0;for(var h=0;h<currentContext.length;h++){var elements;if(currentContext[h]){if(tagName=='*'){elements=getAllChildren(currentContext[h]);}else{elements=currentContext[h].getElementsByTagName(tagName);}
for(var j=0;j<elements.length;j++)found[foundCount++]=elements[j];}}
currentContext=new Array;var currentContextIndex=0;if(bits.length==2){for(var k=0;k<found.length;k++){if(found[k].className&&found[k].className.match(new RegExp('\\b'+className+'\\b'))){if(!parentNode||hasAncestor(found[k],parentNode)||hasAncestor(parentNode,found[k])){currentContext[currentContextIndex++]=found[k];}}}}else{var classNameMatcher=function(el){var i;if(!el.className)return false;for(i=1;i<bits.length;i++)if(!el.className.match(new RegExp('\\b'+bits[i]+'\\b')))return false;return true;}
for(var k=0;k<found.length;k++){if(classNameMatcher(found[k])){if(!parentNode||hasAncestor(found[k],parentNode)||hasAncestor(parentNode,found[k])){currentContext[currentContextIndex++]=found[k];}}}}
continue;}
if(token.match(/^(\w*)\[(\w+)([=~\|\^\$\*]?)=?"?([^\]"]*)"?\]$/)){var tagName=RegExp.$1;var attrName=RegExp.$2;var attrOperator=RegExp.$3;var attrValue=RegExp.$4;if(!tagName){tagName='*';}
var found=new Array;var foundCount=0;for(var h=0;h<currentContext.length;h++){if(currentContext[h]){var elements;if(tagName=='*'){elements=getAllChildren(currentContext[h]);}else{elements=currentContext[h].getElementsByTagName(tagName);}
for(var j=0;j<elements.length;j++){if(!parentNode||hasAncestor(elements[j],parentNode)||hasAncestor(parentNode,elements[j])){found[foundCount++]=elements[j];}}}}
currentContext=new Array;var currentContextIndex=0;var checkFunction;switch(attrOperator){case'=':checkFunction=function(candAttrValue){return(candAttrValue==attrValue);};break;case'~':checkFunction=function(candAttrValue){return(candAttrValue.match(new RegExp('\\b'+attrValue+'\\b')));};break;case'|':checkFunction=function(candAttrValue){return(candAttrValue.match(new RegExp('^'+attrValue+'-?')));};break;case'^':checkFunction=function(candAttrValue){return(candAttrValue.indexOf(attrValue)==0);};break;case'$':checkFunction=function(candAttrValue){return(candAttrValue.lastIndexOf(attrValue)==candAttrValue.length-attrValue.length);};break;case'*':checkFunction=function(candAttrValue){return(candAttrValue.indexOf(attrValue)>-1);};break;default:checkFunction=function(candAttrValue){return candAttrValue;};}
currentContext=new Array;var currentContextIndex=0;for(var k=0;k<found.length;k++){var candAttrValue=attrName=='class'?found[k].className:found[k].getAttribute(attrName);if(checkFunction(candAttrValue)){if(!parentNode||hasAncestor(found[k],parentNode)||hasAncestor(parentNode,found[k])){currentContext[currentContextIndex++]=found[k];}}}
continue;}
if(!currentContext[0]){return;}
tagName=token;var found=new Array;var foundCount=0;for(var h=0;h<currentContext.length;h++){var elements=currentContext[h].getElementsByTagName(tagName);for(var j=0;j<elements.length;j++){if(!parentNode||hasAncestor(elements[j],parentNode)||hasAncestor(parentNode,elements[j])){found[foundCount++]=elements[j];}}}
currentContext=found;}
if(parentNode){var i;for(i=0;i<currentContext.length;i++){if(!hasAncestor(currentContext[i],parentNode))currentContext.splice(i,1);}}
return currentContext;}
function hasAncestor(child,ancestor){if(ancestor){if(ancestor.contains)return ancestor==child||ancestor.contains(child);var p=child;while(p){if(p==ancestor)return true;p=p.parentNode;}}
return false;}
Observable=Class.create();Observable.prototype={observe:function(event,observer){return this.observeMethod(event,observer['on'+Event].bind(observer));},observeMethod:function(event,method){if(!this.observers)this.observers={};if(!this.observers[event])this.observers[event]=[];var nextIdx=this.observers[event].length;this.observers[event][nextIdx]=method;return event+'|'+nextIdx;},stopObserving:function(observerCode){var parts=observerCode.split('|');if(this.observers&&this.observers[parts[0]]&&this.observers[parts[0]][parts[1]])
this.observers[parts[0]][parts[1]]=null;else
throw("Observeable.stopObserving: couldn't find '"+observerCode+"'");},notify:function(event,arg){var i,returnVal=true;if(this.observers&&this.observers[event]){for(i=0;i<this.observers[event].length;i++){if(this.observers[event][i]){if(this.observers[event][i](arg)==false)returnVal=false;}}}
return returnVal;}};if(window.location.href.indexOf('debug_behaviour=')>-1)Behaviour.debug();