var galleryInterval = 2500;

window.addEvent('domready', function() {
	topPartners1 = new Rotator($$('.partner_1 .imageElement'), 1, galleryInterval);
	topPartners1.init();

	topPartners2 = new Rotator($$('.partner_2 .imageElement'), 1, galleryInterval);
	topPartners2.init();

	topPartners3 = new Rotator($$('.partner_3 .imageElement'), 1, galleryInterval);
	topPartners3.init();

	topPartners4 = new Rotator($$('.lastpartner .imageElement'), 1, galleryInterval);
	topPartners4.init();

	infoPartners = new Rotator($$('.infoPartners .item'), 3, galleryInterval);
	infoPartners.init();
});

function Rotator(items, perPage, delay) {
	this.index = 0;
	this.items = items;
	this.delay = delay;
	this.perPage = perPage;
	var thisObj = this;

	this.init = function() {
		thisObj.rotate();
		setInterval(thisObj.rotate, thisObj.delay);
	}

	this.rotate = function() {
		items.setStyles({'display':'none', 'opacity':'0'});
		for(var i = 0; i < thisObj.perPage; i++) {
			if(thisObj.index >= items.length) {
				thisObj.index = 0;
			}

			thisObj.items[thisObj.index].setStyles({'display':'block'});
			thisObj.items[thisObj.index].fade(1);

			thisObj.index++;
		}
	}
}

