
// vie61=1 if IE6 is detected
vie61=0;
if(navigator.appVersion.indexOf("MSIE 6")!=-1) vie61=1;

// remove background of first item in IE6, remove outline of footer links
function setFooter1(){
	var aItems1=document.getElementById("footer").getElementsByTagName("ul");
	for(i=0;i<aItems1.length;i++){
		if(aItems1[i].className.indexOf("footer-second")!=-1)aItems1[i].getElementsByTagName("span")[0].style.background="none";
		else aItems1[i].getElementsByTagName("a")[0].style.background="none";
	}
}
function setFooter2(){
	var aItems1=document.getElementById("footer").getElementsByTagName("a");
	for(i=0;i<aItems1.length;i++){
		aItems1[i].onfocus=function(){this.blur();}
	}
}

// style select boxes and checkboxes
function styleSelectbox1Click(){
	if(this.selOptions.style.visibility=="visible") this.selOptions.style.visibility="hidden";
	else this.selOptions.style.visibility="visible";
	document.getElementById(this.id1+"-options").onmouseover=function(){
		clearTimeout(document.getElementById(this.id1+"-repl").timeout1);
	}
	document.getElementById(this.id1+"-options").onmouseout=function(){
		document.getElementById(this.id1+"-repl").timeout1=setTimeout("document.getElementById('"+this.id1+"-options"+"').style.visibility='hidden'",500);
	}
}
function styleSelectbox1Focus(){
	if(this.isHovered1) return;
	this.selOptions.style.visibility="visible";
}
function styleSelectbox1Fix(){
	document.getElementById(this.id+"-repl").innerHTML=document.getElementById(this.id+"-options").aOptions[this.selectedIndex].innerHTML;
}
function styleSelectbox1(hasLinks,cName){
	this.style.visibility="hidden";
	this.className+=" "+this.id+"-change";
	var selParent=this.parentNode;
	selParent.style.position="relative";
	
	/*Vicente, change dinamics options*/
	if (document.getElementById(this.id+"-repl")!=null) {
		capito=document.getElementById(this.id+"-repl");
		selParent.removeChild(capito); 
		capito=document.getElementById(this.id+"-options");
		selParent.removeChild(capito); 
	}
	
	var tmp1=document.createElement("div");
	tmp1.id=this.id+"-repl";
	tmp1.className=cName+"-repl";
	selParent.appendChild(tmp1);
	var selRepl=document.getElementById(this.id+"-repl");
	var aOptions=this.getElementsByTagName("option");
	selRepl.innerHTML=aOptions[this.selectedIndex].innerHTML;
	selRepl.style.visibility="visible";

	var tmp2=document.createElement("div");
	tmp2.id=this.id+"-options";
	tmp2.className=cName+"-options";
	//tmp2.style.width=selRepl.offsetWidth+20+"px";
	tmp2.style.width=selRepl.offsetWidth-2+"px";
	if (selRepl.id.indexOf("selectHoteles-")!=-1)
		tmp2.style.width="250px";
		
	selParent.appendChild(tmp2);
	var selOptions=document.getElementById(this.id+"-options");

	selRepl.selOptions=selOptions;
	selRepl.id1=this.id;
	selRepl.isHovered1=false;
	selRepl.timeout1=setTimeout("",1);
	selRepl.onclick=styleSelectbox1Click;
	selRepl.onfocus=styleSelectbox1Focus;
	selRepl.onmouseover=function(){
		this.isHovered1=true;
		clearTimeout(this.timeout1);
	}
	selRepl.onmouseout=function(){
		this.isHovered1=false;
		this.timeout1=setTimeout("document.getElementById('"+this.id1+"-options"+"').style.visibility='hidden'",500);
	}

	selOptions.id1=this.id;
	selOptions.selBox=this;
	selOptions.selRepl=selRepl;
	selOptions.aOptions=aOptions;
	for(i=0;i<selOptions.aOptions.length;i++){
		var tmpObj=document.createElement("a");
		tmpObj.optIndex=i;
		tmpObj.href="#";
		tmpObj.innerHTML=selOptions.aOptions[i].innerHTML;
		tmpObj.onclick=function(){
			this.parentNode.selRepl.innerHTML=this.parentNode.aOptions[this.optIndex].innerHTML;
			this.parentNode.style.visibility="hidden";
			if(hasLinks)window.location=this.parentNode.aOptions[this.optIndex].value;
			else this.parentNode.selBox.selectedIndex=this.optIndex;
			if (this.parentNode.id.indexOf("selectHab-")!=-1)
				compruebaBusca();
			if (this.parentNode.id.indexOf("selectDestinos-")!=-1)
				cargaHoteles();
			if (this.parentNode.id.indexOf("selectHoteles-")!=-1)
				verificaZona();

			return false;
		}
		selOptions.appendChild(tmpObj);
	}

	selRepl.tabIndex=0;
	var aItems1=selOptions.getElementsByTagName("a");
	for(i=0;i<aItems1.length;i++){
		aItems1[i].tabIndex=0;
	}
	aItems1[aItems1.length-1].onblur=function(){
		this.parentNode.style.visibility="hidden";
	}

	setTimeout("document.getElementById('"+this.id+"').sFix1()",1);
}
function styleCheckbox1Click(){
	var oBox1=document.getElementById(this.id1);
	if(oBox1.type=="radio"){
		var aItems1=document.getElementsByName(oBox1.name);
		for(i=0;i<aItems1.length;i++){
			document.getElementById(aItems1[i].id+"-repl").className=aItems1[i].cName1+"-repl";
		}
	}
	var oBox2=document.getElementById(this.id1+"-repl");
	if(!oBox1.checked){
		oBox1.checked=true;
		oBox2.className+=" "+this.cName1+"-checked";
	}
	else{
		oBox1.checked=false;
		oBox2.className=this.cName1+"-repl";
	}
}
function styleCheckbox1Fix(){
	if(this.checked){
		document.getElementById(this.id+"-repl").className+=" "+this.cName1+"-checked";
	}
}
function styleCheckbox1(cName){
	this.style.visibility="hidden";
	this.className+=" "+this.id+"-change";
	this.cName1=cName;
	var checkParent=this.parentNode;
	checkParent.style.position="relative";

	var tmp1=document.createElement("div");
	tmp1.id1=this.id;
	tmp1.cName1=cName;
	tmp1.id=this.id+"-repl";
	tmp1.className=cName+"-repl";
	checkParent.appendChild(tmp1);
	var checkRepl=document.getElementById(this.id+"-repl");
	checkRepl.style.visibility="visible";
	checkRepl.tabIndex=0;

	if(document.getElementById(this.id+"-label")){
		var checkLabel=document.getElementById(this.id+"-label");
		checkLabel.id1=this.id;
		checkLabel.cName1=cName;
		checkLabel.onclick=styleCheckbox1Click;
		checkLabel.style.cursor="pointer";
	}
	checkRepl.onclick=styleCheckbox1Click;
	checkRepl.onkeydown=function(event1){
		var vCode;
		if(!event1){
			event1 = window.event;
			vCode = event1.keyCode;
		}
		else vCode=event1.which;
		if(vCode==13){
			this.onclick();
			return false;
		}
	}

	this.cFix1=styleCheckbox1Fix;
	setTimeout("document.getElementById('"+this.id+"').cFix1()",1);
}
lteIE71=false;
eIE1=false;
function lteIE7check(){
	function lteIE7check2(){
		HTMLSelectElement.prototype.styleSelectbox1=styleSelectbox1;
		HTMLSelectElement.prototype.sFix1=styleSelectbox1Fix;
		HTMLInputElement.prototype.styleCheckbox1=styleCheckbox1;
		HTMLInputElement.prototype.cFix1=styleCheckbox1Fix;
	}
	var index1=0;
	if(navigator.appVersion.indexOf("MSIE")!=-1){
		index1=navigator.appVersion.indexOf("MSIE")+6;
		eIE1=true;
	}
	if(index1>0){
		if(navigator.appVersion.substring(index1-1,index1)<=7) lteIE71=true;
		else lteIE7check2();
	}
	else lteIE7check2();
}
lteIE7check();

