// Variables globale
var dispNumNav;

$(document).ready(function(){
    // Etat par defaut des elements
    //    $("#guide_quartier").css({
    //        display:"none"
    //    });
	
	// URL: http://www.dillerdesign.com/experiment/DD_belatedPNG/
	/*if( jQuery.browser.msie && (jQuery.browser.version == '6.0') )
	    DD_belatedPNG.fix('#container_main_top img, #container_main_bottom img, #menu_bottom .box_logo img, \n\
	        #header_main .box_logo img, \n\
	        #container_main,\n\
		#container_main_home #content_container #content_main #content_main_carrousel .carrousel_border_topLeft,\n\
		#container_main_home #content_container #content_main #content_main_carrousel .carrousel_border_topRight,\n\
		#container_main_home #content_container #content_main #content_main_carrousel .carrousel_border_bottomLeft,\n\
		#container_main_home #content_container #content_main #content_main_carrousel .carrousel_border_bottomRight,\n\
		.jcarousel-skin-vge-simple .jcarousel-prev-horizontal,\n\
		.jcarousel-skin-vge-simple .jcarousel-next-horizontal,\n\
		.jcarousel-skin-vge-simple .jcarousel-clip-horizontal .jcarousel-control a,\n\
		.jcarousel-skin-vge-simple .jcarousel-clip-horizontal .jcarousel-control a.curNav,\n\
		#container_center #content_main_carrousel .carrouselTitle h3,\n\
		#container_center #content_main .content_main_language,\n\
		
		.dropdown_opener_closed,\n\
		.dropdown_bottom,\n\
		.submenu_bottom,\n\
		.submenu_top,\n\
		.jcarousel-skin-vge-simple .carrouselImg,\n\
		#menu_bottom_bottom,\n\
		#menu_bottom #menu_bottom_center');*/
	if( jQuery.browser.msie && (jQuery.browser.version == '6.0') )
	    DD_belatedPNG.fix('.dropdown_bottom,\n\
		#container_main_home #content_container #content_main .content_main_visitors,\n\
		#container_main_home #content_container #content_main .content_main_notice,\n\
		.submenu_bottom,\n\
		.dropdown_opener_closed,\n\
		#menu_top li a.btn1,\n\
		.submenu_top');

	 if( jQuery.browser.msie && (jQuery.browser.version == '6.0' || jQuery.browser.version == '7.0') ){
	    /*DD_roundies.addRule('#menu_top a.btn1', '5px 0 0 5px', true);
	    DD_roundies.addRule('#menu_top #plan_de_ville a', '0 5px 5px 0', true);
	    DD_roundies.addRule('#content_surtitre.stickTitle', '5px 5px 0 0', true);
	    DD_roundies.addRule('#container_center.theme #content_surtitre', '5px', true);
	    DD_roundies.addRule('#content_left #content_left_title', '5px 5px 0 0', true);
	    DD_roundies.addRule('#container_center #content_main .blocPublic', '5px', true);
	    DD_roundies.addRule('#container_center #content_main .boxAtterissageAccordion ul', '5px 5px 0 0', true);
	    DD_roundies.addRule('#container_center #content_main .boxAtterissageAccordion ul.listLink', '5px 5px 0 0', true);
	    DD_roundies.addRule('#container_center #content_main .boxAtterissageAccordion #firstMenu', '5px 5px 0 0', true);
	    DD_roundies.addRule('#container_center #content_main .content_1col_grey', '5px 5px 0 0', true);
	    DD_roundies.addRule('#container_right h3.csc-firstHeader', '5px 5px 0 0', true);
	    DD_roundies.addRule('#menu_bottom #menu_bottom_center', '5px 5px 0 0', true);
	    DD_roundies.addRule('#container_main_home #content_container #content_main .content_main_news_links', '5px', true);
	    DD_roundies.addRule('#container_main_home #content_container #content_main .content_main_notice', '5px', true);
	    DD_roundies.addRule('#container_main_home #content_container #content_main .content_main_visitors', '5px', true);
	    DD_roundies.addRule('#container_main_home #content_container #content_main .content_main_language', '5px', true);
	    DD_roundies.addRule('#container_main_home #content_container #content_main .content_main_zone', '5px', true);
	    DD_roundies.addRule('#container_main_home #content_container #content_main .content_main_zone_bottom', '5px', true);*/
    }
	if ($('#container_right_1 ul li').length!=0) {
		$("#container_right_1 ul li:last-child").css('border-bottom','none');
		$("#container_right_1 ul li:last-child").css('margin-bottom','0');
	}
	if ($('.inside_right_column_middle .box_generic').length) {
		$('.inside_right_column_middle .box_generic:last-child .csc-textpic-intext-left').css('border-bottom', 'none');
	}
    // Gestion des pages d'atterrissage
	// Si image : changement de classe pour qu'elle soit collée au surtitre
	if( $('#content_image').length != 0 ){
		//$('#content_surtitre').next('.content_separator_5').css('display','none');
		//$('#content_image').addClass('stickImage');
		$('#content_surtitre').addClass('stickTitle');
		$('#container_image').css("width",$('#content_image img').width());
		if( $('#content_image img').width() < '595' )
			$('#container_image').css("margin",'5px 0 0 20px');
	}
	
	$("#accessibility").css({display:"none"});

	$('#content_main p.bodytext img').each(function(){
		if( $(this).css('float') == 'left' )
			$(this).css({'margin':'5px 10px 10px 0'});
		else
			$(this).css({'margin':'5px 0 10px 10px'});
	});

    // On cache les sous-menus
    // sauf celui qui porte la classe "open_at_load" :
    $("div.subMenu:not('.open_at_load')").hide();
    // On selectionne tous les items de liste portant la classe "toggleSubMenu"

    // On modifie l'évènement "click" sur les liens dans les items de liste
    // qui portent la classe "toggleSubMenu" :
    $("li.toggleSubMenu").children("span").click( function () {
        // Si le sous-menu était déjà ouvert, on le referme :
        if ($(this).parent().children("div.subMenu:visible").length != 0) {
            $(this).parent().children("div.subMenu").slideUp("normal", function () {
                $(this).parent().removeClass("open")
               /* $("#content_left").animate( {
                    marginTop:$("#container_left").height()
                }, "medium");*/
            });
        }
        // Si le sous-menu est caché, on ferme les autres et on l'affiche :
        else {
            $(".nav div.subMenu").slideUp("normal", function () {
				$(this).parent().removeClass("open")
                /*$("#content_left").animate( {
                    marginTop:$("#container_left").height()
                }, "medium");*/
            });
            $(this).parent().children("div.subMenu").slideDown("fast", function () {
                $(this).parent().addClass("open")
                /*$("#content_left").animate( {
                    marginTop:$("#container_left").height()
                }, "medium");*/
            });
        }
        // On empêche le navigateur de suivre le lien :
        //return false;
    });

	/**
	 * Gestion de la hauteur de la page
	 * Ajuste la colonne centrale et la gauche en fonction de la colonne de droite
	 */
	if( $('#content_container').height() < $('#container_right').height() ){
		var rightHeight = parseInt($('#container_right').height()) - parseInt('10')
		$('#content_container').height(rightHeight)
	}

	var leftColHeight = parseInt($('#container_left').height()) + parseInt($('#content_left').height()) + parseInt('120')
	
	if( $('#content_container').height() < leftColHeight ){
		$('#content_container').height(leftColHeight)
	}
	
	/**
	 * Gestion des annonces
	 */

    var p = $("#content_left");
    var w = $("#container_left");
    p.css( {
        'margin-top':w.height()+parseInt('100')
    } );

	// On cache le titre si il n'y a pas d'annonces
	if( $('#content_left_1').html() == '<!--TYPO3SEARCH_begin--><!--TYPO3SEARCH_end-->' )
			$('#content_left').css('display', 'none');

	$('#content_left .texteAnnonce').click(function(){
		window.location = $(this).prevAll('a').attr('href');
	}) ;

    // Initialise le carrousel
    if($(".carrousel").length !== 0)
        jQuery('.carrousel').jcarousel();

	

	if($(".carrousel_simple").length !== 0){
        // Initialisation du carrousel
        dispNumNav = 'caroussel_home';
		jQuery('.carrousel_simple').jcarousel({
            scroll:1,
			wrap: 'last',
			auto: 5,
			animation: 'medium',
			easing: 'linear',
            initCallback: carrousel_initCallback,
            itemLoadCallback: carrousel_itemLoadCallbackFunction
        });
        
    }

	if( $(".carrousel_plan_de_ville").length !== 0 ){
		 dispNumNav = 'caroussel_pdv';
		// Initialisation du carrousel
        jQuery('.carrousel_plan_de_ville').jcarousel({
            scroll:1,
			wrap: 'last',
			auto: 5,
			animation: 'medium',
			easing: 'linear',
            initCallback: carrousel_initCallback,
			itemLoadCallback: carrousel_itemLoadCallbackFunction_illus
        });
	}

    // Gestion du rollover sur le titre - Affichage du caption
    $(".carrouselTitle h3 a").mouseenter( function () {
        if( $(".carrouselTitle h3").css('top') == '161px' ){
            $(".caption").hide('fast');
            $(".carrouselTitle h3").animate({top: "216px"},300, false);
        }else{
            $(".carrouselTitle h3").animate({top: "161px"},300, false);
            $(".caption").show('slow');
        }
        
    } );

    //$(".caption").hide();
        	
    /**
	 *
	 *   GESTION DES SELECTEURS
	 *   utilise extensions.mins.js
	 *
	 **/
    $(".sel_openPage").change( function () {
		if( $(this).val() != '' )
            window.location.href = "http://"+window.location.host+"/"+$(this).val();
    } );

	$(".content_shortcut_middle .wrapper select").change( function () {
		if( $(this).val() != '' )
           window.location.href = "http://"+window.location.host+"/"+$(this).val();
    });

    $('select').sSelect({
        ddMaxHeight: '300px'
    });

    
    // Search query
    var page_query = "";
    // Starting page offset, usually 0 for 1st page, 10 for 2nd, 20 for 3rd.
    var page_start = "";
    // Front end that served the page.
    var page_site = "www";
    //

// Affichage des légendes d'images pour le caroussel
    $("ul.carrousel li.jcarousel-item").each(function(i) // Notice the 'i' argument
        {
            if( $(this).children(".caption").children(".csc-caption").length != 0 ){
                $(this).qtip({
                    content: $(this).children(".caption").children(".csc-caption").html(),
                    position: {
                       // adjust: { x: 0, y: -$("li.jcarousel-item-1 a img").height() },
                        adjust: {x: 0, y: -20},
                        corner:{
                            target: 'bottomMiddle',
                            tooltip: 'topMiddle'
                        }
                    },
                    style: {
                      width: 200,
                      padding: 5,
                      background: '#FFFFFF',
                      color: 'black',
                      textAlign: 'center',
                      border: {
                         width: 1,
                         radius: 2,
                         color: '#CECECE'
                      },
                      tip:{
                        corner: true,
                        size: {
                            x: 20, // Be careful that the x and y values refer to coordinates on screen, not height or width.
                            y : 30 // Depending on which corner your tooltip is at, x and y could mean either height or width!
                       }
                      }
                      //name: 'dark' // Inherit the rest of the attributes from the preset dark style
                   }                   
                })
                
            }
        });

// Gestion des liens pour les listes des sous rubriques - Entrée de thème
// Permet de cliquer sur tout le block
$('div#content_main ul.csc-menu li').mouseover( function () {
    $(this).css('cursor', 'pointer')
    /*$(this).css('background-color', '#F8F8F8')*/
}).mouseout(function(){
     $(this).css('cursor', 'default')
     /*$(this).css('background-color', 'transparent')*/
});

$('div#content_main ul.csc-menu li').click( function () {
    rubLink = $(this).children('a').attr('href');
    window.location = rubLink;
});

// Cartes CFF
$('ul.carteCFF li').each(function(i)
    {
        var nbCartes = $(this).children('p.nbCartesCFF').html()
        if( parseInt(nbCartes) <= 6 ){
            $(this).removeClass('cff_vert');
            $(this).addClass('cff_orange');
        }
        if( parseInt(nbCartes) == 0 ){
            $(this).removeClass('cff_vert');
            $(this).addClass('cff_rouge');
        }
    });

	//Affichage des block de mois
	$('ul.carteCFF').each(function(i)
	{
		// Identifiant des blocks
		$(this).parent().addClass('cff_'+i);
		//$('span.navPrev').css('display','none');

		// Nombre d'élément dans la page
		nbElt = $('div.box_generic').find('ul.carteCFF').length;

		// Masque tous les mois sauf le premier
		if(i != 0)
			$(this).parent().hide()		

		// Précédent
		$(this).prev().children('span.navPrev').click(function (){

			if( $(this).hasClass('disable') )
				return

			prev_item = parseInt(i) - 1

			// Masque le mois courant
			$(this).parent().parent().fadeOut(500,function(){
				$('.cff_'+prev_item).fadeIn(500);
				// Gestion des boutons de nav
				$('span.navNext').removeClass('disable');
				if( prev_item == 0)
					$('span.navPrev').addClass('disable');
			});
		});

		// Suivant
		$(this).prev().children('span.navNext').click(function (){
			
			if( $(this).hasClass('disable') )
				return

			next_item = parseInt(i) + 1
			next_item_tot = parseInt(i) + 2

			$(this).parent().parent().fadeOut(500,function(){
				$('.cff_'+next_item).fadeIn(500);
				// Gestion des boutons de nav
				$('span.navPrev').removeClass('disable');
				// Masque le bouton suivant si on est au dernier mois
				if( next_item_tot == nbElt)
					$('span.navNext').addClass('disable');
			});
		
		});
	});

	// Gestion des listes à puces. Si commence par un lien - Ajout de la classe listLink pour avoir les flèches
	$('#content_main ul li:first-child').each(function(){
		if( $(this).parent().parent().parent().parent().parent().attr('class') != 'boxAtterissageAccordion' ){
			if( $(this).html().substr(0, 2) == '<a' || $(this).html().substr(0, 2) == '<A' ){
				if( !$(this).parent().hasClass('sanspuce') ){
				    $(this).parent().addClass('listLink');
				}
			}
		}
	});

	// Traitement de la zone de recherche

	// Ajout de la propriété autocomplete
	$('#menu_left input[name$="q"], .streetMap input[name$="q"], .content_main_recentnews_wrapper_middle input[name$="q"], #top_decouverte_wrapper input[name$="q"]').attr("autocomplete", "off");

	$('#menu_left input[name$="q"], .streetMap input[name$="q"], .content_main_recentnews_wrapper_middle input[name$="q"], #top_decouverte_wrapper input[name$="q"]').focus( function() {
		if( $(this).val() == 'Rechercher' ) {
			$(this).val('');
		}
		$(this).css("color","#000000");
	});

	$('#menu_left input[name$="q"], .streetMap input[name$="q"], .content_main_recentnews_wrapper_middle input[name$="q"], #top_decouverte_wrapper input[name$="q"]').blur( function() {
		if ( $(this).val() == '' ) {
			$(this).val('Rechercher');
			$(this).css("color","#9f9f9f");
		}
	});

	/**************************************************************************
	 *
	 * POWERMAIL
	 *
	 *************************************************************************/
	 $('input.powermail_submit').wrap('<span class="button"></span>')
	 $('input.tx_powermail_pi1_submitmultiple_forward').wrap('<span class="button"></span>')
	 $('input.tx_powermail_pi1_submitmultiple_back').wrap('<span class="button"></span>')
	 $('.tx_powermail_pi1_fieldwrap_html_navigation').each( function(){
		if( $.trim($(this).html()) == '' )
			$(this).hide();
	 });

	 /*************************************************************************
	  *
	  * PAGE DE REGROUPEMENT DES LIEUX
	  * Affichage sous forme d'accordéon des lieux
	  *
	  ************************************************************************/

	 if( $('div.tx-vgelocations-pi1').length != 0 ){

		$('input[name$="tpl_location"]').each( function(){
			if( $(this).val() =='group_title' ){
				// Regroupement par titre
					$(this).parent().children().hide();

					// Supprime le background des li
					$(this).parent().find('li').css('background','none');
					$(this).parent().find('li span').hide();
					$(this).parent().find('li div.titre_lieu').hide();

					$(this).parent().prev().css('cursor','pointer');
					$(this).parent().prev().children().addClass('titre_groupe');

					$(this).parent().prev().children().hover(function (){
						$(this).css('color', '#0062DC');
					},function(){
						$(this).css('color', '#990000');
					 });

					$(this).parent().prev().click( function(){
						// refermer tous les détails de lieu
						
						$(".detail_lieu").each( function(){
							if( $(this).parent().parent().prev().val() != 'group_title' ){
								$(this).slideUp("fast");
								$(this).parent().removeClass("open");
							}else{
								//$(this).parent().parent().parent().prev().removeClass("open");
								//console.info( $(this).parent().parent().parent().prev().attr('class') )
							}
						});

						if( $(this).children().hasClass('open') ){
							$(this).children().removeClass("open");
							$(this).next().children().slideUp("fast");
						}else{
							$(this).children().addClass("open");
							$(this).next().children().slideDown("slow");
						}
					});
			}else{
					// Regroupement par mot clé
					var cur_container = $(this).parent();
					
					// Séléctionne les fiches de lieux
					cur_container.find('.detail_lieu').each( function(){

						$(this).hide();

						$(this).parent().css('cursor','pointer')

						$(this).parent().click( function(){

							if( $(this).hasClass("open") ){
								$(this).removeClass("open");
								$(this).children(".detail_lieu").slideUp("fast");
							}else{
								$(this).addClass("open");
								$(this).children(".detail_lieu").slideDown("slow");
							}

							curEl = $(this);
							// refermer tous les détails de lieu - sauf ceux regroupé par titre
							$(".detail_lieu").each( function(){

								if( $(this).parent().parent().prev().val() != 'group_title' ){
									if( curEl.html() != $(this).parent().html() ){
										$(this).slideUp("fast");
										$(this).parent().removeClass("open");
									}
								}else{
									$(this).parent().parent().parent().children().hide();
									$(this).parent().parent().parent().prev().children().removeClass("open");
								}
							});
						});
				 });
			}
		});
	}

	/*************************************************************************
	  *
	  * PAGE DE REGROUPEMENT DES CONTACTS
	  * Affichage sous forme d'accordéon des contacts
	  *
	  ************************************************************************/

	 if( $('div.tx-vgecontacts-pi1').length != 0 ){

		$('input[name$="tpl_contact"]').each( function(){
			if( $(this).val() =='group_title' ){
				// Regroupement par titre
					$(this).parent().children().hide();

					// Supprime le background des li
					$(this).parent().find('li').css('background','none');
					$(this).parent().find('li span').hide();
					$(this).parent().find('li div.titre_lieu').hide();

					$(this).parent().prev().css('cursor','pointer');
					$(this).parent().prev().children().addClass('titre_groupe');

					$(this).parent().prev().children().hover(function (){
						$(this).css('color', '#0062DC');
					},function(){
						$(this).css('color', '#990000');
					 });

					$(this).parent().prev().click( function(){
						// refermer tous les détails de lieu

						$(".detail_lieu").each( function(){
							if( $(this).parent().parent().prev().val() != 'group_title' ){
								$(this).slideUp("fast");
								$(this).parent().removeClass("open");
							}else{
								//$(this).parent().parent().parent().prev().removeClass("open");
								//console.info( $(this).parent().parent().parent().prev().attr('class') )
							}
						});

						if( $(this).children().hasClass('open') ){
							$(this).children().removeClass("open");
							$(this).next().children().slideUp("fast");
						}else{
							$(this).children().addClass("open");
							$(this).next().children().slideDown("slow");
						}
					});
			}else{
					// Regroupement par mot clé
					var cur_container = $(this).parent();

					// Séléctionne les fiches de lieux
					cur_container.find('.detail_lieu').each( function(){

						$(this).hide();

						$(this).parent().css('cursor','pointer')

						$(this).parent().click( function(){

							if( $(this).hasClass("open") ){
								$(this).removeClass("open");
								$(this).children(".detail_lieu").slideUp("fast");
							}else{
								$(this).addClass("open");
								$(this).children(".detail_lieu").slideDown("slow");
							}

							curEl = $(this);
							// refermer tous les détails de lieu - sauf ceux regroupé par titre
							$(".detail_lieu").each( function(){

								if( $(this).parent().parent().prev().val() != 'group_title' ){
									if( curEl.html() != $(this).parent().html() ){
										$(this).slideUp("fast");
										$(this).parent().removeClass("open");
									}
								}else{
									$(this).parent().parent().parent().children().hide();
									$(this).parent().parent().parent().prev().children().removeClass("open");
								}
							});
						});
				 });
			}
		});
	}

	 /*************************************************************************
	  *
	  * Affichage des vidéos en LightBox
	  * Librairie : top_up - http://gettopup.com/
	  * Modifications VGE - ligne 455 + 635 + 636
	  *
	  ************************************************************************/
	TopUp.host = location.protocol+"//www.ville-geneve.ch/";
	TopUp.players_path = "fileadmin/public/mediaplayer/";
	TopUp.images_path = "fileadmin/villege/templates/images/top_up/";
	
	if( ($('p.video a').length != 0) || ($('td.video a').length != 0) || ($('th.video a').length != 0) || ($('li.video a').length != 0) || ($('a.video img').length != 0) || ($('a.video_home').length != 0) ){

		

		TopUp.addPresets({
			"p.video a": {
				type: "flashvideo",
				layout: "quicklook",
				modal: 1,
				width: 700,
				height: 400,
				title: 'Vidéo VGE',
				shaded: 1 // Vidéo dans une fenêtre modal
			},
			"td.video a": {
				type: "flashvideo",
				layout: "quicklook",
				modal: 1,
				width: 700,
				height: 400,
				title: "Vidéo Ville de Genève",
				shaded: 1 // Vidéo dans une fenêtre modal
			},
			"th.video a": {
				type: "flashvideo",
				layout: "quicklook",
				modal: 1,
				width: 700,
				height: 400,
				title: "Vidéo Ville de Genève",
				shaded: 1 // Vidéo dans une fenêtre modal
			},
			"li.video a": {
				type: "flashvideo",
				layout: "quicklook",
				modal: 1,
				width: 700,
				height: 400,
				title: "Vidéo Ville de Genève",
				shaded: 1 // Vidéo dans une fenêtre modal
			}
			,
			"a.video": {
				type: "flashvideo",
				layout: "quicklook",
				modal: 1,
				width: 700,
				height: 400,
				title: "Vidéo Ville de Genève",
				shaded: 1 // Vidéo dans une fenêtre modal
			}
			,
			"a.video_home": {
				type: "flashvideo",
				layout: "quicklook",
				modal: 1,
				width: 800,
				height: 600,
				title: "Vidéo Ville de Genève",
				shaded: 1 // Vidéo dans une fenêtre modal
			}
		});
	}

	 /*************************************************************************
	  *
	  * Menu Wiki
	  * Affiche / Masque le menu
	  *
	  ************************************************************************/

	  if ( $(".menu_wiki_middle").lenght != 0 ) {
		  $(".menu_wiki_middle a.small").click( function(){

			 if( $(this).hasClass("close") ){
				$(this).next().show();
				$(this).text("[masquer]")
			 }
			 else {
				$(this).next().hide();
				$(this).text("[afficher]")
				}

			$(this).toggleClass("close");
			return false;
		  });
	  }

	  	 /*************************************************************************
	  *
	  * Zone de partage
	  * Affiche / Masque la zone de partage
	  *
	  ************************************************************************/

	  if ( $(".call_network_area").lenght != 0 ) {
		  
		  var leaveButton = false;
		  var networkEnter = false;
		  var time = 1000;

		  $(".call_network_area").mouseover( function(){
			 if( $(".network_area_top").hasClass("close") ){
				$(".network_area").show();
				$(".network_area_top").toggleClass("close");
			 }

			return false;
		  }).mouseleave( function(){
			  setTimeout(function(){
					if(leaveButton == true){
					  $(".network_area").hide();
					  $(".network_area_top").addClass("close");
					}
				}, time);
				leaveButton = true;
		  });

		  $(".network_area_top").mouseenter( function(){
			  leaveButton = false;
			  networkEnter = true;
		  });

		  $(".network_area_top").mouseleave( function(){
			 setTimeout(function(){
				 if( !$('.network_area_top').hasClass("close") && networkEnter == false ){
					$('.network_area_top').parent().hide();
					$('.network_area_top').toggleClass("close");
				 }
			 }, time);

			 networkEnter = false;

			 return false;
		  });
	  }
});

