
// JavaScript Document
window.addEvent('domready', function() {
	var actIndex = 0;
	var nextIndex = 0;
	var timer;
	var speed = 5000
	var start = false;
	function unactiveLink(){
		for(d=0;d<linkIndex-2;d++){
			var thisLink = document.getElementById('link_'+d);
			thisLink.className = '';
		}
	}
	function activeLink(){
		var isSet = false;
		for(d=0;d<linkIndex-2;d++){
			var thisLink = document.getElementById('link_'+d);
			if(isSet === false){
				//console.log(nextIndex+' >= '+thisLink.rel.toFloat()+' && '+nextIndex+' < '+thisLink.lang.toFloat());
				if(nextIndex >= thisLink.rel.toFloat() && nextIndex < thisLink.lang.toFloat()){
					thisLink.className = 'active';
					//console.log('ACTIVE:'+d);
					isSet = true;
				}
			}
		}
	}
	function showItem(){
		if(start === true){
			hideItem();
		}
		
		unactiveLink();
		activeLink();
		actIndex = nextIndex;
		//console.log('TXTINDEX:'+txtIndex);
		if(actIndex > txtIndex-1){
			actIndex = 1;
		}
		if(start === true){
			var txtEle = $('txt_'+actIndex);
			txtEle.setStyle('display', 'block');
			var fxT = new Fx.Morph(txtEle, {duration:1000, wait:false});
			fxT.start({
				'opacity': 1
			});
		}
		nextIndex = actIndex+1;
		start = true;
	};
	function hideItem(){
		//console.log('HIDE:'+actIndex);
		var txtEle = $('txt_'+actIndex);
		var fxT = new Fx.Morph(txtEle, {duration:0, wait:false});
 		fxT.start({
			'opacity': 0
		});
		txtEle.setStyle('display', 'none');
	};
	// GET DATA
	var headerData = Array();
	var txtIndex = 0;
	var linkIndex = 0;
	$$('#slideShowDisplay div').each(function(item){
		
		item.id = 'txt_'+txtIndex;
		if(txtIndex != 0){
			item.setStyle('opacity', 0);
			item.setStyle('display', 'none');
		}
		txtIndex++;
		//console.log('DATA TXT:'+item.id);
	});
	$$('#btnPrev').each(function(item){
		item.addEvent('click', function(){
			nextIndex = actIndex-1;
			if(nextIndex < 1){ nextIndex = txtIndex-1 }
			//console.log('INDEX:'+nextIndex);
			$clear(timer);
			showItem();
			timer = (function(){ showItem(); }).periodical(speed);
		});
		linkIndex++;
	});
	$$('#btnNext').each(function(item){
		item.addEvent('click', function(){
			nextIndex = actIndex+1;
			if(nextIndex > txtIndex-1){ nextIndex = 1 }
			//console.log('INDEX:'+nextIndex);
			$clear(timer);
			showItem();
			timer = (function(){ showItem(); }).periodical(speed);
		});
		linkIndex++;
	});
	$$('#slideShowDisplay div').each(function(item){
		item.addEvent('mouseover', function(){
			$clear(timer);
		});
		item.addEvent('mouseout', function(){
			timer = (function(){ showItem(); }).periodical(speed);
		});
	});
	showItem();
	timer = (function(){ showItem(); }).periodical(speed);
	
	
});