

//////////////////////////////////////////////////////////////////////
//

function carousel_cufonize ()
{
	Cufon.refresh();
	// Cufon.refresh('.linkeds_bottom .linked_flux-78-78 .titre');
}

//////////////////////////////////////////////////////////////////////
//

$(document).ready(function()
{
	$('.search_btn').click(function()
	{
		search_do ();
	});
	
	$('#menufooter .item-2 a').attr('href', 'http://www.addthis.com/bookmark.php?v=250');
	$('#menufooter .item-2 a').attr('class', 'addthis_button');
	$('#menufooter').append('<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js"></script>');
	var addthis_js_str = '<script type="text/javascript"> var addthis_config = { ui_click: true, ui_cobrand: "", ui_header_color: "#ffffff", ui_header_background: "#000000", services_exclude: "print, email" } </script>';
	$('body').append(addthis_js_str);
	/* 
	*/
	/*
	$('#menufooter .item-0 a').click(function(event){
		event.preventDefault();
	});
	*/
	// Popin de la page "On vous rapelle"
	// $('#head-rappelle a').css('display','none');
	/*
	$('#head-rappelle a').click(function()
	{
		ritz_vous_rapelle ($(this).attr('title'), $(this).attr('href'));
		return false;
	});	
	*/
	// Apparition des titre + legende des mediaheader
	// $('#header #bann .legend').css('display', 'none').fadeIn(1500, null);
	//$('#header #bann .legend').css('display', 'none').slideToggle(1000, null);
	
	$('#mainsubmenu li.id-17').remove(); // css('display', 'none');
		
	// Mise en carousel des listes d'éléments dont le parent à la classe has_carousel 
	jQuery('.has_carousel').jcarousel({
		scroll: 1
	});

	jQuery('.has_carousel_circular').jcarousel({
		wrap: 'circular',
		scroll: 1,	
		itemLoadCallback: {
			onBeforeAnimation: carousel_cufonize
		}
	});
	
	jQuery('.has_carousel.skin, .has_carousel_circular.skin').each(function(){
		var nb_items = $(this).find('li').length;
		if(nb_items < 5)
		{
			$(this).addClass('jcarousel-container-not-scrollable');
		}
	});
	// alert('yop');
	
	
	$('.onhome a').prepend('<span style="margin-right:3px;">></span>');
	$('.fluxlist-as-menubar #items-list').css('margin-left', $('.main_title').outerWidth() + 50);
	
	// Animation au survol des elements de remontees de flux
	/*
	$('.linkeds .item').hover(function (){
		$(this).fadeTo("fast", 0.8).fadeTo("slow", 1);
	});
	*/
	
	// Animation au survol des elements de sousmenu
	/*
	$('#mainsubmenu a, #submenu a').hover(function (){
		$(this).fadeTo("fast", 0.8).fadeTo("slow", 1);
	});
	*/
	$('#nav li a.title').bind('mousedown',function ()
	{
		$(this).addClass('open');
		$(this).parent().find('.menu').css('display', 'block');
	});
	
	$('#nav li a.title').bind('mouseenter',function ()
	{
		$('#nav li a.title').removeClass('open');
		$('#nav .menu').css('display', 'none');
	});
		/*
		*/
	
	$('#nav ul.floor').bind('mouseenter',function ()
	{
		$(this).parent().find('.tab').addClass('opened');
	});
	
	$('#nav li.section').bind('mouseleave',function ()
	{
		$(this).find('.tab').removeClass('opened');
	});
	
	
	// Adapation de la hauteur des elements de second niveau de la navigation principale (fond noir)
	$('#nav li ul ul').css('height',($('#nav .cnt').length * 32 -14) +'px');
	
	// Neutralise le clic sur les titres de premier niveau du menu
	$('#nav a.title, #nav a.tab').click(function(event) {
		event.preventDefault();
	});
		
	// Ouverture/fermeture des actualites en remontees de flux (accueil)
	linkeds_actualites_add_opening_behaviour();
	/*
	$('.linkeds .actualites .intro').mouseout(function (event){
		$(this).parent().children('.lnkf_cnt').toggle();
		$(this).children('.slide-offsetter').toggle();
	});
	*/
	
	
	
	
	// $(".data-18 #items-list h4:eq(1)").css('border','1px solid red').trigger('click');
	
	
	// actualites liste


	// LIVRE DOR
	$(".data-40 .contenu_main").jScrollPane({
		showArrows : true
	});
	// MENTIONS LEGALES
	$(".data-43 .contenu_main, .data-44 .contenu_main").jScrollPane({
		showArrows : true
	});
	// PLAN DU SITE
	$(".data-45 .contenu_main").jScrollPane({
		showArrows : true
	});
	
		/*
	$(".items-list-19").jScrollPane({
		showArrows : true
		scrollbarWidth [int] - the width of the created scrollbar in pixels (defaults to 10)
		scrollbarMargin [int] - the margin to leave to the left of the scrollbar in pixels (defaults to 5)
		wheelSpeed [int] - controls how fast the mouse wheel makes the content scroll in pixels (defaults to 18)
		showArrows [boolean] - controls whether to display arrows for the user to scroll with (defaults to false)
		arrowSize [int] - the height of the arrow buttons if showArrows=true (calculated from CSS if not provided)
		animateTo [boolean] - whether to animate when calling scrollTo and scrollBy (defaults to false)
		dragMinHeight [int] - the minimum height to allow the drag bar to be (defaults to 0)
		dragMaxHeight [int] - the maximum height to allow the drag bar to be (defaults to 99999!)
		animateInterval [int] - The interval in milliseconds to update an animating scrollPane (default 100)
		animateStep [int] - The amount to divide the remaining scroll distance by when animating (default 3)
		maintainPosition [boolean] - Whether you want the contents of the scroll pane to maintain it\'s position when you re-initialise it - so it doesn\'t scroll as you add more content (default true)
		scrollbarOnLeft [boolean] - Whether the scrollbar should appear on the left hand side of the panes content (make sure your CSS also reflects this)
		reinitialiseOnImageLoad [boolean] - Whether the jScrollPane should automatically re-initialise itself when any contained images are loaded (defaults to false)
	});
		*/
	$(".items-list-in-12, .items-list-in-13, .items-list-in-14, .items-list-in-15, .items-list-in-16, .list-block-1col .items-list, .list-block-2cols .items-list, .items-list-41, .items-list-49, .items-list-53, .items-list-78, .items-list-85, .items-list-93").jScrollPane({
		showArrows : true
	});	
	
	reinitialiseScrollPane = function()
	{
		$('#items-list').jScrollPane({
			showArrows : true
		});
	}
	
	advflux_search_return = function()
	{
	   	Cufon.refresh();
	   	reinitialiseScrollPane();
	}
	
	ritz_rooms_init ();
	
	// Ajout dynamique du place holder de la  section Parcours
	// pour l'image devant apparaitre hros-accordion
	$(".data-18 #items-list").prepend('<div id="parcours-img-placeholder"><a class="map-viewer"></a></div>');	

	$(".data-18 #items-list h4").bind('click', function(){
		$("#parcours-img-placeholder a").html($(this).next().contents().find(".media_resume").clone()).css('display', 'none').fadeIn(500, null) ;
	});
	
	$("#parcours-img-placeholder a").html($('.data-18 #items-list .media_resume:eq(0)').clone()).css('display', 'none').fadeIn(500, null) ;

	if( $('#parcours-img-placeholder').length)
	{
		$('.items-flux .titre').bind('mouseenter', function(event){
			
			var id = $(this).next().attr('id').split('-')[3];
			$("#parcours-img-placeholder a").attr('href', 'map-viewer.php?id='+id);
		});
		
		var id = $('.items-flux:eq(0)').attr('id').split('-')[3];
	    $("#parcours-img-placeholder a").attr('href', 'map-viewer.php?id='+id);
	}
	
	if( $('.map-viewer').length)
	{
		$('.map-viewer').bind('click', function(event){
			view_map ( $(this).attr('title'), '/'+$(this).attr('href'));
			event.preventDefault();
		});
	}
	
	legendOpen   = false;
	legendTop    = 200;
	legendBottom = 400;
	
	$('.body-home-section .switch_btn').click(function()
	{
		if(legendOpen)
		{
			$('#submenu.onhome, .submenu-onhome-block').css('display','none');
			$('#bann .legend').css('display','none');
			legendOpen = false;
			$(this).find('.closer').css('display','none');
			$(this).find('.opener').css('display','block');
		}
		else
		{
			Cufon.refresh("#bann .legend");
			$('#submenu.onhome, .submenu-onhome-block').css('display','block');
			$('#bann .legend').css('display','block');
			legendOpen = true;
			$(this).find('.opener').css('display','none');
			$(this).find('.closer').css('display','block');
		}
	});
});

