var numberOfItems = 0;
var currentItem = 0;
var rotateInterval = 7000;
var infiniteLoop = setInterval(rotate,rotateInterval);

$(document).ready(function() {
	numberOfItems = $('.rotate').length;

	$("#hybrid").hide();
	$("#private-cloud").hide();
	$("#run-cloud").addClass("highlight");
	$("#run-cloud").parent().addClass("highlight");
	$(".slider-control a").click(function(){
		$(".intro-slider article").fadeOut("fast");
		$(".slider-control a").removeClass("highlight");
		$(".slider-control li").removeClass("highlight");
		return false;
	});
	
	$("#run-cloud").click(function(){
		display(this, $("#cloud-servers"));
	
	});
	$("#run-hybrid").click(function(){
		display(this, $("#hybrid"));
	});
	$("#run-private").click(function(){
		display(this, $("#private-cloud"));
	});

	$("#run-utility").click(function(){
		display(this, $("#utility-computing"));
	});

	$("#run-hosting").click(function(){
		display(this, $("#app-hosting"));
	});

	$(".rotate-object").mouseover(function() {
		clearInterval(infiniteLoop)
	    });

	$(".rotate-object").mouseout(function() {
		infiniteLoop = setInterval(rotate, rotateInterval);
	    });	

	$("#freemium").click(function(){
		window.location.href = '/darmowe-konta';

	});

	$("#partnership").click(function(){
		window.location.href = '/wspolpraca';

	});
});


function display(link, elem) {
    var fadeTime = 500;
    $(".highlight").css('display','none');
    elem.delay(200).fadeIn(fadeTime);
    $(link).addClass("highlight");
    $(link).parent().addClass("highlight");
}

function rotate() {
    if(currentItem == numberOfItems-1) {
	currentItem = 0;
    } else {
	currentItem++;
    }
    $('.rotate').eq(currentItem).trigger('click');
}
