
function kcseffect(){
  var image='';
  var images=[];
  var current=0;
  var ie=document.all ? true : false;
  var container='';
  var zoomFunc=0;
  var fadeFunc=0;  	  	
  var scale=1.15;
  var maxWidth=0;
  var factor=0;
  var sz=0;
  var resizeSpeed=70;
  var fadeSpeed=70;
  
  this.setContainer=function(div){
	  container=div;
  };
  
  this.setScale=function(scl){
	  scale=scl;
  };
  
  this.setResizeSpeed=function(speed){
	  resizeSpeed=speed;
  };
  
  this.setFadeSpeed=function(speed){
	  fadeSpeed=speed;
  };
  
  this.addImage = function(img){
	var i=new Image();
	i.src=img;
	images.push(i);
  };
	
  function wait(delay){
	var start=new Date().getTime();
	var cur=start;
	while((cur - start) < delay){
	  cur=new Date().getTime();
	}
  }  
	
  function swap(){
	current++;
	if(current>(images.length-1))
	  current=0;
	if((current+1)>(images.length-1))
	  container.style.backgroundImage="url('"+images[0].src+"')";
	else{
      container.style.backgroundImage="url('"+images[current+1].src+"')";
	}
	container.removeChild(image);
	image=document.createElement('img');
	  	
	image.src=images[current].src;
	image.style.width=images[current].width+"px";
	image.style.height=images[current].height+"px";	
	if(ie)
	  image.style.filter="alpha(opacity=100)";
	else
	  image.style.opacity="1.0";	  
	
	maxWidth=(parseInt(images[current].width)*scale);
	factor=images[current].height/images[current].width;
	container.appendChild(image);
	zoomFunc=window.setInterval(zoom,resizeSpeed);	
  }
	  
  function fade(){
    var opacity;
	if(ie){
	  opacity=image.style.filter;
	  opacity=opacity.split("=")[1];
	  
	  opacity=parseInt(opacity.split(")")[0]);
	  opacity-=20;
	  
	  image.style.filter="alpha(opacity="+opacity+")";
	  if(opacity<1){
		window.clearInterval(fadeFunc);					  			  				
	    swap();
	  }
	} else {
	  opacity=image.style.opacity;
	  opacity-=0.2;
	  image.style.opacity=opacity;
	  if(opacity<0.1){
	    window.clearInterval(fadeFunc);					  			  				
		swap();
	  }  
	}
  }
	  
  function zoom(){
	var width=parseInt(image.style.width);
	var newImage;
	if(width<maxWidth){	
	  image.style.width=(width+1)+"px";
	  image.style.height=(parseInt(image.style.width)*factor)+"px";
	  
      /*window.clearInterval(zoomFunc);
	  newImage=document.createElement('img');
	  newImage.src=image.src;
	  newImage.style.width=(width+2)+"px";
	  newImage.style.height=(parseInt(newImage.style.width)*factor)+"px";
	  container.removeChild(image);
	  image=newImage;
	  container.appendChild(image);
	  //zoomFunc=window.setInterval(zoom, resizeSpeed);*/
	} else {
	  window.clearInterval(zoomFunc);
	  fadeFunc=window.setInterval(fade,fadeSpeed);		  		
	}
  }
	  
  this.beginZoom = function (){
	if(container.nodeName!='DIV')
      container=document.getElementById('zoom');

	image=document.createElement('img');
	    	  
	image.src=images[current].src;
	image.style.width=images[current].width+"px";
	image.style.height=images[current].height+"px";
	maxWidth=(parseInt(images[current].width)*scale);
	  
	if(ie){
	  image.style.filter="alpha(opacity=100)";
	}else {
	  image.style.opacity="1.0";
	}
	  
	if((current+1)>(images.length-1))
	  container.style.backgroundImage="url('"+images[0].src+"')";
	else	  
	  container.style.backgroundImage="url('"+images[current+1].src+"')";
	container.appendChild(image);
    factor=images[current].height/images[current].width;
    zoomFunc=window.setInterval(zoom,resizeSpeed);	  
  };
}
