jQuery.noConflict()

/**********************************************************************
 * Correcció dels PNG amb canal alfa (per l'IE)
 **********************************************************************/

jQuery(function() {
    jQuery(document).pngFix();
})

/**********************************************************************
 * "Popup" de les imatges
 **********************************************************************/

jQuery(function() {
    jQuery('.imatge a.ampliar').lightbox()
})

/**********************************************************************
 * Logueig d'errors (a través del Firebug)
 **********************************************************************/

if (typeof console != 'undefined') jQuery.logger.set(console)

/**********************************************************************
 * Tamany de la lletra
 **********************************************************************/
 
jQuery(function() {

    var tamanyOriginal = jQuery.fontSize.get()
    var tamanyRelatiuMaxim = 2

    jQuery.fontSize.setFromCookie()

    jQuery('#canviar-mida-text a.augmentar').click(function(event) {
        event.preventDefault()
        if (jQuery.fontSize.get() >= tamanyOriginal + tamanyRelatiuMaxim) return
        jQuery.fontSize.increase(1)
    })
    
    jQuery('#canviar-mida-text a.reduir').click(function(event) {
        event.preventDefault()
        if (jQuery.fontSize.get() <= tamanyOriginal - tamanyRelatiuMaxim) return
        jQuery.fontSize.decrease(1)
    })
})

/**********************************************************************
 * Inputs amb un value que és la descripció
 **********************************************************************/
 
jQuery(function() {
    jQuery('input.valorEsDescripcio')
        .focus(function() {
            if (! this.getAttribute('_value')) {
                this.setAttribute('_value', this.value)
                this.value = ''
            }
        })
        .blur(function() {
            if (! this.value) {
                this.value = this.getAttribute('_value')
                this.removeAttribute('_value')
            }
        })
})

/**********************************************************************
 * Accions perilloses
 **********************************************************************/
 
jQuery(function() {
    jQuery('.accio_perillosa').click(function(event) {
        var seguir = confirm("N'estàs segur?")
        if (! seguir) event.preventDefault()
    })
})

/**********************************************************************
 * Continguts que es carreguen en línia
 **********************************************************************/
 
jQuery('a.load-inline').livequery('click', function(event) {
    var container = jQuery(this).parents('.load-inline-container')[0]
    if (! container) throw "[load-inline] No s'ha trobat el contenidor associat"
    if (! container.id) throw "[load-inline] El contenidor associat no té id"
    event.preventDefault()
    jQuery(container).load(this.href + ' #' + container.id + ' > *')
})

/*****************************************************************************
 * Cercador
 *****************************************************************************/
jQuery(function() {
    jQuery("#cercador-general").click(function (event) {
        jQuery(this).val("");
    });
    jQuery("#cercador-general").blur(function (event) {
        if(jQuery(this).val() == "") jQuery(this).val("escriu la teva cerca");
    });

});

/**********************************************************************
 * Destacat portada
 **********************************************************************/

function processaDestacatPortada() { 

	jQuery('div#destacats-en-portada div.element-generic').each(function (i) {	
		
		// especifiquem l'alçada del div
		jQuery(this).css({'height' : jQuery(this).height()}); // l'explorer 6 necessita saber l'alçada per posicionar absolutament un ítem		
		
		if(jQuery(this).find('a').size() > 0) { //si el destacat conté algun vincle
		
			jQuery(this).css({'cursor' : 'pointer'}); //que es vegi que és clicable	el div sencer			
			var adrecaPrimerVincle = jQuery(this).find('a:first').attr("href"); 
			jQuery(this).click(function () { 
			window.location = adrecaPrimerVincle; 
			});
		
		}
		
	});

}
