// Homepage Profiler

var profiler_count = $(".company").length;
var profiler_random = Math.floor(Math.random()*(profiler_count-1))+1;

var profiler_current = profiler_random;
var profiler_change = setTimeout("switch_company('next')",8000);

$(document).ready(function(){
	reset_all();
	$('#arrow-right').click(function() { switch_company('next'); });
	$('#arrow-left').click(function() { switch_company('previous'); });
});		

function switch_company(direction) {
	if (direction=='next') {
		next = (profiler_current==profiler_count) ? 1:profiler_current+1;
	} else if (direction=='previous') {
		next = (profiler_current==1) ? profiler_count:profiler_current-1;
	}
	$('#company-'+profiler_current).fadeOut();
	$('#company-'+next).fadeIn();
	profiler_current = next; 
	clearTimeout(profiler_change);
	profiler_change = setTimeout("switch_company('next')",8000);
}

function reset_all() {
	for ( i=1; i<=profiler_count; i++ ) {
		$('#company-'+i).hide();
	}
	$('#company-'+profiler_current).fadeIn();
}


