﻿function Rotate()
{
	this.id = 0;
	this.time = 5000;
	this.time_e = parseInt(this.time / 10);
	this.t = null;
	this.data = $('#cont_BP > div').get();
	this.size = new Array(0,0);
	var sz = new Array();
	for (i = 0; i < this.data.length; i++)
	{
		var img = $(this.data[i]).find('img').get(0);
		if (img)
		{
			if (this.size[0] < parseInt(img.style.width))
				this.size[0] = parseInt(img.style.width);
			if (this.size[1] < parseInt(img.style.height))
				this.size[1] = parseInt(img.style.height);
			sz[i] = new Array(parseInt(img.style.width), parseInt(img.style.height));
		}
	}
	$("#cont_BP").css({width:this.size[0],height:this.size[1]});
	for (i = 0; i < this.data.length; i++)
	{
		if (sz[i] != undefined)
		{
			this.data[i].style.top = ((this.size[1] - sz[i][1]) / 2) + 'px';
			this.data[i].style.left = ((this.size[0] - sz[i][0]) / 2) + 'px';

			this.data[i].style.position = "relative";
		}
	}

	this.next = function(){this.id += 1; if (this.id >= this.data.length) this.id = 0;};
	this.init = function(wait)
	{
		var self = this;
		function rotate()
		{
			$(self.data[self.id]).fadeOut(self.time_e);
			self.next();
			setTimeout(function(){$(self.data[self.id]).fadeIn(self.time_e);}, self.time_e + 1);
			
			self.t = setTimeout(rotate, self.time);
		}
		rotate();
	}
	this.stop = function(){
		if (this.t != null)
			clearTimeout(this.t);
		this.t = null;
	}
}

var rot = new Rotate();
rot.init();
