/* Moteur de recherche Google */

$("a#agrandircarte").live('click',function(){
$("iframe#carte").css({
'width':'751px',
'height':'568px',
'position':'relative',
'padding':'10px',
'margin':'10px 0',
'background':'#fff',
'border':'1px solid #ccc'
});
$(this).html("<a id=retrecircarte>Retrecir</a>");
return(false);
});

$("a#retrecircarte").live('click',function(){
$("iframe#carte").css({
'width':'505px',
'height':'400px',
'position':'relative',
'padding':'0',
'margin':'0',
'background':'#fff',
'border':'none'
});
$(this).html("<a id=agrandircarte>Agrandir</a>");
return(false);
});




if($.browser.msie && $.browser.version=="6.0"){

}
else{

function goToByScroll(id){
$('html,body').animate({scrollTop: $("#"+id).offset().top},'slow');
}

$('html').addClass('js');

$(document).ready( function () {

var $page = "http://www.bobigny.fr/jsp/site/Portal.jsp?page_id=706";
var $moteur = $page + " #cse-search-box";
$("#quick-search").load($moteur);

});
}

/*Rollover txt (page CME)*/

$(document).ready( function () {
$('html').removeClass('js');

$(".rollover_txt p").css({
padding:"1em",
position:"absolute",
"z-index":"1"
});

$(".rollover_txt img").css({
position:"relative",
"z-index":"2"
});


$(".rollover_txt").each(function () {
$(".rollover_txt p").hide();
$(this).children("img").each(function () {
$(this).hover(function(){
$(this).animate({opacity:"0.15"},{queue:false, duration:300 });
$(this).prev("p").show();
return false
},

function(){

$(this).animate({opacity:"1"},{queue:false, duration:300 });
$(".rollover_txt p").hide();
return false

});
});
});
});

/* Menu depliant  */

$(document).ready( function () {


    $(".menu_depliant_sans_java").hide();/*pour garder les ancres*/
		$(".menu_depliant>li").addClass("toggle");
		$(".menu_depliant>li").each(function(){
		$(".details",this).wrapAll("<div class='groupe_details'></div>");
		});
 		$(".menu_depliant .groupe_details").hide();

    $(".menu_depliant h2, .menu_depliant .toggle_lien").each( function () {
        var TexteSpan = $(this).html();
        $(this).replaceWith('<a class="toggle" href="" title="Afficher les détails">' + TexteSpan + '<\/a>') ;
    } ) ;

    // On modifie l'evenement "click" sur les liens dans les items de liste

    $(".menu_depliant li.toggle a.toggle").click( function () {
        // Si le sous-menu deja ouvert, on le referme :
        if ($(this).next(".groupe_details:visible").length != 0) {
            $(this).next(".groupe_details").slideUp("fast",function () { $(this).parent().removeClass("open") });

        }
        // Si le sous-menu est cache, on ferme les autres et on l'affiche :
        else {
            $(".menu_depliant .groupe_details").slideUp("fast",function () { $(this).parent().removeClass("open") });

            $(this).next(".menu_depliant .groupe_details").slideDown("fast",
            function () { $(this).parent().addClass("open") });

        }
        // On empeche le navigateur de suivre le lien :
        return false;
    });

});


/*********************/
/****** Onglets ******/

$(document).ready( function (f) {

//1
//creation du menu
function createmenu(f){
//creation du menu vide
$(this).prepend("<div class=menu><ul></ul></div>");
//remplissage du menu
cible = $(".menu ul", this);
//$(".titre",this).clone().appendTo(cible);
$(".titre",this).appendTo(cible);
titres = $(".menu ul .titre", this);
//pour chaque titre :
titres.each(function(){
lien = $(this).text();
lienid = $(this).attr("id");
$(this).replaceWith('<li><a title="Afficher ' + lien + '" id="'+ lienid +'" href="" >' + lien + '</\a><\/li>') ;
});


//1.1
//creation des variables
var onglet = $(".onglet",this);
var menu = $(".menu", this);
var onglets = $(this);

//2
//actif par defaut


$(".menu a").css("opacity", "0.5");
$(".menu a:first",this).addClass("actif");
$("a.actif").css("opacity", "1");
$(".onglet",this).hide();
$(".onglet:first",this).show();

//3
//survol des boutons

$(menu, this).each( function () {

$("a",this).bind('click',( function () {

    $("a", menu).removeClass("actif").animate({opacity:"0.5"},{queue:false, duration:300 });
    $(this).addClass("actif").animate({opacity:"1"},{queue:false, duration:300 });

  $(onglets).each( function () {

    var onglet_actif_id = $("a.actif", menu).attr("id");

    $(onglet).each( function () {

    var onglet_id = $(this).attr("id");
    if(onglet_id == onglet_actif_id){
    $(onglet).hide();
    $(this).show();

    }
    else{}
   });
 });//fin onglet
 return(false);
}));//fin mouseover
});//fin menu
}

//application de la fonction
$(".onglets").each(createmenu);
});


