//*****************************************
// FUNCIONES DE TRATAMIENTO ESPECIAL
//*****************************************
	//Funciones
	function strpos(haystack, needle, offset) {
		var i = (haystack+'').indexOf(needle, (offset ? offset : 0));
		return i === -1 ? false : i;
	}

    function ventana_mapa(url, title) {
        var win = null;
        var direccion = url;
        var myname = 'preview';
        var w = '835'; 
        var h = '610';
        var scroll = 'no';
        LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
        TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
        settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll
        win = window.open(direccion,myname,settings)
    }
		jQuery.noConflict();        
		jQuery(function(){
			//Galeria de Fotos
			jQuery(".gallery a[rel^='prettyPhoto']").prettyPhoto({theme:'dark_square'});
			
				//Scroll para Galeria de Fotos
				//------------------------------
				jQuery('#preview_galeria img,.galeria_thumb img').click(function() { 
					//En caso de que el Flash/Hear no este oculto
					if (jQuery(window).scrollTop()<266) {
						jQuery.scrollTo('.menu',800);
					}
				});
				
		
			//Botones Derechos
			//-------------------
			jQuery("#videos").click(function() {
				jQuery(".galeria").slideUp("slow", function() {
					jQuery("#right_videos").slideDown("slow");
				});
			})
			
		
			//Reproductor de Videos 2010
			player_abierto = false;
			$jq("#videos_2010").click(function() {
				if (player_abierto == false) {
					player_abierto = true;
					jQuery(this).css("font-weight", "bold");
					jQuery("#fotos").css("font-weight", "normal");
					jQuery(".player_video_2010").slideDown("slow");
				} else {
					player_abierto = false;
					jQuery("#fotos").css("font-weight", "bold");
					jQuery(this).css("font-weight", "normal");
					jQuery(".player_video_2010").slideUp("slow");
				}
			});

			//Botones para Videos
			jQuery("#fotos").click(function() {
				jQuery(this).css("font-weight", "bold");
				jQuery("#videos_2010").css("font-weight", "normal");
				jQuery(".player_video_2010").slideUp("slow");
				jQuery.scrollTo('#menu_media',800);
				player_abierto = false;
			});

            //----------------------------------------------------
	        // INICIO DE LOS MODULOS PARA FECHAS
            //----------------------------------------------------
			jQuery('.fecha_entrada').datepicker({
				inline: true,
				minDate: new Date(),
				firstDay: 1,
				dateFormat: "dd/mm/yy"
			});
			
			jQuery('.fecha_entrada').datepicker('option', 'monthNames', [global["mes"]["enero"],global["mes"]["febrero"],global["mes"]["marzo"],global["mes"]["abril"],global["mes"]["mayo"],global["mes"]["junio"],global["mes"]["julio"],global["mes"]["agosto"],global["mes"]["septiembre"],global["mes"]["octubre"],global["mes"]["noviembre"],global["mes"]["diciembre"]]);
			jQuery('.fecha_entrada').datepicker('option', 'dayNamesMin', [global["dias"]["domingo"],global["dias"]["lunes"],global["dias"]["martes"],global["dias"]["miércoles"],global["dias"]["jueves"],global["dias"]["viernes"],global["dias"]["sábado"]]);
			jQuery('.fecha_entrada').datepicker({ firstDay: 1 });
			//jQuery('.fecha_entrada').datepicker('option', 'dateFormat', "dd/mm/yy");


			//Inferior
			jQuery('.fecha_entrada_inf').datepicker({
				inline: true,
				minDate: new Date(),
				firstDay: 1,
				dateFormat: "dd/mm/yy"
			});            

			jQuery('.fecha_entrada_inf').datepicker('option', 'monthNames', [global["mes"]["enero"],global["mes"]["febrero"],global["mes"]["marzo"],global["mes"]["abril"],global["mes"]["mayo"],global["mes"]["junio"],global["mes"]["julio"],global["mes"]["agosto"],global["mes"]["septiembre"],global["mes"]["octubre"],global["mes"]["noviembre"],global["mes"]["diciembre"]]);
			jQuery('.fecha_entrada_inf').datepicker('option', 'dayNamesMin', [global["dias"]["domingo"],global["dias"]["lunes"],global["dias"]["martes"],global["dias"]["miércoles"],global["dias"]["jueves"],global["dias"]["viernes"],global["dias"]["sábado"]]);
			jQuery('.fecha_entrada_inf').datepicker({ firstDay: 1 });
			//jQuery('.fecha_entrada_inf').datepicker('option', 'dateFormat', "mm/dd/yy");

            
            //-----------------------------            
            // BOTONES PARA RESERVAR
            //-----------------------------
				jQuery("#boton_reservar").click(function() {
                	fecha = jQuery("#fecha_entrada").attr("value");
					numeros = parseInt(jQuery("#noches_superior option:selected").text());
					var fecha = Date.parseExact(fecha, "dd/MM/yyyy").add(numeros).days();					
					var entrada = Date.parseExact(jQuery(".fecha_entrada").attr("value"), "dd/MM/yyyy").toString("dd/MM/yyyy");
					var salida = fecha.toString("dd/MM/yyyy");
					var url = 'http://h10hotels.com/fichas/pasarela_fichas.php?p=todos&d='+global["zona"]+'&h=H10'+global["codigo"]+'&fe='+entrada+'&fs='+salida+'&l='+global["idioma"]+'&ur='+global["url_referencia"];
					
					location.href = url;
					return false;                    
				});
				
				//Inferior
				jQuery(".boton_reservar_inf").click(function() {
                	fecha = jQuery(".fecha_entrada_inf").attr("value");
					numeros = parseInt(jQuery("#noches_superior_inf option:selected").text());
                    
					var fecha = Date.parseExact(fecha, "d/M/yyyy").add(numeros).days();
					var entrada = Date.parseExact(jQuery(".fecha_entrada_inf").attr("value"), "d/M/yyyy").toString("dd/MM/yyyy");
					var salida = fecha.toString("dd/MM/yyyy");
					var url = 'http://h10hotels.com/fichas/pasarela_fichas.php?p=todos&d='+global["zona"]+'&h=H10'+global["codigo"]+'&fe='+entrada+'&fs='+salida+'&l='+global["idioma"]+'&ur='+global["url_referencia"];
					location.href = url;
					return false;                    
				});

            //-----------------------------
			// HILO DE BOTONES
            //-----------------------------
			jQuery("#vermapa").click(function() {
				url = jQuery(this).attr("title");
				ventana_mapa(url, global["id_hotel"]);
			});
            
			jQuery("#llegar_label").click(function() {
				url = jQuery(this).attr("title");
				ventana_mapa(url, global["id_hotel"]);
			});


			//-- Botones de la Galeria de Fotos
			imagen_activa = 0;
			jQuery("#fle_iz").click(function() {
				imagen_activa--;
				if (imagen_activa <= 1) { imagen_activa = (jQuery('.galeria a').size()-1); }

				//Efecto de la Imagen
				jQuery('.galeria a:eq('+imagen_activa+')').each(function(){
					href = jQuery(this).attr("href");
					jQuery(".preview_activo").fadeOut(function() {
						jQuery(".enlace_activo").attr("href", href);
						jQuery(".preview_activo").attr("src",href);

						if (largo !== 1 && strpos(href, "L)")) {
							largo = 1;
							jQuery("#preview_galeria").animate({ height: "550px"}, 500); 
						}
						
						if (largo !== 0 && !strpos(href, "L)")) {
							largo = 0;
							jQuery("#preview_galeria").animate({ height: "310px"}, 500); 
						}

						jQuery(".preview_activo").load(function(){						
							jQuery(".preview_activo").fadeIn();
						});
					});
				});
				
			});


			jQuery("#fle_de").click(function() {
				imagen_activa++;
				if (imagen_activa >= jQuery('.galeria a').size()) { imagen_activa = 0; }

				//Efecto de la Imagen
				jQuery('.galeria_thumb a:eq('+imagen_activa+')').each(function(){
					jQuery("#datas").html(jQuery(this).attr("title"));
					href = jQuery(this).attr("href");
					jQuery(".preview_activo").fadeOut(function() {
						jQuery(".enlace_activo").attr("href", href);
						jQuery(".preview_activo").attr("src",href);

						if (largo !== 1 && strpos(href, "L)")) {
							largo = 1;
							jQuery("#preview_galeria").animate({ height: "550px"}, 500); 
						}
						
						if (largo !== 0 && !strpos(href, "L)")) {
							largo = 0;
							jQuery("#preview_galeria").animate({ height: "310px"}, 500); 
						}
						
						jQuery(".preview_activo").load(function(){						
							jQuery(".preview_activo").fadeIn();
						});
					});
				});
			});
			
			//Mostrar Correos Electronicos
				var Base64 = {
					// private property
					_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
				 
					// public method for encoding
					encode : function (input) {
						var output = "";
						var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
						var i = 0;
				 
						input = Base64._utf8_encode(input);
				 
						while (i < input.length) {
				 
							chr1 = input.charCodeAt(i++);
							chr2 = input.charCodeAt(i++);
							chr3 = input.charCodeAt(i++);
				 
							enc1 = chr1 >> 2;
							enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
							enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
							enc4 = chr3 & 63;
				 
							if (isNaN(chr2)) {
								enc3 = enc4 = 64;
							} else if (isNaN(chr3)) {
								enc4 = 64;
							}
				 
							output = output +
							this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
							this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
				 
						}
				 
						return output;
					},
				 
					// public method for decoding
					decode : function (input) {
						if (input) {
							var output = "";
							var chr1, chr2, chr3;
							var enc1, enc2, enc3, enc4;
							var i = 0;
					 
							input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
					 
							while (i < input.length) {
					 
								enc1 = this._keyStr.indexOf(input.charAt(i++));
								enc2 = this._keyStr.indexOf(input.charAt(i++));
								enc3 = this._keyStr.indexOf(input.charAt(i++));
								enc4 = this._keyStr.indexOf(input.charAt(i++));
					 
								chr1 = (enc1 << 2) | (enc2 >> 4);
								chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
								chr3 = ((enc3 & 3) << 6) | enc4;
					 
								output = output + String.fromCharCode(chr1);
					 
								if (enc3 != 64) {
									output = output + String.fromCharCode(chr2);
								}
								if (enc4 != 64) {
									output = output + String.fromCharCode(chr3);
								}
							}
						}
				 
						output = Base64._utf8_decode(output);
				 
						return output;
				 
					},
				 
					// private method for UTF-8 encoding
					_utf8_encode : function (string) {
						string = string.replace(/\r\n/g,"\n");
						var utftext = "";
				 
						for (var n = 0; n < string.length; n++) {
				 
							var c = string.charCodeAt(n);
				 
							if (c < 128) {
								utftext += String.fromCharCode(c);
							}
							else if((c > 127) && (c < 2048)) {
								utftext += String.fromCharCode((c >> 6) | 192);
								utftext += String.fromCharCode((c & 63) | 128);
							}
							else {
								utftext += String.fromCharCode((c >> 12) | 224);
								utftext += String.fromCharCode(((c >> 6) & 63) | 128);
								utftext += String.fromCharCode((c & 63) | 128);
							}
				 
						}
				 
						return utftext;
					},
				 
					// private method for UTF-8 decoding
					_utf8_decode : function (utftext) {
						if (utftext) {
							var string = "";
							var i = 0;
							var c = c1 = c2 = 0;
					 
							while ( i < utftext.length ) {
					 
								c = utftext.charCodeAt(i);
					 
								if (c < 128) {
									string += String.fromCharCode(c);
									i++;
								}
								else if((c > 191) && (c < 224)) {
									c2 = utftext.charCodeAt(i+1);
									string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
									i += 2;
								}
								else {
									c2 = utftext.charCodeAt(i+1);
									c3 = utftext.charCodeAt(i+2);
									string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
									i += 3;
								}
					 
							}
					 
							return string;
						}
					}
				}
			
			//Activar Base 64
			$jq(".codemail").attr("href", "mailto:"+Base64.decode($jq(".codemail").attr("href")));

		})