//--------------------------- ver 1.0
function multiImg(name) {
	var preloadedImages=new Array();
	var imgLinks=new Array();
	var klen=0;
	var activeIndex=0,prevIndex=0;
	var imgID,aID,interval,iefix=false;
	var img_interval;
	var selfname=name;
	var playbtn;
	var numberlinks;
	var btn_play=new Image(); btn_play.src="images/play.png";
	var btn_pause=new Image(); btn_pause.src="images/pause.png";
	var bottomImg,effect;
	this.hasButtons=true;
	// set params main img id, <a> id, play/pause btn id, timeout between images
	this.set=function(imgid,aid,playbtnid,timeout,nmbrlnks){
		imgID=imgid;
		aID=aid;
		interval=timeout;
		playbtn=playbtnid;
		numberlinks=nmbrlnks
	}
	this.addImage=function(imgsrc,imglink){
		preloadedImages[klen]=new Image();
		imgLinks[klen]=imglink;
		preloadedImages[klen++].src=imgsrc;
		
	}
	this.setNextImage=function(){
		prevIndex=activeIndex;
		activeIndex++;
		if(activeIndex==klen)
			activeIndex=0;
		this.switchActiveImage(activeIndex);
	}
	this.setPrevImage=function(){
		prevIndex=activeIndex;
		activeIndex--;
		if(activeIndex<0)
			activeIndex=klen-1;
		this.switchActiveImage(activeIndex);
	}
	// function to use for a next button
	this.gotoNext=function(){
		this.setNextImage();
		if(img_interval) this.pause();
	}
	// function to use for a prev button
	this.gotoPrev=function(){
		this.setPrevImage();
		if(img_interval) this.pause();
	}
	this.switchActiveImage=function(num){
		var img=document.getElementById(imgID);
		if(!bottomImg){
			bottomImg=document.createElement("IMG");
			if(bottomImg.style){
				bottomImg.style.position="absolute";
				bottomImg.style.left="0px";
				bottomImg.style.top="0px";
				bottomImg.style.zIndex=6;
			}else bottomImg.setAttribute("style","position:absolute;left:0px;top:0px;z-index:1");
			bottomImg.width=img.width;
			bottomImg.height=img.height;
			img.parentNode.appendChild(bottomImg);
			effect=new Fx.Morph(bottomImg,{duration: parseInt(interval/5), transition: Fx.Transitions.linear,
				onComplete: function(){
					bottomImg.src=preloadedImages[activeIndex].src;
					this.set({"opacity":1});
				}});
			bottomImg.src=preloadedImages[0].src;
			effect.set({"opacity":1});
		}
		img.src=preloadedImages[num].src;
		effect.start({"opacity":0});
		document.getElementById(aID).href=imgLinks[num];
		if(this.hasButtons){
			document.getElementById(numberlinks+prevIndex).className="multiimgnumlinkNotActive";
			document.getElementById(numberlinks+num).className="multiimgnumlinkActive";
		}
	}
	// function to use for select num btns
	this.setActiveNum=function(num){
		if(activeIndex!=num){
			prevIndex=activeIndex;
			this.switchActiveImage(num);
			activeIndex=num;
			if(img_interval) this.pause();
		}
	}
	this.start=function(){
		if(klen>1){
			img_interval=setInterval(selfname+".setNextImage()",interval);
			this.switchBtn_to("pause");
		}
	}
	this.pause=function(){
		if(img_interval){
			clearInterval(img_interval);
			img_interval=null;
			this.switchBtn_to("play");
		}else this.start();
	}
	//_private function
	this.switchBtn_to=function(state){
		if(this.hasButtons){
			if(state=="play"){
				if(iefix)
					document.getElementById(playbtn).style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+btn_play.src+"',sizingMethod='scale')";
				else
					document.getElementById(playbtn).src=btn_play.src;
			}else{
				var playbtnX=document.getElementById(playbtn);
				if(playbtnX){
					if(iefix)
						playbtnX.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+btn_pause.src+"',sizingMethod='scale')";
					else
						playbtnX.src=btn_pause.src;
				}
			}
		}
	}
	// function to turn on ie png fix for play/pause button if we use png images
	this.useIEpng_btnfix=function(){
		var arVersion = navigator.appVersion.split("MSIE");
		var version = parseFloat(arVersion[1]);
		if((version >= 5.5) && (document.body.filters)){
			iefix=true;
		}
	}
}
