(function(){
	var d = document;
	var A_TIME = 0.4;
	var A_MODE = 'easeOutCubic';	
	var INTERVAL = 5.0;
	
	var init = function()
	{
		var slidebox = new SlideBox(
			d.getElementById('slideArea'),
			d.getElementById('slideItemWrap'),
			d.getElementById('slideControl'),
			kZtopSlideData
		);
	}
	
	function SlideBox(frame, wrap, control, data){
		this.frame = frame;
		this.wrap  = wrap;
		this.control = control;
		
		this.nowSet = -1;
		this.moveVal = this.frame.offsetWidth;
		this.btnList = [];
		
		this.cycleTimer = null;
		
		this.itemSet(data);
		this.moveSet(0);
		this.timerSet();
		
		var thisE = this;
		addEvent(this.frame, 'mouseover', function(){thisE.timerClear();})
		addEvent(this.frame, 'mouseout', function(){thisE.timerSet();})
	}
		SlideBox.prototype.itemSet = function(data)
		{
			if(data.length>5)data.length=5;
			var thisE = this;
			for(var i=0; i<data.length; i++){
				var li = d.createElement('li');
				this.wrap.appendChild(li);
					var itemLink = d.createElement('a');
					var setLink = data[i].linkUrl ? data[i].linkUrl : 'javascript:void(0)';
					itemLink.href = setLink;
					itemLink.target = data[i].target;
					li.appendChild(itemLink);
					
						var itemImage = d.createElement('img');
						itemImage.src = data[i].image;
						itemImage.alt = data[i].alt;
						itemLink.appendChild(itemImage);
				
				this.btnList[i] = d.createElement('li');
				this.control.appendChild(this.btnList[i]);
					var cLink = d.createElement('a');
					cLink.href = 'javascript:void(0)';
					cLink.className = ('num0'+(i+1) );
					this.btnList[i].appendChild(cLink);
					(function(elem, num){
						addEvent(elem, 'click', function(){thisE.moveSet(num); elem.blur();});						
					})(cLink,i);
			}
			kmsEffect.Position(this.wrap, {x:0, y:0});
		}
		SlideBox.prototype.moveSet = function(num){
			if(num==this.nowSet)return;
			
			var prev = this.nowSet;
			this.nowSet = num;
			
			this.btnList[this.nowSet].className = 'on';
			if(prev>-1)
			{
				this.btnList[prev].className = '';
				this.boxMove(this.nowSet);
			}			
		}
		SlideBox.prototype.boxMove = function()
		{
			kmsEffect.PositionAnimation(
				this.wrap,
				kmsEffect.GetPosition(this.wrap),
				{x:-this.moveVal*this.nowSet, y:0},
				A_TIME,
				A_MODE,
				function()
				{
				}
			);		
		}
		SlideBox.prototype.timerSet = function(){
			this.timerClear();
			var thisE = this;
			this.cycleTimer=setInterval(
				function()
				{
					var set = thisE.nowSet+1;
					if(set==thisE.btnList.length)set=0;
					thisE.moveSet(set)
				},
				INTERVAL*1000
			);			
		}
		SlideBox.prototype.timerClear = function(){
			clearInterval(this.cycleTimer);
		}

	//addEvent
	function addEvent(elem, listener, func)
	{
		var ret = func;
		if(elem.addEventListener){elem.addEventListener(listener, func, false);}
		else if(elem.attachEvent){elem.attachEvent("on" + listener, ret);}
		return ret;
	};
	
	//DOMContentLoaded
	(function(){
		if(d.addEventListener){
			d.addEventListener("DOMContentLoaded", init, false);			
		}
		else if(navigator.userAgent.match(/MSIE/)){
		 try {
			 d.createComment().doScroll();
			 init();
		 } catch(e){ setTimeout(arguments.callee, 1);}
		}
	})();			
})();
