$(document).ready(function() {
	
	$("#hero-cell ul li").click(function()
	{
		clearTimeout(t);
		
		var id = $(this).attr('id');
	    var menu_content = id + '-contents';
	    var image = $("#" + menu_content + " div.hero-imagecontainer").html();
	    var title = $("#" + menu_content + " div.hero-titlecontainer").html();
	    var body = $("#" + menu_content + " div.hero-bodycontainer").html();
	    $('#hero-cell ul li.active').removeClass('active');
	    $('#hero-cell ul li.below-active').removeClass('below-active');
	    $(this).next('li').addClass('below-active');
	    $(this).addClass('active');
	    $(this).removeClass('below-active');
	    
	    
	    var old_image_element = $(".hero-active-image");
	    $(".hero-active-image").removeClass(".hero-active-image");
	    
	    
	    $("#hero-cell-description div.title").css( { opacity: 0.0 } );
	    $("#hero-cell-description div.body").css( { opacity: 0.0 } );
	    
	    $("#hero-cell-description div.title").html(title);
	    $("#hero-cell-description div.body").html(body);
	    
	    $("#hero-cell-description div.title").animate({
	        opacity: 1.0
	      }, 1000, function() {});	    
	    $("#hero-cell-description div.body").animate({
	        opacity: 1.0
	      }, 1000, function() {});

	    
	    $("#" + id + "-image").css("left","0px");
	    $(".hero-cell-image").css("display","none");
	    $("#" + id + "-image").css("display","inline");
	    $("#" + id + "-image").addClass(".hero-active-image");
	    
	    $("#" + id + "-image").animate( { left: "0px" },100 );
		// Ensure colour of Cufon rendered text changes 
		Cufon.refresh();
	    
	}
	);

});


var number_of_menu_items = 3;
var id=1;
var t;	
	
function rotateHero() {
    if (id > number_of_menu_items)
    {
    	id = 1;
    }
	
    var menu_content = id;
    var image = $("#hero-cell-list-item-" + menu_content + "-contents div.hero-imagecontainer").html();
    var title = $("#hero-cell-list-item-" + menu_content + "-contents div.hero-titlecontainer").html();
    var body = $("#hero-cell-list-item-" + menu_content + "-contents div.hero-bodycontainer").html();
    
    $('#hero-cell ul li.active').removeClass('active');
    $('#hero-cell ul li.below-active').removeClass('below-active');
    

    $('#hero-cell-list-item-' + id).addClass('active');
    $('#hero-cell-list-item-' + id).removeClass('below-active');
    $('#hero-cell-list-item-' + id).next('li').addClass('below-active');
	
	$("#hero-cell-description div.title").css( { opacity: 0.0 } );
	$("#hero-cell-description div.body").css( { opacity: 0.0 } );
    
    var old_image_element = $(".hero-active-image");
    $(".hero-active-image").removeClass(".hero-active-image");

    
    $("#hero-cell-description div.title").html(title);
    $("#hero-cell-description div.body").html(body);
	
    $("#hero-cell-description div.title").animate({
        opacity: 1.0
      }, 1000, function() {});	    
    $("#hero-cell-description div.body").animate({
        opacity: 1.0
      }, 1000, function() {});	
	
    $("#hero-cell-list-item-" + menu_content + "-image").css("left","0px");
    $(".hero-cell-image").css("display","none");
    $("#hero-cell-list-item-" + menu_content + "-image").css("display","inline");
    $("#hero-cell-list-item-" + menu_content + "-image").addClass(".hero-active-image");
    
    $("#hero-cell-list-item-" + menu_content + "-image").animate( { left: "0px" },700 );
    
    id = id + 1;
      
    t = setTimeout( "rotateHero()" , 3000 );
	
	// Ensure colour of Cufon rendered text changes 
	Cufon.refresh();
}

rotateHero();
