var curParentCatID = "";
var parentCat;
var isInSubCat = false;

function createSubCatNav() {
	document.getElementById("navOptions").style.display = "none";
	document.getElementById("subCatsDrop").style.display = "";
	document.getElementById("subCatsNav").innerHTML = "<div class=\"navTop\">" + 
		document.getElementById('cat-' + (isInSubCat ? parentCat : catID)).innerHTML + "</div><a id=\"featuredCatItems\" href=\"?cmd=sb-list&id=" +
		(isInSubCat ? parentCat : catID) + "\">Featured " +
		document.getElementById('cat-' + (isInSubCat ? parentCat : catID)).innerHTML + "</a>" +
		subCatCont.innerHTML + "<div class=\"navBtm\"></div>";						
	document.getElementById("subCatsNav").style.display = "";
	(!isInSubCat ? document.getElementById("featuredCatItems").className = "navSelected" : "");
}

function selectCat() {
	if (typeof catID == 'undefined') {
		return
	}
	subCatLink = document.getElementById("sCat-" + catID);
	subCatCont = document.getElementById("cat-" + catID + "-subList");	
	if (subCatLink) {
		subCatParent = subCatLink.parentNode;
		parentCat = subCatParent.id.substring("4", subCatParent.id.length -8);
		subCatCont = document.getElementById("cat-" + parentCat + "-subList");	
		isInSubCat = true;
		subCatLink.className = "navSelected";
		createSubCatNav();
		parentCatID = document.getElementById("cat-" + parentCat);
		document.getElementById("parentCrumb").innerHTML = "<a href=\"?cmd=sb-list&id=" + parentCat + "\">" + parentCatID.innerHTML + "</a>&nbsp;&nbsp;&raquo;&nbsp;&nbsp;";	
	} else if (subCatCont) {
		createSubCatNav();
		if (!checkout) {
			document.getElementById("parentCatHeader").style.display = "";
			document.getElementById("staticCatHeader").style.display = "none";
			//document.getElementById("catHeaderChildren").innerHTML = subCatCont.innerHTML + "<div class=\"clear\"></div>";
		} else if (checkout == "noFeatures") {
			document.getElementById("noFeaCatTitle").innerHTML = document.getElementById("cat-" + catID).innerHTML + " Categories";
			document.getElementById("catHeaderChildren").innerHTML = "<div class=\"clear\"></div>" + subCatCont.innerHTML + "<div class=\"clear\"></div>";								
		}
	} else {
		if (checkout == "noFeatures") {
			document.getElementById("catHeaderChildren").innerHTML = "This catergory is unavailable.";			
		} else {
			document.getElementById("cat-" + catID).className = "navSelected";
		}
	}
	curAllState = "none";
	otherAllState = "";
	curCatHeader = "<div class=\"navDrp\"></div>View All Categories";
	otherCatHeader = "<div class=\"navDrp navExp\"></div>View " + document.getElementById('cat-' + (isInSubCat ? parentCat : catID)).innerHTML;
	document.getElementById("subCatsNav").className = "nav navCatSlct";
}

function subcatPopout(e,catID) {
    if (curParentCatID != "") {
		document.getElementById("cat-" + curParentCatID).className = "isParent";
		document.getElementById("cat-" + curParentCatID + "-subList").style.display = "none";	
        curParentCatID = "";
    }
	var Y =	document.getElementById("cat-" + catID).offsetTop;
	document.getElementById("cat-" + catID).className = "navSelected navSelectedParent";
	document.getElementById("cat-" + catID + "-subList").style.display = "block";
	document.getElementById("cat-" + catID + "-subList").style.top = Y -2 + "px";
	curParentCatID	= catID;
	cancelBubbleEvent(e);
}

document.getElementsByTagName('body')[0].onmouseover = function () {
	if (curParentCatID != "") {
		document.getElementById("cat-" + curParentCatID).className = "isParent";
		document.getElementById("cat-" + curParentCatID + "-subList").style.display = "none";	
		curParentCatID = "";		
	}
	if (isShowAll) {
		hideAll();
	}

}
function cancelBubbleEvent(e) {
    var e = e || window.event;
    e.cancelBubble = true;
    if (e.stopPropagation) e.stopPropagation();
}

//function subcatPopin(catID) {
//	document.getElementById("cat-" + catID).className = "isParent";
//	document.getElementById("cat-" + catID + "-subList").style.display = "none";	
//}
var isShowAll = false;
var wasShowAll = false;
function showAll(evt) {
	document.getElementById("navOptions").style.display = "";
	document.getElementById("navOptions").className = "mainNavPop";
	isShowAll = true;
	wasShowAll = true;
	cancelBubbleEvent(evt);
}

function hideAll(evt) {
	document.getElementById("navOptions").style.display = "none";
	document.getElementById("navOptions").className = "mainNavPop";
	isShowAll = false;
	wasShowAll = false;
}

function dontHide(evt) {
	isShowAll = false;
}

function enableHide(evt) {
	isShowAll = wasShowAll;
}