/* (c) Kalamun 2009 - GPL 3 */

k_Photogallery=function() {
	var currentImg=0;
	var container=false;
	var fader=false;
	var Timer=false;
	var show="true";
	var imgs=Array();
	var telecomando=null;
	var prev=null;
	var pause=null;
	var play=null;
	var next=null;

	this.setContainer=function(c) {
		container=document.getElementById(c);
		}

	this.init=function() {
		fader=document.createElement('DIV');
		fader.style.background="#fff";
		fader.style.position="absolute";
		fader.style.top="0";
		fader.style.left="0";
		fader.style.opacity=1;
		fader.style.zIndex="60";
		fader.style.width="685px";
		fader.style.height="400px";
		container.appendChild(fader);
		telecomando=document.createElement('DIV');
		telecomando.style.background="#fff";
		telecomando.style.position="absolute";
		telecomando.style.top="160px";
		telecomando.style.left="320px";
		telecomando.style.padding="5px";
		telecomando.style.zIndex="61";
		prev=document.createElement('IMG');
		prev.src=BASEDIR+'img/prev.gif';
		prev.style.display='inline';
		prev.onclick=slidePrev;
		play=document.createElement('IMG');
		play.src=BASEDIR+'img/play.gif';
		play.style.display='none';
		play.onclick=slidePlay;
		pause=document.createElement('IMG');
		pause.src=BASEDIR+'img/pause.gif';
		pause.style.display='inline';
		pause.onclick=slidePause;
		next=document.createElement('IMG');
		next.src=BASEDIR+'img/next.gif';
		next.style.display='inline';
		next.onclick=slideNext;
		telecomando.appendChild(prev);
		telecomando.appendChild(play);
		telecomando.appendChild(pause);
		telecomando.appendChild(next);
		telecomando.style.display="none";
		container.appendChild(telecomando);
		container.onmouseover=function() { telecomando.style.display="block"; }
		container.onmouseout=function() { telecomando.style.display="none"; }
		imgs=container.getElementsByTagName('li');
		for(var i=0;imgs[i];i++) {
			imgs[i].style.position="absolute";
			imgs[i].style.top=0;
			imgs[i].style.left=0;
			imgs[i].style.display="none";
			}
		if(imgs.length>0) {
			Timer=setInterval(this.showImg,50);
			}
		}

	this.showImg=function() {
		var i=currentImg;
		var o=0;
		imgs[i].style.display="block";
		if(show=="true") var o=parseFloat(fader.style.opacity)-0.05;
		else if(show=="false") var o=parseFloat(fader.style.opacity)+0.05;
		if(o>1) o=1;
		else if(o<0) o=0;
		fader.style.opacity=o;
		fader.style.MozOpacity=o;
		fader.style.KhtmlOpacity=o;
		fader.style.filter="alpha(opacity="+o*100+")"; 
		if(show=="true"&&o<=0) {
			show="pause";
			if(imgs.length<=1) clearInterval(Timer);
			setTimeout(function() { show="false"; },3000);
			}
		else if(show=="false"&&o>=1) {
			imgs[i].style.display="none";
			currentImg++;
			if(currentImg>imgs.length-1) currentImg=0;
			show="true";
			}
		}
	var showImg=this.showImg;
		
	slidePause=function() {
		show="pause";
		play.style.display="inline";
		pause.style.display="none";
		
		var i=currentImg;
		var o=0;
		imgs[i].style.display="block";
		fader.style.opacity=o;
		fader.style.MozOpacity=o;
		fader.style.KhtmlOpacity=o;
		fader.style.filter="alpha(opacity="+o*100+")"; 
		if(Timer!=false) clearInterval(Timer);
		}
	slidePlay=function() {
		show="false";
		Timer=setInterval(showImg,50);
		play.style.display="none";
		pause.style.display="inline";
		}
	slidePrev=function() {
		if(Timer!=false) clearInterval(Timer);
		currentImg--;
		if(currentImg<0) currentImg=imgs.length-1;
		show="false";
		for(var i=0;imgs[i];i++) {
			imgs[i].style.display="none";
			}
		var i=currentImg;
		imgs[i].style.display="block";
		var o=0;
		fader.style.opacity=o;
		fader.style.MozOpacity=o;
		fader.style.KhtmlOpacity=o;
		fader.style.filter="alpha(opacity="+o*100+")"; 
		slidePause();
		}
	slideNext=function() {
		if(Timer!=false) clearInterval(Timer);
		currentImg++;
		if(currentImg>imgs.length-1) currentImg=0;
		show="false";
		for(var i=0;imgs[i];i++) {
			imgs[i].style.display="none";
			}
		var i=currentImg;
		imgs[i].style.display="block";
		var o=0;
		fader.style.opacity=o;
		fader.style.MozOpacity=o;
		fader.style.KhtmlOpacity=o;
		fader.style.filter="alpha(opacity="+o*100+")"; 
		slidePause();
		}
	}

var imgPlayer=Array();