//style select boxes in booking engine
function styleBookingBoxes(){
	var aItems=document.getElementById("resform").getElementsByTagName("select");
	var i = aItems.length;
	while(i>0){
		aItems[i-1].styleSelectbox1(false,"resform");
		i--;
	}
	//document.getElementById("select1").styleSelectbox1(true); //languages

	if(document.getElementsByTagName("body")[0].className.indexOf("theme1")!=-1){
		var aItems1=document.getElementsByTagName("img");
		for(i=0;i<aItems1.length;i++){
			if(aItems1[i].src.indexOf("icon-star")!=-1&&aItems1[i].src.indexOf("icon-star1")==-1) aItems1[i].src=aItems1[i].src.replace(/icon-star/,"icon-star1");
		}
		var aItems2=document.getElementById("resform").getElementsByTagName("a");
		for(i=0;i<aItems2.length;i++){
			if(aItems2[i].className.indexOf("calendar")!=-1) aItems2[i].getElementsByTagName("img")[0].src=aItems2[i].getElementsByTagName("img")[0].src.replace(/calendar/,"calendar2");
		}
	}
}

//style checkboxes in contact forms and other sections
function styleContactBoxes(){
	if(document.getElementById("contactSelect1")) document.getElementById("contactSelect1").styleSelectbox1(false,"resform");
	if(document.getElementById("acceptcb1")) document.getElementById("acceptcb1").styleCheckbox1("checkbox1");
	if(document.getElementById("acceptcb2")) document.getElementById("acceptcb2").styleCheckbox1("checkbox1");
	if(document.getElementById("selectFotos1")) document.getElementById("selectFotos1").styleSelectbox1(true,"contact");
	if(document.getElementById("selectHabs1")) document.getElementById("selectHabs1").styleSelectbox1(true,"contact");
	if(document.getElementById("selectOfertas1")) document.getElementById("selectOfertas1").styleSelectbox1(true,"resform");
	if(document.getElementById("selectOfertas2")) document.getElementById("selectOfertas2").styleSelectbox1(true,"resform");
	if(document.getElementById("selectQueryType")) document.getElementById("selectQueryType").styleSelectbox1(false,"resform");
}

