$(document).ready(function(){

	/* Menu Nav */
	var left, width;
	setTimeout(function(){
		
		
		if($('#main_menu').find('li.current').html() != null)
		{
			width = $('#main_menu').find('li.current').innerWidth();
			left = $('#main_menu').find('li.current').position().left + (width/2);
		}
		else
		{
			left = '0';
			width = '0';	
		}
		
		$('#menuslide').css({
			'left':-15,
			'width':10,//width,
			'visibility':'visible'
		}).fadeIn(100)
	}, 500);
		
	$('#main_menu li').hover(function(){
		var leftEvent = $(this).position().left,
		widthEvent = $(this).innerWidth();
		
		$('#menuslide').stop().animate({
			'left':leftEvent + widthEvent/2 -10,
			'width':10//widthEvent
		}, 'slow');
		
	},function(){
		$('#menuslide').stop().animate({
			'left':left,
			'width':width
		}, 'slow');
	});
	
	/* SLIDER */
	var nbimages = $('#slider img').size();

	if(nbimages > 1)
	{		
		$('#slider').nivoSlider({
			effect:'fade',
			pauseTime:7000,
			pauseOnHover:false,
			borderRadius: 10,
			captionOpacity: 1
		});			
	}
	
	var nbcoverflipimg = $('#flip li').size() -1;
	
	
	$('#flip').jcoverflip({
	  current: 3,
	  beforeCss: function( el, container, offset ){
		return [
		  $.jcoverflip.animationElement( el, { left: ( container.width( )/2 - 210 - 110*offset + 20*offset )+'px', bottom: '20px' }, { } ),
		  $.jcoverflip.animationElement( el.find( 'img' ), { width: Math.max(10,100-20*offset*offset) + 'px' }, {} )
		];
	  },
	  afterCss: function( el, container, offset ){
		return [
		  $.jcoverflip.animationElement( el, { left: ( container.width( )/2 + 110 + 110*offset )+'px', bottom: '20px' }, { } ),
		  $.jcoverflip.animationElement( el.find( 'img' ), { width: Math.max(10,100-20*offset*offset) + 'px' }, {} )
		];
	  },
	  currentCss: function( el, container ){
		return [
		  $.jcoverflip.animationElement( el, { left: ( container.width( )/2 - 100 )+'px', bottom: 0 }, { } ),
		  $.jcoverflip.animationElement( el.find( 'img' ), { width: '200px' }, { } )
		];
	  },
	  change: function(event, ui){
		$('#scrollbar').slider('value', ui.to* (100/nbcoverflipimg));
	  }
	});
	
	
	$('#scrollbar').slider({
	  value: 50,
	  stop: function(event, ui) {
		if(event.originalEvent) {
		  var newVal = Math.round(ui.value/(100/nbcoverflipimg));
		  $( '#flip' ).jcoverflip( 'current', newVal );
		  $('#scrollbar').slider('value', newVal*(100/nbcoverflipimg));
		}
	  }
	});	
});	


