jQuery(function($) {
var timer;
var fadeLength = 100;    
var shortFadeLength = 50;    
var longFadeLength = 400;    

function button1_click(event)
{
	//$(".slide").css("visibility","hidden");
	//$("#image1").css("visibility","visible");
    
    if(event){
        if(event['type']=='mouseover') { fadeLength = shortFadeLength; } else { fadeLength = longFadeLength; }
    } else {
        fadeLength = longFadeLength;        
    }        

//    $(".slide").css("visibility","hidden");
    $("#image1").css("visibility","visible");
	$("#image1").css("opacity","0");
    $("#image4").animate({opacity:0.0},fadeLength);
    $("#image2").animate({opacity:0.0},fadeLength); // Hide this if rolled-over
    $("#image3").animate({opacity:0.0},fadeLength); // Hide this if rolled-over 
    $("#image1").animate({opacity:1.0},fadeLength); 
	$("ul.buttons li").removeClass("active");
	//$("#image1").animate({"opacity":1},500, "linear", null);
	$("#button1").addClass("active activefirst");
	clearTimeout(timer);
	timer = setTimeout(eval("button2_click"),"3000");
	//$("#image1").animate({"opacity":1},500, "linear", null);
}

function button2_click(event)
{
	//$(".slide").css("visibility","hidden");
	//$("#image2").css("visibility","visible");

    if(event){
        if(event['type']=='mouseover') { fadeLength = shortFadeLength; } else { fadeLength = longFadeLength; }
    } else {
        fadeLength = longFadeLength;        
    }        
//alert($("#image2").css);
//    $(".slide").css("visibility","hidden");
    $("#image2").css("visibility","visible");
	$("#image2").css("opacity","0");
    $("#image4").animate({opacity:0.0},fadeLength); // Hide this if rolled-over
    $("#image1").animate({opacity:0.0},fadeLength);
    $("#image3").animate({opacity:0.0},fadeLength); // Hide this if rolled-over 
    $("#image2").animate({opacity:1.0},fadeLength);
	$("ul.buttons li").removeClass("active activefirst");
	//$("#image2").animate({"opacity":1},500, "linear", null);
	$("#button2").addClass("active");
	clearTimeout(timer);
	timer = setTimeout(eval("button3_click"),"3000");
	//$("#image2").animate({"opacity":1},500, "linear", null);
}

function button3_click(event)
{
	//$(".slide").css("visibility","hidden");
	//$("#image3").css("visibility","visible");

    if(event){
        if(event['type']=='mouseover') { fadeLength = shortFadeLength; } else { fadeLength = longFadeLength; }
    } else {
        fadeLength = longFadeLength;        
    }        
    
//    $(".slide").css("visibility","hidden");
    $("#image3").css("visibility","visible");
	$("#image3").css("opacity","0");
    $("#image4").animate({opacity:0.0},fadeLength); // Hide this if rolled-over
    $("#image2").animate({opacity:0.0},fadeLength);
    $("#image1").animate({opacity:0.0},fadeLength); // Hide this if rolled-over 
    $("#image3").animate({opacity:1.0},fadeLength);
	$("ul.buttons li").removeClass("active activefirst");
	//$("#image3").animate({"opacity":1},500, "linear", null);
	$("#button3").addClass("active");
	clearTimeout(timer);
	timer = setTimeout(eval("button4_click"),"3000");
	//$("#image3").animate({"opacity":1},500, "linear", null);
}

function button4_click(event)
{
	//$(".slide").css("visibility","hidden");
	//$("#image4").css("visibility","visible");
    if(event){
        if(event['type']=='mouseover') { fadeLength = shortFadeLength; } else { fadeLength = longFadeLength; }
    } else {
        fadeLength = longFadeLength;        
    }        
    
//    $(".slide").css("visibility","hidden");
    $("#image4").css("visibility","visible");
	$("#image4").css("opacity","0");
    $("#image3").animate({opacity:0.0},fadeLength);
    $("#image1").animate({opacity:0.0},fadeLength); // Hide this if rolled-over
    $("#image2").animate({opacity:0.0},fadeLength); // Hide this if rolled-over 
    $("#image4").animate({opacity:1.0},fadeLength);
	$("ul.buttons li").removeClass("active activefirst");
	//$("#image4").animate({"opacity":1},500, "linear", null);
	$("#button4").addClass("active");
	clearTimeout(timer);
	timer = setTimeout(eval("button1_click"),"3000"); // Return to slide 1
	//$("#image4").animate({"opacity":1},500, "linear", null);
}

/* 181011 - Only show 4 slides

function button5_click(event)
{
	$(".slide").css("visibility","hidden");
	$("#image5").css("visibility","visible");
	$("#image5").css("opacity","0");
	$("#image5").animate({"opacity":1},300, "linear", null);
	$("ul.buttons li").removeClass("active activefirst");
	$("#image5").animate({"opacity":1},300, "linear", null);
	$("#button5").addClass("active");
	clearTimeout(timer);
	timer = setTimeout(eval("button1_click"),"3000");
	$("#image5").animate({"opacity":1},300, "linear", null);
}

//  Only show 4 slides */

function OnLoad(event)
{
	clearTimeout(timer);
	timer = setTimeout(eval("button2_click"),"3000");
}

// $('#button1').bind('click', button1_click);
// $('#button2').bind('click', button2_click);
// $('#button3').bind('click', button3_click);
// $('#button4').bind('click', button4_click);
// $('#button5').bind('click', button4_click);

$('#button1').bind('mouseover', button1_click);
$('#button2').bind('mouseover', button2_click);
$('#button3').bind('mouseover', button3_click);
$('#button4').bind('mouseover', button4_click);
//$('#button5').bind('mouseover', button5_click); // Only show 4 slides

button1_click();

OnLoad();

});
