var n = 1;
var n2 = 1;
var current = 0;
var current2 = 0;
var imgList = new Array();
var imgList2 = new Array();

function initialize() {
	var latlng = new google.maps.LatLng(42.666901, -8.877558);
	var myOptions = {
		zoom: 12,
		center: latlng,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	};
	var map = new google.maps.Map($("map"), myOptions);
	var contentString = "<b>Rotogal</b><br />Polígono de Espiñeira, Parcela 36 B<br /> 15930 Boiro, España<br />+34 981 84 99 00<br />";
	var infowindow = new google.maps.InfoWindow({
		content: contentString
	});

	var marker = new google.maps.Marker({
		position: latlng, 
		map: map
	});
	google.maps.event.addListener(marker, 'click', function() {
		infowindow.open(map,marker);
	});
	infowindow.open(map,marker);
}

function fx(){
	imgList.set('tween', {duration: 2000});
	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()", 8000);
}

function fx2(){
	imgList2.set('tween', {duration: 1500});
	imgList2[current2].fade(1, 0);
	imgList2[n2].fade(0, 1);
	if(imgList2.length == n2+1){
		current2 = n2;
		n2 = 0;
	}else{
		current2 = n2;
		n2++;
	}
	gtime2 = setTimeout("fx2()", 5000);
}

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($('loop-fotos-2'))){
		imgList2 = $$('#loop-fotos-2 img');
		$each(imgList2, function(el){
			el.setStyle('opacity', 0);
			el.setStyle('display', 'block');
		});
	}
	if($chk($('map'))){
		initialize();
	}
});
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){
			gtime = setTimeout("fx()", 8000);
		}
	}
	if($chk($('loop-fotos-2'))){
		imgList2 = $$('#loop-fotos-2 img');
		
		imgList2[0].fade(0, 1);
		$('loop-fotos-2').setStyle('background-image', 'none');
		if(imgList2.length > 1){
			gtime2 = setTimeout("fx2()", 5000);
		}
	}
});
