var RotationBanner = function()
{
	var that = {
		last: 0,
		current: 0,
		banners: [],
		
		init: function()
		{
			// console.log("RotationBanner :: init");
			$('#topLayer').find('div').each(that.addBanners);
			
			if (!that.getCookie()) 
			{
				that.setCookie(0);
			} 
			else 
			{
				that.last = new Number(that.getCookie());
			
				if (that.last + 1 < that.banners.length)
				{
					that.current = that.last + 1;
				}
				else
				{
					that.current = 0;
				}
			}
			
			$.each(that.banners, that.show);
			
			that.setCookie(that.current);
		},
		
		addBanners: function(index , value)
		{
			// console.log("RotationBanner :: addBanners");
			that.banners.push([index, value]);
		},
		
		// Metoda dostaje jako parametr index bannera;
		setCookie: function(index)
		{
			// console.log("RotationBanner :: setCookie", arguments);
			$.cookie('hochland-rotation-banner', index);
		},
		
		// Metoda pobiera index ostatnio uzytego bannera
		getCookie: function()
		{
			// console.log("RotationBanner :: getCookie");
			return $.cookie('hochland-rotation-banner');
		},
		
		show: function(index , value)
		{
			
			if (value[0] != that.current) 
			{
				$(value[1]).remove();
			}
		}
		
	}
	
	return that;
}

$(document).ready(function() {
	var rotationBanner = new RotationBanner();
	rotationBanner.init();
});
