function Page3() {
	this.id = "page3";
	this.dragProduct = null;
	this.dragStartX = 0;
	this.dragStartY = 0;
	this.altElement = null;
	this.altTimeout = null;
	this.warningElement = null;
	this.warningTimeout = null;
	this.warningExclusiveEmpty = false;
	this.openedSlot = null;
	
	Page3.prototype.update = function() {
		$("page3-basic").innerHTML = "";
		$("page3-extended").innerHTML = "";
		$("page3-special").innerHTML = "";
		$("page3-selected").innerHTML = "";
		for (var i = 0; i < c.products.slots.length; i++) {
			var slot = c.products.slots[i];
			var product = slot.products[0];
			var parent = null;
			var className = null;
			// at se jedna o slot s jendinm, nebo vice produkty, lokace
			// bude vzdyt stejna dle kategorie
			if (product.category.id == Config.basicCategoryId) {
				parent = $("page3-basic");
				className = "product make-basic";
			}
			else if (product.category.id == Config.extendedCategoryId) {
				parent = $("page3-extended");
				className = "product make-extended";
			}
			else if (product.category.id == Config.exclusiveCategoryId) {
				parent = $("page3-special");
				className = "product make-special";
			}
			else {
				// exit u nezname kategorie
				continue;
			}
			// jeden produkt ve slotu = bez menu
			if (slot.products.length == 1) {
				if (product.multiple != 0 && product.multiple == product.amount) {
					HtmlFactory.createElement("A", parent, "product make-empty");
					continue;
				}
				var element = HtmlFactory.createElement("A", parent, (product.multiple == 0) ? "product make-disabled" : className);
				element.href = "javascript:void(0)";
				element.onfocus = delegate(element, element.blur);
				element.onmouseover = delegate(this, this.overProduct, product);
				element.onmouseout = delegate(this, this.outProduct, product);
				element.onmousemove = delegate(null, Alt.update);
				if (product.multiple != 0) {
					element.onclick = delegate(this, this.selectProduct, product);
					//element.onmousedown = delegate(null, DragAndDrop.start, element);
					//element.onmouseup = delegate(this, this.selectProduct, product);
				}
				else {
					element.style.cursor = "default";
				}
				element.innerHTML = "<span unselectable=\"on\">" + product.name + "</span>";
			}
			// vic produktu ve slotu = bude se zobrazovat vyber
			else {
				//alert("slot " + slot.name + " ma vic ja jeden produkt");
				var element = HtmlFactory.createElement("A", parent, className);
				element.href = "javascript:void(0)";
				element.onfocus = delegate(element, element.blur);
				element.onmouseover = delegate(this, this.overSlot, slot);
				element.onmouseout = delegate(this, this.outSlot, slot);
				element.onmousemove = delegate(null, MenuHint.update);
				element.onclick = delegate(this, this.selectSlot, slot);
				element.innerHTML = "<span unselectable=\"on\">" + slot.name + "</span>";
			}
		}
		for (var i = 0; i < c.selection.items.length; i++) {
			var product = c.selection.items[i];
			var className = null;
			if (product.category.id == Config.basicCategoryId) {
				className = "product make-basic";
			}
			else if (product.category.id == Config.extendedCategoryId) {
				className = "product make-extended";
			}
			else if (product.category.id == Config.exclusiveCategoryId) {
				className = "product make-special";
			}
			else {
				continue;
			}
			
			var element = HtmlFactory.createElement("A", $("page3-selected"), className);
			element.href = "javascript:void(0)";
			element.onfocus = delegate(element, element.blur);
			element.onmouseover = delegate(this, this.overProduct, product);
			element.onmouseout = delegate(this, this.outProduct, product);
			element.onmousemove = delegate(null, Alt.update);
			element.onclick = delegate(this, this.unselectProduct, product);
			element.innerHTML = "<span unselectable=\"on\">" + product.fullName + "</span>";
			if (product.amount > 1) {
				element.innerHTML += "<span class=\"number\">" + product.amount + "&times;</span>";
			}
		}
	};

	Page3.prototype.overProduct = function(product) {
		Alt.show(product);
		if (this.openedSlot != null) {
			this.openedSlot = null;
			Menu.hide();
		}
		if (Config.intranetMode == true) {
			c.panel.setProduct(product);
		}
	};
	
	Page3.prototype.overProductInSlot = function(product) {
		Alt.show(product);
		if (Config.intranetMode == true) {
			c.panel.setProduct(product);
		}
	};

	Page3.prototype.outProduct = function(product) {
		Alt.hide();
		if (Config.intranetMode == true) {
			c.panel.toggleUser();
		}
	};

	Page3.prototype.selectProduct = function(product, amount) {
		/*if (DragAndDrop.hasMoved() && DragAndDrop.element.offsetTop < 300) {
			DragAndDrop.stop();
			return;
		}
		DragAndDrop.stop();
		*/
		// UPDATE: pridavat produkty lze pouze, je-li stranka aktivni
		if (c.currentPage != this) {
			Info.show("Na této stránce nelze přidávat produkty a služby, prosím vraťte se na obrazovku s výběrem.");
			return false;
		}
		if (product.multiple >= 0 && product.amount == product.multiple) {
			return false;
		}
		// UPDATE: pridavani po vice kusech
		if (amount != null) {
			product.amount += amount;
		}
		else {
			product.amount += 1;
		}
		if (!c.selection.contains(product)) {
			c.selection.add(product);
		}
		var validated = true;
		if (!this.validateProducts()) {
			//this.unselectProduct(product);
			//return;
			// UPDATE: odebirani po vice kusech
			if (amount != null) {
				product.amount -= amount;
			}
			else {
				product.amount -= 1;
			}
			if (product.amount == 0 && c.selection.contains(product)) {
				c.selection.remove(product);
			}
			validated = false;
		}
		if (Config.intranetMode) {
			c.semaphore.update();
		}
		Alt.hide();
		Menu.hide();
		c.switchingPage = true;
		this.openedSlot = null;
		this.update();
		return validated;
	};

	Page3.prototype.unselectProduct = function(product) {
		
		// UPDATE: Rozdeleni dle verze "old" a "new"
		// stare produkty se davaji pryc v celem mnozstvi a presouvaji se do panelu
		if (product.isOld()) {
			if (c.selection.contains(product)) {
				c.selection.remove(product);
			}
			c.panel.addAccountService("IE", product.name, product.id, product.amount);
			product.amount = 0;
		}
		// nove produkty se chovaji beze zmeny
		else if (product.isNew()) {
			product.amount -= 1;
			if (product.amount == 0 && c.selection.contains(product)) {
				c.selection.remove(product);
			}
			if (!this.validateProducts()) {
				//this.selectProduct(product);
				//return;
				if (product.multiple >= 0 && product.amount == product.multiple) {
					return;
				}
				product.amount += 1;
				if (!c.selection.contains(product)) {
					c.selection.add(product);
				}
			}
		}
		if (Config.intranetMode) {
			c.semaphore.update();
		}
		Alt.hide();
		c.switchingPage = true;
		this.update();
	};

	Page3.prototype.validateProducts = function() {
		var message = c.selection.validate();
		if (message != null) {
			Warning.show(message);
			return false;
		}
		return true;
	};

	Page3.prototype.overSlot = function(slot) {
		if (this.openedSlot == slot) {
			return;
		}
		if (this.openedSlot != null) {
			this.openedSlot = null;
			Menu.hide();
		}
		MenuHint.show(slot.name, slot.tooltip1, slot.tooltip2);
		c.switchingPage = false;
	};
	
	Page3.prototype.outSlot = function(slot) {
		MenuHint.hide();
		c.switchingPage = false;
	};

	Page3.prototype.selectSlot = function(slot) {
		/* v pripade, ze je Menu videt, zavira se */
		if (this.openedSlot == slot) {
			this.openedSlot = null;
			Menu.hide();
			MenuHint.show(slot.name, slot.tooltip1, slot.tooltip2);
			return;
		}
		c.switchingPage = true;
		this.openedSlot = slot;
		MenuHint.hide();
		Menu.show(slot.title, slot.products.length);
		//this.update();
		// zobrazeni jednotlivych produktu
		// POZOR: max 4 produkty!
		for (var i = 0; i < slot.products.length && i < 4; i++) {
			var product = slot.products[i];
			var className = null;
			if (product.category.id == Config.basicCategoryId) {
				className = "product make-basic";
			}
			else if (product.category.id == Config.extendedCategoryId) {
				className = "product make-extended";
			}
			else if (product.category.id == Config.exclusiveCategoryId) {
				className = "product make-special";
			}
			// FIXME: je nutno doplnit obraznky pro prazdne varianty dle kategorii
			// otazka? bude vubec mozne vybrat nabizeny produkt v menu pouze jednou?
			if (product.multiple != 0 && product.multiple == product.amount) {
				HtmlFactory.createElement("A", $(Menu.containerId), className + "-empty");
				continue;
			}
			var element = HtmlFactory.createElement("A", $(Menu.containerId), className);
			element.href = "javascript:void(0)";
			element.onfocus = delegate(element, element.blur);
			element.onmouseover = delegate(this, this.overProductInSlot, product);
			element.onmouseout = delegate(this, this.outProduct, product);
			element.onmousemove = delegate(null, Alt.update);
			if (product.multiple == 0) {
				// disabled
				element.className += "-disabled"; 
				element.style.cursor = "default";
			}
			else {
				element.onclick = delegate(this, this.selectProduct, product);
				//element.onmousedown = delegate(null, DragAndDrop.start, element);
				//element.onmouseup = delegate(this, this.selectProduct, product);
			}
			element.innerHTML = "<span unselectable=\"on\">" + product.name + "</span>";
		}
	};

	Page3.prototype.enter = function() {
		$(this.id).style.visibility = "visible";
		$(this.id).unselectable = "on";
		if (Config.intranetMode == true) {
			if (!c.panel.showed) c.panel.show();
			if (!c.panel.opened) c.panel.toggle();
			// UPDATE: bude schovano na zacatku
			if (c.panel.opened) c.panel.toggle();
		}
		//this.altElement = HtmlFactory.createElement("DIV", $(this.id), "alt");
		//this.altElement.style.visibility = "hidden";
		this.update();
	};

	Page3.prototype.leave = function() {
		//HtmlFactory.removeElement(this.altElement);
		Menu.hide();
		$(this.id).style.visibility = "hidden";
		c.switchingPage = false;
	};

	Page3.prototype.next = function() {
		// UPDATE: hlaska o prazdnem vyberu produktu special preskocena
		//if (c.selection.findByCategories(Config.exclusiveCategoryId).items.length == 0 && !this.warningExclusiveEmpty) {
		//	this.warningExclusiveEmpty = true;
		//	Info.show("Doporučujeme Vám výběr některého z produktů Speciál, které Vás ochrání v nepříjemných situacích.");
		//}
		//else {
			c.changePage(c.page4);
		//}
	};

}

