//---time value
var cnt = 0;
var maintimer;

//---Thumbnail event
window.addEvent('domready', function () {
	$$('.thum-photo').addEvent('click', function (evt) {
		evt.stop();
		return true;
	});
});


//---CALL Timer(PAGE LOAD)
window.addEvent('domready', function () {
	cnt = 0;
	$$('.main-photo').setStyle('background','none');
	maintimer = setInterval("imgChange()",5000);
	$('photo-area-00').setStyle('display','block');
});


//---IMG change
function imgChange(){
	//alert(cnt);
	cnt ++;
	
	var timeid = 'photo-area-0'+cnt;
	//alert(timeid);
	
	
	//---test
	
	imagecurrent(timeid);
	
	if(cnt >= 5){
		cnt = 0;
	}
}


//---CURRENT IMAGE
function imagecurrent(cno){
	
	var id = cno;
	
	//alert(id);
	var pho = id.indexOf('-');
	var phoNo = id.substr(pho+6);
	
	var block = 'photo-area-'+phoNo;
	var thum = 'thum-photo-'+phoNo;
	//alert(block);
	
	
	//---ready
	
	//var photoarea = $(block);
	//var thumphoto = $(thum);
	var tween = new Fx.Tween($(block), {duration: 1000, link: 'cancel'});
	
	//---close
	$$('.photo-area').setStyle('display','none');
	$$('.thum-photo').setStyle('margin','2px auto');
	$$('.thum-photo').setStyle('padding','1px');
	$$('.thum-photo').setStyle('border','none');
	
	//---open
	
	$(block).setStyle('opacity','0').setStyle('display','block');
	$(thum).setStyles({
		'margin': '0px',
		'border': '2px solid #444444'
	});
	
	tween.start('opacity', 0, 1).chain(function () {
		//alert(block);
		return true;
	});
}


//---Timer STOP
window.addEvent('domready', function () {
	$$('.thum-photo').addEvent('mouseenter', function () {
		clearInterval(maintimer);
		
		var id = this.id;
		var pho = id.indexOf('-');
		
		//---reset—p
		var phoNo = id.substr(pho+6);
		var block = 'photo-area'+phoNo;
		var thum = 'thum-photo'+phoNo;
		
		//---cnt—p
		var phoNo = id.substr(pho+8);
		
		
		//---Current RESET
		if(phoNo == 5){
			cnt = 0;
		}else{
			cnt = phoNo;
		}
		
		
		//---close
		$$('.photo-area').setStyle('display','none');
		$$('.thum-photo').setStyle('margin','2px auto');
		$$('.thum-photo').setStyle('padding','1px');
		$$('.thum-photo').setStyle('border','none');
		
		//---open
		var tween = new Fx.Tween($(block), {duration: 1000, link: 'cancel'});
		
		//alert(thum);
		
		$(block).setStyle('opacity','0').setStyle('display','block');
		$(thum).setStyles({
			'margin': '0px',
			'border': '2px solid #444444'
		});
		
		tween.start('opacity', 0, 1).chain(function () {
			//alert(block);
			return true;
		});
		
	});
	
	$$('.thum-photo').addEvent('mouseleave', function () {
		maintimer = setInterval("imgChange()",5000);
	});
});