
(function($)
{


  $.fn.easySlider = function(options)
  {
    var defaults = {
      prevId : 'prev-splash-page',
      nextId : 'next-splash-page',
      speed : 800
    };


	

    var options = $.extend(defaults, options);

    return this.each(function()
    {
      obj = $(this);
	 

	
	 $("#slider").mouseover(function(){
	   stopTimer();
    }).mouseout(function(){
	   addTimer();
    });

	 
	  function addTimer()
	  {
		  obj.everyTime(10000, "autoscroller", function() {
			if(t >= ts)
			{
				animate("first");
			}
			else
			{
				animate("next");
			}
		  });
	  }
	  addTimer();
	  function restartTimer()
	  {
		obj.stopTime("autoscroller");
		addTimer();
	  }
	  function stopTimer()
	  {
		obj.stopTime("autoscroller");
	  }
      
      
      var s = $("li", obj).length,
          w = obj.width(),
          h = obj.height(),
          ts = s - 1,
          t = 0;      
      $("ul", obj).css('width', s * w);
      
      $('#'+options.nextId).click(function()
      {
        animate("next");
		restartTimer();
        return false;
      });
      
      $('#'+options.prevId).click(function()
      {
        animate("prev");
		restartTimer();
        return false;
      });
      
      function animate(dir)
      {
	  
        if(dir == "next")
        {
          t = (t >= ts) ? ts : t + 1;
        } 
        else if(dir == "prev")
        {
          t = (t <= 0) ? 0 : t - 1;
        }
		else if(dir == "first")
        {
		  t = 0;
		}
		else if(dir == "last")
        {
		  t = ts;
		}
		
        p = (t * w * -1);
        
        $("ul", obj).animate({
            marginLeft : p
        }, options.speed);
        
      };
      
    });
  };

})(jQuery);


