var request = null;
var capa = document.getElementById("cont");
try{request = new XMLHttpRequest();} catch(micro) {
	try {request = new ActiveXObject("Msxml2.XMLHTTP");} catch(otromicro) {
		try {request = new ActiveXObject("Microsoft.XMLHTTP");} catch(failed) {
			request = null;
		}
	}
}
if(request==null) alert("Error creando objeto request.");

function ajax(url,donde){
	capa = donde;
	capa.innerHTML = "procesando ...";
	request.open("GET",url, true);
	request.onreadystatechange = cambia;
	request.send(null);
}

function c(web){
	var url;
	capa = document.getElementById("cont");
	if(web=='donde'){
		capa.innerHTML = "<div id='mapa' style='width:800px;height:450px;'></div>";
		//capa.style.width = "800px";
		//capa.style.height = "400px";
		vermapa();
	}else{
		capa.innerHTML =  "Cargando ...";
		if(web.indexOf('?')>=0) url = "/"+web+"&sid="+Math.random()
		else url = "/"+web+"?sid="+Math.random()
		request.open("GET",url, true);
		request.onreadystatechange = cambia;
		request.send(null);
	}
}

function vermapa(){
	capa = document.getElementById("mapa");
	var map = new GMap2(capa);
	map.addControl(new GSmallMapControl());
	map.addControl(new GMapTypeControl());
	map.setCenter(new GLatLng(42.128682,-8.817470), 13);
	var pamerica = new GMarker(new GLatLng(42.138672,-8.817070));
	map.addOverlay(pamerica);
	pamerica.bindInfoWindowHtml("<b>Complejo Deportivo<br />Dunas de Gaifar</b><br /><img src='img/pamericamini.jpg' alt='' /><br />Praia Am&eacute;rica - NIGRAN");
	var baiona = new GMarker(new GLatLng(42.115552, -8.825030));
	map.addOverlay(baiona);
	baiona.bindInfoWindowHtml("<b>Camping Baiona</b><br /><img src='img/baionamini.jpg' alt='' /><br />Praia Ladeira - BAIONA");
}

function cambia(){
	if(request.readyState==4){
		if(request.status==200){
			capa.innerHTML = request.responseText;
		}else{
			capa.innerHTML = "Error: "+ request.status;
		}
	}
}

function f(nome){
	document.getElementById('foto').src = "img/"+nome;
}

var aparece = true;
function fotos(n) {
	//speed for each frame
	var speed = 10;
	var timer = 0;
	if(aparece){
		aparece = false;
		opacStart = 0;
		opacEnd = 100;
	}else{
		aparece = true;
		opacStart = 100;
		opacEnd = 0;
	}
	
	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(var i=opacStart; i>=opacEnd; i--) {
			setTimeout("changeOpac("+ i +")",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(var i=opacStart; i<=opacEnd; i++){
			setTimeout("changeOpac(" + i +")",(timer * speed));
			timer++;
		}
	}
	
	if((opacEnd)==100){
		document.getElementById('top').innerHTML = "<img src='img/top/"+ n +".jpg' />";
		if(n<16) n++;
		else n=0;
	}
	setTimeout("fotos("+n+")",5000);
}

//change the opacity for different browsers
function changeOpac(opacity) {
	var s = document.getElementById('top').style;
	s.opacity = (opacity / 100); //Mozilla
	s.MozOpacity = (opacity / 100);
	s.KhtmlOpacity = (opacity / 100);
	s.filter = "alpha(opacity=" + opacity + ")"; //IE
}
function foto(id,pie){
	var ph = document.getElementById('photo');
	ph.innerHTML = "<img src='fotos/"+id+".jpg' /><br />"+ pie;
	ph.style.visibility = "visible";
}
function unfoto(){
	document.getElementById('photo').style.visibility='hidden';
}
