/*
 * JS pour la section Accueil
 * SGL - egzakt.com
 * 2010-02-07
 */
 
 
 
/*Début compteur date*/
	today = new Date();

BigDay = new Date("April 1, 2011")
msPerDay = 24 * 60 * 60 * 1000 ;
timeLeft = (BigDay.getTime() - today.getTime());
e_daysLeft = timeLeft / msPerDay;
daysLeft = Math.floor(e_daysLeft);
e_hrsLeft = (e_daysLeft - daysLeft)*24;
hrsLeft = Math.floor(e_hrsLeft);
minsLeft = Math.floor((e_hrsLeft - hrsLeft)*60);
/*Fin compteur date*/



function accueil_ready() {
	Animation.init();
}






/* OBJET Animation
 * Animation a l'accueil
 * @author SGL
 * @date 2010-02-08
 */
 
var Animation = {

	donnees_i18n: {
		fr: [ 
			/* { surtitre: "Message du bâtonnier", titre: "Le Barreau prend position | Tournée<br>du bâtonnier", lien: "/videos/batonnier.html", target: "", img: "message-batonnier.jpg" }, */
			{ surtitre: "Journée internationale<br>de la femme", titre: "2012", lien: "http://www.barreau.qc.ca/avocats/equite/journee/index.html", target: "", img: "journee-femme.jpg" },
			 { surtitre: "Grands rendez-vous de la formation", titre: "Réservez votre place dès maintenant!", lien: "http://www.grandsrendezvous.qc.ca/", target: "_blank", img: "grf.jpg" },
			 /*{ surtitre: "Le Droit de savoir", titre: "Saison 2 - Tous les lundis, &agrave; 20&nbsp;h", lien: "http://www.ledroitdesavoir.ca/", target: "_blank", img: "dds2.jpg" },*/
			{ surtitre: "Web-pro", titre: "Maintenant cinq formations reconnues!", lien: "http://webpro.barreau.qc.ca/", target: "_blank", img: "webpro.jpg" },
			{ surtitre: "Langage clair", titre: "Téléchargez le guide et visionnez les capsules vidéos", lien: "/avocats/praticien/langage-clair/index.html", target: "", img: "langage-clair.jpg" },
			/*{ surtitre: "Cotisations annuelles", titre: "Deuxième versement avant le 1<sup>er</sup> octobre", lien: "/avocats/tableau-ordre/inscription/index.html", target: "_self", img: "ia-2e.jpg" },*/
			/*{ surtitre: "L'avocat de 2021", titre: "Rapport - Pratique privée et avenir de la profession", lien: "/publications/avocats/index.html#pp2021", target: "", img: "avocats-2021.jpg" }*/


			/**/
			/*{ surtitre: "Inscription annuelle et cotisations", titre: "Avant le 1<sup>er</sup> avril", lien: "/avocats/tableau-ordre/inscription/index.html", target: "_self", img: "2011-ia.jpg" },*/
			/*{ surtitre: "Formation continue", titre: "Il vous reste <b>" + daysLeft + " jours</b> pour remplir votre obligation", lien: "/avocats/formation-continue/obligatoire/index.html", target: "_self", img: "fco.jpg" },*/
			/*{ surtitre: "Formation continue", titre: "Dernière journée pour remplir votre obligation", lien: "/avocats/formation-continue/obligatoire/index.html", target: "_self", img: "fco.jpg" },*/
			/*{ surtitre: "Protection du public", titre: "Rencontrez Isabelle, votre guide virtuelle", lien: "/public/index.html", target: "_self", img: "isabelle.jpg" },*/
			
		],
		en: [ 
			/* { surtitre: "Message du bâtonnier", titre: "Le Barreau prend position | Tournée<br>du bâtonnier", lien: "/videos/batonnier.html", target: "", img: "message-batonnier.jpg" }, */
			{ surtitre: "Journée internationale<br>de la femme", titre: "2012", lien: "http://www.barreau.qc.ca/avocats/equite/journee/index.html", target: "", img: "journee-femme.jpg" },
			 { surtitre: "Grands rendez-vous de la formation", titre: "Book your passport now!", lien: "http://www.grandsrendezvous.qc.ca/", target: "_blank", img: "grf.jpg" },
			/* { surtitre: "Le Droit de savoir", titre: "Saison 2 - Tous les lundis, &agrave; 20&nbsp;h", lien: "http://www.ledroitdesavoir.ca/", target: "_blank", img: "dds2.jpg" },*/
			 { surtitre: "Plain language", titre: "Download the free guide and watch videos (French)", lien: "/avocats/praticien/langage-clair/index.html", target: "", img: "langage-clair.jpg" },
			 	{ surtitre: "Web-pro", titre: "Now five  recognized  activities!", lien: "http://webpro.barreau.qc.ca/", target: "_blank", img: "webpro.jpg" },
			 /*{ surtitre: "Cotisations annuelles", titre: "Deuxième versement avant le 1<sup>er</sup> octobre", lien: "/avocats/tableau-ordre/inscription/index.html", target: "_self", img: "ia-2e.jpg" },*/
				/*{ surtitre: "L'avocat de 2021", titre: "Rapport - Pratique privée et avenir de la profession", lien: "/publications/avocats/index.html#pp2021", target: "", img: "avocats-2021.jpg" }*/

						
			/**/
			/**/
			/*{ surtitre: "Continuing education", titre: "Last day to fulfill your obligation", lien: "/avocats/formation-continue/obligatoire/index.html?Langue=en", target: "_self", img: "fco.jpg" },*/
			/*{ surtitre: "New Regulation", titre: "Accounting and standards of professionnal practice", lien: "/barreau/lois-reglements/comptabilite.html?Langue=en", target: "_self", img: "reglement.jpg" },*/
						/*{ surtitre: "Public protection", titre: "Meet Isabelle<br>(in French only)", lien: "/public/index.html", target: "_self", img: "isabelle.jpg" },*/
			/*{ surtitre: "Annual registration and fees", titre: "Before April 1<sup>st</sup> 2011", lien: "/avocats/tableau-ordre/inscription/index.html", target: "_self", img: "2011-ia.jpg" },*/
			/*{ surtitre: "<i>Le Droit de savoir</i>", titre: "The TV Magazine about your rights<br>(in French only)", lien: "http://www.ledroitdesavoir.ca/", target: "_blank", img: "dds.jpg" }*/
		]
	},
	
	image_path: "/images/"+langue+"/animation/",
	donnees: { },
	
	in_anim: false,		// Si l'animation est active (change_realisation_anim)
	in_action: false,	// En cours de transision	(in_action_realisation)
	change_time: 4000,	// Temps entre chaque frame (millisecondes) (change_frame_time)
	change_timer: null,	// Timer (change_realisation_timer))
	
	nav_css: "#animation .navigation",
	nav_puce_css: "#animation div.selected",
	
	init: function() {

		this.donnees = langue == "en" ? this.donnees_i18n.en : this.donnees_i18n.fr;
		
		this.populate();

		$(this.nav_css+' a').click(function() {
			Animation.change(this,'#animation .frame_top',true);
			return false;
		});

		$('#animation a, '+this.nav_css+' a').hover(
			function() { return Animation.stop(); },
			function() { return Animation.start(); }
		);
		
		$('#animation .frame_top').click(function () {
			if (Animation.in_action || $(this).attr('href') == '')
				return false;
		});

		this.debuter();
	},
	
	debuter: function () {
	
		this.in_anim = true;
	
		if (!this.change_timer)
			this.change_timer = setInterval(function() { Animation.interval_function(); },this.change_time);
	},

	interval_function: function () {
		var next_element = $(this.nav_css+' a.selected').next().length == 0 ? $(this.nav_css+' a:first') : $(this.nav_css+' a.selected').next();
		this.change(next_element,'#animation .frame_top',false);
	},


	change: function (handle,conteneur,force) {
	
		if (this.in_action)
			return false;
	
		if ($(handle).hasClass('selected'))
			return false;
	
		if (!this.in_anim && !force)
			return false;
		
		this.in_action = true;
		
		if (force) {
			this.unset_selected(this.nav_css+' a');
			this.set_selected(handle);
		}
	
		// Laisser la tuile en arriere pour faire une belle transition
		$('#animation .frame_bottom').css('backgroundImage',$(conteneur).css('backgroundImage'));

		$(conteneur).fadeOut("fast",function() {

			var new_frame = Animation.donnees[parseInt($(handle).attr('id').replace(/lien_frame_/,''))];
			$(conteneur).css('backgroundImage','url('+Animation.image_path+new_frame.img+')');
			
			if (new_frame.lien == "") {
				$(conteneur).attr('href','');
				$(conteneur).addClass('frame_top_span');
			} else {
				$(conteneur).attr('href',new_frame.lien);
				$(conteneur).removeClass('frame_top_span');
			}
			$(conteneur).attr('target',new_frame.target);

			if (!force) {
				Animation.unset_selected(Animation.nav_css+' a');
				Animation.set_selected(handle);
			}

			$(conteneur).fadeIn("normal",function() {
				Animation.in_action = false;
			});
		});
		
		

		return false;
	},
	
	erreur: function () {
		this.in_action = false;
		//alert("Une erreur s'est produite.");
	},
	
	
	start: function () {
		if (!this.change_timer) this.change_timer = setInterval(function() { Animation.interval_function(); },this.change_time);
		this.change_anim = true;
	},

	stop: function () {
		this.change_anim = false;
		clearInterval(this.change_timer);
		this.change_timer = null;
	},
	
	populate: function () {
	
		if (this.donnees.length < 1)
			return false;
		
		$.each(this.donnees,function(i, n) {
			if(typeof n != "undefined") {
				$('<a>').attr("id","lien_frame_"+i).attr("href",n.lien).html(n.titre).appendTo(Animation.nav_css);
				$('<strong>').html(n.surtitre).prependTo("#"+"lien_frame_"+i);
			}
		});
		
		this.set_selected(this.nav_css+' a:first');
		
		$('#animation .frame_top').css('backgroundImage','url('+Animation.image_path+this.donnees[0].img+')');
		$('#animation .frame_top').attr('href',this.donnees[0].lien);
		$('#animation .frame_top').attr('target',this.donnees[0].target);
	},
	
	set_selected: function (handle) {
		$(handle).addClass('selected');

		// Calcul de l'offset top
		var i = $(this.nav_css+' a').index(handle);
		var top = (i*61)+1;
		
		
		//$(this.nav_puce_css).animate({ top: top }, 500);
		
		$(Animation.nav_puce_css).css('top',top+'px');
		
		$(this.nav_puce_css).show();
	},
	
	unset_selected: function (handle) {
		$(handle).removeClass('selected');
		$(this.nav_puce_css).hide();
	}




};



