// JavaScript Document

jQuery.noConflict ();

var anchoImagenes = 940;
var intervaloMarquesina;
var intervaloMostrarMarquesina;
var imagenActual;
var imagenesTotal;
var idiomaActual;
var idi;
var timeoutLanguages;
var categoriasTaylor = new Array ("All");
var categoriasScheduled = new Array ("All");
var categoriasTaylorSeleccionadas = new Array ();
var categoriasScheduledSeleccionadas = new Array ();
var vel = 300;
var flickr_id = '67778954@N05';
var marquesinaAbierta = true;
//var urlBase = 'http://localhost:8888/valenciaguias/www/wp-content/themes/valenciaguias/';
var urlBase = 'http://www.valenciaguias.com/wp-content/themes/valenciaguias/';
var formActual;
var idiomas = new Array ();
var pag;
var pagina;
var comienzo;
var ie;

var idiomas = {
	en : {
		icono: "gb",
		lenguaje: "English"
	},
	es : {
		icono: "es",
		lenguaje: "Español"
	},
	fr : {
		icono: "fr",
		lenguaje: "Française"
	},
	de : {
		icono: "de",
		lenguaje: "Deutsch"
	},
	nl : {
		icono: "nl",
		lenguaje: "Nederlandse"
	}
};

jQuery(document).ready (function() {
//	jQuery ('#wrapper').fadeTo (0, 0);
	
	WebFontConfig = {
		google: { 
			families: [ 'Open+Sans:400,400italic,700,700italic:latin' ] 
		},
		loading: function () {
		},
		fontactive: function (fontFamily, fontDescription) {
			setTimeout ("arrancar (pagina)", 1000);
		}
	};
	(function() {
   		var wf = document.createElement('script');
	    wf.src = ('https:' == document.location.protocol ? 'https' : 'http') +
    	    '://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js';
	    wf.type = 'text/javascript';
    	wf.async = 'true';
	    var s = document.getElementsByTagName('script')[0];
    	s.parentNode.insertBefore(wf, s);
	})();
	
	imagenActual = 0;
	
	var urlJSON = 'http://free.worldweatheronline.com/feed/weather.ashx?q=Valencia,Spain&format=json&num_of_days=2&key=55f89cab63132527111005&callback=?';
	
	jQuery.getJSON (urlJSON,
		function (datos) {
			var condActual = datos.data.current_condition[0];
			var hoy = datos.data.weather[0];
			
			var tempAct = condActual.temp_C;
			var tempMax = hoy.tempMaxC;
			var icono = "http://www.aptitudelab.com/webs/valenciaguias/img/clima/" + hoy.weatherCode + ".png";
//			var icono = "http://www.aptitudelab.com/webs/valenciaguias/img/clima/nublado.png";
			
			var tMax = (tempAct > tempMax) ? tempAct : tempMax;
			
			var html = "<strong>Valencia</strong> " + condActual.temp_C + "&deg;<br /><span class='degree_mini'>H: " + tMax + "&deg; - L: " + hoy.tempMinC + "&deg;</span>";
			
			jQuery ('#degree').html (html);
			jQuery ('#weather_icon a img').attr ('src', icono);
		});
		
/*	idiomaActual = window.navigator.language;
	
	idi = idiomaActual.substr (0,2);*/
	
	jQuery ('#languages')
/*		.bind ('mouseover', function () {
			clearTimeout (timeoutLanguages);
			jQuery (this).stop().animate ( {height: '75px'}, vel);
		})
		.bind ('mouseout', function () {
			var element = this;
			timeoutLanguages = setTimeout (function (capa) {
					jQuery (element).stop().animate ( {height: '11px'}, vel); 
				}, 1000);
		})*/
		.find ('#'+idi)
		.css ('top', '0')
		.removeClass ('idioma_apagado')
		.siblings()
		.each (function (i) {
			var pos = (i+1) * 14;
			jQuery (this)
				.css ('top', pos+'px')
				.addClass ('idioma_apagado');			
		});
		
	jQuery ('#logo')
		.click (function () {
			moverPantalla (0, 0, vel);
		});
	
	jQuery ('#nav .menu_enlace')
		.last()
			.siblings()
				.addClass ('menu_con_borde')
			.end()
		.end()
		.each (function (i) {
			jQuery (this)
				.click (function () {
					if (i != 4) {
						moverPantalla (i, 0, vel);
					}
					else {
						abrirContacto ();
					};
				});
			});
		
	jQuery ('.marquesina_texto')
		.first ()
			.fadeTo (0, 1);
	
	jQuery ('.social_enlace')
		.hover (
			function () {
				jQuery (this).find('img').stop().animate ({top: '-22px'}, 200);
			},
			function () {
				jQuery (this).find('img').stop().animate ({top: '0px'}, 200);
			});
		
	jQuery ('.boton_up a')
		.hover (function () {
			jQuery (this).find ('img').stop().animate ({ top: '-32px' }, 200);
			}, function () {
			jQuery (this).find ('img').stop().animate ({ top: '0px' }, 200);
		})			
		.click (function () {
			jQuery ('html, body').stop().animate ( {scrollTop: 0}, vel*2);
		});
	
	jQuery ('.texto_post').each (function (i) {
		jQuery (this).find ('.post_column_1')
			.each (function () {
				jQuery (this)
					.find ('p')
						.first()
							.addClass ('primer_parrafo')
						.end()
					.end()	
					.find ('p')
						.last()
							.addClass ('ultimo_parrafo');
			})
			.eq (0)
				.addClass ('columna_izquierda')
			.end ()	
			.eq (1)
				.addClass ('columna_derecha');
	 });
	
	jQuery ('.boton_slideshow')
		.first ()
			.find ('img').stop().animate ({ top: '-11px'}, 0)
			.end()
		.end()
		.each (function (i) {
			jQuery (this).click (function () {
				cambiarImagen (jQuery ('#marquesina_imagenes'), i, true, true);
			});
		});
		
	intervaloMarquesina = setInterval ('avanzarImagen (jQuery ("#marquesina_imagenes"), true)', 3000);
	
	jQuery ('#marquesina_imagenes li')
		.each (function (n) {
			if (n == 0) {
				jQuery (this)
					.find ('img')
						.show();
			};
			
			jQuery (this)
				.find ('.marquesina_anuncio').each (function (i) {
					var alto = parseInt(jQuery (this).css ('height'));
					var ancho = parseInt(jQuery (this).css ('width'));
					
					var medidas = (alto > ancho) ? alto : ancho;
					
					jQuery (this).css ({
						width: medidas,
						height: medidas,
						padding: 20
					});
					
					var margenTop;
					var margenLeft;
					
					if (ancho > alto) {
						margenTop = (ancho - alto) / 2;
						margenLeft = 0;
					}
					
					jQuery (this).corner (medidas*2+'px');
					
					jQuery (this).find ('.marquesina_texto').css ({
						marginTop: margenTop,
						marginLeft: margenLeft
					});
				});
		});
			
//	ajustarAltura (0);
	
	jQuery ('#marquesina_mostrar_ocultar')
		.hover (function () {
				jQuery (this).addClass ('marquesina_hover');
			}, function () {
				jQuery (this).removeClass ('marquesina_hover');
		})
		.click (function () {
			mostrarMarquesina ();
		});
		
	jQuery ('#marquesina_navegar')
		.stop().fadeTo (0, 0, function () { jQuery (this).hide(); })
		.find ('.marquesina_nav')
			.eq (1)
				.hover (function () {
					jQuery (this).addClass ('marquesina_hover');
				}, function () {
					jQuery (this).removeClass ('marquesina_hover');
				})
				.bind ('click', function () {
					avanzarImagen (jQuery ('#marquesina_imagenes'), true, false);
				})
				.css ('marginLeft', '2px');
				
	jQuery ('.post_empresa') 
		.find ('.categoria')
			.hover (
				function () {
					jQuery (this).addClass ('categoria_activo_hover');
				},
				function () {
					jQuery (this).removeClass ('categoria_activo_hover');
				})
			.bind ('click', abrirContacto);
	
	jQuery ('#taylormade')
		.find ('.post_empresa')
			.first ()
				.css ({
					marginTop: 20,
					marginBottom: 20
				})
			.end ()
			.last ()
				.css ('marginBottom', '20px')
			.end ()
		.end ()
		.find ('.linea_subir')
			.eq (0)
				.css ('marginTop', '15px')
			.end ()
			.eq(1)
				.css ('marginTop', '0');

	jQuery ('#scheduled')
		.find ('.post_empresa')
			.first ()
				.css ({
					marginTop: 20,
					marginBottom: 20
				})
			.end ()
			.last ()
				.css ('marginBottom', '20px')
			.end ()
		.end ()
		.find ('.linea_subir')
			.eq (0)
				.css ('marginTop', '15px')
			.end ()
			.eq(1)
				.css ('marginTop', '0');
				
	jQuery ('#bicicletas')
		.find ('.linea_subir')
			.eq (0)
				.css ('marginTop', '15px');
				
	jQuery ('.ficha_contenidoBici').each (function () {
		jQuery (this)
			.find ('.ficha_doble')
				.first ()
					.css ('marginTop', '0')
				.end ()
				.last ()
					.css ('border', '0');
	});

	var posX = 0;
	var posY = 0;
	
	$rutas_taylor = jQuery ('#rutas_taylormade .rutas_thumbnail');
	$rutas_scheduled = jQuery ('#rutas_scheduled .rutas_thumbnail');
	
	var altura_taylor = 149 * Math.ceil($rutas_taylor.length / 4);
	var altura_scheduled = 149 * Math.ceil($rutas_scheduled.length / 4);
	
	jQuery ('#rutas_taylormade')
		.css ('height', altura_taylor+'px')
		.find ('.rutas_thumbnail')
			.each (function (i) {
				jQuery (this).css ({
					left: posX,
					top: posY,
					zIndex: 100-i
				});
			
				if ((i+1)%4 == 0) {
					posY += 149;
					posX = 0;
				}
				else {
					posX += 241;
				}
				
				jQuery (this)
					.hover (function () {
						jQuery (this)
							.find ('.sobre_thumbnail')
								.stop()
								.animate ({ left: -160 }, vel);
						}, function () {
							jQuery (this)
								.find ('.sobre_thumbnail')
									.stop()
									.animate ({ left: 0 }, vel*2);
						})
					.click (function () {
						var postOffset = jQuery ('#rutas_taylormade_desc .linea_subir').eq(i).offset();
						var destino = postOffset.top - 20;
					
						jQuery ('html, body').stop().animate ( {scrollTop: destino}, vel*2);
					});
			});
			
	posX = 0;
	posY = 0;
		
	jQuery ('#rutas_scheduled')
		.css ('height', altura_scheduled+'px')
		.find ('.rutas_thumbnail')
			.each (function (i) {
				jQuery (this).css ({
					left: posX,
					top: posY,
					zIndex: 100-i
				});
			
				if ((i+1)%4 == 0) {
					posY += 149;
					posX = 0;
				}
				else {
					posX += 241;
				}
				
				jQuery (this)
					.hover (function () {
						jQuery (this)
							.find ('.sobre_thumbnail')
								.stop()
								.animate ({ left: -160 }, 300);
					}, function () {
						jQuery (this)
							.find ('.sobre_thumbnail')
								.stop()
								.animate ({ left: 0 }, vel*2);
					})
					.click (function () {
						var postOffset = jQuery ('#rutas_scheduled_desc .linea_subir').eq(i).offset();
						var destino = postOffset.top - 20;
					
						jQuery ('html, body').stop().animate ( {scrollTop: destino}, vel*2);
					});
			});
			
	jQuery ('.marquesina_boton')
		.find ('img')
			.css ('position', 'absolute')
		.end()
		.hover (function () {
			jQuery (this).find('img').stop().animate ({top: '-75px'}, 0);
		}, function () {
			jQuery (this).find('img').stop().animate ({top: '0px'}, 0);
		})
		.each (function (i) {
			var num = i+1;
			jQuery (this).click (function () {
				moverPantalla (num, 0, vel);
			});
		});
										   
	jQuery ('.rutas_boton')
		.find ('img')
			.css ('position', 'absolute')
		.end()
		.hover (function () {
			jQuery (this).find('img').stop().animate ({top: '-48px'}, 0);
		}, function () {
			jQuery (this).find('img').stop().animate ({top: '0px'}, 0);
		})
		.each (function (i) {
			var num = i+1;
			jQuery (this).click (function () {
				moverPantalla (num, 0, vel);
			});
		});
										   
/*	jQuery ('.marquesina_boton_dentro')
		.find ('img')
			.css ('position', 'absolute')
		.end()
		.hover (function () {
			jQuery (this).find('img').stop().animate ({top: '-48px'}, 0);
		}, function () {
			jQuery (this).find('img').stop().animate ({top: '0px'}, 0);
		})
		.each (function (i) {
			var num;
			
			if (i == 0) {
				num = 2;
			}
			else {
				num = 1;
			};
			
			jQuery (this).click (function () {
				moverPantalla (num, 0);
			});
		});*/
										   
				
		
/*	jQuery ('a[href="#taylormadeprivatetours"]')
		.click (function () {
				moverPantalla (1, 0);
			});
		
	jQuery ('a[href="#scheduledtours"]')
		.click (function () {
				moverPantalla (2, 0);
			});*/
		
	jQuery ('#taylormade .categorias .categoria')
		.each (function (i) {
			jQuery (this).hover (function () {
				if (jQuery (this).hasClass ('categoria_activo')) {
					jQuery (this).addClass ('categoria_activo_hover');
				};
			}, function () {
				if (jQuery (this).hasClass ('categoria_activo')) {
					jQuery (this).removeClass ('categoria_activo_hover');
				};
			});										   
										   
			jQuery (this).click (function () {
				if (jQuery (this).hasClass ('categoria_inactivo')) {
					jQuery (this)
						.addClass ('categoria_activo')
						.removeClass ('categoria_inactivo');
				}
				
				var ruta = jQuery (this).parent().parent().attr ('id');
				var catClic = categoriasTaylor[i];
				
				var posX = 0;
				var posY = 0;
				var num = 0;
				var cambio = false;
				
				if (i == i) {
					categoriasTaylorSeleccionadas = new Array ();
					
					if (!jQuery ('.categorias .categoria').eq(i).hasClass ('categoria_inactivo')) {
						jQuery ('.categorias .categoria').eq(i)
							.addClass ('categoria_inactivo')
							.removeClass ('categoria_activo')
							.siblings()
								.addClass ('categoria_activo')
								.removeClass ('categoria_activo_hover')
								.removeClass ('categoria_inactivo');
								
						if (i == 0) {
							jQuery ('#rutas_taylormade div.rutas_thumbnail').each (function (i) {
								var numLinea = i + 1;
								var del = num*50;
							
								jQuery (this)
									.show()
									.stop()
									.delay (del)
										.animate ({ left: posX, top: posY, opacity: 1 }, 300);
					
								if ((num+1)%4 == 0) {
									posY += 149;
									posX = 0;
								}
								else {
									posX += 241;
								}
						
								jQuery ('#rutas_taylormade_desc .ruta').eq(i).show();
								jQuery ('#rutas_taylormade_desc .linea_subir').eq(numLinea).show();
								jQuery ('#rutas_taylormade_desc .boton_up').eq(numLinea).show();
							
								num++;
							});
						}
						else {
							jQuery ('#rutas_taylormade div.rutas_thumbnail').each (function (j) {
								var numLinea = j + 1;
		
								if (!jQuery (this).is ('.'+catClic)) {
									jQuery (this).stop().fadeTo (300, 0, function () {
										jQuery (this).css ({ top: 0, left: 0 });
										jQuery (this).hide ();
									});
									
									jQuery ('#rutas_taylormade_desc .ruta').eq(j).hide();
									jQuery ('#rutas_taylormade_desc .linea_subir').eq(numLinea).hide();
									jQuery ('#rutas_taylormade_desc .boton_up').eq(numLinea).hide();
								}
								else {
									var del = num*50;
									
									jQuery (this)
										.show()
										.stop()
										.delay (del)
											.animate ({ left: posX, top: posY, opacity: 1 }, 300);
					
									if ((num+1)%4 == 0) {
										posY += 149;
										posX = 0;
									}
									else {
										posX += 241;
									}
							
									jQuery ('#rutas_taylormade_desc .ruta').eq(j).show();
									jQuery ('#rutas_taylormade_desc .linea_subir').eq(numLinea).show();
									jQuery ('#rutas_taylormade_desc .boton_up').eq(numLinea).show();
								
									num++;
								};
							});
						};
						
						var altura_taylor = 149 * Math.ceil(num / 4);
						jQuery ('#rutas_taylormade').stop().animate ({ height: altura_taylor }, 300, function () {
							ajustarAltura (1);
						});
					}
 				}
			});
		})
		.first()
			.addClass ('categoria_inactivo')
			.siblings ()
				.addClass ('categoria_activo');
			
	jQuery ('.ruta_galeria').each (function (i) {
		if (jQuery (this).attr ('id') != "") {
			cargarImagenesFlickr (jQuery (this).attr ('id'), jQuery (this), 464, 260, false);
		}
	});
	
	jQuery ('.ruta_info') 
		.find ('.categoria').each (function (i) {
			jQuery (this)
				.hover (
					function () {
						jQuery (this).addClass ('categoria_activo_hover');
					},
					function () {
						jQuery (this).removeClass ('categoria_activo_hover');
					})
				.bind ('click', function () {
					abrirReserva (i, jQuery(this).attr ("dias"));
				});
		});
	
/*	jQuery ('.ruta_media').each (function () {
		var $ruta_mapa = jQuery (this).find ('.ruta_mapa')
			.hover (function () {
				jQuery (this).stop().animate ({ left: '0px' }, 300);
			}, function () {
				jQuery (this).stop().animate ({ left: '-460px' }, 300);
			});
			
		jQuery (this).find ('.ruta_galeria')
			.hover (function () {
				$ruta_mapa.stop().animate ({ left: '-700px' }, 300);
			}, function () {
				$ruta_mapa.stop().animate ({ left: '-460px' }, 300);
			});
	});*/

	jQuery ('.ruta_consultar')
		.hover (
			function () {
				jQuery (this).addClass ('categoria_activo_hover');
			},
			function () {
				jQuery (this).removeClass ('categoria_activo_hover');
			});

	jQuery ('.formulario')
		.find ('.right')
			.hover (
				function () {
					jQuery (this).addClass ('marquesina_hover');
				},
				function () {
					jQuery (this).removeClass ('marquesina_hover');
				})
			.bind ('click', function () {
				chequearFormularioContacto (document.getElementById('formContacto'), jQuery ('.formulario'));
			})
		.end()
		.find ('label')
			.each (function (i) {
				jQuery (this)
					.bind ('click', function () {
						jQuery ('.formulario').find ('.con_label').eq(i).focus();
					});
			})
		.end()
		.find ('.con_label')
			.each (function (i) {
				if (jQuery(this).attr ('value') != '') {
					jQuery ('.formulario label').eq(i).hide();
				};
				
				jQuery (this)
					.focus (function () {
						jQuery ('.formulario label').eq(i).hide();
					})
					.blur (function () {
						if (jQuery (this).attr ('value') == "") {
							jQuery ('.formulario label').eq(i).show();
						};
					});
			})
		.end()
		.find ('.elem_texto')
			.each (function (i) {
				jQuery (this)
					.keydown (function (e) {
						if (e.keyCode == 13) {
							chequearFormularioContacto (document.getElementById('formContacto'), jQuery ('.formulario'));
						}
			});
		});
			
	jQuery ('.galeria')
		.each ( function () {
			cargarImagenesFlickr (jQuery (this).attr ('set'), jQuery (this), 598, 337, true);
		});
		
	jQuery ('.idioma')
		.find ('a')
			.each (function () {
				jQuery (this)
					.bind ('click', function () {
						var url = jQuery (this).attr ('href');
				
						url += pagina;
						
						jQuery (this).attr ('href', url);
					});
			});
});