//////////////////////////////////////////////////////////////////////

function view_map (title, file)
{
	Shadowbox.open({
		player : 	'iframe',
		title:      title,
        content:    file, // '/medias/videos/demo.flv',
        height:     410,
        width:      770
    });
}

//////////////////////////////////////////////////////////////////////

function linkeds_actualites_add_opening_behaviour ()
{
	$('.linkeds .actualites h4').click(function (event){
		$('.linkeds .actualites .lnkf_cnt, .linkeds .actualites h4').unbind('mouseenter');
		
		if($('.linkeds .actualites .int').hasClass('opened'))
		{
			$('.linkeds .actualites .int').removeClass('opened');
		}
		else
		{
			$('.linkeds .actualites .int').addClass('opened');
		}
		$('.linkeds .actualites .slide-offsetter').slideToggle(250, null);
		$('.linkeds .actualites .lnkf_cnt').slideToggle(250, null);
	});
		// var c = $('.linkeds .actualites h4');
	$('.linkeds .actualites .lnkf_cnt, .linkeds .actualites h4').mouseenter(function (event){
		$('.linkeds .actualites .lnkf_cnt, .linkeds .actualites h4').unbind('mouseenter');
		$('.linkeds .actualites .int').addClass('opened');
		$('.linkeds .actualites .slide-offsetter').slideUp(250, null);
		$('.linkeds .actualites .lnkf_cnt').slideDown(250, linkeds_actualites_add_closing_behaviour);
	});
}

