(function($) {
    $(document).ready(function() {
    	// Taille de la fenetre du navigateur
        var width = $(window).width() - 174 ;
        var height = $(window).height() ;
        
        var contenu_height = $('#conteneur_contenu').height();
        var contenu_newHeight = height_first + 30;
        if (contenu_height < contenu_newHeight) {
            $('#conteneur_contenu').height(height);
        }
       
        $('#bascule_on').hide();
        $('#bascule_off').hover(function(){
            $(this).attr('src','static/images/common/bascule_hover.gif');
        }, function() {
            $(this).attr('src','static/images/common/bascule.gif');
        });
        $ ('#bascule_on').hover(function(){
            $(this).attr('src','static/images/common/bascule_on_hover.gif');
        }, function() {
            $(this).attr('src','static/images/common/bascule_on.gif');
        });
        $('#bascule_off, #switch_fond, #voir_photos').livequery('click', function(){
            $('.fermable').hide();
            $('#conteneur_contenu').width(45);
            $('#bascule_off, #switch_fond, #x_mania').hide();
            $('#bascule_on, #conteneur_cache').show();
            $('.oeuvre', '#conteneur_cache').css('top', (539 - $('.oeuvre', '#conteneur_cache').height()) + 'px');
            $(window).resize();
        });
        $('#bascule_on').click(function(){
            $('.fermable').show();
            $('#conteneur_contenu').width(589);
            $('#bascule_off, #switch_fond, #x_mania').show();
            $('#bascule_on, #conteneur_cache').hide();
            $(window).resize();
        });

//        Logger('Width : ' + width);
//        Logger('Height : ' + height);
        
        // Taille de l'image au chargement de la page
        var width_ini = $('#imgTag').width();
        var height_ini = $('#imgTag').height();
        
//        Logger('Width_ini : ' + width_ini);
//        Logger('Height_ini : ' + height_ini);
        
        // Calcul du ratio d'affichage de l'image
        var width_defaut = width;
        var ratio_width_defaut = width / width_ini ;
//        Logger ('Ratio : ' + ratio_width_defaut);
        
        // Calcul de la taille de l'image
        var width_first = width_ini * ratio_width_defaut;
        var height_first = height_ini * ratio_width_defaut;
        
//        Logger('Width_first : ' + width_first);
//        Logger('Height_first : ' + height_first);
        
        
        $('#imgTag').width(width_first);
        $('#imgTag').height(height_first);
        
        var contenu_height = $('#conteneur_contenu').height();
        var contenu_newHeight = height_first + 30;
        if (contenu_height < contenu_newHeight) {
            $('#conteneur_contenu').height(height_first + 30);
        }
        $('#conteneur_fond').height(height_first);
        $(window).resize(function() {
            var height_resize = $(window).height() ;
            var width_resize = $(window).width() - 174 ;
            var ratio_height = height_resize / height ;
            var ratio_width = width_resize / width ;
            var newWidth =  width_first * ratio_width;
            var newHeight = height_first * ratio_width;
            $('#imgTag').width(newWidth);
            $('#imgTag').height(newHeight);
            if (contenu_height < newHeight) {
                $('#conteneur_contenu').height(newHeight + 30);
            }
            $('#conteneur_fond').height(height);
        });

        $('a.ajax', '#fond').livequery('click', function() {
            $('#fond').load(this.href, null, function() {
                $('#switch_fond, #x_mania').hide();
                /*$('#x_mania').hide();*/
                $('#conteneur_cache').show();
                $('.oeuvre', '#conteneur_cache').css('top', (539 - $('.oeuvre', '#conteneur_cache').height()) + 'px');
                $(window).resize();
            });
            return false;
        });

		$('#form_pro input#datedepart, #form_pro input#datearrivee').datepicker({ dateFormat: 'dd/mm/yy', showOn: 'button', buttonImage: 'static/images/professionnel/calendar.gif', buttonImageOnly: true });
    });

    // Configuration highslide
    $.extend(hs, {
        graphicsDir : base_url + 'static/highslide/graphics/',
        align : 'center',
        expandDuration : 0,
        restoreDuration: 0,
        enableKeyListener: false,
        dimmingOpacity : 0.75
    });
    if (language_js == 'fr') {
        $.extend(hs.lang, {
            loadingText :     'Chargement...',
            loadingTitle :    'Cliquer pour annuler',
            focusTitle :      'Cliquer pour amener au premier plan',
            fullExpandTitle : 'Afficher à la taille réelle',
            fullExpandText :  'Taille réelle',
            creditsText :     '',
            creditsTitle :    '',
            previousText :    'Précédent',
            previousTitle :   'Précédent (flèche gauche)',
            nextText :        'Suivant',
            nextTitle :       'Suivant (flèche droite)',
            moveTitle :       'Déplacer',
            moveText :        'Déplacer',
            closeText :       'Fermer',
            closeTitle :      'Fermer (esc ou Echap)',
            resizeTitle :     'Redimensionner',
            playText :        'Lancer',
            playTitle :       'Lancer le diaporama (barre d\'espace)',
            pauseText :       'Pause',
            pauseTitle :      'Suspendre le diaporama (barre d\'espace)',
            number :          'Image %1 sur %2',
            restoreTitle :    'Cliquer pour fermer l\'image, cliquer et faire glisser pour déplacer, utiliser les touches flèches droite et gauche pour suivant et précédent.'
        });
    }
    hs.registerOverlay({
        html: '<div class="closebutton" onclick="return hs.close(this)" title="' + hs.lang.closeText + '"></div>',
        position: 'top right',
        useOnHtml: true,
        fade: 0 // fading the semi-transparent overlay looks bad in IE
    });

})(jQuery);

function UserValidationNewsletter(theform) {
    $('#newsletter .message').html('');
    jQuery(theform).ajaxSubmit({
        success: function(data){
            if (data.substr(0, 7) == 'erreur=') {
                $('#newsletter .message').html(data.substr(7));
            } else {
                $('#newsletter input[name=mail]').val('');
                $(data).insertAfter('#newsletter').css({
                    position : 'relative',
                    top : $('#newsletter').outerHeight() * -1
                });
            }
        }
    });
    return false;
}

var addthis_pub="biennale";
var addthis_options = 'digg, myspace, facebook, favorites, delicious, google, twitter';