function imagenesMarquesina (num) {
	jQuery ('#marquesina_imagenes')
		.attr ('total', num)
		.attr ('actual', 0);
}

function avanzarImagen ($capa, marq, tex) {
	var num = parseInt ($capa.attr('actual')) + 1;
	var tot = parseInt ($capa.attr('total'));
	
	num = (num == tot) ? 0 : num;
	
	cambiarImagen ($capa, num, false, marq, tex);	
}

function retrocederImagen ($capa, marq, tex) {
	var num = parseInt ($capa.attr('actual')) - 1;
	var tot = parseInt ($capa.attr('total'));
	
	num = (num == -1) ? tot-1 : num;
	
	cambiarImagen ($capa, num, false, marq, tex);	
}

function cambiarImagen ($capa, num, bol, marq, tex) {
	var actual = parseInt ($capa.attr ('actual'));
	var total = parseInt ($capa.attr ('total'));
	
	if (num == 0) {
		$capa.find ('.marquesina_izquierda')
			.unbind ('mouseenter mouseleave click')
			.removeClass ('marquesina_activo')
			.removeClass ('marquesina_hover')
			.addClass ('marquesina_inactivo');
	}
	else {
		if ($capa.find ('.marquesina_izquierda').hasClass ('marquesina_inactivo')) {
			$capa.find ('.marquesina_izquierda')
				.removeClass ('marquesina_inactivo')
				.addClass ('marquesina_activo')
				.hover (function () {
					jQuery (this).addClass ('marquesina_hover');
				}, function () {
					jQuery (this).removeClass ('marquesina_hover');
				})
				.bind ('click', function () {
					retrocederImagen ($capa, marq, tex);
				});
		}
	}
	
	if (num == total-1) {
		$capa.find ('.marquesina_derecha')
			.unbind ('mouseenter mouseleave click')
			.removeClass ('marquesina_activo')
			.removeClass ('marquesina_hover')
			.addClass ('marquesina_inactivo');
	}
	else {
		if ($capa.find ('.marquesina_derecha').hasClass ('marquesina_inactivo')) {
			$capa.find ('.marquesina_derecha')
				.removeClass ('marquesina_inactivo')
				.addClass ('marquesina_activo')
				.hover (function () {
					jQuery (this).addClass ('marquesina_hover');
				}, function () {
					jQuery (this).removeClass ('marquesina_hover');
				})
				.bind ('click', function () {
					avanzarImagen ($capa, marq, tex);
				});
		}
	}
	
	if (marquesinaAbierta && bol) {
		clearInterval (intervaloMarquesina);
	}
	
	$capa.find ('img')
		.eq (actual)
			.fadeTo (vel*2, 0, function () { jQuery (this).hide (); })
		.end()
		.eq (num)
			.fadeTo (vel*2, 1)
		.end();
		
	if (tex) {
		$capa.find ('.desc_flickr')
			.eq (actual)
				.fadeTo (vel*2, 0)
			.end()
			.eq (num)
				.fadeTo (vel*2, 1)
			.end();
	};
	
	if (marq) {
		jQuery ('.marquesina_texto')
			.eq (actual)
				.fadeTo (vel, 0)
			.end()
			.eq (num)
				.fadeTo (vel, 1)
			.end();
	};
	
	actual = num;
	
	$capa.attr ('actual', actual);
	
	if (marq) {
		jQuery ('.boton_slideshow')
			.eq (actual)
				.find ('img').stop().animate ({ top: '-11px'}, 0)
				.end()
				.siblings ()
					.find ('img').stop().animate ({ top: '0px'}, 0);
	};
	
	if (bol && marquesinaAbierta) {
		intervaloMarquesina = setInterval ('avanzarImagen (jQuery ("#marquesina_imagenes"), true, false)', 3000);
	};
};

