/**
 *
 * @package SprintCMSv2_abmsolicitors.co.uk
 * @author docnet
 * @copyright Copyright &copy; 2010, Doctor Net Limited
 *
 * News Ticker
 *
 */

// Global namespace
var ABM = {};

// Ticker module
// Based on http://www.gcmingati.net/wordpress/wp-content/lab/jquery/newsticker/jq-liscroll/scrollanimate.html
ABM.ticker = (function () {
   var $obj_strip, // ticker
   int_strip_width = 0, // ticker width
   int_container_width = 515, // mask
   int_velocity_divisor = 0.065, // higher increases speed, lower vice versa

   initialise = function () {
      $obj_strip = $('#ticker');
      set_strip_width();
      $obj_strip.hover(pause, animate);
		reset();
   },
   // work out the strip width (from the items in it)
   set_strip_width = function (){
      $obj_strip.find("li").each(function(int_i) {
         int_strip_width += $(this, int_i).outerWidth(true);
		});

		$obj_strip.width(int_strip_width);
   },
   // move ticker to initial position
   reset = function () {
      $obj_strip.css("marginLeft", int_container_width);
      animate();
   },
   pause = function () {
      $obj_strip.stop();
   },
   animate = function() {
      var int_remaining_pixels = int_strip_width  + (+$obj_strip.css('marginLeft').replace("px", ""));
      var int_transition_time = int_remaining_pixels / int_velocity_divisor;
      $obj_strip.animate({marginLeft: -int_strip_width}, int_transition_time, "linear", reset);
   };

   $(document).ready(function () {
	   initialise();
   });

	return {};
}());
