jQuery.noConflict()

/**********************************************************************
 * Correcció dels PNG amb canal alfa (per l'IE)
 **********************************************************************/

jQuery(function() {
	jQuery(document).pngFix();
})

/**********************************************************************
 * Tamany de la lletra
 **********************************************************************/
 
jQuery(function() {

    var tamanyOriginal = jQuery.fontSize.get()
    var tamanyRelatiuMaxim = 2

    jQuery.fontSize.setFromCookie()

    jQuery('#augmentar').click(function(event) {
        event.preventDefault()
        if (jQuery.fontSize.get() >= tamanyOriginal + tamanyRelatiuMaxim) return
        jQuery.fontSize.increase(1)
    })
    
    jQuery('#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() {
    
    var buidarSiPredeterminat = function() {
        if (! this.getAttribute('_value')) {
            this.setAttribute('_value', this.value)
            this.value = ''
        }
    }
    
    var predeterminatSiBuit = function() {
        if (! this.value) {
            this.value = this.getAttribute('_value')
            this.removeAttribute('_value')
        }
    }

    jQuery('input.valor-es-descripcio')
        .focus(buidarSiPredeterminat)
        .blur(predeterminatSiBuit)
        .each(function () {
            var input = jQuery(this)
            input.parents('form').submit(function() {
                input.each(buidarSiPredeterminat)
            })
        })
})

/**********************************************************************
 * Pestanyes
 **********************************************************************/
 
jQuery(function() {

    var pestanyaContingut = function(pestanya) {
        return jQuery(jQuery(pestanya).attr('href'))
    }

    var hide = function() {
        pestanyaContingut(this).hide()
        jQuery(this).removeClass('activa')
    }
    
    var show = function() {
        pestanyaContingut(this).show()
        jQuery(this).addClass('activa')
    }
    
    var click = function(event) {
        event.preventDefault()
        jQuery(this).parent('.pestanyes').find('a').each(hide)
        jQuery(this).each(show)
    }
    
    jQuery('.pestanyes a')
        .each(hide)
        .click(click)
        
    jQuery('.pestanyes a:first').each(show)
})

/**********************************************************************
 * Modal de les imatges
 **********************************************************************/

jQuery(function() {

    Shadowbox.init({
        skipSetup: true,
        text: {
            cancel: '',
            loading: 'Carregant...',
            close: 'Tancar'
        }
    })
        
    jQuery('a.ampliar').click(function(event) {
        Shadowbox.open(this, {
            title: jQuery(this).parent().find('p').text()
        })
        event.preventDefault()
    })
})
