/**
* Homepage main banner rotation
*
* @author Tomas Rasek
* @copyright Castus
* @version 2010030301
*/
var mainBanner = {
	interval: 4000,
	fadeInInterval: 500,
	ID: 1,
	currentID: 1,

	/**
	 * Inicialization
	 */
	init: function() {
		this.setEvents();
		this.setMainBanner();
		this.startRotate();
	},

	/**
	 * Set events
	 */
	setEvents: function() {
		var reference = this;
		$('#editorial_block_center').mouseout(function() {
			reference.startRotate();
		});
		$('#editorial_block_center').mouseover(function() {
			reference.stopRotate();
		});
	},

	/**
	 * Set ID
	 */
	setID: function(givenID) {
		if (givenID > $('.hpBanner').length) {
			givenID = 1;
		}
		this.ID = givenID;
	},

	/**
	 * Set current ID
	 */
	setCurrentID: function(givenID) {
		this.currentID = givenID;
	},

	/**
	 * start timer
	 */
	startRotate: function() {
		this.timer = window.setInterval("mainBanner.setMainBanner()", this.interval);

	},

	/**
	 * Stop timer
	 */
	stopRotate: function() {
		window.clearInterval(this.timer);
	},

	/**
	 * Set active tab
	 */
	setMainBanner: function() {
		var reference = this;

		if (this.ID != this.currentID) {
			$('#hpBanner' + this.ID + ' .hpInner').hide();
			$('#hpBanner' + this.ID).show();
			$('#hpBanner' + this.ID + ' .hpInner').fadeIn(this.fadeInInterval);
			$('#hpBanner' + this.currentID + ' .hpInner').fadeOut(this.fadeInInterval, function() {
				$('#hpBanner' + this.currentID).hide();
			});
			reference.setCurrentID(reference.ID);
			reference.setID(reference.ID + 1);

		}
		else {
			this.setID(this.ID + 1);
		}
 	}
}

$(document).ready(function() {
	mainBanner.init();
});
