function rotateTab(study, clicked) {
	var nextStudy;
	var next;
	var active;
	var number;
	
	if (clicked == true) { 
		window.TabClicked = true;
	} else {
		if (window.TabClicked == true) {
			return false;
		}
	}
	
	$(".case_study_container").hide();
	
	if (study == 'start') {
		nextStudy = 'electrical';	
		$("#case_study1_container").show();		
	}
	
	if (study == 'life') {
		next = $('#lifesciences');
		number = "/images/bg_case-studies1-trans.png";
		$("#case_study1_container").show();			
		nextStudy = 'electrical';
	}
	
	if (study == 'electrical') {
		next = $('#electrical');		
		number = "/images/bg_case-studies2-trans.png";
		$("#case_study2_container").show();
		nextStudy = 'mechanical';			
	}
	
	if (study == 'mechanical') {
		next = $('#mechanical');	
		number = "/images/bg_case-studies3-trans.png";
		$("#case_study3_container").show();
		nextStudy = 'clean';			
	}
	
	if (study == 'clean') {
		next = $('#cleantech');	
		number = "/images/bg_case-studies4-trans.png";
		$("#case_study4_container").show();
		nextStudy = 'life';			
	}

	if (study != 'start') {	
		
		active = $('#switch div.active-background');
		active.addClass('last-active-background');
		
		next.css({opacity: 0.0})
			.addClass('active-background')
			.animate({opacity: 1.0}, 1000, function() {
					active.removeClass('active-background last-active-background');
			});
			
		$("#bg_case_studies_counter").attr({src: number});	
	}

	if (window.TabClicked != true) {
		setTimeout("rotateTab('" + nextStudy + "',false)", 4000);
	}
}

/* Initialize everything */
$(document).ready(function() {
//preload images
var image1 = $('<img />').attr('src', '/images/bg_home_lifesciences.jpg');
var image2 = $('<img />').attr('src', '/images/bg_home_electrical.jpg');
var image3 = $('<img />').attr('src', '/images/bg_home_mechanical.jpg');
var image4 = $('<img />').attr('src', '/images/bg_home_cleantech.jpg');

	rotateTab('start',false);

	$('area').click(function() {
		var url = $(this).attr('href'); 
		rotateTab(url, true);
		return false;
	});
});