// header gallery
function setGallery1(){
	function setGallery2(){
		var timg=document.getElementById("timage");
		var timgTmp=document.getElementById("timage-tmp");
		if(this.parentNode.className.indexOf("ennavitem")!=-1){
			var aItems=this.parentNode.parentNode.getElementsByTagName("a");
		}
		else{
			var aItems=this.parentNode.getElementsByTagName("a");
		}
		if(!aEnnavPrimages1[this.index1].complete||!timg.complete||!timgTmp.complete){
			return false;
		}
		for(i=0;i<aItems.length;i++){
			aItems[i].className="";
		}
		this.className="selected";
		timg.style.width=timg.offsetWidth+"px";
		timg.style.height=timg.offsetHeight+"px";
		timgTmp.src="";
		timgTmp.src=timg.src;
		timgTmp.style.width=timg.style.width;
		timgTmp.style.height=timgTmp.offsetHeight+"px";
		$(timgTmp).css({opacity:"1"});
		timgTmp.style.display="block";
		timg.src=this.href;
		$(timgTmp).stop().animate({ opacity:"0" }, 1000);
		return false;
	}
	function setGallery3(){
		this.setGallery2();
		if(typeof(galTimeout1)!="undefined") clearTimeout(galTimeout1);
		return false;
	}
	if(!document.getElementById("timage")||!document.getElementById("timage-tmp")||!document.getElementById("ennav")) return;
	var aLinks=document.getElementById("ennav").getElementsByTagName("a");
	document.getElementById("timage").src=aLinks[0].href;
	document.getElementById("timage-tmp").src=aLinks[0].href;
	aLinks[0].className="selected";
	aEnnavPrimages1=new Array();
	for(i=0;i<aLinks.length;i++){
		var tmp=new Image();
		tmp.src=aLinks[i].href;
		aEnnavPrimages1.push(tmp);
		aLinks[i].index1=i;
		aLinks[i].setGallery2=setGallery2;
		aLinks[i].onclick=setGallery3;
		aLinks[i].onfocus=function(){this.blur();}
	}
	setGalTimeout1();
}
galTimeoutIndex1=1;
function setGalIndex1(){
	if(galTimeoutIndex1<$("#ennav a").length-1) galTimeoutIndex1+=1;
	else galTimeoutIndex1 = 0;
}
function setGalTimeout1(){
	if($("#ennav a").length==1) return;
	galTimeout1=setTimeout('$("#ennav a")[galTimeoutIndex1].setGallery2();setGalIndex1();setGalTimeout1();',5000);
}

