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

/* ########## Add to favorites ########## */

$('a#add_to_fav').click(function(e){
	e.preventDefault(); // this will prevent the anchor tag from going the user off to the link
	var bookmarkUrl = this.href;
	var bookmarkTitle = this.title;
 
	if (window.sidebar) { // For Mozilla Firefox Bookmark
		window.sidebar.addPanel(bookmarkTitle, bookmarkUrl,"");
	} else if( window.external || document.all) { // For IE Favorite
		window.external.AddFavorite( bookmarkUrl, bookmarkTitle);
	} else if(window.opera) { // For Opera Browsers
		$("a#add_to_fav").attr("href",bookmarkUrl);
		$("a#add_to_fav").attr("title",bookmarkTitle);
		$("a#add_to_fav").attr("rel","sidebar");
	} else { // for other browsers which does not support
		 alert("Votre navigateur ne supporte pas cette action d'ajout &agrave; vos favoris");
		 return false;
	}
});


/* ########## Slideshow ########## */
	
	// run carouFredSel
	$("#slideshow").carouFredSel({
		items: {
			visible: 3,
			minimum: 1,
			start: -1 // the first slide appears to the center
		},
		scroll: {
			items: 1,
			easing: "linear",
			duration: 2000,
			pauseOnHover: true,
			onBefore: function(oldItems, newItems) {
				oldItems.children('.slide_title').fadeIn();
				newItems.filter(':first, :eq(2)').children('.slide_title').fadeOut();
			}
		},
		auto: 5000,
		prev : {   
			button  : "#nav_left",
			key     : "left"
		},
		next : {
			button  : "#nav_right",
			key     : "right"
		}	
	});

	// browser width
	var browser = $(window).width();
	// slide width
	var slide = $('.slide').innerWidth();
	// negative margin to apply
	var margin = ( ( browser - slide ) / 2 ) - slide - 2;
	// apply negative margin
	$('#slider div.caroufredsel_wrapper').css({'margin-left':margin+'px'});	
	
	// placement du cadre
	var width = ( browser - 971 ) / 2;
	var rwidth = width + 2;
	var rightpos = width + 969;
	var leftpos = width;
	
	$('#ssframe_center_top, #ssframe_center_bottom').css({ 'left': leftpos+'px' });
	$('#ssframe_left').css({ 'width' : width+'px' });
	$('#ssframe_right').css({ 'width' : rwidth+'px', 'left': rightpos+'px' });
	
	// hide title from lateral posts
	$('.slide:eq(0), .slide:eq(2)').children('.slide_title').hide();
	
	// fonction de redimensionnement
	$(window).resize(function(){
		var browser = $(window).width();
		var slide = $('.slide').innerWidth();
		var margin = ( ( browser - slide ) / 2 ) - slide - 2;
		$('#slider div.caroufredsel_wrapper').css({'margin-left':margin+'px'});
		// placement du cadre
		var width = ( browser - 971 ) / 2;
		var rwidth = width + 2;
		var rightpos = width + 969;
		var leftpos = width;
		
		$('#ssframe_center_top, #ssframe_center_bottom').css({ 'left': leftpos+'px' });
		$('#ssframe_left').css({ 'width' : width+'px' });
		$('#ssframe_right').css({ 'width' : rwidth+'px', 'left': rightpos+'px' });		
	});	
	

});
