
(function($){
  var settings = { 
  };
	var updatePositionInterval;
	var SPEED = 3;
	var movingRight;
	var movingLeft;
	var animInterval = 10;
  var methods = {
    init:function(options){
		$.extend(settings, options);
		
		$(this).each(function(){
			
			$(".arrow_left",this).mouseover(function(){
				movingLeft = true;
				updatePositionInterval = setInterval(
					function() {
						if(movingRight) {
							  var newX = parseInt($(".GallerySlider").css("left")) - SPEED;
							  $(".GallerySlider").css("left",newX);
						  } else if(movingLeft) {
							  var newX = parseInt($(".GallerySlider").css("left")) + SPEED;
							  $(".GallerySlider").css("left",newX);
						  }
						  if(newX > 0)
						  {
							  newX = 0;
							  $(".arrow_left").css("visibility","hidden");
						  } else $(".arrow_left").css("visibility","visible");

							$(".arrow_right").css("visibility","visible");
						    $(".GallerySlider").css("left",newX);
					}
					,animInterval);
			}).mouseout(function(){
				movingLeft = false;
				clearInterval(updatePositionInterval);
			});
			
			$(".arrow_right",this).mouseover(function(){
				movingRight = true;
				updatePositionInterval = setInterval(
					function() {
						  var newX = parseInt($(".GallerySlider").css("left")) - SPEED;
						  var tim = parseInt($("#theImages").width());
						  var maxX = parseInt($(".GalleryItems").width());
						  maxX -= tim - 10;
						  
						  if(Math.abs(newX) > maxX)
						  {
							  newX = -maxX;
							  $(".arrow_right").css("visibility","hidden");
						  } else $(".arrow_right").css("visibility","visible");
						 $(".arrow_left").css("visibility","visible");
						  
						  $(".GallerySlider").css("left",newX);
					}
					,animInterval);
			}).mouseout(function(){
				movingRight = false;
				clearInterval(updatePositionInterval);
			});
			
			
			 var newX = parseInt($(".GallerySlider").css("left"));
			  var tim = parseInt($("#theImages").width());
			  var maxX = parseInt($(".GalleryItems").width());
			  maxX -= tim - 10;
			  
			  if(Math.abs(newX) > maxX)
			  {
				  newX = -maxX;
				  $(".arrow_right").css("visibility","hidden");
			  } else $(".arrow_right").css("visibility","visible");
			 if(newX >= 0)
			  {
				  newX = 0;
				  $(".arrow_left").css("visibility","hidden");
			  } else $(".arrow_left").css("visibility","visible");
			  
		});
	}
  };
  
  function updatePosition() {
	  if(movingRight) {
		  var newX = parseInt($(".GallerySlider").css("left")) - SPEED;
		  $(".GallerySlider").css("left",newX);
	  } else if(movingLeft) {
		  var newX = parseInt($(".GallerySlider").css("left")) + SPEED;
		  $(".GallerySlider").css("left",newX);
	  }
	  updateArrowVisibility();
  }

	function updateArrowVisibility() {
		
	}
	
  $.fn.subnavSlide = function(method){
    if (methods[method]){
      return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
    } else if (typeof method === 'object' || !method) {
      return methods.init.apply(this, arguments);
    } else {
      $.error('Method ' +  method + ' does not exist on jQuery.subnavSlide');
    }    
  };
  
})(jQuery);

$(function() {
	$(".subnav_slide").subnavSlide();
});
