window.addEvent('domready', function() {
	HideSliders();
	RunTestimonials();
});

window.addEvent('load', function() {
	if ($('logo') && $('logo').hasClass('animated')) {
		LogoAnimation();
	}
});

function HighlightSector(clicked,sector) {
	if (sector == 'all') {
		sector = '';
	}

	$$('.sector_selector a').tween('color', '#4e545e');
	clicked.tween('color', '#fff');

	$$('.client_list table div').each(function(target) {
		target.tween('color', '#4e545e');
	});
	
	$$('.client_list table .' + sector).each(function(target) {
		target.tween('color', '#fff');
	});
}

function RunClientCloud() {	
	$$('.client_cloud>li').each(function(target) {
		var x = $random(0,500);
		var y = $random(0,120);
		
		target.setStyle('margin-left', x);
		target.setStyle('margin-top', y);
	});
	
	$$('.client_cloud>li.all').each(function(target) {
		target.setStyle('margin-left', 550);
		target.setStyle('margin-top', 210);
	});
}

function RunTestimonials() {
	var biggest = 0;
	$$('.testimonials li').each(function(target) {
		biggest = target.getSize().y > biggest ? target.getSize().y : biggest;
		target.setStyle('height', 0);
	});
	
	if ( $$('.testimonials')[0] ) {
		$$('.testimonials')[0].setStyle('height', biggest);
	
		DisplayTestimonial();
		var testimonialRunner = function(){ DisplayTestimonial(); };
		testimonialRunner.periodical(8000); //Will add the number of seconds at the Site.
	}
}

function DisplayTestimonial() {
	var current = $$('.testimonials li.active')[0];
	var next = current.getNext();
	if (!next) {
		next = $$('.testimonials li')[1];
	}
	
	current.set('tween', {
		duration: 2000,
		onComplete: function() {
			current.removeClass('active').setStyle('height', 0);
			next.fade('hide').addClass('active').setStyle('height', 'auto').fade('in');;
		}
	});
	
	next.set('tween', {
		duration: 2000,
		onComplete: function() {}
	});
	
	current.tween('opacity', 0);
}

function LogoAnimation() {
	$$('.logo.animated div').each(function(target) {
		target.fade('hide');
	});
	
	setTimeout("$('communicate').fade('in')",500);
	setTimeout("$('connect').fade('in')",1500);
	setTimeout("$('come_alive').fade('in')",2500);
}

function SetSlider(new_target) {
	$$('.sliders>li').each(function(target) {
		target.tween('width', 0);
	});
	$$('.navigation>li').each(function(target) {
		target.tween('background-position', '166px 0');
	});

	setTimeout("ShowSlider(" + new_target + ")",1000);
	
	var randno = Math.floor ( Math.random() * slider_bgs.length );	
	new_bg = slider_bgs[randno];

	setTimeout("SwapBG(" + new_bg + ")",1750);		
}

function SwapBG(new_bg) {
	$('bignav').setStyle('background-image','url(/cgi-local/db_images/slider_images/cache/' + new_bg + '-image-831-271-crop.jpg)');
}

function ShowSlider(new_target) {
	$('slider-' + new_target).tween('width', 831);
	$('handle-' + new_target).tween('background-position', '0 0px');
}

function HideSliders() {
	$$('#bignav>li').each(function(target) {
		target.set('tween', { duration: 750 });
	});
}