function log(text) {
var node, temp;
	temp = window.document.getElementsByTagName("BODY");
	node = temp[0];
	node.appendChild(window.document.createTextNode(text));
	node.appendChild(window.document.createElement("BR"));
}


function Map(occ) {
//redoslijed nije bitan
//vrlo sporo za puno podataka
this.occ = occ*1;

this.key_array = new Array(occ);
this.value_array = new Array(occ)
for (i = 0; i<this.occ ; i++) {
	this.key_array[i] = null;
	this.value_array[i] = null;
}


//za nextove 
this.cursor = 0;

this.reset_iterator = function() {
	this.cursor = 0;
}

this.next = function () {
var temp;
	temp = this.value_array[this.cursor];

	//za next next()
	this.cursor = this.cursor + 1;
	
	return temp;
}

this.hasNext = function () {
	for (i = this.cursor; i < this.occ ; i++) {
		if (this.key_array[i] != null) { //ne func
			return true;
		}
	}
return false;
}

this.put = function (s_key, value) {
	//prvo provjerimo ima li vec taj key , ako ima stavimo value
	for (i = 0; i<this.occ ; i++) {
		if (this.key_array[i] == s_key) {
			this.value_array[i] = value;
			return;
		}
	}
	//ako nema key dodamo stavku na prvo slobodno mjesto
	for (i = 0; i<this.occ ; i++) {
		if (this.key_array[i] == null) {
			this.key_array[i] = s_key;
			this.value_array[i] = value;
			return;
		}
	}
	//ako dodjemo dovde znaci da nem mjesta vise
	alert("List["+this.occ+"] is full !");
	return;
}

this.get = function (s_key) {
	
	for (i = 0; i<this.occ ; i++) {
		if (this.key_array[i] == s_key) {
			return this.value_array[i];
		}
	}

return null;
}

this.remove = function (s_key) {
	
	for (i = 0; i<this.occ ; i++) {
		if (this.key_array[i] == s_key) {
			this.key_array[i] = null;
			this.value_array[i] = null;
		}
	}
}

this.clear = function () {
	
	for (i = 0; i<this.occ ; i++) {
		this.key_array[i] = null;
		this.value_array[i] = null;
	}

return null;
}

}//end object

