// Adobe Dreamweaver
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//  Global Red
function swapDisplay(object, displaied){ //v1.1
	var obj = document.getElementById(object);
	if (obj.style.display=='block'){ obj.style.display='none'; } else {	if(displaied){ obj.style.display='block';	} else{ obj.style.display='none'; } }
}

/*function bodyOffHeight(){ //v1.0
	var h = (document.body.scrollHeight)+'px';
	document.getElementById('body_off').style.height= h;
}
function bodyOff(){ //v1.0
	var w = (document.body.scrollWidth)+'px';
	var h = (document.body.scrollHeight)+'px';
	document.getElementById('body_off').style.width= w;
	document.getElementById('body_off').style.height= h;
}
*/
function centerWindow(object) { //v1.0
	var obj = document.getElementById(object);
	if (typeof window.innerWidth != 'undefined'){
       var w = window.innerWidth;
       var h = window.innerHeight;
    }else if(typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth !='undefined' && document.documentElement.clientWidth != 0){
        var w =document.documentElement.clientWidth;
        var h =document.documentElement.clientHeight;
    }else{
        var w = document.getElementsByTagName('body')[0].clientWidth;
        var h =document.getElementsByTagName('body')[0].clientHeight;
    }
	var left = Math.max((w/2)-200); // Ya que el tamaño del div es 400
	var top = Math.max((h/2)-100);
	obj.style.left = left+'px';
	obj.style.top = top+'px';
}
//� � � � � � � � � � � JQUERY
$(document).ready(function(){
	$("#utilMenu ul li a").click(function(e) {
		switch(e.target.id){
		case "win_lng1":
            //change status & style menu
            $("#win_lng1").addClass("active");
            $("#win_login1").removeClass("active");
            $("#win_login1").removeClass("active");
            //display selected division, hide others
            $(".lng").fadeIn(700);
            $(".login").css("display", "none");
            $(".login2").css("display", "none");
			return false;
        break;
		case "win_login1":
            //change status & style menu
            $("#win_lng1").removeClass("active");
            $("#win_login2").removeClass("active");
            $("#win_login1").addClass("active");
            //display selected division, hide others
            $(".lng").css("display", "none");
            $(".login2").css("display", "none");
            $(".login").fadeIn(700);
			return false;
        break;
		case "win_login2":
            //change status & style menu
            $("#win_lng1").removeClass("active");
            $("#win_login1").removeClass("active");
            $("#win_login2").addClass("active");
            //display selected division, hide others
            $(".lng").css("display", "none");
            $(".login").css("display", "none");
            $(".login2").fadeIn(700);
			return false;
        break;
		}
	});

	$(".b_close1").click(function () {
			$(".lng").stop(true,true).fadeOut();
			$(".login").stop(true,true).fadeOut();
			$(".login2").stop(true,true).fadeOut();
			$("#win_lng1").removeClass("active");
            $("#win_login1").removeClass("active");
            $("#win_login2").removeClass("active");
			return false;
		}
	);
	$(".b_close2").click(function () {
		$(".lng").stop(true,true).fadeOut();
		$(".login").stop(true,true).fadeOut();
		$(".login2").stop(true,true).fadeOut();
		$("#win_lng1").removeClass("active");
        $("#win_login1").removeClass("active");
        $("#win_login2").removeClass("active");
		return false;
	}
	
	);

	// Galeria - Hide & Show
	$("#win_photo1").click(function(){
		$("#body_off").show();
		$("#body_off").fadeTo(500, 0.80);
		$("#win_galeria").fadeIn(500);
		$("#win_video").fadeOut(200);
		return false;
		}
	);
	// Galeria - Hide & Show					   
	$("#win_video1").click(function(){
		$("#body_off").show();
		$("#body_off").fadeTo(500, 0.80);
		$("#win_galeria").fadeOut(200);
		$("#win_video").fadeIn(500);
		return false;
		}
	);
	$(".win_video_b_close1").click(function(){
		$("#body_off").hide();
		$("#body_off").fadeTo(200, 0.00);
		$("#win_galeria").fadeOut(200);
		$("#win_video").fadeOut(200);
		return false;
		}
	);
	$("#body_off").click(function(){
		$("#body_off").hide();
		$("#body_off").fadeTo(200, 0.00);
		$("#win_galeria").fadeOut(200);
		$("#win_video").fadeOut(200);
		pause(); // Pausar Youtube Video
		return false;
		}
	);
	//Init body_off
	$("#body_off").css("height", $(document).height());
	$("#body_off").fadeTo("fast", 0.0);

	// Nota legal - hide & Show
	$("#win_nota1").click(function(){
		$("#body_off").show();
		$("#body_off").fadeTo(500, 0.80);
		$("#win_notalegal").fadeIn(500);
		return false;
		}
	);
	$("#body_off").click(function(){
		$("#body_off").hide();
		$("#body_off").fadeTo(200, 0.00);
		$("#win_notalegal").fadeOut(200);
		return false;
		}
	);
	$(".win_nota_b_close1").click(function(){
		$("#body_off").hide();
		$("#body_off").fadeTo(200, 0.00);
		$("#win_notalegal").fadeOut(200);
		return false;
		}
	);
	$("#body_off").fadeTo("fast", 0.0);

	var div_info = null;
	$("a.tarifa_mas_info").click(function(e) {
		if(div_info!=null)$(div_info).fadeOut(700);
		div_info = "#d_"+e.target.id;
		$("#d_"+e.target.id).fadeIn(700);
        return false;
	});

	$("a.habitacion_mas_info").click(function(e) {
		if(div_info!=null)$(div_info).fadeOut(700);
		div_info = "#d_"+e.target.id;

		$("#d_"+e.target.id).fadeIn(700);
        return false;
	});


	$("a.tarifa_mas_info_cerrar").click(function(e) {
		$("#d"+e.target.id).fadeOut(700);
		div_info = 	null;
        return false;
	});

	$("a.habitacion_mas_info_cerrar").click(function(e) {
		$("#d"+e.target.id).fadeOut(700);
		div_info = 	null;
        return false;
	});

	$("#link_win_info1").click (function(){
		$("#win_info1").show();
		return false;
	});
	$(".b_close1").click(function () {
		$("#win_info1").hide(); 
		return false;
	});
	$("#ver_sandos_map").click(function () {
		$("#hoteles_map").hide(0);
		$("#sandos_map").show(500);
		return false;
	});
	$("#ver_hoteles_map").click(function () {
		$("#sandos_map").hide(0);
		$("#hoteles_map").show(500);
		return false;
	});
	
});
$(window).resize(function(){
	$("#body_off").css("height", $(document).height());
	$("#body_off").css("width", $(document).width());
});
$(window).load(function(){
	$("#body_off").css("height", $(document).height());
	$("#body_off").css("width", $(document).width());
	
});



