/**
 * Shadow
 * @author Mitsuaki Ishimoto
 * @param {Object} arg
 */
function Shadow(arg){
	var self = this;
	/*
	 * styles
	 */
	this.bgColor = '#000000';
	this.opacity = 80;
	this.tmpOpacity = 0;
	/*
	 * document object of the frame
	 */
	this.elm;
	/*
	 * time ID for animation
	 */
	this.timeId;
	/*
	 * lock to animation
	 */
	this.lockAnimation = false;
	this.createShadow = function(){
		self.elm = document.createElement('div');
		self.elm.onclick = function(){
			return false;
		}
		self.elm.id = arg.id;
		var width  = (document.documentElement.scrollWidth > getClientSize().width)? document.documentElement.scrollWidth : getClientSize().width;
		var height = (document.documentElement.scrollHeight > getClientSize().height)? document.documentElement.scrollHeight : getClientSize().height;
		self.elm.style.width  = width + 'px';
		self.elm.style.height = height + 'px';
		self.elm.style.backgroundColor = self.bgColor;
		document.getElementById('products').appendChild(self.elm);
	}
	this.deleteShadow = function(){
		var oldNode = (document.getElementById(arg.id));
		if(oldNode){
			oldNode.parentNode.removeChild(oldNode);
		}
	}
	this.fadeIn = function(){
		if(self.opacity > self.tmpOpacity){
			self.tmpOpacity = self.tmpOpacity + 20;
			self.setOpacityValue(self.tmpOpacity);
			self.timeId = setTimeout(
				function(){
					self.fadeIn();
				},
				30
			);
		}
		else{
			self.lockAnimation = false;
			self.tmpOpacity = 80;
			self.setOpacityValue(self.opacity);
			clearTimeout(self.timeId);
		}
	}
	this.fadeOut = function(){
		if(self.tmpOpacity > 0){
			self.tmpOpacity = self.tmpOpacity - 20;
			self.setOpacityValue(self.tmpOpacity);
			self.timeId = setTimeout(
				function(){
					self.fadeOut();
				},
				30
			);
		}
		else{
			self.lockAnimation = false;
			self.tmpOpacity = 0;
			self.setOpacityValue(self.opacity);
			clearTimeout(self.timeId);
			self.deleteShadow();
		}
	}
	this.setOpacityValue = function(value){
		if(!!(window.attachEvent && !window.opera)){
			self.elm.style.filter = 'Alpha(opacity = ' + value + ')';
		}
		else{
			self.elm.style.opacity = (value / 100);
		}
	}
	/**
	 * turn on a shadow
	 * 
	 */
	this.on = function(){
		self.createShadow();
		self.setOpacityValue(self.opacity);
	}
	/**
	 * turn on a shadow animated
	 * 
	 */
	this.onAnimation = function(){
		self.createShadow();
		if(self.lockAnimation === false){
			self.fadeIn();
		}
		self.lockAnimation = true;
	}
	/**
	 * turn off a shadow
	 * 
	 */
	this.off = function(){
		self.deleteShadow();
	}
	/**
	 * turn off a shadow animated
	 * 
	 */
	this.offAnimation = function(){
		if(self.lockAnimation === false){
			self.fadeOut();
		}
		self.lockAnimation = true;
	}
	this.init = function(){
		addListen(
			window,
			'resize',
			function(){
        		var width  = (document.documentElement.scrollWidth > getClientSize().width)? document.documentElement.scrollWidth : getClientSize().width;
        		var height = (document.documentElement.scrollHeight > getClientSize().height)? document.documentElement.scrollHeight : getClientSize().height;
				self.elm.style.width = width + 'px';
				self.elm.style.height = height + 'px';
			}
		);
	}
	self.init()
}