function linkeds_actualites_add_closing_behaviour ()
{
	$('.linkeds .actualites').mouseleave(function (event){
		$('.linkeds .actualites').unbind('mouseleave');
		$('.linkeds .actualites .int').removeClass('opened');
		$('.linkeds .actualites .slide-offsetter').slideDown(500, null);
		$('.linkeds .actualites .lnkf_cnt').slideUp(500, linkeds_actualites_add_opening_behaviour);
	});
	// alert('linkeds_actualites_add_closing_behaviour');
	/*
	var c = $('.linkeds .actualites .intro h4');
	
	c.mouseout (function (event){
		linkeds_actualites_toggle (c, 500);
	});
	var c = $('.linkeds .actualites *');
	
	c.mouseover (function (event){
		var c = $('.linkeds .actualites *');
		linkeds_actualites_toggle (c, speed)
		
		linkeds_actualites_toggle ($(this).parent(), 500);
	});
	*/
}

//////////////////////////////////////////////////////////////////////

function ritz_rooms_init ()
{
	// Application des scrolls aux elements désignés
	// this initialises the demo scollpanes on the page.
	// $(".ritz-rooms .texts-panel .panels .tabs").css("position", "absolute");		
	$(".ritz-rooms .txt").css("border", "none");			
	$(".ritz-rooms .txt").css("height", "150px");			
	
	$(".ritz-rooms .txt").jScrollPane({
		showArrows : true
		/*
		scrollbarWidth [int] - the width of the created scrollbar in pixels (defaults to 10)
		scrollbarMargin [int] - the margin to leave to the left of the scrollbar in pixels (defaults to 5)
		wheelSpeed [int] - controls how fast the mouse wheel makes the content scroll in pixels (defaults to 18)
		showArrows [boolean] - controls whether to display arrows for the user to scroll with (defaults to false)
		arrowSize [int] - the height of the arrow buttons if showArrows=true (calculated from CSS if not provided)
		animateTo [boolean] - whether to animate when calling scrollTo and scrollBy (defaults to false)
		dragMinHeight [int] - the minimum height to allow the drag bar to be (defaults to 0)
		dragMaxHeight [int] - the maximum height to allow the drag bar to be (defaults to 99999!)
		animateInterval [int] - The interval in milliseconds to update an animating scrollPane (default 100)
		animateStep [int] - The amount to divide the remaining scroll distance by when animating (default 3)
		maintainPosition [boolean] - Whether you want the contents of the scroll pane to maintain it\'s position when you re-initialise it - so it doesn\'t scroll as you add more content (default true)
		scrollbarOnLeft [boolean] - Whether the scrollbar should appear on the left hand side of the panes content (make sure your CSS also reflects this)
		reinitialiseOnImageLoad [boolean] - Whether the jScrollPane should automatically re-initialise itself when any contained images are loaded (defaults to false)
		*/
	});
	
	var ritz_room_tab_opened = 'txt_1';

	$(".ritz-rooms .texts-panel .tabs a").bind('click', function ()
	{
		var toshow = $(this).attr("id");
		$(".ritz-rooms .texts-panel .tabs a").removeClass('current');
		ritz_room_tab_opened = this.id;
		$(".ritz-rooms .texts-panel .tabs #"+ritz_room_tab_opened).addClass('current');
		// $(".slides .slide-1, .slides .slide-2, .slides .slide-3").css("display", "none");
		// $(".ritz-rooms .texts-panel .slides ."+ritz_room_tab_opened).css("display", "block");	
		// $(".slides .slide-1, .slides .slide-2, .slides .slide-3").css("display", "none");
		
		for( z=1; z<4; z++)
		{
			if ('txt_'+z == toshow)
			{
				$(".slides .slide-"+z).css("display", "block");
				$(".slides .slide-"+z+" .txt").jScrollPane({ showArrows : true });
			}
			else
			{
				$(".slides .slide-"+z).css("display", "none");
			}
		}
		
		/*
		$('.slides>div').each(function()
		{
			alert($(this).attr("id"));
			if ($(this).attr("id") == toshow)
			{
				$(this).css("display", "block");
				$(".ritz-rooms .txt").jScrollPane({ showArrows : true });
			}
			else
			{
				$(this).css("display", "none");
			}
		});
		*/
		// $(".slides ."+$(this).attr("id")).css("display", "block"); // .fadeIn(500, null);
		// Cufon.refresh(".tabs a");
	});
	
	$(".ritz-rooms .slides .slide-2, .ritz-rooms .slides .slide-3").css("display", "none");	
	
	// $(".ritz-rooms .texts-panel .tabs a#txt_1").trigger('click');
	
	// alert('u');
	$('#nav li ul.floor a.title').mouseenter(function ()
	{
		// $(this).parent().find('.menu').css('border','1px solid red !important');
		$(this).parent().find('.menu').css('top', 112 - $(document).scrollTop());
	});
	
}
//////////////////////////////////////////////////////////////////////

