jQuery(function( $ ){
	/**
	 * Most jQuery.localScroll's settings, actually belong to jQuery.ScrollTo, check it's demo for an example of each option.
	 * @see http://flesler.demos.com/jquery/scrollTo/
	 * You can use EVERY single setting of jQuery.ScrollTo, in the settings hash you send to jQuery.LocalScroll.
	 */
	
	// The default axis is 'y', but in this demo, I want to scroll both
	// You can modify any default like this
	$.localScroll.defaults.axis = 'x';
	
	// Scroll initially if there's a hash (#something) in the url 
	$.localScroll.hash(
		{
		target: $(window), // Could be a selector or a jQuery object too.
		easing:'easeOutBack',
		duration:1800
		}
	);
	
	/**
	 * NOTE: I use $.localScroll instead of $('#navigation').localScroll() so I
	 * also affect the >> and << links. I want every link in the page to scroll.
	 */
	$.localScroll({
		target: $(window), // could be a selector or a jQuery object too.
		duration:1800,
		easing:'easeOutBack',
		hash:true,
		onBefore:function( e, anchor, $target ){
			// The 'this' is the settings object, can be modified
		},
		onAfter:function( anchor, settings ){
			// The 'this' contains the scrolled element (#content)
		}
	});
});

function init_fancy()
	{
	/* fancy box pour les references et google maps */ 
			
	$("a[rel=solutions_group]").fancybox(
			{
			'width'				: '700 px',
			'height'			: 'auto',
			'titlePosition'		: 'inside',
			'transitionIn'		: 'fade',
			'transitionOut'		: 'fade',
			'changeFade'		: 'slow',
			'autoScale'     	: false
			}
		);
	
	$("a[rel=references_group]").fancybox(
			{
			'width'				: 'auto',
			'height'			: 'auto',
			'titlePosition'		: 'over',
			'transitionIn'		: 'fade',
			'transitionOut'		: 'fade',
			'changeFade'		: 'slow',
			'titlePosition'		: 'over',
			'titleFormat'		: function() {return '<div class="caption" style="width:100%;  background:#CCC;"><a target="_blank" href="'+this.title+'">Visitez le site</a></div>';}				
			}
		);
	
	/* site du mois */
	$("#hep_content").fancybox(
			{ 
			'width'				: '85%',
			'height'			: '85%'
			}
		);
	
	$("#googleMap").fancybox(
			{
			'width'				: '85%',
			'height'			: '85%',
			'autoScale'     	: false,
			'transitionIn'		: 'fade',
			'transitionOut'		: 'fade',
			'type'				: 'iframe'
			}
		);
	}

function init_accordion()
	{
	/* ---Accordeon equipe-- */

	$("#listeEquipe").accordion({event:'mouseover',header:'h4.header', active:'false'});	

	/* ---  */
	}

function init_hep()
	{
	/* -- Bubble top site du mois -- */

	$("#hep a").hover(
		function()
			{
			$(this).next("em").stop(true, true).animate({opacity: "show", top: "-40"}, "slow");
			}, 
		function()
			{
			$(this).next("em").animate({opacity: "hide", top: "-70"}, "fast");
			}
		);
	}

/**
 * Retourne la valeurs d'un paramËtre de l'url
 *@param name {string}  nom du paramËtre ‡ rÈcupÈrer
 *@returns {string} valeur du paramËtre
 */
function gup( 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];
}

var item_to_open = false;
$(document).ready(function(){
		// init des items
		init_fancy();
		init_accordion();
		init_hep();
		
		// gestion params url
		if (window.location.href.indexOf('?item=') != -1)
			{
			item_to_open = gup('item');
			window.setTimeout(function(){$('#'+item_to_open).trigger('click');}, 2000);
			}
		else if (window.location.href.indexOf('#') == -1)
			{
			window.setTimeout(function(){$.scrollTo($('#agence'), 2500, {easing:"swing" });}, 500);
			}
		}
	); // fin doc.ready
