/**
 * @author Karl Swedberg
 * http://www.learningjquery.com/2006/10/scroll-up-headline-reader
 * MODIFIED: 
 * 		6/17/09 JSH at http://www.jswebinc.com
 *		 	Converted to noconflict mode so it will not interfere with other frameworks.
 * INSTRUCTIONS:
 * 		Create a div with id="scrollup"
 * 		Create a div with class="rotator_headline" for each headline
 * 		Add to head of file:
 * 			<script src="/dev/Scripts/JQuery/jquery_1_3_2_compressed.js" type="text/javascript"></script>
 *			<script type="text/javascript" src="rotator.pauseOnHover_noConflict.js"></script>
 *			<link href="rotator.pauseOnHover.css" rel="stylesheet" type="text/css">
 * 			
 */

//////////////////
// SETTINGS
/////////////////

// Set height of testimonials box, in pixels.  Do not append "px", just enter the number.
var jBoxHeight = 250;

// Time, in milliseconds, between rotations
var jRotationInterval = 8000;

//////////////////
// END SETTINGS
/////////////////

var headline_count;
var headline_interval;
var old_headline = 0;
var current_headline=0;

var $J = jQuery.noConflict();


$J(document).ready(function(){
 
 // set box height
 $J("div#scrollup").css('height',jBoxHeight+'px');
 $J("div.rotator_headline").css('top',jBoxHeight+'px');
 
 headline_count = $J("div.rotator_headline").size();
  $J("div.rotator_headline:eq("+current_headline+")").css('top','5px');
  
  headline_interval = setInterval(headline_rotate,jRotationInterval); //time in milliseconds
  $J('#scrollup').hover(function() {
    clearInterval(headline_interval);
  }, function() {
    headline_interval = setInterval(headline_rotate,jRotationInterval); //time in milliseconds
    headline_rotate();
  });
});

function headline_rotate() {
  current_headline = (old_headline + 1) % headline_count; //remainder will always equal old_headline until it reaches headline_count - at which point it becomes zero. clock arithmetic
  $J("div.rotator_headline:eq(" + old_headline + ")").animate({top: -jBoxHeight+'px'},"slow", function() {
    $J(this).css('top',jBoxHeight +'px');
    });
  $J("div.rotator_headline:eq(" + current_headline + ")").show().animate({top: 5},"slow");  
  old_headline = current_headline;
}


