﻿

var headline_count;
var headline_interval;
var old_headline = 0;
var current_headline = 0;
var play_pause = 'pause';

$(document).ready(function() {
    headline_count = $("div.headline").size();

    // setup the first headline
    $("div.headline:eq(" + current_headline + ")").css('top', '0px');

    // setup the counter text
    $("#scroll_counter span").text('1 of ' + headline_count);

    // call the rotate function at regular intervals
    headline_interval = setInterval(headline_rotate, 9000);
    
	
	
    $('#scrollup').hover(
    function() {
    clearInterval(headline_interval);
    },
    function() {
    headline_interval = setInterval(headline_rotate,9000);
    }
    );
  

   $('#scroll_play_pause').click(function() {
        if (play_pause == 'pause') {
            clearInterval(headline_interval);
            $(this).css('background-image', 'url(/items/images/bt-play.gif)');
            play_pause = 'play';
        } else {
            headline_interval = setInterval(headline_rotate, 9000);
            headline_rotate();
            $(this).css('background-image', 'url(/items/images/bt-pause.gif)');
            play_pause = 'pause';
        }
    });


    $('#scroll_next').click(function() {
        clearInterval(headline_interval);
        headline_interval = setInterval(headline_rotate, 9000);
        headline_rotate();
    });
});

function headline_rotate() {
    current_headline = (old_headline + 1) % headline_count;


    $("div.headline:eq(" + old_headline + ")").animate({ top: -205 }, "slow", function() {
    $(this).css('top', '210px');
});

    $("div.headline:eq(" + current_headline + ")").animate({ top: 0 }, "slow");

    old_headline = current_headline;

    // incriment the headline text
    $("#scroll_counter span").text((current_headline + 1) + ' of ' + headline_count);

}




$(document).ready(function() {
  $('<a id="top" name="top"></a>').prependTo('body');
  $('<a href="#top" class="back-top" title="Go back to the top of the page">back to top&#710;</a>').insertBefore('div.jobResult:gt(2):even');
});