/**
 * @author ponnamykiep
 */

function drawNavigation(dataObj, navDiv, subNavDiv, activeIndex){
	if (!navDiv) {
		alert("ERROR: drawNavigation(): 'navDiv' param missing.");
		return;
	}
	if (activeIndex == undefined) activeIndex = [0];
	var navItemClass = "navItem";
	var navItemActiveClass = "navItemActive";
	var navSubItemClass = "navSubItem";
	var navSubItemActiveClass = "navSubItemActive";
	for (var i=0; i<dataObj.length; i++){
		var html = "";
		html += "<div id='nav_" + i + "' ";
		if (i == activeIndex[0]) html += "class='" + navItemActiveClass + "' ";
		else html += "class='" + navItemClass + "' ";
		html += ">\n";
		
		html += "<a href='" + getNav(i) + "'>\n";
		html += dataObj[i].label + "\n";
		html += "</a>\n";
		navDiv.innerHTML += html;
		
	}
	// Create nav subitems
	if (dataObj[activeIndex[0]].subItem){
		for (var j=0; j < dataObj[activeIndex[0]].subItem.length; j++){
			/*
			var subNode = document.createElement("div");
			var subNodeValue = document.createTextNode(dataObj[activeIndex[0]].subItem[j].label);
			subNode.setAttribute("id","subnav_"+activeIndex + "-" + j);	
			if (j == activeIndex[1]) subNode.setAttribute("class",navSubItemActiveClass);
			else subNode.setAttribute("class",navSubItemClass);	
			var subNodeAnchor = document.createElement("a");
			subNodeAnchor.setAttribute("href", "javascript:void(0);");
			subNodeAnchor.setAttribute("onclick", "doNav(" + activeIndex[0] + "," + j + ");");
			subNodeAnchor.appendChild(subNodeValue);
			subNode.appendChild(subNodeAnchor);
			subNavDiv.appendChild(subNode);
			*/
			var html = "";
			html += "<div id='subnav_" + activeIndex + "-" + j + "' ";
			if (j == activeIndex[1]) html += "class='" + navSubItemActiveClass + "' ";
			else html += "class='" + navSubItemClass + "' ";
			html += ">\n";
			//html += "<a href='javascript:void(0);' onclick='doNav(" + activeIndex[0] + "," + j + ");'>\n";
			html += "<a href='" + getNav(activeIndex[0], j) + "'>\n";
			html += dataObj[activeIndex[0]].subItem[j].label + "\n";
			html += "</a>\n";
			subNavDiv.innerHTML += html;
		}
	}else{
		var subNode = document.createElement("div");
		subNode.setAttribute("class",navSubItemClass);	
		subNavDiv.appendChild(subNode);
	}
}

function getNav(index, subIndex){
	var action = "";
	if (subIndex != undefined){
		action = navItems[index].subItem[subIndex].value;
	}else{
		action = navItems[index].value;
	}
	//document.location.href = action;
	return action;
}

