/**
 *  @package	Flickrshow
 *  @subpackage	Javascript
 *  @author		Ben Sekulowicz-Barclay
 *  @version    7.1
 *
 *  Flickrshow is a Beseku thing licensed under a Creative Commons Attribution 3.0 
 *  Unported License. For more information visit http://www.flickrshow.com.
 */
 
function flickrshow(i,g){if(!(this instanceof flickrshow))return new flickrshow(i,g);var a=this;a.addEvent=function(b,d,c){if(b.addEventListener)b.addEventListener(d,c,false);else if(b.attachEvent){b["e"+d+c]=c;b[d+c]=function(){b["e"+d+c](window.event)};b.attachEvent("on"+d,b[d+c])}};a.addUrl=function(){var b={api_key:"6cb7449543a9595800bc0c365223a4e8",extras:"url_s,url_m,url_z,url_l",format:"json",jsoncallback:"flickrshow_jsonp_"+a.constants.random,page:a.settings.page,per_page:a.settings.per_page};
if(a.settings.license)b.license=a.settings.license;if(a.settings.gallery){b.method="flickr.galleries.getPhotos";b.gallery_id=a.settings.gallery}else if(a.settings.group){b.method="flickr.groups.pools.getPhotos";b.group_id=a.settings.group}else if(a.settings.set){b.method="flickr.photosets.getPhotos";b.photoset_id=a.settings.set}else if(a.settings.person){b.method="flickr.people.getPhotosOf";b.user_id=a.settings.person}else if(a.settings.tags||a.settings.user){b.method="flickr.photos.search";if(a.settings.tags)b.tags=
a.settings.tags;if(a.settings.user)b.user_id=a.settings.user}else b.method="flickr.photos.getRecent";var d="http://api.flickr.com/services/rest/?";for(var c in b)d+=c+"="+b[c]+"&";return d};a.animate=function(b,d,c,e,f){"undefined"!==typeof a.constants.intervals[f]&&window.clearInterval(a.constants.intervals[f]);a.constants.intervals[f]=window.setInterval(function(){var h=Math.round(b.style[d].replace(/([a-zA-Z]{2})$/,"")),j=Math.round(c-h);if(Math.abs(j)>1)b.style[d]=Math.floor(h+j/2)+"px";else{b.style[d]=
c+"px";window.clearInterval(a.constants.intervals[f])}},e/1.5)};a.onClickLeft=function(){if(a.constants.isLoading!==true){a.constants.imageCurrent=a.constants.imageCurrent-1<0?a.constants.imageTotal-1:a.constants.imageCurrent-1;a.animate(a.elements.images,"left","-"+a.constants.imageCurrent*a.elements.target.offsetWidth,a.constants.speed,"i");a.showTitle();typeof a.settings.onMove=="function"&&a.settings.onMove(a.elements.images.childNodes[a.constants.imageCurrent].childNodes[0])}};a.onClickPlay=
function(){if(a.constants.isPlaying===false){a.constants.isPlaying=true;a.elements.buttons.childNodes[2].style.backgroundImage="url("+a.constants.base_url+"static/images/is.png)";a.constants.intervals.playing=window.setInterval(function(){a.onClickRight()},a.settings.interval);typeof a.settings.onPlay=="function"&&a.settings.onPlay()}else{a.constants.isPlaying=false;a.elements.buttons.childNodes[2].style.backgroundImage="url("+a.constants.base_url+"static/images/ip.png)";window.clearInterval(a.constants.intervals.playing);
typeof a.settings.onPause=="function"&&a.settings.onPause(a.elements.images.childNodes[a.constants.imageCurrent].childNodes[0])}};a.onClickRight=function(){if(a.constants.isLoading!==true){a.constants.imageCurrent=a.constants.imageCurrent+2>a.constants.imageTotal?0:a.constants.imageCurrent+1;a.animate(a.elements.images,"left","-"+a.constants.imageCurrent*a.elements.target.offsetWidth,a.constants.speed,"i");a.showTitle();typeof a.settings.onMove=="function"&&a.settings.onMove(a.elements.images.childNodes[a.constants.imageCurrent].childNodes[0])}};
a.onLoadImage=function(b){b=b.srcElement||b.target;var d=b.offsetHeight,c=b.offsetWidth,e=0,f=0;if(c>d){f=Math.ceil(a.elements.target.offsetWidth+a.elements.target.offsetHeight/100);e=Math.ceil(f/c*d)}else{e=Math.ceil(a.elements.target.offsetHeight+a.elements.target.offsetHeight/100);f=Math.ceil(e/d*c)}try{b.style.height=e+"px";b.style.left=Math.round((a.elements.target.offsetWidth-f)/2)+"px";b.style.position="absolute";b.style.top=Math.round((a.elements.target.offsetHeight-e)/2)+"px";b.style.width=
f+"px"}catch(h){}a.constants.imageLoaded++;b=Math.round(a.constants.imageLoaded/a.constants.imageTotal*240);a.animate(a.elements.loading.childNodes[0],"width",b<=36?36:b,"loading");if(a.constants.imageLoaded===a.constants.imageTotal){a.showTitle();a.elements.container.removeChild(a.elements.loading);a.elements.images.style.visibility="visible";a.constants.isLoading=false;a.settings.autoplay===true&&a.onClickPlay();typeof a.settings.onLoad=="function"&&a.settings.onLoad()}};a.onLoadJson=function(b){a.elements.script.parentNode.removeChild(a.elements.script);
if(b.photoset){for(var d in b.photoset.photo)b.photoset.photo[d].owner=b.photoset.owner;b.photos=b.photoset}if(b.stat&&b.stat=="fail"||!b.photos)throw"Flickrshow: "+(b.message||"There was an unknown error with the data returned by Flickr");a.constants.imageTotal=b.photos.photo.length;for(var c in b.photos.photo){d=document.createElement("img");d.setAttribute("data-flickr-title",b.photos.photo[c].title);d.setAttribute("data-flickr-photo_id",b.photos.photo[c].id);d.setAttribute("data-flickr-owner",
b.photos.photo[c].owner);d.setAttribute("rel",c);d.style.cursor="pointer";d.style.display="block";d.style.margin="0";d.style.padding="0";var e=a.elements.target.offsetHeight*a.elements.target.offsetWidth,f=b.photos.photo[c].height_z*b.photos.photo[c].width_z,h=b.photos.photo[c].height_m*b.photos.photo[c].width_m,j=b.photos.photo[c].height_s*b.photos.photo[c].width_s;if(!b.photos.photo[c].url_m)b.photos.photo[c].url_m=b.photos.photo[c].url_s;if(!b.photos.photo[c].url_z)b.photos.photo[c].url_z=b.photos.photo[c].url_m;
if(!b.photos.photo[c].url_l)b.photos.photo[c].url_l=b.photos.photo[c].url_z;d.src=e>f?b.photos.photo[c].url_l+"?"+a.constants.random:e>h?b.photos.photo[c].url_z+"?"+a.constants.random:e>j?b.photos.photo[c].url_m+"?"+a.constants.random:b.photos.photo[c].url_s+"?"+a.constants.random;e=document.createElement("li");e.style.left=c*a.elements.target.offsetWidth+"px";e.style.height=a.elements.target.offsetHeight+"px";e.style.margin="0";e.style.overflow="hidden";e.style.padding="0";e.style.position="absolute";
e.style.top="0";e.style.width=a.elements.target.offsetWidth+"px";e.appendChild(d);a.elements.images.appendChild(e);a.addEvent(d,"load",a.onLoadImage)}};a.onLoadWindow=function(){a.elements.target=typeof a.elements.target==="string"?document.getElementById(a.elements.target):a.elements.target;a.elements.target.innerHTML='<div class="flickrshow-container" style="background:transparent;height:'+a.elements.target.offsetHeight+"px;margin:0;overflow:hidden;padding:0;position:relative;width:"+a.elements.target.offsetWidth+
'px"><div class="flickrshow-loading" style="background:transparent url('+a.constants.base_url+'static/images/bg.png);border-radius:12px;height:24px;left:50%;margin:-12px 0 0 -120px;overflow:hidden;padding:0;position:absolute;top:50%;width:240px;-moz-border-radius:12px;-webkit-border-radius:12px"><div class="flickrshow-loading-bar" style="background:#000;border-radius:12px;height:24px;left:0;margin:0;padding:0;position:absolute;top:0;width:0;-moz-border-radius:12px;-webkit-border-radius:12px"></div></div><ul class="flickrshow-images" style="background:transparent;height:'+
a.elements.target.offsetHeight+"px;left:0;list-style:none;margin:0;padding:0;position:absolute;top:0;visibility:hidden;width:"+a.elements.target.offsetWidth+'px"></ul><div class="flickrshow-buttons" style="background:transparent url('+a.constants.base_url+"static/images/bg.png);height:40px;margin:0;padding:0;position:absolute;top:"+a.elements.target.offsetHeight+"px;width:"+a.elements.target.offsetWidth+'px"><div class="flickrshow-buttons-left" style="background:#000 url('+a.constants.base_url+'static/images/il.png) 50% 50% no-repeat;border-radius:12px;cursor:pointer;height:24px;left:auto;margin:0;padding:0;position:absolute;right:40px;top:8px;width:24px;-moz-border-radius:12px;-webkit-border-radius:12px"></div><div class="flickrshow-buttons-right" style="background:#000 url('+
a.constants.base_url+'static/images/ir.png) 50% 50% no-repeat;border-radius:12px;cursor:pointer;height:24px;left:auto;margin:0;padding:0;position:absolute;right:8px;top:8px;width:24px;-moz-border-radius:12px;-webkit-border-radius:12px"></div><div class="flickrshow-buttons-play" style="background:#000 url('+a.constants.base_url+'static/images/ip.png) 50% 50% no-repeat;border-radius:12px;cursor:pointer;height:24px;left:8px;margin:0;padding:0;position:absolute;right:auto;top:8px;width:24px;-moz-border-radius:12px;-webkit-border-radius:12px"></div><p class="flickrshow-buttons-title" style="background:#000;border-radius:12px;color:#FFF;cursor:pointer;font:normal normal 600 11px/24px helvetica,arial,sans-serif;height:24px;left:40px;margin:0;overflow:hidden;padding:0 0;position:absolute;right:auto;text-align:center;text-shadow:none;text-transform:capitalize;top:8px;width:'+
(a.elements.target.offsetWidth-112)+'px;-moz-border-radius:12px;-webkit-border-radius:12px">&nbsp;</p></div></div>';a.elements.container=a.elements.target.childNodes[0];a.elements.buttons=a.elements.target.childNodes[0].childNodes[2];a.elements.images=a.elements.target.childNodes[0].childNodes[1];a.elements.loading=a.elements.target.childNodes[0].childNodes[0];if(false===a.settings.hide_buttons){a.addEvent(a.elements.images,"click",a.toggleButtons);a.addEvent(a.elements.container,"mouseover",a.showButtons);
a.addEvent(a.elements.container,"mouseout",a.hideButtons);a.addEvent(a.elements.buttons.childNodes[0],"click",a.onClickLeft);a.addEvent(a.elements.buttons.childNodes[1],"click",a.onClickRight);a.addEvent(a.elements.buttons.childNodes[2],"click",a.onClickPlay);a.addEvent(a.elements.buttons.childNodes[3],"click",a.showFlickr)}window["flickrshow_jsonp_"+a.constants.random]=a.onLoadJson;a.elements.script=document.createElement("script");a.elements.script.async=true;a.elements.script.src=a.addUrl("flickrshow_jsonp_"+
a.constants.random);(document.getElementsByTagName("head")[0]||document.getElementsByTagName("body")[0]).appendChild(a.elements.script)};a.hideButtons=function(){if(!(a.constants.isLoading===true||a.constants.isButtonsOpen===false)){a.constants.isButtonsOpen=false;a.animate(a.elements.buttons,"top",a.elements.target.offsetHeight,a.constants.speed,"buttons")}};a.showButtons=function(){if(!(a.constants.isLoading===true||a.constants.isButtonsOpen===true)){a.constants.isButtonsOpen=true;a.animate(a.elements.buttons,
"top",a.elements.target.offsetHeight-40,a.constants.speed,"buttons")}};a.toggleButtons=function(){a.constants.isButtonsOpen===true?a.hideButtons():a.showButtons()};a.showFlickr=function(){var b=a.elements.images.childNodes[a.constants.imageCurrent].childNodes[0];if("undefined"!==typeof b)window.location="http://www.flickr.com/photos/"+b.getAttribute("data-flickr-owner")+"/"+b.getAttribute("data-flickr-photo_id")+"/"};a.showTitle=function(){var b=a.elements.images.childNodes[a.constants.imageCurrent].childNodes[0];
if("undefined"!==typeof b)a.elements.buttons.childNodes[3].innerHTML=a.constants.imageCurrent+1+"/"+a.constants.imageTotal+" - "+b.getAttribute("data-flickr-title")};a.constants={base_url:"http://www.flickrshow.com/",intervals:[],imageCurrent:0,imageLoaded:0,imageTotal:0,isButtonsOpen:false,isLoading:true,isPlaying:false,random:Math.floor(Math.random()*999999999999),speed:100};a.elements={buttons:null,button1:null,button2:null,button3:null,button4:null,container:null,images:null,loading:null,script:null,
target:null};a.settings={autoplay:false,gallery:null,group:null,hide_buttons:false,interval:3000,license:"1,2,3,4,5,6,7",onLoad:null,onMove:null,onPlay:null,onPause:null,page:"1",person:null,per_page:"50",set:null,tags:null,user:null};a.elements.target=i;for(var k in a.settings)if("undefined"!==typeof g[k])a.settings[k]=g[k];if("undefined"!==typeof g.flickr_group)a.settings.group=g.flickr_group;if("undefined"!==typeof g.flickr_photoset)a.settings.set=g.flickr_photoset;if("undefined"!==typeof g.flickr_tags)a.settings.tags=
g.flickr_tags;if("undefined"!==typeof g.flickr_user)a.settings.user=g.flickr_user;a.addEvent(window,"load",a.onLoadWindow);return{constants:a.constants,elements:a.elements,settings:a.settings,left:a.onClickLeft,right:a.onClickRight,play:a.onClickPlay}}if(typeof window.jQuery!="undefined")window.jQuery.fn.flickrshow=function(i){return new flickrshow(window.jQuery(this)[0],i)};

