jQuery(function($){
var timer;

/* 8, 15, 20*/

function button1_click(event, is_human)
{
	$(".siot-slide").css("visibility","hidden");
	$("#siot-image1").css("visibility","visible");
	$("#siot-image1").css("opacity","0");
	$("#siot-image1").animate({"opacity":1},300, "linear", null);
	$("ul.siot-buttons li").removeClass("siot-active");
	$("#siot-home-leftmenu").removeClass("siot-home-leftmenu-inactive");
	$("#siot-home-leftmenu a").removeClass("siot-home-leftmenu-active");
	$("#siot-image1").animate({"opacity":1},300, "linear", null);
	$("#siot-button1").addClass("siot-active");
	clearTimeout(timer);
	if (is_human==false){
		timer = setTimeout(function(){button2_click(event, false)},"8000");
	}
	$("#siot-image1").animate({"opacity":1},300, "linear", null);
}

function button2_click(event, is_human)
{
	$(".siot-slide").css("visibility","hidden");
	$("#siot-image2").css("visibility","visible");
	$("#siot-image2").css("opacity","0");
	$("#siot-image2").animate({"opacity":1},300, "linear", null);
	$("ul.siot-buttons li").removeClass("siot-active");
	$("#siot-home-leftmenu").removeClass("siot-home-leftmenu-inactive");
	$("#siot-home-leftmenu a").removeClass("siot-home-leftmenu-active");
	$("#siot-image2").animate({"opacity":1},300, "linear", null);
	$("#siot-button2").addClass("siot-active");
	clearTimeout(timer);
	if (is_human==false){timer = setTimeout(function(){button3_click(event, false)},"8000");}
	$("#siot-image2").animate({"opacity":1},300, "linear", null);
}

function button3_click(event, is_human)
{
	$(".siot-slide").css("visibility","hidden");
	$("#siot-image3").css("visibility","visible");
	$("#siot-image3").css("opacity","0");
	$("#siot-image3").animate({"opacity":1},300, "linear", null);
	$("ul.siot-buttons li").removeClass("siot-active");
	$("#siot-home-leftmenu").removeClass("siot-home-leftmenu-inactive");
	$("#siot-home-leftmenu a").removeClass("siot-home-leftmenu-active");
	$("#siot-image3").animate({"opacity":1},300, "linear", null);
	$("#siot-button3").addClass("siot-active");
	clearTimeout(timer);
	if (is_human==false){timer = setTimeout(function(){left_menu(event, 0, false)},"8000");}
	$("#siot-image3").animate({"opacity":1},300, "linear", null);
}

function left_menu(event, control_no, is_human)
{
	$(".siot-slide").css("visibility","hidden");
	/*alert(control_no);*/
	$("#siot-home-" + stuff[control_no]).css("visibility","visible");
	$("#siot-home-" + stuff[control_no]).css("opacity","0");
	$("#siot-home-" + stuff[control_no]).animate({"opacity":1},300, "linear", null);
	$("ul.siot-buttons li").removeClass("siot-active");
	$("#siot-home-leftmenu a").removeClass("siot-home-leftmenu-active");
	$("#siot-home-" + stuff[control_no]).animate({"opacity":1},300, "linear", null);
	$("#siot-home-leftmenu-" + stuff[control_no]).addClass("siot-home-leftmenu-active");
	$("#siot-home-leftmenu").addClass("siot-home-leftmenu-inactive");
	clearTimeout(timer);
	if (is_human==false){	
		switch(parseInt(control_no)){
			case 0: case 1: case 2: case 3:
				timer = setTimeout(function(){left_menu(event, parseInt(control_no) + 1, false)},"15000");
				break;
			case 4:
				timer = setTimeout(function(){left_menu(event, parseInt(control_no) + 1, false)},"20000");
				break;
			case 5:
				timer = setTimeout(function(){button1_click(event, false)},"15000");
		}
	}
	$("#siot-home-" + stuff[control_no]).animate({"opacity":1},300, "linear", null);
}

function OnLoad(event)
{
	stuff = new Array();
	stuff[1] = "employers";
	stuff[2] = "international";
	stuff[3] = "skills-recognition";
	stuff[4] = "sustainability";
	stuff[5] = "short-courses";
	stuff[0] = "students";

	$('#siot-button1').bind('click', button1_click);	
	$('#siot-button2').bind('click', button2_click);
	$('#siot-button3').bind('click', button3_click);
	
	
	/*
	
	//see http://docs.jquery.com/How_jQuery_Works#Callback_with_arguments
	$('#siot-home-leftmenu-students').bind('click', function(){
		left_menu(event, 0, true);
	});
	
	$('#siot-home-leftmenu-international').bind('click', function(){
		left_menu(event, 2, true);
	});
	
	$('#siot-home-leftmenu-short-courses').bind('click', function(){
		left_menu(event, 5, true);
	});
	
	$('#siot-home-leftmenu-employers').bind('click', function(){
		left_menu(event, 1, true);
	});
	
	$('#siot-home-leftmenu-skills-recognition').bind('click', function(){
		left_menu(event, 3, true);
	});
	
	$('#siot-home-leftmenu-sustainability').bind('click', function(){
		left_menu(event, 4, true);
	});


	*/

	/*For some reason, the x in the nameless function always returns the index of the last defined stuff entry*/
	/*	
	for (x in stuff)
	{
		alert(x);
		$('#siot-home-leftmenu-' + stuff[x]).bind('click', function(){left_menu(event, x, true);});
	}*/
	

		$(".siot-slide").css("visibility","hidden");
	clearTimeout(timer);
	button1_click(event, false);
}

OnLoad();

});