(function ($){
	
	var defaults = {
		duration : 500,
		delay	 : 4000
	};
	
	$.fn.horizontalSlider = function(settings, panelWidth) {
		
		var $mask 			= $(this),
			$container 		= $mask.find('>div'),
			
			$panels 		= $container.find('>div'),
			currentPanel 	= 1,
			panelCount 		= $panels.length,
			panelWidth      = panelWidth || 460;
		
		var panelCount = $panels.length;	 	
		$mask.css({
			overflow : 'hidden'
		});
		
		$container.css({
			width 	 : panelCount * (panelWidth + 20)
		});
		
		var containerWidth 	= $container.width();
		
		$mask.scrollLeft(0);
		
		$('#sliderbuttonleft').click(function(){
			
			if(currentPanel <= 0) {
				currentPanel = 0;	
			} else {
				currentPanel--;
			}
			
			slide();
			return false;
		});

		$('#sliderbuttonright').click(function(){
			
			if(currentPanel = (panelCount-1)) {
				currentPanel++;
				slide();
			}

			return false;
		});

		function slide() {
				
			$mask.animate({ scrollLeft : currentPanel * ( containerWidth / panelCount) }, 500);
			
			currentPanel++;
			if ( currentPanel >= panelCount ) {
				currentPanel = 0;
			}
		}
		
		setInterval(slide, 4000);
	}
	
})(jQuery)
