﻿/* ====================================================
 * Navigation
 */

function Navigation(nav, firstLevelNodes) {
	this.nav = nav;
	this.firstLevelNodes = firstLevelNodes;
}

// first Level access

Navigation.prototype.firstLevelMoveOver = function(firstIndex) {
	this.firstLevelNodes[firstIndex].moveOver();
}

Navigation.prototype.firstLevelMoveOut = function(firstIndex) {
	this.firstLevelNodes[firstIndex].moveOut();
}

Navigation.prototype.firstLevelClick = function(firstIndex) {
	this.firstLevelNodes[firstIndex].click();
}

// second Level access

Navigation.prototype.secondLevelMoveOver = function(firstIndex, secondIndex) {
	this.firstLevelNodes[firstIndex].secondLevelNodes[secondIndex].moveOver();
}

Navigation.prototype.secondLevelMoveOut = function(firstIndex, secondIndex) {
	this.firstLevelNodes[firstIndex].secondLevelNodes[secondIndex].moveOut();
}

Navigation.prototype.secondLevelClick = function(firstIndex, secondIndex) {
	this.firstLevelNodes[firstIndex].secondLevelNodes[secondIndex].click();
}

// third Level access

Navigation.prototype.thirdLevelMoveOver = function(firstIndex, secondIndex, thirdIndex) {
	this.firstLevelNodes[firstIndex].secondLevelNodes[secondIndex].thirdLevelNodes[thirdIndex].moveOver();
}

Navigation.prototype.thirdLevelMoveOut = function(firstIndex, secondIndex, thirdIndex) {
	this.firstLevelNodes[firstIndex].secondLevelNodes[secondIndex].thirdLevelNodes[thirdIndex].moveOut();
}

Navigation.prototype.thirdLevelClick = function(firstIndex, secondIndex, thirdIndex) {
	this.firstLevelNodes[firstIndex].secondLevelNodes[secondIndex].thirdLevelNodes[thirdIndex].click();
}


// management access

Navigation.prototype.reset = function() {
	return;
}

Navigation.prototype.toString = function() {
	var output = "Navigation:\n--------------------\n";
	for(var i = 0; i < this.firstLevelNodes.length; i++) {
		output = output + this.firstLevelNodes[i] + " \n";
	}
	return output + "--------------------\n";
}


/* ====================================================
 * FirstLevelNode
 */

function FirstLevelNode(id, pageId, title, subNav, secondLevelNodes, onPath, isActive) {
	this.id = id;
	this.pageId = pageId;
	this.title = title;
	this.subNav = subNav;
	this.secondLevelNodes = secondLevelNodes;
	this.onPath = onPath;
	this.isActive = isActive;
}

FirstLevelNode.prototype.extend = function() {
	this.subNav.style.display = "block";
}

FirstLevelNode.prototype.reduce = function() {
	this.subNav.style.display = "none";
}

FirstLevelNode.prototype.moveOver = function() {
	if (!this.isActive) {
		this.title.style.cursor = "pointer";
	}
}

FirstLevelNode.prototype.moveOut = function() {
	if (!this.isActive) {
		this.title.style.cursor = "auto";
	}
}

FirstLevelNode.prototype.click = function() {
	window.location = "./index.php?go=" + this.pageId;
}


FirstLevelNode.prototype.toString = function() {
	var output = this.id + " (-> " + this.pageId + ", " + this.onPath + ", " + this.isActive + ")\n";
	for(var i = 0; i < this.secondLevelNodes.length; i++) {
		output = output + this.secondLevelNodes[i] + "\n";
	}
	return output;
}



/* ====================================================
 * SecondLevelNode
 */
 
function SecondLevelNode(id, pageId, title, subNav, thirdLevelNodes, onPath, isActive) {
	this.id = id;
	this.pageId = pageId;
	this.title = title;
	this.subNav = subNav;
	this.thirdLevelNodes = thirdLevelNodes;
	this.onPath = onPath;
	this.isActive = isActive;
}

SecondLevelNode.prototype.extend = function() {
	this.subNav.style.display = "block";
}

SecondLevelNode.prototype.reduce = function() {
	this.subNav.style.display = "none";
}

SecondLevelNode.prototype.moveOver = function() {
	if (!this.isActive) {
		this.title.style.backgroundColor = "#E3E3E3";
		this.title.style.cursor = "pointer";
	}
}

SecondLevelNode.prototype.moveOut = function() {
	if (!this.isActive) {
		if (!this.onPath) {
			this.title.style.backgroundColor = "#FFFFFF";
		}
		this.title.style.cursor = "auto";
	}
}

SecondLevelNode.prototype.click = function() {
	window.location = "./index.php?go=" + this.pageId;
}

SecondLevelNode.prototype.toString = function() {
	var output = "- " + this.id + " (-> " + this.pageId + ", " + this.onPath + ", " + this.isActive + ")\n";
	for(var i = 0; i < this.thirdLevelNodes.length; i++) {
		output = output + this.thirdLevelNodes[i] + "\n";
	}
	return output;
}



/* ====================================================
 * ThirdLevelNode
 */

function ThirdLevelNode(id, pageId, title, onPath, isActive) {
	this.id = id;
	this.pageId = pageId;
	this.title = title;
	this.onPath = onPath;
	this.isActive = isActive;
}

ThirdLevelNode.prototype.moveOver = function() {
	if (!this.isActive) {
		this.title.style.backgroundColor = "#E3E3E3";
		this.title.style.cursor = "pointer";
	}
}

ThirdLevelNode.prototype.moveOut = function() {
	if (!this.isActive) {
		if (!this.onPath) {
			this.title.style.backgroundColor = "#FFFFFF";
		}
		this.title.style.cursor = "auto";
	}
}

ThirdLevelNode.prototype.click = function() {
	window.location = "./index.php?go=" + this.pageId;
}

ThirdLevelNode.prototype.toString = function() {
	return "-- " + this.id + " (-> " + this.pageId + ", " + this.onPath + ", " + this.isActive + ")";
}