$(document).ready(function() {

/* Menu */
	$('#menu > ul > li').each(function() {
		$(this).mouseover(function(){
			$(this).addClass('over');
		});
		$(this).mouseout(function(){
			$(this).removeClass('over');
		});
	});
	
	
/* Pestanias buscador hoteles */
	$('.busqueda-pestanias').each(function(){
		if ($(this).find('.vermas')[0]) {
			$(this).find('.busca-avanzada').hide();
			$(this).find('.vermas a').toggle(function(){
				$(this).addClass('abierto');
				$(this).parent().next().slideDown();
			},function(){
				$(this).removeClass('abierto');
				$(this).parent().next().slideUp();
			});
		}
	});
	
	
/* Pestanias (generico para todas las pestañas) */
	$('.pestanias').each( function() {
		$(this).find('.pestanias-wrapper a').each(function(){
			var _href = this.href.match(/#.*$/);
			if (!_href) // Si es un enlace sin anchor lo deja tal cual
				return true;
			this._href = _href[0];			
			$(this).click(function(){
				if (this._href != null) {
					var pestanias_parent = $(this).parents('.pestanias');
					
					//$(pestanias_parent).children('.pestania').hide();
					$(pestanias_parent).children('.pestania').css({position:'absolute', visibility:'hidden'});
					//$(this._href).show();
					$(this._href).css({position:'static', visibility:'visible'});
					
					$(pestanias_parent).find('.marcado').removeClass('marcado');
					$(this).parent().addClass('marcado');
					return false;
				}
			});
			
		});
	
		var pestanias_on = $(this).find('.pestanias-wrapper .marcado a');
		if(pestanias_on.length>0){	
			var marcada = $(this).find('.pestanias-wrapper .marcado a')[0]._href;
			if (marcada) {
				/*
				$(this).children('.pestania').hide();
				$(marcada).show();
				*/
	
				$(this).children('.pestania').css({position:'absolute', visibility:'hidden'});
				$(marcada).css({position:'static', visibility:'visible'});
			}
		}
	});


	if ($.jcarousel) {
	/* Carrusel fotogalerias */
		$('.mod-fotogal-viajeros').jcarousel();
	/* Carrusel fotos ficha hotel/restaurante */
		$('.ficha-hotel .fotos-hotel ul').jcarousel({scroll:1});
	/* Carrusel home */
		//$('.mod-carrusel ul').jcarousel();
	}
	
/* Masinfo fotogalerias */
	$('.mod-fotogal-viajeros .inner').css('left', '-130px' );
	$('.mod-fotogal-viajeros li').each(function(){
		this.inner = $(this).children('.inner')[0];
		$(this).bind('mouseenter',function(){
			$(this.inner).animate({left:0},'fast');
		}).bind('mouseleave',function(){
			$(this.inner).stop(1000).animate({left:'-130px'},'fast');
		});
	});
	
/* Mod destacamos */	
	$('.mod-destacamos').each(function(){

        $(this).find('.inner-destacamos li img').each(function() {
			var xref = this.src.match(/\/recorte\/([0-9]{8}[_0-9a-zA-Z]*)\//)[1];
			this._src = '/imagenRecorte.php?imgXref=' + xref + '.Ies&fotogaleria=1';
        });

		$(this).find('.inner-destacamos li').bind('mouseenter',function(){
			if (!$(this).hasClass('over')) {
				var newsrc = $(this).find('img')[0]._src;
				$('.inner-destacamos .over').removeClass('over');
				$(this).addClass('over');
				$('.inner-destacamos .cont_imagen img').hide().attr('src',newsrc).fadeIn('fast');
			}
		});
	});
	
/* Pie */
	$('#pie .sh').css({position : 'absolute'}).hide().bind('mouseenter',function(){$(this).show()}).bind('mouseleave',function(){$(this).hide()});
	$('#pie .despliega').each(function() {
		this._href = this.href.match(/(#.*)$/)[1];
		$(this).bind('mouseenter',function(){
			$(this._href+'').show();
		}).bind('mouseleave',function(){
			$(this._href+'').hide();
		});
	});
	
	
});

// PLAYERS
function loadEmbedObject(str){
        document.write(str);
}

function loadEmbedObjectInDiv(myDiv, str){
        myDiv.innerHTML = str;
}

