/* All code is Copyright 2007 Hans Schmucker and provided under the CC Attribute-ShareAlike license. http://creativecommons.org/licenses/by-sa/3.0/ */
			var glb={};
			var js={};
				
			js.encapsulate=function(fc,data){
				return (function(){fc(data,arguments);});
			}

			js.timetween=function(callback,totaltime, se, adparam){
				var animdata={};
				animdata.totaltime=totaltime;
				animdata.callback=callback;
				
				animdata.startvals=[];
				animdata.range=[];
				animdata.endvals=[];
				animdata.param=adparam;

				for(var i=0;i<se.length;i++){
					animdata.startvals.push(se[i][0]);
					animdata.range.push(se[i][1]-se[i][0]);
					animdata.endvals.push(se[i][1]);
				}
				
				var loop=null;
				loop=function(data,adparamsi){
					if(data.time>=data.totaltime) data.callback(data.endvals,true,data.param);
					else{
						var vals=[];
						var p=data.time/data.totaltime;
						for(var i=0;i<data.startvals.length;i++)
							vals.push(data.startvals[i]+data.range[i]*p);

						data.callback(vals,false,data.param);
						data.time=(new Date()).getTime()-data.start;
						window.setTimeout(js.encapsulate(function(d,a){ loop(d,a);} ,data),0);
					}
					
				}
				animdata.start=(new Date()).getTime();
				animdata.time=0;
				loop(animdata);
			}
			
			js.addEventListener=function(obj,type,callback){
				if(obj.addEventListener!=undefined) obj.addEventListener(type,callback,false);
				else if(obj.attachEvent!=undefined) obj.attachEvent("on"+type,callback);
				else{
					var o=obj["on"+type];
					obj["on"+type]=(o?function(evt){o(evt);callback(evt);}:callback);
				}
			}
			
			js.getElementsByClass=function(tag, name) {
				var cloud = document.getElementsByTagName(tag);
				var res = [];
				for(var i=0; i<cloud.length; i++) if(cloud[i].className == name) res.push(cloud[i]);
				return res;
			}
			
			js.imagesLoaded=function(parent){
				var cloud=parent.getElementsByTagName("img");
				for(var i=0;i<cloud.length;i++) if(!(cloud[i].complete || cloud[i].error)) return false;
				return true;
			}

			
			function elementSetOpacity(percs,end,param){
				var el=param.el;
				if(el.style.filter!=undefined) el.style.filter="alpha(opacity="+percs[0]+")";
				else el.style.opacity=percs[0]/100;
				
				if(end) param.onend(param.slideshow);
			}
			
			function elementFade(el,time,onend,sl){
				
				js.timetween(elementSetOpacity,time, [[100,0]],{"el":el,"onend":onend,"slideshow":sl});
			}
			
			function slideshowFade(slideshow){
				if(!slideshow.next.complete) slideshow.next.complete=js.imagesLoaded(slideshow.next.node);
				
				if(!slideshow.next.complete){
					var imgs=slideshow.next.node.getElementsByTagName("img");
					slideshow.next.done=false;
					for(var i=0;i<imgs.length;i++){
						js.addEventListener(imgs[i],"load",js.encapsulate(function(sl){
							if(sl.next.done) return;
							
							sl.next.complete=js.imagesLoaded(sl.next.node);
							if(sl.next.complete){
								sl.next.done=true;
								elementFade(sl.fadingnode.node,sl.blendtime,sl.ondone,sl);
							}
							
						},slideshow));
					}
				}else elementFade(slideshow.fadingnode.node,slideshow.blendtime,slideshow.ondone,slideshow);

			}
			
			
			
			function slideshowRotate(slideshow){
				slideshow.busy=false;
				slideshowGoto(slideshow,(slideshow.current+1)%slideshow.childNodes.length);
			}
			
			function hoverDone(slideshow){
				slideshow.busy=false;
				slideshow.active=(slideshow.current?true:false);
				if(slideshow.active!=slideshow.activeDest) slideshowGoto(slideshow,(slideshow.activeDest?1:0))
			}
			
			function slideshowGoto(slideshow,frame){
				var next=slideshow.childNodes[frame];
				var current=slideshow.childNodes[slideshow.current];
				
				slideshow.container.appendChild(next.node);
				slideshow.container.appendChild(current.node);
				
				elementSetOpacity([100],false,{"el":next.node});
				elementSetOpacity([100],false,{"el":current.node});
				next.node.style.display="block";
				current.node.style.display="block";
				
				slideshow.next=next;
				slideshow.fadingnode=current;
				slideshow.busy=true;
				slideshow.current=frame;
				window.setTimeout(
					js.encapsulate(function(sl){
						slideshowFade(slideshow);
					},slideshow)
				,slideshow.disptime);
				
			}
			
			function setupRotation(blendTime,displayTime){
				var els=js.getElementsByClass("div","rotImg");
				var wels=js.getElementsByClass("div","rotImgWrap");
				if(!els || els.length==0 || !wels || wels.length==0) return;

				glb.slideshows=[];
				
				for(var i=0;i<wels.length;i++){
					wels[i].style.border="none";
					wels[i].style.overflow="hidden";
					wels[i].parentNode.className="rotImgFading";
					glb.slideshows.push({"current":0,"container":wels[i],"childNodes":[],"blendtime":blendTime,"disptime":displayTime,"ondone":slideshowRotate});
				}
				
				for(var i=0;i<els.length;i++){
					for(var j=0;j<glb.slideshows.length;j++){
						if(els[i].parentNode==glb.slideshows[j].container) glb.slideshows[j].childNodes.push({"node":els[i],"complete":false});
					}
				}
				
				for(var i=0;i<glb.slideshows.length;i++){
					for(var j=0;j<glb.slideshows[i].childNodes.length;j++){
						glb.slideshows[i].childNodes[j].node.style.display="none";
						glb.slideshows[i].childNodes[j].node.style.position="absolute";
						glb.slideshows[i].childNodes[j].node.style.left="0px";
						glb.slideshows[i].childNodes[j].node.style.top="0px";
					}
					slideshowRotate(glb.slideshows[i]);
				}
			}
			
			function setupHoverButtons(blendTime){
				var els=js.getElementsByClass("div","rotImgHover");
				if(!els || els.length==0) return;

				glb.hovers=[];
				
				for(var i=0;i<els.length;i++){
					var hover={"current":0,"container":els[i],"childNodes":[],"blendtime":blendTime,"ondone":hoverDone};
					var inactive=document.createElement("div");
					for(var j=0;j<hover.container.childNodes.length;j++){
						inactive.appendChild(hover.container.childNodes[j].cloneNode(true));
					}
					for(;hover.container.childNodes.length!=0;){
						hover.container.removeChild(hover.container.firstChild);
					}
					var active=inactive.cloneNode(true);
					var imgCloud=active.getElementsByTagName("img");
					for(var j=0;j<imgCloud.length;j++){
						imgCloud[j].setAttribute("src",imgCloud[j].getAttribute("src").replace(/mouseout/g, "mouseover"));
					}
					inactive.style.display="block";
					active.style.display="none";
					hover.container.appendChild(inactive);
					hover.container.appendChild(active);
					hover.active=false;
					hover.activeDest=false;
					hover.childNodes.push({"node":inactive,"complete":false});
					hover.childNodes.push({"node":active,"complete":false});
					
					for(var j=0;j<hover.childNodes.length;j++){
						hover.childNodes[j].node.style.position="absolute";
						hover.childNodes[j].node.style.left="0px";
						hover.childNodes[j].node.style.top="0px";
					}
					
					
					js.addEventListener(hover.container,"mouseover",js.encapsulate(function(data){
						data.hover.activeDest=data.active;
						
						if(!data.hover.busy && data.hover.active!=data.hover.activeDest){
							slideshowGoto(data.hover,(data.hover.activeDest?1:0));
						}
					},{"hover":hover,"active":true}));
					
					js.addEventListener(hover.container,"mouseout",js.encapsulate(function(data){
						data.hover.activeDest=data.active;
						if(!data.hover.busy && data.hover.active!=data.hover.activeDest) slideshowGoto(data.hover,(data.hover.activeDest?1:0));
					},{"hover":hover,"active":false}));
					
					glb.hovers.push(hover);
				}
			
			}
			
			