// Remise à zéro des formulaires pour GSA
function resetForms() {
    for (var i = 0; i < document.forms.length; i++ ) {
        document.forms[i].reset();
    }
}

function openAccessibility() {
    // Recuperation de la propriete visible de la barre d'accessibilite
    state_barre_acc = $("#accessibility").css("display");

    // Chgt d'etat
    if(state_barre_acc == "block")
        $("#accessibility").css({
            display:"none"
        });
    else
        $("#accessibility").css({
            display:"block"
        });
}

// Gestion du menu Guide des quartiers
function openGuideQuartiers() {
    state_guide = $("#guide_quartier").css("display");
    if(state_guide  == "block")
        $("#guide_quartier").css({
            display:"none"
        });
    else
        $("#guide_quartier").css({
            display:"block"
        });
}

/**
 * Carrousel
 *
 */
function carrousel_initCallback(carrousel) {

	// Disable autoscrolling if the user clicks the prev or next button.
    carrousel.buttonNext.bind('click', function() {
        carrousel.startAuto(0);
    });

    carrousel.buttonPrev.bind('click', function() {
        carrousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carrousel.clip.hover(function() {
        carrousel.stopAuto();
    }, function() {
        carrousel.startAuto();
    });

	if(dispNumNav == 'caroussel_home'){ //Variable globale définie à l'init du carrousel
		// Ajout des boutons de navigation (1 2 3...)
		block_num_detail = '';
		for (i = 1; i <= $(".jcarousel-item").length; i++) {
			if(i == 1)
				block_num_detail += "<a href='#' class='curNav'>"+i+"</a>&nbsp;"
			else
				block_num_detail += "<a href='#'>"+i+"</a>&nbsp;"
		}
		block_num = "<div class='jcarousel-control'>"+block_num_detail+"</div>"
		$(".jcarousel-clip-horizontal").append(block_num);

		// Ajout de l'écouteur
		if( $(".jcarousel-control").length != 0 ) {
			$('.jcarousel-control a').bind('click', function() {
				// Disable autoscrolling
				carrousel.startAuto(0);

				if( $(this).html() != $('.jcarousel-control a.curNav').html() ){
					carrousel_display_nextItem( $(this), "number", carrousel );
					carrousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
				}

				return false;
			});

			$('.jcarousel-control a').bind('click', function() {
				 return false;
			});
		}
	}
	else if(dispNumNav == 'caroussel_pdv'){
		// Ajout des boutons de navigation (1 2 3...)
		block_num_detail = '';
		for (i = 1; i <= $(".jcarousel-item").length; i++) {
			if(i == 1)
				block_num_detail += "<div class='carrousel_illus curNav'> </div>"
			else
				block_num_detail += "<div class='carrousel_illus'> </div>"
		}
		block_num = "<div class='jcarousel-control'>"+block_num_detail+"<div class='clear_both'> </div></div>"
		$(".jcarousel-clip-horizontal").before(block_num);
	}
}

function carrousel_display_nextItem(curObj, typeButton, curCarrousel) {
   $(".caption").hide();

    // Calcul le numéro du block suivant
    if(typeButton == "arrow")
        nextItemNum = parseInt( curObj ) + 1;
    else
        nextItemNum = parseInt( curObj.html() ) + 1;

	// Ajout de l'état actif sur les boutons

	$('.jcarousel-control').children().removeClass('curNav');
	$('.jcarousel-control').children().each(function(){
			if( $(this).html() == curObj )
				$(this).addClass('curNav');
	});

    // Ajout du block de la photo suivante sauf pour la dernière
    if(nextItemNum <= $(".jcarousel-item").length){

        nextItem = ".jcarousel-item-"+ nextItemNum+" h3";
        linkItem = ".jcarousel-item-"+ nextItemNum+" a";

        block_nextItem = "<div class='jcarousel-next-item'>Suivant ("+nextItemNum+"/"+$(".jcarousel-item").length+") : <a href='"+nextItemNum+"'>" + $(nextItem).text() + "</a></div>"

        $(".jcarousel-next-item").remove();
        $(".jcarousel-clip-horizontal").append( block_nextItem )
    }
    else{
        $(".jcarousel-next-item").remove();
    }

    $('.jcarousel-next-item a').bind('click', function() {
            curCarrousel.scroll(jQuery.jcarousel.intval( $(this).attr("href") ));
            return false;
        });
}

function carrousel_itemLoadCallbackFunction(carrousel, state){
	carrousel_display_nextItem(carrousel.first, "arrow", carrousel)
}

function carrousel_itemLoadCallbackFunction_illus(carrousel, state){
	// Ajout de l'état actif sur les boutons
	$('.jcarousel-control').children().removeClass('curNav');
	var k = 0; // Position de l'enfant
	var pos_car = parseInt( carrousel.first );
	$('.jcarousel-control').children().each(function(){
		k++;
		if( k == pos_car)
			$(this).addClass('curNav');
	});
}

/***************************************************************************
 * Définition de la variable $_GET 
 */
function getQueryParams(qs) {
    qs = qs.split("+").join(" ");

	var params = new Array();
    var tokens;
	var regex = /[?&]?([^=]+)=([^&]*)/g;

    while ( ( tokens = regex.exec(qs) ) != null ) {
        var zeroLengthMatch = !tokens[0].length;
		// Fix IE's incorrect lastIndex
		if (zeroLengthMatch && regex.lastIndex > tokens.index)
			regex.lastIndex--;

		params[decodeURIComponent(tokens[1])] = decodeURIComponent(tokens[2]);

		// Avoid an infinite loop with zero-length matches
		if (zeroLengthMatch)
			regex.lastIndex++;
    }

    return params;
}

var $_GET = getQueryParams(document.location.search);

