var paused = false;
var n = 1;
var current = 0;
var imgList = new Array();
function fx(){
	if(paused == false){
		imgList[current].fade(1, 0);
		imgList[n].fade(0, 1);
		if(imgList.length == n+1){
			current = n;
			n = 0;
		}else{
			current = n;
			n++;
		}
		gtime = setTimeout("fx()", 3500);
	}
}
function randOrd(){
	return (Math.round(Math.random())-0.5);
}

window.addEvent('domready', function(){
	if($chk($('loop-fotos'))){
		imgList = $$('#loop-fotos img');
		$each(imgList, function(el){
			el.setStyle('opacity', 0);
			el.setStyle('display', 'block');
		});
		if($chk($('pause'))){
			$('pause').addEvent('click', function(ev){
				var ev = new Event(ev).stop();
				if(paused == false){
					clearTimeout(gtime);
					paused = true;
					this.setStyle('background-position', '0 -10px');
				}else{
					paused = false;
					fx();
					this.setStyle('background-position', '0 0');
				}
			});
		}
	}
	winList = $$('.window');
	closeList = $$('.close');
	aList = $$('#menu a.bot');
	$each(winList, function(el){
		el.setStyle('opacity', 0);
		el.setStyle('display', 'block');
	});
	$each(aList, function(el){
		el.addEvent('click', function(ev){
			ev = new Event(ev).stop();
			winList.fade(0);
			$(this.get('id').replace('bot', 'window')).fade(1);
			aList.removeClass('sel');
			this.addClass('sel');
		});
	});
	$each(closeList, function(el){
		el.addEvent('click', function(ev){
			ev = new Event(ev).stop();
			aList.removeClass('sel');
			winList.fade(0);
		});
	});
});

window.addEvent('load', function(){
	if($chk($('loop-fotos'))){
		imgList = $$('#loop-fotos img');
		imgList[0].fade(0, 1);
		$('loop-fotos').setStyle('background-image', 'none');
		if(imgList.length > 1){
			if(paused == false){
				gtime = setTimeout("fx()", 3500);
			}
		}
	}
});