function setIdioma (idioma, pagi) {
	pag = parseInt(pagi);
	idi = idioma;
	
	if (pag == 0) {
		pagina = 4;
	}
	else {
		pagina = pag;
	}
	
	pagina = pag;
	
	moverPantalla (pag, 0, 0);
	
	if (idi != "en" && idi != "es") {
		idi = "en";
	};
	
	if (idi == "es") {
		idiNum = 1;
	}
	else if (idi == "en") {
		idiNum = 2;
	};

	jQuery ('#languages')
/*		.bind ('mouseover', function () {
			clearTimeout (timeoutLanguages);
			jQuery (this).stop().animate ( {height: '75px'}, vel);
		})
		.bind ('mouseout', function () {
			var element = this;
			timeoutLanguages = setTimeout (function (capa) {
					jQuery (element).stop().animate ( {height: '11px'}, vel); 
				}, 1000);
		})*/
		.find ('#'+idi)
		.css ('top', '0')
		.removeClass ('idioma_apagado')
		.siblings()
		.each (function (i) {
			var pos = (i+1) * 14;
			jQuery (this)
				.css ('top', pos+'px')
				.addClass ('idioma_apagado')
				.hover (
					function () {
						jQuery (this)
							.addClass ('idioma_hover')
							.removeClass ('idioma_apagado');
					},
					function () {
						jQuery (this)
							.removeClass ('idioma_hover')
							.addClass ('idioma_apagado');
					});
		});
};

