$(function(){

if( $('#top-highlights').get(0) == null )
		return;

$('#top-highlights')[0].counter = 0;
$('#top-highlights')[0].rotate = 1;

$( 'div[id^=topnewsmain_]' )
.mouseover(function(){ $('#top-highlights')[0].rotate = 0; })
.mouseout(function(){ $('#top-highlights')[0].rotate = 1; });

__news_rotation_func = function() {
if ( $('#top-highlights')[0].rotate == 1) {
var highlights = $('#top-highlights');

var current = highlights[0].counter % highlightCount;
highlights[0].counter++;
var next = highlights[0].counter % highlightCount;

$( 'div[id^=topnewsmain_]', highlights  ).hide();
$( '#topnewsmain_' + next.toString(), highlights  ).show();
}
}
if(parseInt(timerCount) != 0){
$('#top-highlights').get(0).timer = $._timer(parseInt(timerCount), __news_rotation_func );
}

});

jQuery._timer = function (interval, callback) {

	  /**
	   *
	   * timer() provides a cleaner way to handle intervals
	   *
	   * @usage $.timer(interval, callback);
	   *
	   *
	   * @example $.timer(1000, function (timer) { alert("hello"); timer.stop();
	   *          });
	   * @desc Show an alert box after 1 second and stop
	   *
	   * @example var second = false; $.timer(1000, function (timer) { if
	   *          (!second) { alert('First time!'); second = true;
	   *          timer.reset(3000); } else { alert('Second time'); timer.stop(); }
	   *          });
	   * @desc Show an alert box after 1 second and show another after 3 seconds
	   *
	   *
	   */

	  var interval = interval || 100;

	  if (!callback) return false;

	  __timer = function (interval, callback) {
	    this.stop = function () {
	      clearInterval(self.id);
	    };

	    this.internalCallback = function () {
	      callback(self);
	    };

	    this.reset = function (val) {
	      if (self.id)
	        clearInterval(self.id);

	      var val = val || 100;
	      this.id = setInterval(this.internalCallback, val);
	    };

	    this.interval = interval;
	    this.id = setInterval(this.internalCallback, this.interval);

	    var self = this;
	  };

	  return new __timer(interval, callback);
	};
