$(document).ready(function() {

$('#banner div.slide').each(function(index) {
  $(this).addClass('img-' + index);
  });
  
$('#controls li').each(function(index) {
  $(this).addClass('control-' + index);
  });
  
var items = $("div.slide").length;  
var control = 0;
var back_control;
var back_index
var speed = 8000;
$('div.slide').css('display', 'none');
$('div.img-0').css('display', 'block');
$('#controls .control-0').addClass('active');


function rotate() {  
  
    if ($('body').hasClass('blurred'))
    {
    return false;
    }
  
    $('#controls li.control-' + control).removeClass('active');
  
    if(control == (items-1))
     {control = 0;}
    else {control++}
    
    if (control == 0)
      {back_control = items-1;}
    else {back_control = control - 1;}
    
    $('#controls li.control-' + control).addClass('active');
    $('div.img-' + back_control).fadeOut(600, function() { 
  
      $('div.img-' + control).fadeIn(600);    
    }); 
       
;}
	
$('#controls li').click(function() {
  $('#controls li').removeClass('active');  
  var index = $("#controls li").index(this);
  $('#controls li.control-' + index).addClass('active');
  $('div.img-' + control).fadeOut(600, function() {   
      $('div.img-' + index).fadeIn(600); 
     
  });
  
  control = index;
  
});

var run = setInterval(rotate, speed);
		         		    
$('#banner').hover(
         
        function() {
        clearInterval(run);    
        },
        function() {
            run = setInterval(rotate, speed); 
        }
    );  

function onBlur() {
    document.body.className = 'blurred';
};
function onFocus(){
    document.body.className = 'focused';
};

if (/*@cc_on!@*/false) { // check for Internet Explorer
    document.onfocusin = onFocus;
    document.onfocusout = onBlur;
} else {
    window.onfocus = onFocus;
    window.onblur = onBlur;
}


});
       

       
                        