/*********************/
/**** affichage de parties ****/
$(document).ready( function (f) {
//1
//creation du menu
function createmenu(f){

//id des onglets
$("div.partie").each(function(){
var $ident = $(this).children("h2").text();
$(this).attr("id", $ident);
});


//menu
$("div.partie:first",this).before("<div class=menuu><ul></ul></div>");
$cible = $(".menuu ul", this);
$("h2",this).clone().appendTo($cible);
$lienh2 = $(".menuu ul h2", this);

$lienh2.each(function(){
  lien = $(this).text();
  $(this).replaceWith('<li><a title="Afficher ' + lien + '" id="'+ lien +'" href="'+ lien +'" >' + lien + '</\a><\/li>') ;
  });

//1.1
//creation des variables
var $onglets = $(this);
var $menu = $(".menuu");
var $menuelem = $(".menuu a");
var $onglet = $(".partie",this);



//2
//actif par defaut

$(".menuu a:first",this).addClass("actif");
$onglet.hide();
$(".partie:first",this).show();

//3
//survol des boutons


$(".menuu a").live('click',( function () {
    $menuelem.removeClass("actif");
    $(this).addClass("actif");
    var onglet_actif_id = $("a.actif", $menu).attr("id");

    $onglet.each( function () {
        var onglet_id = $(this).attr("id");
        if(onglet_id == onglet_actif_id)
              {
              $onglet.hide();
              $(this).show();
              }
        else{}
   });



 return(false);
}));

}

//application de la fonction
$(".ancres").each(createmenu);
});

/**************test galerie photo.js********************/

/*remplacer les anciens liens par de nouveaux liens ajax*/
$(document).ready( function () {
$.ajaxSetup({cache: false});

    $("#evenementiel .galerie_photo a").each( function () {
        var textespan = $(this).attr('href');
        var titre = $(this).html();
        $(this).replaceWith('<a class="lien_ok" href="'+ textespan +'" title="'+ textespan +'">' + titre + '<\/a>') ;
    });

/*remplacer les anciens liens par de nouveaux liens ajax*/

$("a.lien_ok:first").parent("div").addClass("on");



$("a.lien_ok").click(
function () {
var url = $(this).attr('href');
var urlok = url +" div.ajax *";
$("a.lien_ok").parent("div").removeClass("on");
$(this).parent("div").addClass("on");

$("div.ajax").append('<img src="http://www.bobigny.fr/images/local/skin/load_ajax.gif" alt="chargement">').show('normal',
function(){
$.ajaxSetup({cache: false});
			$("div.ajax").load(urlok);

			});
return false;
});


});

/**************liens pages galeries photo ********************/


