var ClickGate=Class.create({REQUIRED_Prototype:"1.6.0.2",require:function(a){if((typeof window[a]=="undefined")||(this.convertVersionString(window[a].Version)<this.convertVersionString(this["REQUIRED_"+a]))){throw ("ClickGate requires "+a+" >= "+this["REQUIRED_"+a])}},convertVersionString:function(a){var b=a.replace(/_.*|\./g,"");b=parseInt(b+"0".times(4-b.length));return a.indexOf("_")>-1?b-1:b},initialize:function(d,c,l){this.require("Prototype");this.selector=d;this.settings=c;this.options=l;this.debug=this.options.debug||false;this.name=this.options.name||"ClickGate";this.attribute=this.options.attribute||"href";this.callback=this.options.callback||null;this.type=this.options.type||"onclick";this.data=new Hash();this.clickBinding=this.click.bindAsEventListener(this);var a=$$(this.selector);this.log("started with selector <"+this.selector+">, found <"+a.length+"> elements");for(var f=0;f<a.length;f++){var g=a[f];var j=g.readAttribute(this.attribute);if(j){this.log(f+1+". "+Object.inspect(g)+" has attribute <"+this.attribute+"> with value <"+j+">");for(var e=0;e<this.settings.length;e++){var h=this.settings[e].pattern;if(new String(j).match(new RegExp(h))){var b=this.name+"Id"+(f+1);if($(g.readAttribute("id"))){b=g.readAttribute("id")}else{g.writeAttribute("id",b)}this.data.set(b,{value:j,action:this.settings[e].action,pattern:h});if(this.debug){g.setStyle({border:"1px solid blue"})}this.log(f+1+". added for pattern <"+h+"> with id <"+b+">");if("observe"==this.type){g.writeAttribute(this.attribute,"javascript:void(0);");Event.observe(g,"click",this.clickBinding)}else{g.onclick=this.clickBinding}break}}}else{this.log(f+1+". "+Object.inspect(g)+" has no attribute <"+this.attribute+">")}}this.log("initialized "+Object.inspect(this.data))},log:function(a){if(this.debug&&"object"==typeof(console)&&"function"==typeof(console.log)){console.log(this.name+": "+a)}},click:function(c){var a=Event.element(c);if(a.parentNode.nodeName.toLowerCase()=="a"){a=a.parentNode}var f=a.readAttribute("id");var b=this.data.get(f);var e=b.value;var d=b.action;this.log("id <"+f+"> was clicked, stored value is <"+e+">, type of action is <"+typeof(this.callback)+">");if("function"==typeof(d)){this.log("action");d(this,f,e)}if("function"==typeof(this.callback)){this.log("callback");this.callback(this,f,e)}if("observe"!=this.type){return false}},proceed:function(c){var a=this.data.get(c);var b=a.value;if("href"==this.attribute){document.location.href=b}}});
