/**
* @name     Half Court Shot
* @author <codes>      mediaHACK - http://www.mediahack.com [codes at teh mediahack dotz com]
* @author <pretties>      KomodoMedia - http://www.komodomedia.com [rogie at teh komodomedia dotz com]
* @date         2010.07.28
* @version	1.101129
* 
* This has been a mediaHACK and KomodoMedia  collab. Our powers
* combined are Super-Sonic-Bionic. Trust pound#.
*
* @copyright   2010 - mH
* @licence  MIT Licensed. Nice if you give origination cred.
* 
**/

function HalfCourtShot(settings){this.settings=settings;this.play;this.goal=document.getElementsByTagName("body")[0];var allstarsIMO=["rogie","simplebits","shauninman","jsm","squaredeye"];var cointoss=Math.floor(Math.random()*5);this.player=allstarsIMO[cointoss];this.jersey=this.player;this.shots=0;this.page;this.per_page;this.following=false;this.className="hcs";this.apiUrl="http://api.dribbble.com/";this.playType="players";this.url="";HalfCourtShot.currentIndex=HalfCourtShot.currentIndex||0;this.index=HalfCourtShot.currentIndex++;this.debug=false;this.callThePlay=function(){var ball=this;if(ball.settings==null){return}for(var x in ball.settings){if(ball[x]!=undefined){ball[x]=ball.settings[x]}}};this.shootDaBall=function(){var ball=this;var sCallback="HalfCourtShot.callback"+ball.index;HalfCourtShot["callback"+ball.index]=function(data){ball.jumboTron(data)};ball.genUrl();var instId="halfCourtShot"+ball.currentIndex;HalfCourtShot[instId]=document.createElement("script");HalfCourtShot[instId].setAttribute("id",instId);HalfCourtShot[instId].setAttribute("type","text/javascript");HalfCourtShot[instId].setAttribute("src",ball.url);document.getElementsByTagName("body")[0].appendChild(HalfCourtShot[instId])};this.jumboTron=function(data){var ball=this;var bounds=document.createElement("div");bounds.setAttribute("class",ball.className);var imgList=document.createElement("ul");var thumbList=document.createElement("ul");var show=(ball.shots)?ball.shots:data.shots.length;if(show>data.shots.length){show=data.shots.length}var mainShot=show;if(ball.warmUp){show+=ball.numberOfLayups}if(data.shots){for(var x=0;x<show;x++){var li=ball.buildImageListItem(data.shots[x]);imgList.appendChild(li)}}else{if(data.image_url||data.avatar_url){var li=ball.buildImageListItem(data);imgList.appendChild(li)}}bounds.appendChild(imgList);if(ball.warmUp){bounds.appendChild(thumbList)}if(typeof ball.goal=="string"){ball.goal=document.getElementById(ball.goal)}ball.goal.appendChild(bounds);ball.goal.innerHTML=ball.goal.innerHTML;if(ball.onComplete){ball.onComplete()}};this.buildImageListItem=function(d){var image_url=(d.image_url)?d.image_url:d.avatar_url;var a=document.createElement("a");a.setAttribute("href",d.url);a.setAttribute("title",d.title);var img=document.createElement("img");img.setAttribute("src",image_url);var lay=document.createElement("span");lay.setAttribute("class","overlay");if(d.width){img.setAttribute("width",d.width)}if(d.height){img.setAttribute("height",d.height)}if(d.title){img.setAttribute("title",d.title)}else{if(d.name){img.setAttribute("title",d.name)}}if(d.title){img.setAttribute("alt",d.title)}else{if(d.name){img.setAttribute("alt",d.name)}}a.appendChild(img);a.appendChild(lay);var li=document.createElement("li");li.appendChild(a);return li};this.genUrl=function(){var randomNo=Math.floor(Math.random()*9999999);if(typeof this.jersey=="string"){if(this.page!=undefined){pageOpts="page="+this.page}if(this.per_page!=undefined){pageOpts=pageOpts+"&per_page="+this.per_page}}if(this.playType=="shots"){var pageOpts="";if(this.jersey=="debuts"||this.jersey=="everyone"||this.jersey=="popular"){this.url=this.apiUrl+this.playType+"/"+this.jersey+"/?"+pageOpts+"&r="+randomNo+"&callback=HalfCourtShot.callback"+this.index}else{this.url=this.apiUrl+this.playType+"/"+this.jersey+"/?r="+randomNo+"&callback=HalfCourtShot.callback"+this.index}if(this.debug){console.log(this.url)}}else{if(this.playType=="players"){var jerseyType=parseInt(this.jersey);if(parseInt(this.jersey)){this.url=this.apiUrl+this.playType+"/"+this.jersey+"/?r="+randomNo+"&callback=HalfCourtShot.callback"+this.index}else{var followingOpts=(eval(this.following))?"following/":"";this.url=this.apiUrl+this.playType+"/"+this.jersey+"/shots/"+followingOpts+"?r="+randomNo+"&callback=HalfCourtShot.callback"+this.index}}}};this.rideThePine=function(v){if(this.debug){console.log(this[v])}};this.hitTheFloor=function(){this.callThePlay();this.shootDaBall()};this.hitTheFloor()};
