// Kameleon Digital, <http://www.kameleondigital.com>, Copyright (c) 2008-2011

var kamTwitterFeed=new Class({Implements:Options,options:{count:5},screenName:null,urls:{twitter:"http://twitter.com/",search:"http://twitter.com/#!/search/",apiPrefix:"http://twitter.com/statuses/user_timeline/",apiSuffix:".json?"},initialize:function(b,a){if(b){this.setOptions(a);this.screenName=b}else{alert("ERROR > kamTwitterFeed > initialize > screenName is invalid")}},getFeed:function(b){if(typeOf(b)=="function"){var d=this.urls;var a=this.apiParamKeys;var c=new URI(d.apiPrefix+this.screenName+d.apiSuffix);c.setData({count:this.options.count,clientsource:"kamTwitterFeed",kamReqTime:new Date().getTime()},true);new Request.JSONP({url:c.toString(),onComplete:function(e){e.each(function(g){var f=g.text;f=f.replace(/\b(((https*\:\/\/)|www\.)[^\"\']+?)(([!?,.\)]+)?(\s|$))/g,function(h){return'<a href="'+h+'" rel="kamPopUp">'+h+"</a>"});f=f.replace(/@([a-zA-Z0-9]*)/g,function(h){return'<a href="'+d.twitter+h.replace("@","")+'" rel="kamPopUp">'+h+"</a>"});f=f.replace(/#([a-zA-Z0-9]*)/g,function(h){return'<a href="'+d.search+encodeURIComponent(h)+'" rel="kamPopUp">'+h+"</a>"});g.text=f});b(e)}.bind(this)}).send()}else{alert("ERROR > kamTwitterFeed > getFeed > callbackHandler is invalid")}},inject:function(a){a=document.id(a);if(a){a.empty();this.getFeed(function(c){var b=new Element("ul").inject(a);c.each(function(d){new Element("li",{html:d.text}).inject(b)});if(typeof kamUi!="undefined"){kamUi.initialise(b)}})}else{alert("ERROR > kamTwitterFeed > inject > invalid container supplied")}}});
