/* 
 * 
/*--------------------------------------------------------------------------*/
function slideshow(arg){
	/*
	{
		"coveringPhotoId" : str_id,
		"bgPhotoId" : str_id,
		"srcPhotoAry" : [ary]
	}
	*/
	var self = this;
	var doc = document;
	this.fadeLock = false;
	this.counter = 1;/*set 0, if you want the leisure!*/
	
	this.coveringPhotoId = arg.coveringPhotoId;
	this.bgPhotoId = arg.bgPhotoId;
	this.srcPhotoAry = arg.srcPhotoAry;
	
	this.init = function(){
		doc.getElementById(self.bgPhotoId).style.backgroundPosition = 'left top';
		doc.getElementById(self.bgPhotoId).style.backgroundRepeat = 'no-repeat';
		doc.getElementById(self.bgPhotoId).style.backgroundImage = "url('" + self.srcPhotoAry[0] + "')";
		var getCache = function(){
			var tmpAry = new Array();
			for(var i=0,n=self.srcPhotoAry.length; i<n; i++){
				tmpAry['pic' + i] = new Image();
				tmpAry['pic' + i].src = self.srcPhotoAry[i];
			}
		}
		getCache();
	}
	this.changePic = function(num){
		if(!self.fadeLock){
			self.fadeLock = true;
			self.coveringPhoto.start(num);
		}
	}
	this.coveringPhoto = {
		"opacity" : 0,
		"timeId" : '',
		"start" : function(num){
			doc.getElementById(self.coveringPhotoId).src = self.srcPhotoAry[num];
			self.coveringPhoto.fadeIn();
		},
		"fadeIn" : function(){
			if(self.coveringPhoto.opacity >= 100){
				clearTimeout(self.coveringPhoto.timeId);
				self.fadeLock = false;
				self.bgPhoto.changeSrc(doc.getElementById(self.coveringPhotoId).src);
				self.coveringPhoto.opacity = 0;
				self.coveringPhoto.setOpacity(self.coveringPhoto.opacity);
			}
			else{
				self.coveringPhoto.opacity = self.coveringPhoto.opacity + 2;
				self.coveringPhoto.setOpacity(self.coveringPhoto.opacity);
				self.coveringPhoto.timeId = setTimeout(
					function(){
						self.coveringPhoto.fadeIn();
					},
					40
				);
			}
		},
		"setOpacity" : function(value){
			if(!!(window.attachEvent && !window.opera)){
				doc.getElementById(self.coveringPhotoId).style.filter = 'Alpha(opacity=' + value + ')';
			}
			else{
				doc.getElementById(self.coveringPhotoId).style.opacity = value / 100;
			}
		}
	}
	this.bgPhoto = {
		"changeSrc" : function(src){
			doc.getElementById(self.bgPhotoId).style.backgroundImage = "url('" + src + "')";
		}
	}
	this.animation = function(){
		if(self.srcPhotoAry.length != 0){
			self.changePic(self.counter % self.srcPhotoAry.length);
			self.counter++;
		}
		setTimeout(function(){self.animation();},5000);
	}
	self.init();
	self.animation();
}