
/* ---------------------------------------------------------------
 *
 *          Fonctions ALBUM PHOTOS
 *
 * -------------------------------------------------------------*/

function StatApercu(t) {
  if ($('#cboxLoadedContent').css('display') == "block") {
      // insérer quelquepart le titre de l'album ??
    titre = $('#cboxPhoto').attr('src');
    txt = $('#cboxTitle').text();
    if (txt != "" && txt != titre) titre += " : "+txt;
    if (!est_admin) try { _gaq.push(['_trackEvent', 'Aperçu ouvert '+t+' secondes et plus', titre]);   } catch(err) {}
    if (t == 5) apercu_to = setTimeout('StatApercu(30);',25000);
  }
}
var titre_current = "Photo";
var titre_album = "";
var apercu_to = null;
function initColorBox(ta,ti,os){
    openstate = false;
    t="thumbs";
    if (ta !== undefined) {
        titre_album = ta;
        if (os !== undefined) openstate=os;
        else openstate = true;        
        if (ti == 'apercu') {
            titre_current = "Aperçu";
            t = ti;
            $('a[rel="'+t+'"]').each(function(){if ($(this).attr('title') == null || $(this).attr('title') == "") $(this).attr('title',$(this).text());});
        } else {
            t = t+ti;
            $('a[rel="'+t+'"]').each(function(){$(this).attr('title',$(this).attr('href'));});
        }
    }

    $('a[rel="'+t+'"]').colorbox({
          open : openstate,
          transition: 'fade',
          speed: 350,
          onLoad: function() {
             $('#cboxContentDescription').hide();
             clearTimeout(apercu_to);
          },
          onCleanup: function() {
             $('#cboxContentDescription').hide();
             clearTimeout(apercu_to);
          },
          onComplete: function() {
             if (d = ZEN('d'+$(this).attr('id'))) {
                $('#cboxContentDescription').html('<div id="contenu_albp" style="position:relative;">'+d.innerHTML+'</div>').slideDown({duration: 'fast', easing: 'swing', queue:false});
                if (est_admin) { // IMPORTANT -- corriger avant d'activer !
                    idp = parseInt($(this).attr('id').substring(3));                    
                    $('#cboxContentDescription').prepend('<div class="admin_options ui-corner-all"><div style="display:none;"><img class="admin_bouton" ondrag="return false;" onmousedown="SoumettreModifContenu('+idp+',this,\'albp\'); return false;" title="Enregistrer" src="images/Bouton_enregistrer.gif" /><img class="admin_bouton" ondrag="return false;" onmousedown="AnnulerContenu(this); return false;" title="Annuler cette modification" src="images/Bouton_annuler.gif" /></div><div><img class="admin_bouton" onmousedown="ModifierContenu('+idp+',this,\'albp\'); return false;" title="Modifications simples" src="images/Bouton_modifier_simple.gif" /></div></div>');
                }
             }
             apercu_to = setTimeout('StatApercu(5);',5000);
             // empêche la copie par simple drag, ou encore empêche de sortir de la page en draggant involontairement dans le navigateur..
             //$('#cboxPhoto').mousedown(function(e){e.preventDefault();}).bind('drag',function(e){e.preventDefault();});
          },
          previous:'Précédente',
          next:'Suivante',
          close:'Fermer',
          current: '<b>'+titre_album+'</b>  -  '+titre_current+' {current} de {total}'
     });
//       slideshow:true, slideshowSpeed:4500, slideshowAuto:false, slideshowStart:' (Démarrer diaporama) ', slideshowStop:' (Arrêter diaporama) ',
     if (!ZEN('cboxContentDescription'))
        $('#cboxLoadedContent').after('<div id="cboxContentDescription"></div>');
     $('#cboxContentDescription').hide();
}

var album_actif = "";
var cache_albums = new Array();
function AlbLoaded(idalbum) {
     initColorBox();
     if (est_admin) CorrigeOA();
     $('#album_pres_thumbs').stop(false,true).css('opacity',0.1).fadeTo({duration:'slow',queue:false},1);
     $('#album_titre_page_'+idalbum).find('img').remove();
     if (liste_mod['alb'] && liste_mod['alb'] == page_active) {
         $("#album_pres_thumbs_titre").css('visibility','visible');
         
         if (!est_admin) try { _gaq.push(['_trackEvent', 'Album consulté (chapître)', titre_album]);   } catch(err) {}
         src_alb = liste_fp[page_active]+'?alb='+album_actif;
         $('#lien_bookmark').attr('href',src_alb).text(titre_album);
         if (!est_admin){           
           $('#zen_fblike').html('<iframe src="http://www.facebook.com/plugins/like.php?href='+encodeURIComponent(url_base+src_alb)+'&amp;layout=button_count&amp;show_faces=false&amp;width=90&amp;action=like&amp;font&amp;colorscheme=dark&amp;height=25" scrolling="no" frameborder="0" allowTransparency="true"></iframe>');
           $('#zen_tweet').html('<iframe allowtransparency="true" frameborder="0" scrolling="no" src="http://platform.twitter.com/widgets/tweet_button.html?url='+encodeURIComponent(url_base+src_alb)+'&text='+encodeURIComponent(titre_album)+'&source=tweetbutton&count=horizontal" style="width:130px; height:50px;"></iframe>');
         }
     }
     edition_active = false;
}

function AfficheAlbumThumbs(idalbum) {
  if (CheckEdition()) {
    album_actif = idalbum;
    // si pas admin, mettre la string en cache, et ne pas demander deux fois...


    //$("#album_pres_thumbs, #album_pres_thumbs_titre").fadeOut('fast');
    $("#album_pres_thumbs_titre").css('visibility','hidden'); // conserve la hauteur...
    $('#album_pres_thumbs').stop(true,true).fadeOut({duration:'slow',queue:false});
    if (liste_mod['alb'] && liste_mod['alb'] == page_active)
        $('.zenfb_jaime').remove(); //si c'est pas déjà fait..

    // mettre dans current le nom de la page !
    // ainsi que dans la bonne page.. :)
    titre_album = $('#album_titre_page_'+idalbum).text();
    $('#album_titre_page_'+idalbum).append('<img src="loading.gif" style="height:10px;" alt="Chargement de la page" />');
    $('#album_pres_thumbs_titre').text(titre_album);

    if (!est_admin && cache_albums[idalbum]) {
       $('#album_pres_thumbs').html(cache_albums[idalbum]);
       AlbLoaded(idalbum);
    }
    else
        $('#album_pres_thumbs')
        .load('album_pages.php?idalbum='+idalbum,
          function() {
             cache_albums[idalbum] = $('#album_pres_thumbs').html();
             AlbLoaded(idalbum);
             if (est_intra) CheckTimeup();
        });

    /*ZEN('iframe_historique').src='zen_historique.php?session=1&p='+page_active+'&alb='+idalbum;*/
  }
}