$(document).ready( function () {

initBinding();
/*f1*/
function initBinding()
{

	$('.listImages a.liste').hide();
	var TOTAL = $(".listImages .image a.liste").size();

	var GALERIES = new Array();
	$('.listImages a.liste').each(function() {GALERIES.push($(this).attr('href'));})
	var GALERIESTITRE = new Array();
	$('.listImages a.liste').each(function() {GALERIESTITRE.push($(this).attr('title'));})


	$(".listImages").wrap('<div id="galeries">');
	$(".listImages .image").after('<p id="navigation"><a href="'+ GALERIES[0] +'" id="prec" title="'+ GALERIESTITRE[0] +'"></a><a href="'+ GALERIES[0] +'" id="suiv" title="'+ GALERIESTITRE[0] +'"></a></p>');
	$('.listImages a#prec').hide();

	var i=0;
/******CLIC******/

$(".listImages #navigation a#suiv").live('click',( function () {

		if (i<(TOTAL-1)){i++;}
		if(i>0){$('.listImages a#prec').show();}
		if(i==(TOTAL-1)){$(this).hide();}


		$(this).attr("title", GALERIESTITRE[i]);
		$(this).attr("href", GALERIES[i]);

		var HREF = $(this).attr('href');
		var ID = $(this).attr('href').slice(28);
		var TITRE = $(this).attr('title');

		$("#galeries .image_contenu img").attr("src", 'image?resource_type=page_thumbnail&id=' + ID).attr("title", TITRE);
		$("#galeries .image_contenu a").attr("href", HREF);
		$("#galeries .legende a").text(TITRE).attr("href", HREF).attr("title", TITRE);

		return(false);

}));


$(".listImages #navigation a#prec").live('click',( function () {

		if (i!=0){i--;}
		if(i!=(TOTAL-1)){$('.listImages a#suiv').show();}
		if(i==0){$(this).hide();}

		$(this).attr("title", GALERIESTITRE[i]);
		$(this).attr("href", GALERIES[i]);

		var HREF = $(this).attr('href');
		var ID = $(this).attr('href').slice(28);
		var TITRE = $(this).attr('title');

		$("#galeries .image_contenu img").attr("src", 'image?resource_type=page_thumbnail&id=' + ID).attr("title", TITRE);
		$("#galeries .image_contenu a").attr("href", HREF);
		$("#galeries .legende a").text(TITRE).attr("href", HREF).attr("title", TITRE);

		return(false);

}));

/*-f2*/

}
/*-f1*/

});


/************ fin ajax une ***********/



/*Menu.js*/


