function agendaShow(madiv) {
	if (madiv == "actualites_agenda") {
		jQuery('#actualites_agenda').show();
		jQuery('#actualites_cluster').hide();
		jQuery('#actualites_a_agenda').addClass("actif");
		jQuery('#actualites_a_cluster').removeClass("actif");
	}
	else {
		jQuery('#actualites_agenda').hide();
		jQuery('#actualites_cluster').show();
		jQuery('#actualites_a_agenda').removeClass("actif");
		jQuery('#actualites_a_cluster').addClass("actif");
	}
		
}

function mycarousel_initCallback(carousel) {
	carousel.buttonNext.bind('click', function() {
		carousel.startAuto(0);
	});

	carousel.buttonPrev.bind('click', function() {
		carousel.startAuto(0);
	});

	carousel.clip.hover(function() {
		carousel.stopAuto();
	}, function() {
		carousel.startAuto();
	});
};

jQuery(document).ready(function (){
	var length = 0;
	var current = 0;
	
	var diapos = new Array();
	
	var $this;
	
	$.fn.diaporama = function(){
		return this.each(function(){
			$this = $(this);
			$('ul', this).hide();
			length = $('ul li', this).length;
			lis = $('ul li', this);
			if (length <= 1) {
				$('a.left, a.right', this).hide();
			}
			else {
				$('a.left', this).click(function() {
					current--;
					if (current < 0) {
						current = length - 1;
					}
					lis.each(function (i) {
						if (i == current) {
							var my_a = $('a', this);
							$('div#phototeque', $this).css('background-image', 'url("' + my_a.attr('rel') + '")');
							var target = "#";
							if (my_a.attr('href') != "")
								target = my_a.attr('href');
							$('h2', $this).html('<a href="' + target + '">' + my_a.text() + '</a>');
						}
					});
				});
				$('a.right', this).click(function() {
					current++;
					if (current >= length) {
						current = 0;
					}
					lis.each(function (i) {
						if (i == current) {
							var my_a = $('a', this);
							$('div#phototeque', $this).css('background-image', 'url("' + my_a.attr('rel') + '")');
							var target = "#";
							if (my_a.attr('href') != "")
								target = jQuery(this).attr('href');
							$('h2', $this).html('<a href="' + target + '">' + my_a.text() + '</a>');
						}
					});
				});
			}
			
			var firstLi = $('ul li:first a', this);
			$('div#phototeque', this).css('background-image', 'url("' + firstLi.attr('rel') + '")');
			var target = "#";
			if (firstLi.attr('href') != "")
				target = firstLi.attr('href');
			$('h2', this).html('<a href="' + target + '">' + firstLi.text() + '</a>');
			setInterval(function(){
				current++;
				if (current >= length) {
					current = 0;
				}
				lis.each(function (i) {
					if (i == current) {
						var my_a = $('a', this);
						$('div#phototeque', $this).css('background-image', 'url("' + my_a.attr('rel') + '")');
						var target = "#";
						if (my_a.attr('href') != "")
							target = jQuery(this).attr('href');
						$('h2', $this).html('<a href="' + target + '">' + my_a.text() + '</a>');
					}
				}); 
            }, 5000);

		});
	};
	
	jQuery("#col-centrale a").each(function() {
		var nameTitle = jQuery(this).attr('title');
		if (nameTitle != "") {
			jQuery("a").each(function(){
				var $this = this;
				if (jQuery.browser.msie) {
					if (jQuery($this).attr('href').indexOf("#" + nameTitle) >= 0) {
						jQuery($this).click(function(){
							jQuery('div#' + nameTitle).toggle(500);
						});
					}
				}
				else {
					if (jQuery($this).attr('href') == "#" + nameTitle) {
						jQuery($this).click(function(){
							jQuery('div#' + nameTitle).toggle(500);
						});
					}
				}
			});
		}
	});
	
	jQuery("#col-centrale a img").each(function () {
		jQuery(this).parent().attr('target', '_blank');
	});
	
	jQuery("#marche").diaporama();
	
	
	jQuery("#fondateurs_carrousel").jcarousel({
		auto: 3,
		scroll: 2,
		wrap: 'last',
		initCallback: mycarousel_initCallback
	});
	
		
	jQuery("ul#fondateurs_carrousel li a img").each(function (){
		jQuery(this).css({
			'top': parseInt((80 - parseInt(jQuery(this).height())) / 2) + 'px',
			'position' : 'relative'
		});
	});
	
});	

function str_replace(search, replace, subject) {
    // Replaces all occurrences of search in haystack with replace  
    // 
    // version: 903.421
    // discuss at: http://phpjs.org/functions/str_replace
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Gabriel Paderni
    // +   improved by: Philip Peterson
    // +   improved by: Simon Willison (http://simonwillison.net)
    // +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +   bugfixed by: Anton Ongson
    // +      input by: Onno Marsman
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +    tweaked by: Onno Marsman
    // +      input by: Brett Zamir
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: str_replace(' ', '.', 'Kevin van Zonneveld');
    // *     returns 1: 'Kevin.van.Zonneveld'
    // *     example 2: str_replace(['{name}', 'l'], ['hello', 'm'], '{name}, lars');
    // *     returns 2: 'hemmo, mars'
    var s = subject;
    var ra = r instanceof Array, sa = s instanceof Array;
    var f = [].concat(search);
    var r = [].concat(replace);
    var i = (s = [].concat(s)).length;
    var j = 0;
    
    while (j = 0, i--) {
        if (s[i]) {
            while (s[i] = (s[i]+'').split(f[j]).join(ra ? r[j] || "" : r[0]), ++j in f){};
        }
    }

    return sa ? s : s[0];
}
