var gBan=0;
var ban;
var gMostra=true;

window.onload=function() {
	var d=$('flashcontent');
	if (d) {
		gBan=d.childNodes.length-1;
		ban=d.firstChild;
		d.style.height='185px';
		if (ban) {
			anima();
		} else {
			d.parentNode.removeChild(d);
		}
	}
}

function anima() {
	ban.style.display='none';
	new Effect.Appear(ban, { duration: 2.0, afterFinish:function() { 
												new PeriodicalExecuter(function(pe) {
													pe.stop();
													new Effect.Fade(ban, { duration: 2.0 });
													//ban.style.display='none';
														
													if (ban.nextSibling) {
														ban=ban.nextSibling;
													} else {
														ban=ban.parentNode.firstChild;
													}
													
													anima();
												},3);
											} 
										});
}

function mostraTab(tab) {
	tabs=tab.parentNode.parentNode.parentNode.childNodes;
	
	for (var k=0;k<tabs.length;k++) {
		tabs[k].firstChild.firstChild.className='tabInactive';
		if (tab==tabs[k].firstChild.firstChild) {
			var j=k;
		}
	}
	
	tab.className='tabActive';
	
	var tConts=$('tabCont').childNodes;
	
	for (var k=0;k<tConts.length;k++) {
		tConts[k].style.display='none';
	}
	
	tConts[j].style.display='block';
} 

function enviar() {
	var d1=$('d1');
	var d2=$('d2');
	var d3=$('d3');
	var d4=$('d4');
	
	d1.style.display="none";
	d2.style.display="none";
	d3.style.display="none";
	d4.style.display="none";
	
	if ($('txtNom').value=="") {
		d4.style.display='block';
		return;
	}
	
	if ($('txtApellidos').value=="") {
		d4.style.display='block';
		return;
	}
	
	if ($('txtMail').value=="") {
		d4.style.display='block';
		return;
	}
	
	if ($('txtMensaje').value=="") {
		d4.style.display="block";
		return;
	}
	
	d1.style.display='block';
	
	var url="../inc/sendMail.php";
	var params="nombre="+$('txtNom').value;
	params=params+"&apellidos="+$('txtApellidos').value;
	params=params+"&direccion="+$('txtDir').value;
	params=params+"&cp="+$('txtCP').value;
	params=params+"&pob="+$('txtPob').value;
	params=params+"&pais="+$('txtPais').value;
	params=params+"&tel="+$('txtTel').value;
	params=params+"&mail="+$('txtMail').value;
	params=params+"&mensaje="+$('txtMensaje').value;
	
	var ajax=new Ajax.Request(url, {
		method:'post',
		postBody: params,
		onComplete: function(reply) {
			if (reply.responseText=="ok") {
				d1.style.display='none';
				d2.style.display='block';
				$('txtNom').value="";
				$('txtApellidos').value="";
				$('txtDir').value="";
				$('txtCP').value="";
				$('txtPob').value="";
				$('txtPais').value="";
				$('txtTel').value="";
				$('txtMail').value="";
				$('txtMensaje').value="";
			} else {
				d1.style.display='none';
				d3.style.display='block';
			}
		}
	});
}

function mostra(e,img) {
	img=$(img);
	var ancho=img.getWidth();
	var alto=img.getHeight();
	
	var d=$(img.parentNode.nextSibling);
	var imagen=$(d.firstChild);
	
	var pos=img.viewportOffset();
	var page=getPageSize();
	
	d.show();
	
	var w=imagen.getWidth();
	var h=imagen.getHeight();
	
	d.style.width=w+"px";
	d.style.height=h+"px";
	
	if ((pos[0]+w+20)>page[0]) {
		d.style.left=(pos[0]-w-10)+"px";
	} else {
		d.style.left=(pos[0]+ancho)+"px";
	}
	
	if (this.pageYOffset) {
		var nScrollY=this.pageYOffset;
	} else {
		var nScrollY=document.body.scrollHeight-this.screen.availHeight;
	}
	
	if ((pos[1]+nScrollY+h+20)>page[1]) {
		d.style.top=(pos[1]-h-10)+"px";
	} else {
		d.style.top=pos[1]+"px";
	}
	
	
	/*
	d.style.top=e.clientY+"px";
	d.style.left=e.clientX+"px";
	*/
	
}

function amaga(e,img) {
	var d=$(img.parentNode.nextSibling);
	
	d.hide();
}

function  getPageSize() {
	 var xScroll, yScroll;
		
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = window.innerWidth + window.scrollMaxX;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		
		var windowWidth, windowHeight;
		
		if (self.innerHeight) {	// all except Explorer
			if(document.documentElement.clientWidth){
				windowWidth = document.documentElement.clientWidth; 
			} else {
				windowWidth = self.innerWidth;
			}
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	
		
		// for small pages with total height less then height of the viewport
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else { 
			pageHeight = yScroll;
		}
	
		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth){	
			pageWidth = xScroll;		
		} else {
			pageWidth = windowWidth;
		}

		return [pageWidth,pageHeight];
}