var flickrshows=[],flickrshow=function(e,f){
	var c=this;
	c.animate=function(m,i,k,l,h){
		if("undefined"!==typeof c.constant.intervals[h]){
			clearInterval(c.constant.intervals[h]);
		}
		c.constant.intervals[h]=setInterval(function(){
			var n=Math.round(m.style[i].replace(/([a-zA-Z]{2})$/,""));
			var j=Math.round(k-n);
			if((Math.abs(j))>1){
				m.style[i]=Math.floor(n+(j/2))+"px";
			}
			else{
				m.style[i]=k+"px";
				clearInterval(c.constant.intervals[h]);
			}
		}
		,l/1.5);
	};
	c.addEvent=function(j,h,i){
		if(j.attachEvent){
			j["e"+h+i]=i;
			j[h+i]=function(){
				j["e"+h+i](window.event,j);
			};
			j.attachEvent("on"+h,j[h+i]);
		}
		else{
			j.addEventListener(h,i,false);
		}
	};
	c.hideButtons=function(){
		if((c.constant.isLoading===true)||(c.constant.isButtonsOpen===false)){return;}
		c.constant.isButtonsOpen=false;
		c.animate(c.elements.b,"top",c.elements.t.offsetHeight,c.settings.speed,"b");
	};
	c.showButtons=function(){
		if((c.constant.isLoading===true)||(c.constant.isButtonsOpen===true)){return;}
		c.constant.isButtonsOpen=true;
		c.animate(c.elements.b,"top",c.elements.t.offsetHeight-40,c.settings.speed,"b");
	};
	c.updateDeets=function(){
		var h=c.elements.i.childNodes[c.constant.imageCurrent].childNodes[0];
		if("undefined"===typeof h){return;}
		c.elements.b.childNodes[3].innerHTML=(c.constant.imageCurrent+1)+"/"+c.constant.imageTotal+" - "+h.getAttribute("flickrshow-t");
	};
	c.left=function(){
		if(c.constant.isLoading===true){return;}
		c.constant.imageCurrent=((c.constant.imageCurrent-1)<0)?c.constant.imageTotal-1:c.constant.imageCurrent-1;
		c.animate(c.elements.i,"left","-"+(c.constant.imageCurrent*c.elements.t.offsetWidth),c.settings.speed,"i");
		c.updateDeets();
	};
	c.right=function(){
		if(c.constant.isLoading===true){return;}
		c.constant.imageCurrent=((c.constant.imageCurrent+2)>c.constant.imageTotal)?0:c.constant.imageCurrent+1;
		c.animate(c.elements.i,"left","-"+(c.constant.imageCurrent*c.elements.t.offsetWidth),c.settings.speed,"i");
		c.updateDeets();
	};
	c.play=function(){
		if(c.constant.isPlaying===false){
			c.constant.isPlaying=true;
			c.elements.b.childNodes[2].style.backgroundImage="url("+c.constant.uri1+"sites/all/files/iframes/slideshow_themes/"+c.settings.theme+"/is.png)";
			c.constant.intervals.p=setInterval(function(){
				c.right();
			},
			c.settings.interval);
		}
		else{
			c.constant.isPlaying=false;
			c.elements.b.childNodes[2].style.backgroundImage="url("+c.constant.uri1+"sites/all/files/iframes/slideshow_themes/"+c.settings.theme+"/ip.png)";
			clearInterval(c.constant.intervals.p);
		}
	};
	c.jsonLoad=function(){
		if("object"!==typeof flickrshows[c.constant.unique]){return;}
		clearInterval(c.constant.intervals.json);
		if("undefined"!==typeof flickrshows[c.constant.unique]["error"]){
			c.elements.w.innerHTML='<p style="color:#A00;font:normal normal 400 12px/18px helvetica,arial,sans-serif;left:0;margin:0;padding:0;posiiton:absolute;text-align:center;top:0;width:100%">'+flickrshows[c.constant.unique]["error"]+"</p>";
		}
		else{
			c.constant.imageTotal=flickrshows[c.constant.unique].length;
			for(var k in flickrshows[c.constant.unique]){
				var j=document.createElement("img");
				j.setAttribute("flickrshow-t",flickrshows[c.constant.unique][k].title);
				j.setAttribute("flickrshow-u",flickrshows[c.constant.unique][k].url);
				j.setAttribute("rel",k);
				j.style.cursor="pointer";
				j.style.display="block";
				j.style.margin="0";
				j.style.padding="0";
				j.src=flickrshows[c.constant.unique][k].src_m;
				/*if((c.elements.t.offsetHeight>500)||(c.elements.t.offsetWidth>500)){
					j.src=flickrshows[c.constant.unique][k].src_m;
				}
				else{
					if((c.elements.t.offsetHeight<240)||(c.elements.t.offsetWidth<240)){
						j.src=flickrshows[c.constant.unique][k].src_s;
					}
					else{
						j.src=flickrshows[c.constant.unique][k].src_m;
					}
				}*/
				var h=document.createElement("li");
				h.style.left=(k*c.elements.t.offsetWidth)+"px";
				h.style.height=c.elements.t.offsetHeight+"px";
				h.style.margin="0";
				h.style.overflow="hidden";
				h.style.padding="0";
				h.style.position="absolute";
				h.style.top="0";
				h.style.width=c.elements.t.offsetWidth+"px";
				h.appendChild(j);
				c.elements.i.appendChild(h);
				c.addEvent(j,"click",function(r,o){
					var n=(("undefined"!==typeof o)?o:r.target),m=n.offsetWidth,q=n.offsetHeight,p,l;
					//document.location.href=n.getAttribute("flickrshow-u");
					window.open(n.getAttribute("flickrshow-u"));
				});
				c.addEvent(j,"load",function(s,p){
					var n=(("undefined"!==typeof p)?p:s.target),m=n.offsetWidth,r=n.offsetHeight,q,l,o;
					if(m>r){
						l=c.elements.t.offsetWidth+(c.elements.t.offsetHeight/100);
						q=Math.ceil((l/m)*r);
					}
					else{
						q=c.elements.t.offsetHeight+(c.elements.t.offsetHeight/100);
						l=Math.ceil((q/r)*m);}n.style.height=q+"px";
						n.style.left=Math.round((c.elements.t.offsetWidth-l)/2)+"px";
						n.style.position="absolute";
						n.style.top=Math.round((c.elements.t.offsetHeight-q)/2)+"px";
						n.style.width=l+"px";
						c.constant.imageLoaded++;
						o=Math.round((c.constant.imageLoaded/c.constant.imageTotal)*240);
						c.animate(c.elements.l.childNodes[0],"width",((o<=36)?36:o),"i");
						if(c.constant.imageLoaded===c.constant.imageTotal){
							c.showLoad();
						}
					}
				);
			}
		}
	};
	c.showLoad=function(){
		c.updateDeets();
		c.elements.w.removeChild(c.elements.l);
		c.elements.i.style.visibility="visible";
		c.constant.isLoading=false;
		if(c.settings.autoplay===true){
			c.play();
		}
	};
	c.constant={
		intervals:[],imageCurrent:0,imageLoaded:0,imageTotal:0,isButtonsOpen:false,isLoading:true,isPlaying:false,unique:Math.round(Math.random()*1000000000000),uri:"http://v7.flickrshow.com/",uri1:"http://www.350.org/"
	};
	c.elements={
		b:null,i:null,l:null,t:null,w:null
	};
	c.settings={
		autoplay:false,group:"",hide_buttons:false,interval:3000,page:"1",per_page:"50",set:"",speed:100,tags:"",theme:"black",user:""
	};
	c.elements.t=document.getElementById(e);
	for(var d in c.settings){
		if("undefined"!==typeof f[d]){
			c.settings[d]=f[d];
		}
	}
	var a,g;
	switch(c.settings.theme){
		case"white":
			ca="#FFF";
			cb="#EEE";
			cc="#DDD";
			cd="#111";
		break;
		case"denali":
			ca="#556675";
			cb="#E7E9F3";
			cc="#303941";
			cd="#556675";
		break;
		default:
			ca="#000";/*circls with buttons color*/
			cb="#111";/*progress background color*/
			cc="#222";/*progress filler color*/
			cd="#FFF";/*text color*/
		break;
	}
	c.elements.t.innerHTML='<div id="'+e+'-fs-w" style="background:transparent;height:'+c.elements.t.offsetHeight+"px;margin:0;overflow:hidden;padding:0;position:relative;width:"+c.elements.t.offsetWidth+'px"><div id="'+e+'-fs-l" style="background:'+cb+';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 id="'+e+'-fs-l-b" style="background:'+cc+';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 id="'+e+'-fs-i" style="background:transparent;height:'+c.elements.t.offsetHeight+"px;left:0;list-style:none;margin:0;padding:0;position:absolute;top:0;visibility:hidden;width:"+c.elements.t.offsetWidth+'px"></ul><div id="'+e+'-fs-b" style="background:transparent url('+c.constant.uri1+"sites/all/files/iframes/slideshow_themes/"+c.settings.theme+"/b2.png);height:40px;margin:0;padding:0;position:absolute;top:"+c.elements.t.offsetHeight+"px;width:"+c.elements.t.offsetWidth+'px"><div id="'+e+'-fs-b-l" style="background:'+ca+" url("+c.constant.uri1+"sites/all/files/iframes/slideshow_themes/"+c.settings.theme+'/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 id="'+e+'-fs-b-r" style="background:'+ca+" url("+c.constant.uri1+"sites/all/files/iframes/slideshow_themes/"+c.settings.theme+'/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 id="'+e+'-fs-b-p" style="background:'+ca+" url("+c.constant.uri1+"sites/all/files/iframes/slideshow_themes/"+c.settings.theme+'/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 id="'+e+'-fs-b-d" style="background:transparent url('+c.constant.uri1+"sites/all/files/iframes/slideshow_themes/"+c.settings.theme+"/b0.png);border-radius:12px;color:"+cd+";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:"+(c.elements.t.offsetWidth-112)+'px;-moz-border-radius:12px;-webkit-border-radius:12px">Title Goes Here</p></div></div>';
	c.elements.w=c.elements.t.childNodes[0];
	c.elements.l=c.elements.t.childNodes[0].childNodes[0];
	c.elements.i=c.elements.t.childNodes[0].childNodes[1];
	c.elements.b=c.elements.t.childNodes[0].childNodes[2];
	if(false===c.settings.hide_buttons){
		c.addEvent(c.elements.t,"mouseover",function(h){
			c.showButtons();
		});
		c.addEvent(c.elements.t,"mouseout",function(h){
			c.hideButtons();
		});
		c.addEvent(c.elements.b.childNodes[0],"click",function(h){
			c.left();
		});
		c.addEvent(c.elements.b.childNodes[1],"click",function(h){
			c.right();
		});
		c.addEvent(c.elements.b.childNodes[2],"click",function(h){
			c.play();
		});
	}
	var b=document.createElement("script");
	b.type="text/javascript";
	b.src=c.constant.uri+"php/json.php?group="+c.settings.group+"&page="+c.settings.page+"&per_page="+c.settings.per_page+"&set="+c.settings.set+"&tags="+c.settings.tags+"&user="+c.settings.user+"&unique="+c.constant.unique;
	(document.getElementsByTagName("head")[0]||document.getElementsByTagName("body")[0]).appendChild(b);
	c.constant.intervals.json=setInterval(function(){
		c.jsonLoad();
	}
	,100);
	return{
		play:function(){
			c.play();
		}
		,left:function(){
			c.left();
		}
		,right:function(){
			c.right();
		}
	};
};
