var tipsLevel1 = {
	interval: 5000,
	ID: 1,

	/**
	 * Inicializace
	 */
	init: function() {
		this.setEvents();
		this.imagePreload();
		this.setMainImage();
		this.startRotate();
	},

	/**
	 * Nastaveni udalosti
	 */
	setEvents: function() {
		var reference = this;
		$('.imageBox').mouseover(function() {
			$('#tipsBox img:first').stop();
			$('#tipsBox img:first').css('opacity', '');

			reference.ID = parseInt($(this).attr('id').replace(/tip/, ''));
			reference.setMainImage();
		});
		$('#tipsBox').mouseout(function() {
			reference.startRotate();
		});
		$('#tipsBox').mouseover(function() {
			reference.stopRotate();
		});
	},

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

	/**
	 * Aktivace timeru
	 */
	startRotate: function() {
		this.timer = window.setInterval("tipsLevel1.setMainImage()", this.interval);

	},

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

	/**
	 * Nastaveni aktivniho tipu
	 */
	setMainImage: function() {
		var title = $('#tip' + this.ID + ' h3').html();
		var imageSRC = $('#tip' + this.ID + ' img').attr('src');
		var alt = $('#tip' + this.ID + ' img').attr('alt');
		var href = $('#tip' + this.ID + ' a').attr('href');
		var imageSRCw512 = imageSRC.replace(/jpg_male/, 'jpg_velke');
		var content = $('#tip' + this.ID + ' div.content').html();
		var imageSRCCurrent = $('#tipsBox img:first').attr('src');


		if (imageSRCw512 != imageSRCCurrent) {
			$('#tipsBox p.mainImage').css("background-image", "url('" + $('#tipsBox img:first').attr("src") + "')");

			$('#tipsBox img:first').hide();
			$('#tipsBox div.level1Content').hide();
			$('#tipsBox h3:first').hide();

			$('#contextBG').attr('class', $('#tip' + this.ID + ' a').attr('name'));
			$('#tipsBox h3:first').html(title);
			$('#tipsBox div.level1Content').html(content);
			$('#tipsBox .mainImage a').attr('href', href);
			$('#tipsBox img:first').attr('src', imageSRCw512);
			$('#tipsBox img:first').attr('alt', alt);

			$('#tipsBox img:first').fadeIn(300);
			$('#tipsBox div.level1Content').fadeIn(300);
			$('#tipsBox h3:first').fadeIn(300);
			$('#contextBG').fadeIn(300);
		}

		/* zruseni aktivniho obrazku */
		this.disactiveImage();

		/* nastaveni obrazku na aktvini */
		imageSRC = imageSRC.replace(/jpg_male/, 'jpg_velke');
		this.activeImage(imageSRC);

		/* zvyseni ID pro timer */
		this.setID(this.ID + 1);
	},

	/**
	 * Nasteveni spodniho obrazku obrazku jako aktivni
	 */
	activeImage: function(imageSRC) {
		$('#tip' + this.ID).toggleClass('imageBoxActive');
	},

	/**
	 * Zruseni spodniho aktivniho obrazku
	 */
	disactiveImage: function() {
		$('.imageBoxActive').toggleClass('imageBoxActive');
	},

	/**
	 * Preload velkych obrazku u tipu
	 */
	imagePreload: function() {
		$('#tipsBox .imageBox img').each(function() {
			var imageSRC = this.src.replace(/jpg_male/, 'jpg_velke');
			preloadImage = new Image();
			preloadImage.src = imageSRC;
		});
	}
}