/*
MenuBar ce biti u stvari staticni linkovi kako god stavljeni, 
+ DIV staticni sub_menui
a ovaj objekt sluzi da se zakace handleri za staticne linkove
tako da cemo onda te DIV-ove pokazivati i sakrivaati preko handlera
*/
function MenuBar(var_name) {

this.var_name = var_name;
this.ie5 = document.all && document.getElementById;
this.ns6 = document.getElementById && !document.all;


//@see this.mouse_over_document_handler()
this.timeout_finished = true;
this.timeout_id = null;

//MAP
this.menus = new Map(25);

//init
document.onmouseover = new Function("e","window."+this.var_name+".mouse_over_document_handler(e);  ");


/* EVENT PROPAGATION MODELI--------------------------------------
ide uvijek i u IE i u NN6+ ide odozgora po TESTU
3 modela propagacije :
w3c DOM - NN6+  	BOTH(default UP)
NN4  			DOWN
IE4+			UP

ZNACI IE i NN6+ obadva idu UP
*/
//ovo se kaci na sam document objekt tako da znamo da smo se makli sa menua
this.mouse_over_document_handler = function (e) {
	//sprijeci multithread
	if (this.timeout_finished) {
		this.timeout_finished = false;
		this.timeout_id = window.setTimeout(this.var_name + ".close_all_timeout()",0);
	}
	//log("mouse_over DOCUMENT");
}

//za sami MenuBar	
//OVO SEPOZIVA SAMO SA LINKOVA (ili bilo kojeg elementa ustvari) i nemoj zvati nigdje drugdje jer radi cancel eventa
this.mouse_over_handler = function (e, div_id, pos_element, isSubMenu) {
	
	//ovdje pri otvaranju suba cemo sprijeciti da se zatvaraju Menui ako je vec pokrenut timer koji ce ih zatvoriti
	if (this.timeout_id != null) {
		window.clearTimeout(this.timeout_id);
		this.timeout_finished = true;
		this.timeout_id = null;
	}
	
	
	div = document.getElementById(div_id);
	
	if (!isSubMenu) {
		this.close_all();
		div.style.left = this.findX(pos_element);
		div.style.top = this.findY(pos_element);
	} else {
		div.style.left = this.findXSub(pos_element);
		div.style.top = this.findYSub(pos_element);
	}
	
	div.style.visibility = "visible";
	
	//stavljam svaki put nakon nekog vremena ce se ponavljati ina kraju biti svi
	//u mapi i ponavljati se dalje
	this.menus.put(div_id, div);

	//sprjecavanje zatvaranja subMenua kad to netreba----
	//catch onmouseover i sprijeci da ide dalje

	if (this.timeout_id != null) {	window.clearTimeout(this.timeout_id); this.timeout_finished = true; this.timeout_id = null;}

	
	div.onmouseover = new Function("e","if (window."+this.var_name+".ns6) {e.cancelBubble = true;} if (window."+this.var_name+".ie5) {event.cancelBubble = true;} if (window."+this.var_name+".timeout_id != null) { window.clearTimeout(window."+this.var_name+".timeout_id); window."+this.var_name+".timeout_finished = true; window."+this.var_name+".timeout_id = null;}");
	//i ovaj event koji nas je i aktivirao isto ugasi bubling
	if (this.ns6) {e.cancelBubble = true;}
	if (this.ie5) {event.cancelBubble = true;}
}

this.close_all_timeout = function () {

	this.close_all();
	this.timeout_finished = true;
	this.timeout_id = null;
}

this.close_all = function () {
var temp_div;
	//ako posoji neki otvoren zatvori ga ili najsigurnije sve postavi na hidden
	this.menus.reset_iterator();

	while (this.menus.hasNext() ) {
		temp_div = this.menus.next();
		temp_div.style.visibility = "hidden";
	}
}


this.findX = function (pos_element) {
	var prolaz = true;
	var temp;
	var x_ret=0;
	
		temp = pos_element;
	
		while (prolaz) {
	
			temp = temp.offsetParent;
	
			if (temp != null) {
				if (true) {
					x_ret = x_ret + temp.offsetLeft*1;
				}
			} else {
				prolaz=false;
			}
		}
	
		x_ret = x_ret + pos_element.offsetLeft*1;
	
	return x_ret;
}

this.findY = function (pos_element) {
	var prolaz = true;
	var temp;
	var y_ret=0;
	
		temp = pos_element;
	
		while (prolaz) {
	
			temp = temp.offsetParent;
	
			if (temp != null) {
				if (true) {
						y_ret = y_ret + temp.offsetTop*1;
				}
			} else {
				prolaz=false;
			}
		}
	
		y_ret = y_ret + pos_element.offsetTop*1;
		y_ret = y_ret + pos_element.offsetHeight*1;
	
	return y_ret;
}

this.findXSub = function (pos_element) {
	var prolaz = true;
	var temp;
	var x_ret=0;
	
		temp = pos_element;
	
		while (prolaz) {
	
			temp = temp.offsetParent;
	
			if (temp != null) {
				if (true) {
					x_ret = x_ret + temp.offsetLeft*1;
				}
			} else {
				prolaz=false;
			}
		}
	
		x_ret = x_ret + pos_element.offsetLeft*1;
		x_ret = x_ret + pos_element.offsetWidth*1;
	
	return x_ret;
}

this.findYSub = function (pos_element) {
	var prolaz = true;
	var temp;
	var y_ret=0;
	
		temp = pos_element;
	
		while (prolaz) {
	
			temp = temp.offsetParent;
	
			if (temp != null) {
				if (true) {
						y_ret = y_ret + temp.offsetTop*1;
				}
			} else {
				prolaz=false;
			}
		}
	
		y_ret = y_ret + pos_element.offsetTop*1;
		y_ret = y_ret + pos_element.offsetHeight*1;
	
	return y_ret;
}

} //end object