//set slide
function setSlide1(slName){
	function setSlide2(elId,state1){
		var aItems=document.getElementById(elId).getElementsByTagName("div");
		for(i=0;i<aItems.length;i++){
			if(aItems[i].className.indexOf("-repl")!=-1){
				if(state1==true) aItems[i].style.visibility="visible";
				else aItems[i].style.visibility="hidden";
			}
		}
	}
	if(!document.getElementById(slName)||!document.getElementById(slName+"-content")) return;
	if(lteIE71) setSlide2(slName+"-content",false);
	var slideButton=document.getElementById(slName);
	var slideContent=document.getElementById(slName+"-content");
	isSliding1=false;

	slideButton.onclick=function(){
		if(isSliding1) return false;
		isSliding1=true;
		var slideContent=$("#"+this.id+"-content");
		if($(slideContent).is(":hidden")){
			this.parentNode.className+=" slidebutton-selected";
			if(lteIE71) $(slideContent).stop().slideDown(function(){setSlide2(this.id,true);heightCheck1();});
			else $(slideContent).stop().slideDown(function(){heightCheck1();});
		}
		else {
			this.parentNode.className=this.parentNode.className.replace(/slidebutton-selected/,"");
			$(slideContent).hide();
			if(lteIE71) {
				setSlide2(this.id+"-content",false);
				heightCheck1();
			}
			else heightCheck1();
			isSliding1=false;
		}
		return false;
	}
	slideButton.onfocus=function(){
		this.blur();
	}
}

//clear default text in form field on click
function clearField1(){
	this.value="";
	this.onclick=function(){}
}

function heightCheck1(){
	if($(".content1")[0]) var vContent1=$(".content1")[0];
	else return;
	if(vContent1.offsetHeight>1000) {
		$(vContent1).append("<div id='heightCorrect1' style='position:absolute;height:"+(vContent1.offsetHeight-200)+"px; width:320px;background-color:"+(($("body")[0].className.indexOf('theme1')!=-1)?"#EDE7D0":"#eeeeee")+";left:53px;top:"+vContent1.offsetTop+"px;z-index:0;'></div>");
	}
	else{
		if($("#heightCorrect1")[0]) $("#heightCorrect1").remove();
	}
	isSliding1=false;
}
$(function(){heightCheck1()})