function mostrarMarquesina () {
	clearInterval (intervaloMarquesina);
	marquesinaAbierta = false;
	
	jQuery ('#marquesina_mostrar_ocultar')
		.stop().animate ( {top: 30}, 300, function () {
			jQuery (this)
				.removeClass ('marquesina_mostrar')
				.addClass ('marquesina_ocultar')
				.unbind ('click')
				.bind ('click', function () {
					ocultarMarquesina ();
				});
		});
		
	jQuery ('#marquesina_navegar').stop().fadeTo (300, 1);
	jQuery ('#marquesina_textos').stop().fadeTo (300, 1);
	
	jQuery ('#marquesina_slideshow')
		.animate ( {top: 425}, vel);
	
	jQuery ('#marquesina_contenido')
		.animate ( {left: -anchoImagenes}, vel*2);
		
	jQuery ('#marquesina_imagenes')
		.bind ('mouseleave', function (e) {
			jQuery (this).unbind ('mouseleave');
//			setTimeout (ocultarMarquesina, vel*2);
		});
};

function ocultarMarquesina () {
	marquesinaAbierta = true;
	intervaloMarquesina = setInterval ('avanzarImagen (jQuery ("#marquesina_imagenes"), true)', 3000);
	
	jQuery ('#marquesina_mostrar_ocultar')
		.stop().animate ( {top: 345}, 300, function () {
			jQuery (this)
				.addClass ('marquesina_mostrar')
				.removeClass ('marquesina_ocultar')
				.unbind ('click')
				.bind ('click', function () {
					mostrarMarquesina ();
				});
		});
	
	jQuery ('#marquesina_navegar').stop().fadeTo (300, 0, function () { jQuery (this).hide(); });
	jQuery ('#marquesina_textos').stop().fadeTo (300, 0, function () { jQuery (this).hide(); });

	jQuery ('#marquesina_slideshow')
		.animate ( {top: 395}, vel*2);
	
	jQuery ('#marquesina_contenido')
		.animate ( {left: 0}, vel*2);
};