sfHover = function() {
	var sfEls = document.getElementById("menu").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

sfHover = function() {
	var sfEls = document.getElementById("menu");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

function toggle(obj) {
	var el = document.getElementById(obj);
	if ( el.style.display != 'none' ) {
		el.style.display = 'none';
	}
	else {
		el.style.display = '';

	}
}


/*Taille du texte*/

if($.browser.msie && $.browser.version=="6.0"){

}
else{

$(document).ready( function () {

$(function(){
$('#accessibilite a.text_size').click(function(){
  var ourText = $(".document .corps");
          var currFontSize = ourText.css('fontSize');
          var currHeight = ourText.css('line-height');
          var finalNum = parseFloat(currFontSize, 10);
          var finalHeight = parseFloat(currHeight, 10);
          var stringEnding = currFontSize.slice(-2);
          var stringEndingheight = currHeight.slice(-2);
          if(this.id == 'plus') {
               finalNum *= 1.2;
               finalHeight *= 1.2;
           }
          else if (this.id == 'moins'){
               finalNum /=1.2;
               finalHeight /= 1.2;
            }
           var $add= finalNum + stringEnding;
           var $addtwo= finalHeight + stringEndingheight;

           ourText.css('fontSize',$add);
           ourText.css('line-height', $addtwo);
       });
   });
});
}


/*Cacher la colonne 2

$(document).ready( function () {

$(function(){
var $doc =$(".document h1");
var $col1 =$("#three-zones-first");
var $col2 =$("#three-zones-second");
$($doc).after
("<a class='cacher_colonne' title='Masquer la colonne 2'>Masquer la colonne 2</a>");


$('a.cacher_colonne').click( function (){

			if (!$(this).hasClass("on")) {
			$(this).text("Afficher la colonne 2");
			$(this).attr('title','Afficher la colonne 2');
			$(this).addClass("on");
			$col1.css('width','720px');
      $col2.css('display','none');
			}

			else if ($(this).hasClass("on")) {
			$(this).text(">");
			$(this).attr('title','Masquer la colonne 2');
			$(this).removeClass("on");
			$col1.css('width','480px');
      $col2.css('display','block');
			}


});
});
});

*/
/*Bonjour Bobigny deroulant*/

$(document).ready( function () {

$('.bjb .miniature').hover( function (){
			$(this).animate({height: "160px"},{queue:false, duration:500 });
			},
			function() {
   		$(this).animate({height: "70px"},{queue:false, duration:500 });
			}
			);


});




/* Menus deroulants*/
function getRequestParameter( name ) {
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec( window.location.href );
if( results == null )
return "";
else
return results[1];
}


$(document).ready( function () {
    $(".navigation li").each( function () {
	if ($(this).attr("id")== "page_" + getRequestParameter("page_id")) {
		$(this).addClass("current");
		$(this).find(">ul").addClass("current");
		$(this).find(">ul").find(">li").addClass("other");
        }
    });
var test;
do {
	test=false
	$(".navigation ul").each( function () {
		if ($(this).find(">li").hasClass("current") && !$(this).hasClass("current")) {
			$(this).addClass("current");
			test = true;
			$(this).find(">li").each( function () {
				if (!$(this).hasClass("current")) {
					$(this).addClass("other");
				}
			});
		}

 });
$(".navigation li").each( function () {
		if ($(this).find(">ul").hasClass("current") && !$(this).hasClass("current")) {
			$(this).addClass("current");
			test = true;
		}

 });
} while (test==true);

} ) ;



/* =========================================================
// jquery.panorama.js
// Author: Arnault PACHOT & FrÃ©dÃ©ric Martini
// Copyright (c) 2009
// licence : GPL
========================================================= */
(function($) {
	$.fn.panorama = function(options) {
		this.each(function(){
			var settings = {
				viewport_width:910,
				speed: 15000,
				direction: 'left',
				control_display: 'yes',
				start_position: 0,
				auto_start: false,
				mode_360: false,
				loop_180: false
			};
			if(options) $.extend(settings, options);


			var elemWidth =  parseInt($(this).attr('width'));
			var elemHeight = parseInt($(this).attr('height'))+29;
			/* --------------------------------------------------
			// RÃ©cupÃ©ration automatique de la taille de l'image :
			// Si un des attributs width ou height est absent,
			// on rÃ©cupÃ¨re la vrai taille de l'image :
			if (isNaN(elemWidth) || isNaN(elemHeight)) {
				var img = new Image();
				img.src = $(this).attr('src');
				if (isNaN(elemWidth)) elemWidth = img.width;
				if (isNaN(elemHeight)) elemHeight = img.height;
			}*/
			// --------------------------------------------------
			var currentElement = this;
			var panoramaViewport, panoramaContainer;


			$(this).css('position', 'relative')
				.css('margin', '0')
				.css('padding', '0')
				.css('border', 'none')
				.wrap("<div class='panorama-container'></div>");
			if (settings.mode_360)
				$(this).clone().insertAfter(this);

			panoramaContainer = $(this).parent();
			panoramaContainer.wrap("<div class='panorama-viewport'></div>").parent().css('width',settings.viewport_width+'px')
				.append("<div class='panorama-control'><span class='panorama-control-left' title='gauche'>&#9668;</span> <span class='panorama-control-pause' title='pause'>&#9632;</span> <span class='panorama-control-right' title='droite'>&#9658;</span> </div>");

			panoramaViewport = panoramaContainer.parent();

			panoramaViewport.css('height', elemHeight+'px').find('span.panorama-control-left').bind('mouseover', function() {
				$(panoramaContainer).stop();
				settings.direction = 'right';
				panorama_animate(panoramaContainer, elemWidth, settings);
				return false;
			});
			panoramaViewport.bind('mouseover', function() {
				$(panoramaContainer).stop();
			});
			panoramaViewport.find('span.panorama-control-right').bind('mouseover', function() {
				$(panoramaContainer).stop();
				settings.direction = 'left';
				panorama_animate(panoramaContainer, elemWidth, settings);
				return false;
			});
			panoramaViewport.find('span.panorama-control-pause').bind('mouseover', function() {
				$(panoramaContainer).stop();
				return false;
			});

			if (settings.control_display == 'yes') {
				panoramaViewport.find('.panorama-control').show();
			} else {
				panoramaViewport.bind('mouseover', function(){
					$(this).find('.panorama-control').show();
					return false;
				}).bind('mouseout', function(){
					$(this).find('.panorama-control').hide();
					return false;
				});

			}

			$(this).parent().css('margin-left', '-'+settings.start_position+'px');

			if (settings.auto_start)
				panorama_animate(panoramaContainer, elemWidth, settings);

		});
		function panorama_animate(element, elemWidth, settings) {
			currentPosition = 0-parseInt($(element).css('margin-left'));
			if (settings.direction == 'right') {

				$(element).animate({marginLeft: 0}, 1000+elemWidth ,'linear', function (){
					if (settings.mode_360) {
						$(element).css('marginLeft', '-'+(parseInt(parseInt(elemWidth))+'px'));
						panorama_animate(element, elemWidth, settings);
					} else if (settings.loop_180) {
						settings.direction = 'left'; // changement de sens
						panorama_animate(element, elemWidth, settings);
					}
				});
			} else {
				var rightlimit;
				if (settings.mode_360)
					rightlimit = elemWidth;
				else
					rightlimit = elemWidth-settings.viewport_width;

				$(element).animate({marginLeft: -rightlimit}, 1000+elemWidth, 'linear', function (){
					if (settings.mode_360) {
						$(element).css('margin-left', 0);
						panorama_animate(element, elemWidth, settings);
					} else if (settings.loop_180) {
						settings.direction = 'right'; // changement de sens
						panorama_animate(element, elemWidth, settings);
					}
				});
			}


		}

	};

$(document).ready(function(){
	$("img.panorama").panorama();
});
})(jQuery);

/************/
/* CARROUSEL*/

$(document).ready( function () {

$(".carrousel").attr("id", function (arr) {
return arr;
});
function createcarrousel(){

$("img",this).wrap('<div class="image"></div>');

//On donne des id numeriques aux cadre de classe "element"
$("div.element",this).attr("id", function (arr) {
return arr;
});

//Variable de données numérique

Reference = $(".element:first-child" ,this);
NbElement = $(".element", this).length;
Hauteur = $(".element:first-child img" ,this);

//On emballe
$(this).wrap('<div class="carrousel-conteneur"></div>')
.css("width", (Reference.width() * NbElement) );

$(this).parent(".carrousel-conteneur")
.css("width",  Reference.width())
.css("overflow", "hidden")
.append(''
+    '<ul id="carrousel-pagination">'
+    '   <li id="carrousel-prev"><a title="précédent">&#9668; <span id="prev"></span></a></li>'
+    '   <li id="carrousel-next"><a title="suivant"><span id="next"></span>&nbsp;&#9658;</a></li>'
+    '</ul>'
+'');


//Initialisation du compteur

var pop = $(this).attr("id");

var Carr=new Array(); // regular array (add an optional integer
Carr[0]="0";       // argument to control array's size)
Carr[1]="0";

//Suivant
var cecarrousel = $(this).parent(".carrousel-conteneur");

$("#carrousel-next", cecarrousel).click(function() {
Nombre=$(".carrousel .element", cecarrousel).length;

  //Si le calque courant n'est pas "dernier"
	if(Carr[pop] < (Nombre-1) ){

		//On ajoute 1
		Carr[pop]++

		// Mouvement du carrousel en arriere-plan

		$(".carrousel", cecarrousel).animate({
		marginLeft : - (Reference.width() * Carr[pop])
		});
	} // fin if

  //Si le calque courant est le "dernier"
	else if(Carr[pop] == (Nombre-1) ){

		//On ajoute 1
		Carr[pop]=0

		// Mouvement du carrousel en arriere-plan

		$(".carrousel", cecarrousel).animate({
		marginLeft : - (Reference.width() * Carr[pop])
		});
	} // fin if

}); // fin fonction

//Precedent
$("#carrousel-prev", cecarrousel).click(function() {

	//Si le compteur est superieur a  0
	if(Carr[pop] > 0){

		//On retire 1
		Carr[pop] --;

		// Mouvement du carrousel en arriere-plan
		$(".carrousel", cecarrousel).animate({
		marginLeft : - (Reference.width() * Carr[pop])
		});
	} // fin if

}); // fin fonction

}

$(".carrousel").each(createcarrousel);

});


/******************************/
/** on retire la class flash **/

if($.browser.msie && $.browser.version=="6.0"){

}
else{
$(document).ready( function () {
$('html').removeClass('js');
});
}

