/**
 * @author rob
 */

(function($){


$.fn.vscroll = function(options) {
	var opts 						= $.extend({}, $.fn.vscroll.defaults, options);
	
  return this.each(function() {
		

 
		var $scroll_item   	= $(this).find(opts.vscroll_toscroll);
		var $scroll_up 	 		=	$(this).find(opts.vscroll_up);
		var $scroll_down 		=	$(this).find(opts.vscroll_down);
		var vscroll_pos 		= 0;
		
		//hide DOWN  if the element if we don't need it 
		if ($scroll_item.height() <= $scroll_item.parent().height() ) { $scroll_down.css("visibility", "hidden"); }
								
		$scroll_up.click(function(event) {
  		if (vscroll_pos >= 0) { $scroll_up.css("visibility", "hidden"); } 
  		else { vscroll_pos += opts.vscroll_size; }
			$scroll_item.animate({top: vscroll_pos},"normal")
			if ($scroll_down.css("visibility") == "hidden") { $scroll_down.css("visibility", "visible"); }  //if hidden show DOWN element
  		if (vscroll_pos >= 0) { $scroll_up.css("visibility", "hidden"); } // if visible hide UP element
  		 event.preventDefault();
  		});
			
		$scroll_down.click(function(event) {
			vscroll_pos -=  opts.vscroll_size;
			$scroll_item.animate({top: vscroll_pos},"normal")
			if ($scroll_up.css("visibility") == "hidden") { $scroll_up.css("visibility", "visible"); }  //if hidden show UP element
			if ($scroll_item.height() <= ( Math.abs(vscroll_pos) + $scroll_item.parent().height() ) ) { $scroll_down.css("visibility", "hidden"); }  //hide DOWN - make sure don't scroll to far also checking containers height
			event.preventDefault();
		});
  		     
  });
};


$.fn.vscroll.defaults = {
	 vscroll_toscroll: ".vscroll_toscroll",
   vscroll_up: ".vscroll_up",
   vscroll_down: ".vscroll_down",
   vscroll_size: 84
};

})(jQuery);

 
