/* ****************************************************
 
 	@file:		   global.js
	@description:  Comportements globaux
	@author:       remi (ixmedia.com)
	@updated:	   20080725

***************************************************** */

/**
 * @section Localization (l10n)
 * @description Dans le cas où on aurait des textes à instancier en Javascript
 * 				on doit prévoir le multi-linguisme.
 ******************************************************************************/

var I18N = {

	// Langage par défaut
	// ------------------------
	default_lang : 'en',

	// Français
	// ----------------------------------------------------------------------------
	fr : {
		thickbox : {
			caption_all_photos 	 : "Voir toutes les photos &gt;&gt;",
			url_all_photos	 	 : 'Content.aspx?PageId=97',
			next_image			 : 'Photo suivante',
			previous_image		 : 'Photo précédente',
			close_this_window	 : 'Fermer cette fenêtre'
		}
	},

	// English
	// ----------------------------------------------------------------------------
	en : {
		thickbox : {
			caption_all_photos		: "View all pictures &gt;&gt;",
			url_all_photos	 	 	: 'Content.aspx?PageId=97',
			next_image				: 'Next photo',
			previous_image			: 'Previous photo',
			close_this_window		: 'Close this window'
		}
	}

}

var LANG = $('html').attr('lang'); if (!LANG) { LANG = I18N.default_lang; } I18N = (I18N[LANG]) ? I18N[LANG] : I18N[I18N.default_lang]

/**
 * @section Comportements globaux
 ******************************************************************************/

document.createElement('abbr'); // on créé un élément ABBR bidon pour qu'il soit reconnu par IE6-
$(document).ready(function() {

    /**
    * @section Highlight de la navigation
    ******************************************************************************/

    var url =
	$.parseUrl.filePath
	.replace(/\/(fr|en)\//, '')
	.replace(/^([^\/]+)\/.*$/, "$1")
	.replace(/\.html$/, "");

    $('.nav li.nav-' + url).addClass('active');
    $('.utilitaires li.nav-' + url).addClass('active');


    /**
    * @section Vidéo ouvert en thickbox
    ******************************************************************************/
    if ($('div.thickbox_video').length > 0) {
        var video = $('div.thickbox_video a')[0]
        var vdata = $.metadata.get(video);
        $(video).media({
            width: vdata.width,
            height: vdata.height,
            autoplay: false,
            caption: false // supress caption text 
        });

    }

    /**
    * @section Nouvelles: Menu déroulant des années
    ******************************************************************************/

    var $nouvelles_annee = $('.nouvelles-annee');
    if ($nouvelles_annee.length > 0) {
        $nouvelles_annee.find('li.liste').hide().siblings().find('a').click(function() {
            $(this).parent().next().slideToggle(200);
            return false;
        });
    }
    $(document).click(function() {
        $('.nouvelles-annee li.liste:visible').slideUp(200);
    })

    /**
    * @section PNG transparents
    ******************************************************************************/
    $('img[@src$=.png]').ifixpng();

    /**
    * @section Nouvelles: Galerie (fix pour la dernière photo de la rangée)
    ******************************************************************************/

    var $galerie = $('.galerie-photos');
    if ($galerie.length > 0) {
        $galerie.find('ul li:nth-child(4)').css('margin-right', '0')
    }

    /**
    * @section Programmes: Témoignages (lien "Plus")
    ******************************************************************************/

    if ($('.programme-temoignages').length > 0) {
        $('.temoignage div.plus').hide();
        $('.temoignage p.plus a').click(function() {
            
            var $plus = $(this).parent().prev();
            if ($plus.is(':visible')) {
                $(this).removeClass('open');
                if (LANG == 'fr')
                    $(this).html('Poursuivre la lecture >');
                else
                    $(this).html('Read more >');
            } else {
                if (LANG == 'fr')
                    $(this).html('Fermer');
                else
                    $(this).html('Close');
                $(this).addClass('open');
            }

            $plus.slideToggle();
            return false;
        })
    }

    /**
    * @section Partager
    ******************************************************************************/

    var partager_urls = {
        'delicious': function() {
        window.open('http://del.icio.us/post?v=4;url=' + encodeURIComponent(location.href) + ';title=' + encodeURIComponent(document.title), "", "width=1000,height=600,menubar=1,resizable=1,scrollbars=1");
        },
        'digg': function() {
        window.open('http://digg.com/submit?phase=2&url=' + encodeURIComponent(location.href) + '&title=' + encodeURIComponent(document.title), "", "width=1000,height=700,menubar=1,resizable=1,scrollbars=1");
        },
        'facebook': function() {
            var d = document,
			f = 'http://www.facebook.com/share',
			l = d.location,
			e = encodeURIComponent,
			p = '.php?src=bm&v=4&i=0&u=' + e(l.href) + '&t=' + e(d.title); // 1216735280 ?
            a = function() { if (!window.open(f + 'r' + p, 'sharer', 'toolbar=0,status=0,resizable=1,width=626,height=436')) l.href = f + p };
            if (/Firefox/.test(navigator.userAgent)) setTimeout(a, 0);
            else { a() }
        },
        'google': function() {
        window.open('http://www.google.com/bookmarks/mark?op=edit&output=popup&bkmk=' + encodeURIComponent(location.href) + '&title=' + encodeURIComponent(document.title), "", "width=1000,height=600,menubar=1,resizable=1,scrollbars=1");
        }

    }

    $('.partager a').click(function() {
        var classe = this.parentNode.className;
        partager_urls[classe].call();
        return false;
    })



});

/**
 * @section sIFR 2
 ******************************************************************************/

if (typeof sIFR == "function") {

    var tizaPath = "../js/sifr/tiza.swf"; // /js/sifr/tiza.swf
	var stylesheets = document.getElementsByTagName('link');
	var stylesheet_couleur = null;
	var sifr_couleurs = {
		'orange': '#eea000',
		'red': '#e02713',
		'green': '#72c512',
		'blue': '#00a0df'
	}

	$.each(stylesheets, function(i, n) {
	    if (n.rel.match(/stylesheet/) != null && n.href.match(/couleurs/) != null) {
	        stylesheet_couleur = n.title;
	        return false;
	    }
	});
	
	var jcm_couleur = sifr_couleurs[stylesheet_couleur];

	sIFR.bHideBrowserText = true;
	sIFR.replaceElement(".titre h1", named({
		sFlashSrc: tizaPath,
		sColor: "#ffffff",
		sCase: "upper",
		sWmode: 'transparent'
	}));
	sIFR.replaceElement(".programme-entete span", named({
	    sFlashSrc: tizaPath,
		sColor: jcm_couleur,
		sCase: "upper",
		sWmode: 'transparent'
	}));
	sIFR.replaceElement(".accueil-entete h1,.accueil-entete h2", named({
    	sFlashSrc: tizaPath,
	    sColor: '#FFFFFF',
		sCase: "upper",
		sFlashVars : '&textalign=center',
		sWmode: 'transparent'
	}));
	sIFR.replaceElement(".accueil-intro h1", named({
	    sFlashSrc: tizaPath,
		sLinkColor: '#FFFFFF',
		sColor: jcm_couleur,
		sCase: "upper",
		sWmode: 'transparent'
	}));
}
