/**
 * Scripts personalizados para el módulo default
 */

$(function() {

	// Modificaciones para el formulario
	if ($('#page-title .search-cont input#search').val() != '') $('#page-title .search-cont input#search').css('background-color','#FFFFFF');
	$('#page-title .search-cont input#search').click(function() {
		$(this).css('background-color','#FFFFFF');
	});
	$('#page-title .search-cont input#search').blur(function() {
		if ($(this).val() == '')
			$(this).css('background-color','transparent');
	});
	$('#page-title .search-cont form').submit(function() {
		$(this).attr('action',$(this).attr('action')+'/termino/'+$('#page-title .search-cont input#search').val());
	});
		
	/**
	 * Para que el documento sea xhtml válido, tenemos que evitar el target="_blank"
	 * en los enlaces. Para ello hacemos esta pequeña trampa
	 * {@link http://www.badlydrawntoy.com/2009/03/03/replacing-target_blank-for-strict-xhtml-using-jquery-redux/}
	 */
	$('a[rel="external"]').click( function() {
		window.open(this.href);
		return false;
	});

	//-----------------------------------------------------------------------------------	
	/**
	 * FN.DARKEN: Si pinchamos en un elemento que tenga class="darken" oscurecemos la pantalla
	 */
	$.fn.darken = function(msg) {
		$('#dialog').removeClass('invisible');
		if(msg!=undefined) {
			$('#dialog').dialog('option', 'title', msg).dialog('open');
			//$('#dialog-msg').html(msg);
		} else {
			$('#dialog').dialog('open');
		}
	};		

	//-----------------------------------------------------------------------------------
	/**
	 * DARKEN: Evento para mostrar la capa si pulsamos cualquier elemento class="darken"
	 */
	$('.darken').each(function() {
		$(this).click(function() { $.fn.darken(); });
	});		
	
	//-----------------------------------------------------------------------------------
	/**
	 * DIALOG + PROGRESSBAR: Con esta función mostramos la capa que oscurece la pantalla
	 * y un mensaje de texto personalizable
	 */	
	$("#progressbar").progressbar({ value: 100 });	
	$("#dialog").dialog({
		autoOpen: false,
		closeOnEscape: false,
		draggable: false,
		bgiframe: true,
		height: 140,
		width: 420,
		modal: true,
		resizable: false,
		buttons: {}
		/* position: ['center', 'center'], show: 'clip', hide: 'clip' */		
	});
});
/*
$(window).load(function() {
	var footerHeight = $('#footer').height();
	
	if ($(window).height() > $('#container').height()) {
		
		footerHeight += $(window).height() - $('#container').height();
		$('#footer').height(footerHeight);
	}
});
*/

