jQuery.fn.extend({

  toogslider : function(time) {
  	jQuery(this).each(function()
  	{
	    var $container = jQuery(this).find('.scrollContainer');
	    var $panels = jQuery(this).find('.panel');
	    var $scroll = jQuery(this).find('.scroll');
	        
	    var horizontal = true;    
	    if (horizontal) {
	      $panels.css({ 'float' : 'left', 'position' : 'relative' });
	      $container.css('width', $panels[0].offsetWidth * $panels.length);
	    };
	
	    // boutons prev / next
	    //$scroll.before('<img class="scrollButtons left" src="images/scroll_left.png" />').after('<img class="scrollButtons right" src="images/scroll_right.png" />');
	    
	    jQuery(this).find('.navigation a').click(selectNav);
	      
	    if (window.location.hash) {
	      jQuery(this).find('.navigation a[href=#' + window.location.hash.substr(1) + ']').click();
	    } else {
	      jQuery(this).find('.navigation a:first').click();
	    }
	
	    if (time)
	    {
	      jQuery(this).everyTime(time, function() {
	        var next = jQuery(this).find('.navigation a.selected').parent().next().find('a');
	        if (next.length) next.click();
	        else jQuery(this).find('.navigation a:first').click();
	      });
	    }
	    
	    var scrollOptions = {
	      target: $scroll,
	      items: $panels,
	      //navigation: jQuery(this).find('.navigation a'),
	      prev: 'img.left', 
	      next: 'img.right',
	      axis: 'xy',
	      offset: parseInt((horizontal ? $container.css('paddingTop') : $container.css('paddingLeft')) || 0) * -1,
	      duration: 500,
	      easing: 'swing'
	    };
	
	    jQuery.localScroll(scrollOptions);
	    scrollOptions.duration = 1;
	    jQuery.localScroll.hash(scrollOptions);
    });
    
    function selectNav(e) {
      jQuery(this).parents('ul:first').find('a').removeClass('selected');
      jQuery(this).addClass('selected');
    }

  }
});