function moverPantalla (a, b, velocidad) {
	var delay;
	pagina = a;
	
	var pos = jQuery ('html, body').scrollTop();
	var posFin = -a * 990;
		
	if (pos != 0) {
		delay = velocidad*2;
	}
	else {
		delay = 0;
	}
	
	var posCont = jQuery ('#contenido').css ('left');
	
	var delay2 = (a == 0 && posCont == "0px") ? 0 : velocidad*2;
	
	jQuery ('html, body')
		.stop()
		.animate ({ scrollTop: 0 }, delay, function () {
			jQuery ('.apartado').show();
			
			ajustarAltura (a);
					
			jQuery (this).find ('#contenido')
				.stop()
				.animate ({ left: posFin }, delay2, function () {
					jQuery ('.apartado').eq(a).siblings().hide();
					
					if (a == 0) {
						var destino;
					
						if (b==0) {
							destino = 0;
						}
						else {
							var num = b-1;
				
							var postOffset = jQuery ('.linea_subir').eq(num).offset();
							destino = postOffset.top - 20;
						}
					
						jQuery ('html, body').stop().animate ( {scrollTop: destino}, velocidad*2);
					}
				});
		});

};

function abrirContacto () {
	jQuery.facebox(function() {
		cargaInt = jQuery.get(urlBase+'contacto_'+idi+'.html', function(data) {
			jQuery('.content').html (data);	
			
			formActual = "Contacto";
			
			activarFormulario ("nada");
		});
	});
};

