var currentNews = 0;
var holdNews = false;

$.fn.smartBackgroundImage = function(url){  
 var t = this;  
$('<img />')    
  .attr('src', url).
  load(function(){
    t.each(function(){
      $(this).css('backgroundImage', 'url('+url+')' );
    });    
  });   
 return this; 
}
var currentAsset = 1;
var maxAsset = 3;
$(document).ready(function() {
  $(".header-float-img").hide();
  $("#hfi_1").show();
  setInterval('animateHeader()', 8000);
});

function animateHeader() {
  $("#hfi_" + currentAsset.toString()).hide(); //.fadeOut('fast');

  currentAsset++;
  if (currentAsset > maxAsset)  {
    currentAsset = 1;
  }
  $("#hfi_" + currentAsset.toString()).fadeIn('slow');
  //setTimeout(animateHeader(), 18000);
}

$(document).ready( function(){
  holdNews = false;
  $("#newsslider").mouseover(function() { holdNews = true; });
  $("#newsslider").mouseout(function() { holdNews = false; });
  displayNextNews();
});

function displayNextNews() {
    if (!holdNews) {
    if (currentNews == 0) {
      $(".newsitem").hide();
    }
    else {
      $("#ni_" + currentNews.toString()).fadeOut('slow');
    }
    currentNews++;
    if (currentNews > $(".newsitem").length) { currentNews = 1; }
    $("#ni_" + currentNews.toString()).fadeIn(3000);
    }
  if ($(".newsitem").length > 1) {
    setTimeout('displayNextNews()', 6000);
    }
}