function ritz_vous_rapelle (title, file)
{
	Shadowbox.open({
		player : 	'iframe',
		title:      title,
        content:    file, // '/medias/videos/demo.flv',
        height:     380,
        width:      430
    });
}


//////////////////////////////////////////////////////////////////////

 function ritz_parcours_load ()
{
	var data_str  = 'do=search&';
	data_str += 'search_str='+ /*str_replace(' ', '/', */$('.search_str').val() /*)*/  ;
	/*
 	alert( menu +' : '+ data_str);
	window.location = './search/'+ data_str;
	*/
	$.ajax({
		cache: false,
		type: "POST",
		url: "./actions/ritz_parcours_load.php",
		data: data_str, 
		success: function(feedback)
		{	
			// alert('feedback : '+ feedback);
			$('#data').html('feedback : '+ feedback);
		}
	});
}

//////////////////////////////////////////////////////////////////////

 function search_do ()
{
	var data_str  = 'do=search&';
	data_str += 'search_str='+ /*str_replace(' ', '/', */$('.search_str').val() /*)*/  ;
 	/*
	alert( ' : '+ data_str);
	window.location = './search/'+ data_str;
	*/
	$.ajax({
		cache: false,
		type: "POST",
		url: "./actions/search.php",
		data: data_str, 
		success: function(feedback)
		{	
			// alert('feedback : '+ feedback);
			$('#data').html('feedback : '+ feedback);
		}
	});
}

//////////////////////////////////////////////////////////////////////
//

function witness ()
{
	alert(page_id+' : '+ $('#data').html());
}
//////////////////////////////////////////////////////////////////////
function str_replace(search, replace, subject) {
    // http://kevin.vanzonneveld.net
    // +   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];
}


//////////////////////////////////////////////////////////////////////
//