function abrirReserva (num, str) {
	jQuery.facebox(function() {
		cargaInt = jQuery.get(urlBase+'reserva_'+idi+'.php?num='+num+'&lang='+idi, function(data) {
			jQuery('.content').html (data);	
			
			formActual = "Rutas";
			
			activarFormulario (str);
		});
	});
};

function anadirCategoria (nom, bol) {
	if (bol) {
		categoriasTaylor.push (nom);
	}
	else {
		categoriasScheduled.push (nom);
	}
};

function cargarImagenesFlickr (set, $capa, width, height, bol) {
	var urlJSON = 'http://api.flickr.com/services/rest/?method=flickr.photosets.getPhotos&api_key=d3624bdcff55f0bc8b968ef7e127f011&photoset_id='+set+'&extras=description%2C+url_l%2C+url_m&per_page=500&format=json&jsoncallback=?'
	
	if (bol) {
		var textos = new Array();
	};
	
	jQuery.ajax ({
		url: urlJSON,
		cache: false,
		dataType: "json",
		success: function (data) {
			if (data.photoset.photo) {
				var html = '<ul>';
				jQuery.each (data.photoset.photo, function (i, n) {
					var item = data.photoset.photo[i];
					var ruta = item.url_m;
					html += '<li><img src="'+ruta+'" title="'+item.title+'" width="'+width+'" height="'+height+'" /></li>';
					
					if (bol) {
						textos[i] = item.title;
					};
				});
				
				html += '</ul>';
				
				if (idi == "en" && bol) {
					for (var j=0; j<textos.length; j++) {
						if (textos[j].toLowerCase() == "equipo de gesti\xf3n") {
							textos[j] = "Valencia Gu\xedas Management Team";
						}
						else if (textos[j].toLowerCase() == "ana merelo (direcci\xf3n)") {
							textos[j]  = "Ana Merelo (Managing Director)";
						}
						else if (textos[j].toLowerCase() == "bego\xf1a sesa (contabilidad)") {
							textos[j]  = "Bego\xf1a Sesa (Accounts)";
						}
						else if (textos[j].toLowerCase() == "borja llorens (reservas)") {
							textos[j]  = "Borja Llorens (Booking)";
						}
						else if (textos[j].toLowerCase() == "genevieve schook (reservas)") {
							textos[j]  = "Genevieve Schook (Booking)";
						}
						else if (textos[j].toLowerCase() == "eugenia d\xe1valos (reservas)") {
							textos[j]  = "Eugenia D\xe1valos (Booking)";
						}
						else if (textos[j].toLowerCase() == "mar\xeda soler (reservas)") {
							textos[j]  = "Mar\xeda Soler (Booking)";
						}
						else if (textos[j].toLowerCase() == "jose ferri (comercial y marketing)") {
							textos[j]  = "Jose Ferri (sales & marketing)";
						}
					};
				};
				
				if (bol) {
					for (i=0; i<textos.length; i++) {
						html += '<div class="desc_flickr">'+textos[i]+'</div>';
					};
				};
				
				$capa
					.append (html)
					.attr ('total', data.photoset.photo.length)
					.attr ('actual', 0)
					.find('img')
					.first()
						.show()
							
				if (bol) {
					$capa
						.find ('.desc_flickr')
							.first()
								.fadeTo (0, 1);
				};
							
			
				if (data.photoset.photo.length > 1) {
					$capa
						.find ('.galeria_navegar')
							.fadeTo (vel, 1)
						.end ()
						.find ('.marquesina_nav')
							.eq (1)
								.hover (function () {
									jQuery (this).addClass ('marquesina_hover');
								}, function () {
									jQuery (this).removeClass ('marquesina_hover');
								})
								.bind ('click', function () {
									avanzarImagen ($capa, false, bol);
								})
								.css ('marginLeft', '2px');
				};
			}
		}
	});
};

function ajustarAltura (num) {
	var altoEscena = jQuery ('#contenido .apartado').eq (num).height();
	
	var altoEscenaNum = parseFloat (altoEscena);
	
	if (num == 4) {
		altoEscenaNum = 1680;
	};
					
	jQuery ('#contenedor').stop().animate ({'height': altoEscenaNum}, 300);
}

jQuery.fn.reverse = function() {
    return this.pushStack(this.get().reverse(), arguments);
};

function esIE () {
	ie = true;
	
	jQuery ('.menu_enlace')
		.css ('fontSize', '1em');
		
	setTimeout ("arrancar ()", 1000);
};

function arrancar () {
	if (ie) {
		jQuery ('#wrapper').show();
	}
	else {
		jQuery ('#wrapper').fadeTo (vel, 1);
	};
	
	ajustarAltura (pagina);
};
