/**
 * @author Joan Fernandez
 * Realizamos las funciones necesarias de jQuery al cargarse el DOM.
 *
 */	
$(document).ready(function() {
				
/**
 * @author Joan Fernandez
 * Pie de imágenes
 * TODO El span no coge el width adecuado a la primera, sino cuando se recarga la pag.	  
 *
 */						   
	/*$('img.jfoot').each(function(){								
		var alt = ($(this).attr('alt') != '') ? $(this).attr('alt') : '';
		if (alt != ''){
			if ( $(this).hasClass('img_left')) {
				$(this).removeClass('img_left');
				var w = $(this).width();

				$(this).wrap('<div class="img_with_foot img_left">','</div>').after('<span style="width:' + (w - 10) + 'px;" >'+alt+'</span>');			
			} else if ( $(this).hasClass('img_right')){
				$(this).removeClass('img_right');
				var w = $(this).width();
				$(this).wrap('<div class="img_with_foot img_right">','</div>').after('<span style="width:' + (w-10) + 'px;">'+alt+'</span>');	
			}
		}
	});
	*/
	
/**
 * Preload de imágenes
 *
 */	
	/*$('.prel').each(function() {
		//console.info(this);
		$(this).hide();
		$(this).load(function() {
			//$(this).width($(this).parent().width()).height($(this).parent().height());
			$(this).fadeIn("slow");
		});
	});*/
	
	$('a.inactive').click(function() {
		return false;
	})
	$('a.selected').click(function() {
		return false;
	})
	
	
/**
 * Slideshow de la cabecera
 *
 */
	$('#slideshow_header').cycle({
		fx: 'fade',
		speed: 2500,
		timeout: 2000
	});
	

/**
 * Slideshow galerias
 *
 */
	var src = '';
	var url = 
	$('.js-hidden').each(function(){
	    src=($(this).attr('src'))
	    var url = 'url('+src+')'
	    var obj = {
	        'background-image' : url,
	        'background-position': '50% 50%',
	        'background-repeat': 'no-repeat'
	    }
	    $(this).parent().css(obj);
	    $(this).css('display', 'none');
	});

	
	$('#front-gallery-wrapper .content-wrapper').cycle({
		fx: 'fade',
		speed: 4500,
		timeout: 4500
	});
	
/**
  * 
  * TODO cada vez que pasemos el cursor sobre el enlace, este comience con el slideshow
  * de imágenes que nos devuelve YT.
  * FIXED: 08/01/09 23:06
  * 
 **/ 
	$('div.video_caps').hover(
		function () { // hover in
			$(this).removeClass('cycle_off').addClass('cycle_on');
			$(this).cycle({
				fx: 'fade',
				speed: 2500,
				timeout: 3000
			});
		},
		function () { // hover out
			$(this).removeClass('cycle_on').addClass('cycle_off');
			$(this).cycle({
				autostop: 'wrap'
			});
		}
	);
	
/**
 * Capital Letter con jQuery y sIFR	  
 *
 */
	$('p.capital').dropJ();
	$('p.capital span').addClass('typeface-js');
	
	/*$('p.capital span').sifr({
		width: 60,	
		height: 60,
		font: 'Coister Black',
		path: 'http://lacaida.dev/js/fonts/',
		color: '#C4A134',
		offsetTop: -8,
		offsetLeft: -4
	 });*/
	 
/**
 * Fancybox
 *
 */	 
 	$('a[rel="lightbox"]').fancybox({
 		'hideOnContentClick': true,
 		'frameWidth': 485,
 		'frameHeight': 385
 	});
 	
 	$('a[rel="videobox"]').fancybox({
 		'zoomSpeedOut': 0,
 		'frameWidth': 485,
 		'frameHeight': 385 		
 	});
 	
/**
 * Slider noticias
 *
 */	 	
	 /*$('div.contenedor_noticias_portada').easySlider({
	 	orientation:'vertical'
	 });*/
	 $('#contenedor_noticias_portada').pager('div');
	

/**
 * Paginación del pregón
 *
 */	 	
 	$('#texto_pregon').pager('p');
/**
 * Errores en el envio del formulario
 *
 */
 	$('div.errors').hide();
	$('span.close_msg').toggle(
		function () {
			$(this).parent().fadeOut('slow');
		},
		function() {
			$(this).text('Mostrar errores');
			$(this).parent().fadeOut('slow');
		}
	);
	
	
	$("a[@rel$='external']").click(function(){
		//$(this).target = "_blank";
		this.target = "_blank";
		//alert('works');
	});
	
	
	/**
	 * PNGFIX for IE
	 */
	if (jQuery.browser.version == '6.0' && jQuery.browser.msie){
		DD_belatedPNG.fix('#logo_header img');
		//DD_belatedPNG.fix('#header');
	}	
	
	/**
	 * HIDE/SHOW MENU
	 */
	
	jQuery("ul.level-2.hide").hide();
	jQuery("a.open-content").click(function() {
		var ident = jQuery(this).attr("id").split('-')[1];
		var selector = '#ul-'+ident;
		if(jQuery(selector).hasClass('hide')) {
			jQuery(selector).removeClass('hide').show('slow').addClass('show');
		}else{
			jQuery(selector).removeClass('show').hide('slow').addClass('hide');
		}
		return(false);
	});
	
	Cufon.replace('h2.cufon-title');

});