var headline_count2;
var headline_interval2;
var old_headline2 = 0;
var current_headline2 = 0;
var play_pause2 = 'play';

$(document).ready(function(){
    headline_count2 = $("div.headline2").size();
    
    // setup the first headline
    $("div.headline2:eq("+current_headline2+")").css('top', '5px');
    
    // setup the counter text
    $("#scroll_counter2").text('1 to 4 of ' + (headline_count2 * 4));
    
    // call the rotate function at regular intervals
  //  headline_interval2 = setInterval(headline_rotate_next2,5000);
/*  
    $('#scrollup').hover(
        function() {
        clearInterval(headline_interval);
        }, 
        function() {
            headline_interval = setInterval(headline_rotate_next,5000);
            headline_rotate_next();
        }
    );*/

    $('#scroll_play_pause2').click(function(){
        if( play_pause2 == 'pause' ) {
            clearInterval(headline_interval2);
            $(this).text('>');
            play_pause2 = 'play';
        } else {
            headline_interval2 = setInterval(headline_rotate_next2,5000);
            headline_rotate_next2();
            $(this).text('| |') ;
            play_pause2 = 'pause';
        }
    });
    
    $('#scroll_next2').click(function(){
            //clearInterval(headline_interval2);
           // headline_interval2 = setInterval(headline_rotate_next2,5000);
            headline_rotate_next2();
    });
    
    $('#scroll_prev2').click(function(){
           // clearInterval(headline_interval2);
           // headline_interval2 = setInterval(headline_rotate_prev2,5000);
            headline_rotate_prev2();
    });
});

function headline_rotate_next2() {
  current_headline2 = (old_headline2 + 1) % headline_count2;
  

  $("div.headline2:eq(" + old_headline2 + ")")
	.animate({top: -135},"slow", function() {
	  $(this).css('top', '131px');
	});

  $("div.headline2:eq(" + current_headline2 + ")")
	.animate({top: 5},"slow");
  
  old_headline2 = current_headline2;  
  
  // incriment the headline text
  $("#scroll_counter2").text( (current_headline2 * 4 +1) + ' to ' + (current_headline2 * 4 +4) + ' of ' + (headline_count2 * 4));
  
}

function headline_rotate_prev2() {
	if (current_headline2 < 1) {
		current_headline2 = headline_count2 -1;
	} else {
  		current_headline2 = (old_headline2 - 1 ) % headline_count2;
	}
  

  $("div.headline2:eq(" + old_headline2 + ")")
	.animate({top: -135},"slow", function() {
	  $(this).css('top', '131px');
	});

  $("div.headline2:eq(" + current_headline2 + ")")
	.animate({top: 5},"slow");
  
  old_headline2 = current_headline2;  
  
  // incriment the headline text
  $("#scroll_counter2").text( (current_headline2+1) + ' to ' + (current_headline2+4) + ' of ' + (headline_count2 * 4));
  
}