// Galeria - Esconder galeria desde flash.
function galleryHide() {
	//$("#body_off").fadeOut(200);
	$("#body_off").fadeTo(200, 0.00, hide);
	$("#win_galeria").fadeOut(200);
	function hide() {
		  $("#body_off").hide();
	}
};


// Window Nota_legal
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

// WinVideo
var ytplayers = new Array();

function onYouTubePlayerReady(playerId) {
	regex = /(\w+)_(\d+)/;
	var playerIndex = playerId.replace(regex, "$2");
	ytplayers[playerIndex] = document.getElementById(playerId);
}

function pause() {
	var videoSelectedIdx = document.getElementById('i_menu:videoSelect').value;
	if (ytplayers[videoSelectedIdx] != undefined) {
		ytplayers[videoSelectedIdx].pauseVideo();
	}
}

function jsChangeYouTubeVideo() {
	var parar = false;
	var i = 0;
	var videoSelectedIdx = document.getElementById('i_menu:videoSelect').value;
	var lastVideoSelectedIdx = document.getElementById('winSelectedVideo').value;

	if (videoSelectedIdx != lastVideoSelectedIdx) {
		if (ytplayers[lastVideoSelectedIdx] != undefined) {
			ytplayers[lastVideoSelectedIdx].pauseVideo();
		}
		
		while (!parar) {
			if (i != videoSelectedIdx) {
				if (document.getElementById('provideo_' + i) != null) {
					swapDisplay('provideo_' + i, false);
				} else {			
					parar = true;				
				}
			}
			i++;
		}
		var selected = 'provideo_' + videoSelectedIdx;
		swapDisplay(selected, true);
		document.getElementById('winSelectedVideo').value = videoSelectedIdx;
	}	
}