/* ****************************************************

	@file         global.js
	@description  Comportements globaux
	vim: set noet ts=4 fdm=marker fenc=utf-8:

***************************************************** */

// On charge le module "maps" de l’API de Google
google.load("maps", "2");

// Création de l´élément ABBR pour IE6
document.createElement('abbr');

(function($) {

	$(function() {

		/* @section Carte Google {{{
		******************************************************************************/
		google.setOnLoadCallback(function() {
			if ( $('body').is('.template-participation') && $.browser.msie ) {
			} else {
				var map = new google.maps.Map2(document.getElementById("carte-inner"));
				map.setCenter(new google.maps.LatLng(46.79747416096174, -71.28376007080078), 13);
				map.disableDragging();
			}
		});

		/*}}}*/

		/* @section Positionnement des éléments au load, resize et fontresize {{{
		******************************************************************************/
		$(window).resize(function() {
			redraw();
		});

		$(document).bind("fontresize", function () {
			redraw();
		});

		function redraw() {
			
			var h_window = $(window).height() - 174;
			var h_contenu = $('#contenu').height();

			if ( h_window > h_contenu ) {
				$('#viewport').height( ($(window).height()-174) + 'px' );
			}
			var h = ( h_window - h_contenu ) / 2;
			if ( h >= 0 ) {
				$('#contenu').css('paddingTop', h+'px');
			}
		}

		redraw();
		/*}}}*/

		/* @section Affichage du vidéo modèle {{{
		******************************************************************************/
		$('.modele .lien a').click(function() {
			var $popup = $('.popup');
			if ( $popup.is('.visible') ) {
				$popup.css({'left':'-99999px','right':'auto'}).removeClass('visible');
			} else {
				$popup.css({'top':(-1 * $popup.height())+'px','left':'auto','right':'-150px'}).addClass('visible');
			}
			return false;
		});	
		$('.bulle-fermer').click(function() {
			$('.popup').css({'left':'-99999px','right':'auto'}).removeClass('visible');
		});
		/*}}}*/

		/* @section Formulaire de participation {{{
		******************************************************************************/
		$('body.template-participation form').each(function() {
			var $this = $(this);
			var compteur_jeunes = $this.find('.jeunes').attr('class').match(/jeunes-([0-9]+)/);
			compteur_jeunes = parseInt( compteur_jeunes[1] );
			$this.find('.jeunes').find('.ajouter a').click(function() {
				compteur_jeunes++;
				var html = '<ul class="groupe jeune">'+$(this).parents('.jeunes').find('ul').eq(0).html()+'</ul>';
				html = html.replace(/jeune-1-/g, 'jeune-'+compteur_jeunes+'-');
				html = html.replace(/jeune\[1\]/g, 'jeune['+compteur_jeunes+']');
				html = html.replace(/\s?champ-erreur\s?/g, '');
				$(html).insertBefore( $(this).parent() ).find('input').val('');
				return false;
			});
			if ( !$.browser.msie || ( $.browser.msie && $.browser.version > 6 ) ) {
				$('.tip').attr('title', '<img src="/img/tooltips/tooltip-url.png" alt="" />').tooltip({
					track : true,
					delay : 0
				});
			}
		});
		/*}}}*/

	})

})(jQuery);

