var hinterval;
var hclicked;
var hinterval_time = 5000;
var hoffset = 2; // must start for secont article sinse first is present in default page

function updateHeadline() {
	//debugger; 
	// alert(hoffset);
  //$.getJSON(location.protocol + "//" + location.host + "/headlines/feed/" + hoffset, function(json) {
  $.getJSON(location.protocol + "//" + location.host + "/iconnet/feed.asp?nid="+hoffset, function(json) {
   
   $("span.hcontent").fadeOut("slow", function() {
      hoffset = json.offset;
	 //alert(hoffset);
      $("span.hcontent").html(json.title);
      if(hclicked != true) {
        hclicked = true;
        $(this).fadeIn("slow", function() {
          hclicked = false;
        });
      }
    });
  });
}

function nextHeadline() {
  hoffset++;
  updateHeadline();
}

function prevHeadline() {
  hoffset--;
  updateHeadline();
}

function startHeadlineTimer() {
  hinterval = setInterval(nextHeadline, hinterval_time);
}

function stopHeadlineTimer() {
  clearInterval(hinterval);
}

$(function() {
  // on document ready
  startHeadlineTimer();
 
  // stop timer on mouseover
  $("span.hcontent").hover(function() {
    stopHeadlineTimer();
  }, function() {
    stopHeadlineTimer();
    startHeadlineTimer();
  });
});

