(function($){  
	$.fn.galleryslider = function(options) {  
	var defaults = {  
		width: "100%",
		height: 480,
		direction: "horizontal",
		hideScollBar: true,
		mouseMove: false,
		mouseSensitiv: true,
		bildabstand: 5
	};
	
	var options = $.extend(defaults, options);
	
	return this.each(function() {  
		obj 	= $(this);  
		elList 	= $(this).children('ul');
		
		// Set Initials 4 wrapper
		if (options.hideScollBar == true)
			$('html').css("overflow", "hidden");		
		obj.css("width",options.width); 
		obj.css("height",options.height); 
		
		// Set Initials 4 List
		if (options.direction == "horizontal") {
			elList.children('li').css("float","left"); 
					
			var elListSize = 0;
			elList.children('li').each(function(){
				var tmpEl = $(this).children('img').width() + options.bildabstand;
				$(this).css({ width: tmpEl });
				elListSize += tmpEl;
			});
			elList.css("width", elListSize + 1); // +1 wegen unterschiedlicher größenberechnung in den Browsern
			elList.css("width"); 
		}
		
		if (options.mouseMove == true) {
			obj.mousemove(function(move){
				var windowSize;
				var gallerySize;
				
				if (options.direction == "horizontal") {
					gallerySize = $(this).width();
					windowSize = $(window).width();
					
					scrollto = Math.round((elListSize - windowSize) * move.pageX / windowSize);
					elList.animate({
						left: -scrollto
					}, {
						queue: false,
						duration: scrollto
					});
					
				} else if (options.direction == "vertical") {
					gallerySize = $(this).height();
					windowSize = $(window).height();
					
					scrollto = Math.round((elListSize - windowSize) * move.pageY / windowSize);
					elList.animate({
						top: -scrollto
					}, {
						queue: false,
						duration: scrollto
					});
				}
			});
		} else {		
			var gallerySize = $(this).width();
			var windowSize = $(window).width();
					
			var maxScrollLeft = (elListSize - windowSize);
			var maxScrollRight = 0;			
			
			obj.children('.leftarrow').mouseenter(function(){
				//if(options.mouseSensitiv == true){
				//	$(this).mousemove(function(e){
     			//		 console.log(Math.abs((e.pageX - 230) * 10)); // 0 - 2000+
   				//	}); 	
				//} NEXT VERSION
				
				elList.animate({
					left: +maxScrollRight
				},Math.abs(maxScrollLeft)+15000);
			
				$(this).mouseleave(function(){
					elList.stop();
				});
			});

			obj.children('.rightarrow').mouseenter(function(){
				//if(options.mouseSensitiv == true){
				//	$(this).mousemove(function(e){
     			//		 console.log(Math.abs(((windowSize - e.pageX) - 230) * 10)); // 0 - 2000+
   				//	}); 	
				//} NEXT VERSION
				
				elList.animate({
					left: -maxScrollLeft
				},Math.abs(maxScrollLeft)+15000);
			
				$(this).mouseleave(function(){
					elList.stop();
				});		
			});
		}
	});  
};
})(jQuery); 

$(window).bind("resize", function(){
	obj.animate({top:0}, {queue:false, duration:0}); //set gallery to top if resized
});
