/*
Horizontal Scroll adapted from Andrew Valums
http://valums.com/scroll-menu-jquery/

Creates a horizontal scroll from an unordered list
<div class="hscroll">
  <ul>
    <li><a href="#"><img src="img/1.jpg" alt="Menu"/><span>Menu</span></a></li>
  </ul>
</div>
*/
//$(".hscroll").hscroll();

(function($) {
		  
$.fn.hscroll = function(options) {

	// Extend our default options with those provided.
	var opts = $.extend({}, $.fn.hscroll.defaults, options);
	
	//loop through the items
	this.each(function() {  
		var $this = $(this);
		
		//Remove scrollbars
		$this.css({overflow: 'hidden'});
		
		//Get our elements for faster access and set overlay width
		var ul = $this.children("ul");
		//Find last image container
		var li_last = ul.find('li:last-child');

		//Get menu width
		var div_width = $this.width();
		
		//this is normally under the mousemove function
		var ul_width = li_last[0].offsetLeft + li_last.outerWidth() + opts.padding_left;
		
		//When user move mouse over menu
		$this.mousemove(function(e){
			//As images are loaded ul width increases,
			//so we recalculate it each time
			//var ulWidth = li_last[0].offsetLeft + li_last.outerWidth() + opts.padding_left;
		
			var left = (e.pageX - $this.offset().left) * (ul_width-div_width) / div_width;
	
			$this.scrollLeft(left);
			//$this.stop().animate({scrollLeft: left});
		});
		

	
	//end $.each loop
	});
	
	// returns the jQuery object to allow for chainability.  
	return this;
}

// plugin defaults - added as a property on our plugin function
$.fn.hscroll.defaults = {
	padding_left: 5 //ul left padding
};

})(jQuery);