function pageLoaded1(){

//needed to style select and checkbox in IE7 and lower
if(lteIE71){
	var aItems1=document.getElementsByTagName("select");
	for(i=0;i<aItems1.length;i++){
		aItems1[i].styleSelectbox1=styleSelectbox1;
		aItems1[i].sFix1=styleSelectbox1Fix;
	}
	var aItems2=document.getElementsByTagName("input");
	for(i=0;i<aItems2.length;i++){
		aItems2[i].styleCheckbox1=styleCheckbox1;
		aItems2[i].cFix1=styleCheckbox1Fix;
	}
}

styleBookingBoxes();
styleContactBoxes();

//clear default text in newsletter email field on click
if($("#Email")[0]) $("#Email")[0].onclick=clearField1;

//clicking a thumb overlay follows the link behind it
if(document.getElementById("htcontainer")){
	var aItems1=document.getElementById("htcontainer").getElementsByTagName("div");
	for(i=0;i<aItems1.length;i++){
		if(aItems1[i].className.indexOf("httext")!=-1) aItems1[i].onclick=function(){
			window.location=this.parentNode.getElementsByTagName("a")[0].href;
		}
	}
}

//footer links
if(document.getElementById("footer")&&vie61) setFooter1();
if(document.getElementById("footer")) setFooter2();

if(document.getElementById("content1")){
	if(document.getElementById("content1").offsetHeight>1000) document.getElementById("content1").style.backgroundPosition="53px top";
}

//looks for button with id "slide1" and content with id "slide1-content"
setSlide1("slide1");

//button hover for ie
if(eIE1){
	$(".button").mouseover(function(){
		if(this.className.indexOf("button1")!=-1) this.className+=" button1-hover";
		else this.className+=" button-hover";
	});
	$(".button").mouseout(function(){
		if(this.className.indexOf("button1-hover")!=-1) this.className=this.className.replace(/ button1-hover/,"");
		else this.className=this.className.replace(/ button-hover/,"");
	});
}
if(vie61){
	$(".slidebutton").mouseover(function(){
		this.className+=" slidebutton-selected";
	});
	$(".slidebutton").mouseout(function(){
		this.className=this.className.replace(/ slidebutton-selected/,"");
	});
	$("#mainmenu-home td").mouseover(function(){
		this.className+=" hovered";
	});
	$("#mainmenu-home td").mouseout(function(){
		this.className=this.className.replace(/ hovered/,"");
	});
	$("#mainmenu-home td").click(function(){
		window.location=this.getElementsByTagName("a")[0].href;
	});
	$(".hrc2text").click(function(){
		window.location=this.getElementsByTagName("a")[0].href;
	});
	if($(".ennav-second")[0]){
		$(".ennav-second").clone().insertBefore($(".ennav-second"));
		$(".ennav-second")[1].style.filter="none";
		var ie6tmp1=$(".ennav-second")[0].getElementsByTagName("a");
		$(ie6tmp1).each(function(){
			this.style.visibility="hidden";
		});
	}
}

//employment
if($(".s-cvform")[0]) {
	$(".s-cvform select").each(function(i){
		if (this.id!='pais' && this.id!='paiscial') {
			this.styleSelectbox1(false,"resform");
			$("#"+this.id+"-repl")[0].parentNode.style.zIndex=999-i;
		}
	});
	$(".cb1").each(function(){
		this.styleCheckbox1("checkbox2");
	});
	$(".rb1").each(function(){
		this.styleCheckbox1("radio1");
	});
}
if($("input[type='file']")[0]){
	function fileInpTime1(){
		aFileDiv1[this.index1].innerHTML=this.value;
		setTimeout("aFileInp1["+this.index1+"].fileInpTime1()",500);
	}
	aFileInp1=$("input[type='file']");
	aFileDiv1=new Array();
	$(aFileInp1).each(function(i){
		this.index1=i;
		aFileDiv1.push(this.parentNode.getElementsByTagName("div")[0]);
		this.fileInpTime1=fileInpTime1;
		this.fileInpTime1();
		this.onfocus=function(){
			$(aFileDiv1[this.index1]).addClass("s-fi-path-focus");
			this.click();
		}
		this.onblur=function(){
			$(aFileDiv1[this.index1]).removeClass("s-fi-path-focus");
		}
		if(eIE1){
			this.style.visibility="hidden";
			this.style.filter="alpha(opacity='100')";
			var buttonTmp1=this.parentNode.getElementsByTagName("div")[1];
			buttonTmp1.onclick=function(){
				this.parentNode.getElementsByTagName("input")[0].click();
				document.selection.empty();
			}
			buttonTmp1.tabIndex=0;
			buttonTmp1.onfocus=function(){
				$(aFileDiv1[this.parentNode.getElementsByTagName("input")[0].index1]).addClass("s-fi-path-focus");
				this.click();
			}
			buttonTmp1.onblur=function(){
				$(aFileDiv1[this.parentNode.getElementsByTagName("input")[0].index1]).removeClass("s-fi-path-focus");
			}
		}
	});
}
$(".s-close").each(function(){
	this.onclick=function(){
		this.parentNode.style.visibility="hidden";
	}
});

}
