jQuery(document).ready(function() {
	
	/* Da formato al título*/
	function formatTitle(title, currentArray, currentIndex, currentOpts) {
		return '<span id="fancybox-title-over">Imagen ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
	}
	
	/* Oculta el título cuando el puntero no está sobre la imagen*/
	function hideTitle() {
		$("#fancybox-wrap").hover(function() {
			$("#fancybox-title").show();
		}, function() {
			$("#fancybox-title").hide();
		});
	}
	
	/* Lightbox en los enlaces que contienen una imagen*/
	$("a[href$=.jpg],a[href$=.png],a[href$=.gif]").fancybox({

		'overlayOpacity'	: 0.5,
		'overlayColor'		: '#000000',
		'transitionIn'	    : 'elastic',
		'transitionOut'   	: 'elastic',
		'speedIn'		    : 600, 
		'speedOut'		    : 200, 
		'titlePosition' 	: 'over',
		'onComplete'		: hideTitle,
		'titleFormat'		: formatTitle		
	});
	
	/* Lightbox en los enlaces que contienen iframe rel="framelightbox"*/
	$("a[rel=framelightbox]").fancybox({
		'width'				: '75%',
		'height'			: '75%',
        'autoScale'     	: false,
        'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titleShow'			: false,
		'type'				: 'iframe'
	});
	
	/* Lightbox en los enlaces que contienen rel="tubelightbox"*/
	$("a[rel=tubelightbox]").click(function() {
		$.fancybox({
			'overlayOpacity'	: 0.5,
			'overlayColor'		: '#000000',
			'padding'		: 0,
			'autoScale'		: false,
			'transitionIn'	: 'none',
			'transitionOut'	: 'none',
			'titleShow'		: false,
			'width'			: 680,
			'height'		: 495,
			'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
			'type'			: 'swf',
			'swf'			: {
				'wmode'		: 'transparent',
				'allowfullscreen'	: 'true'
			}
		});

		return false;
	});

});

