leftNav = function(jsonObject, mainSection, subSection, divName) {	
	//global variable declarations
	leftNavInfo = new Object();
	leftNavInfo.jsonObject = jsonObject;
	leftNavInfo.MainNavPosition = '';
	leftNavInfo.leftNavDiv = divName;
	
	// determinig current and sub page names
	leftNavInfo.mainSection = mainSection;
	leftNavInfo.subSection = subSection;
	
	//
	for (var i = 0; i < leftNavInfo.jsonObject.nav.length; i++) {
		if (leftNavInfo.jsonObject.nav[i].name == leftNavInfo.mainSection) {
			leftNavInfo.MainNavPosition = i;
		}
	}
	this.createLeftNav();
}

leftNav.prototype.createLeftNav = function() {
	// declare simple variables
	//var sNav = leftNavInfo.jsonObject.nav[leftNavInfo.MainNavPosition];
	var sNav = leftNavInfo.jsonObject.nav;

	var leftNav = '';
	
	if (leftNavInfo.jsonObject.global[0].sectionName != "") {
		leftNav += '<span id="primaryName">';
		if (leftNavInfo.jsonObject.global[0].navImage != null) {
			leftNav += '<img src="' + leftNavInfo.jsonObject.global[0].siteURL + leftNavInfo.jsonObject.global[0].navImage + '" alt="' + leftNavInfo.jsonObject.global[0].sectionName + '" />';
		} else {
			leftNav += leftNavInfo.jsonObject.global[0].sectionName;
		}
		leftNav += '</span>';
	}

	for (var i = 0; i < sNav.length; i++) {

		if (sNav[i].name == leftNavInfo.mainSection) {
			// determining if there's a second level
			if ((sNav[i].subNav != null) && (sNav[i].link == '')) {
				if (sNav[i].link == '') {
					leftNav += '<a href="javascript:leftNav.showSideNav(\'' + i + '\')" id="Link' + i + '" class="leftNav">' + sNav[i].name + '</a>';
				} else {
					leftNav += '<a href="' + sNav[i].link + '" id="Link' + i + '" class="leftNav">' + sNav[i].name + '</a>';
				}
				var thisNavItem = i;
			} else {
				leftNav += '<a href="';
				if (sNav[i].target == '') {
					leftNav += leftNavInfo.jsonObject.global[0].siteURL;
				}
				leftNav += sNav[i].link + '" id="Link' + i + '" class="leftNavBlack">' + sNav[i].name + '</a>';
			}
			
			// determining if there's a second level
			if ((sNav[i].subNav != null) && (sNav[i].link != '')) {
				// lets build the sublinks
				leftNav += this.createSubLinks(i, 'on');
			}			
		} else {
			// determining if there's a second level

			if ((sNav[i].subNav != null) && (sNav[i].link == '')) {
				leftNav += '<a href="javascript:leftNav.showSideNav(\'' + i + '\')" id="Link' + i + '" class="leftNav">' + sNav[i].name + '</a>';
			} else {
				leftNav += '<a href="';
				if (sNav[i].target == '') {
					leftNav += leftNavInfo.jsonObject.global[0].siteURL;
				}
				leftNav += sNav[i].link + '" id="Link' + i + '" class="leftNav">' + sNav[i].name + '</a>';
			}
			
			// determining if there's a second level
			if (sNav[i].subNav != null) {
				// lets build the sublinks
				leftNav += this.createSubLinks(i, 'off');
			}
		}
	}
	//alert(leftNavInfo.subNavCounter);
	document.getElementById(leftNavInfo.leftNavDiv).innerHTML = leftNav;

	if (thisNavItem != null) {
		this.changeLink(thisNavItem);
	}
}

leftNav.prototype.createSubLinks = function(i, displayVar){
	var sNav = leftNavInfo.jsonObject.nav;
	var subLinks = '';
	
	subLinks += '<div class="leftNavDiv" id="nav' + i + '" ';
	if (displayVar == 'off') {
		subLinks += 'style="display: none;"';
	}
	subLinks += '>';
	//leftNavInfo.subSection
	for (var t = 0; t < sNav[i].subNav.length; t++) {
		subLinks += '<a';
		// determine selected state
		if (leftNavInfo.subSection == sNav[i].subNav[t].name) {
			subLinks += ' class="select"';
		}
		subLinks += ' href="';
		if (sNav[i].subNav[t].target == '') {
			subLinks += leftNavInfo.jsonObject.global[0].siteURL;
		}
		subLinks += sNav[i].subNav[t].link + '">' + sNav[i].subNav[t].name + '</a>';
	}
	subLinks += '</div>';
	
	return subLinks;
}

leftNav.prototype.showSideNav = function(divnumber) {
	
	var navLink = document.getElementsByTagName('a');
	var navCounter = 0;
	
	for(var no = 0; no < navLink.length; no++){
		if(navLink[no].className=='leftNav'){
			navCounter++;
		}
	}
	
	for (var i = 0; i < (navCounter + 1); i++) {
		
		if (document.getElementById('nav' + i)) {
			var thisNavDiv = document.getElementById('nav' + i);
			
			if (i != divnumber) {
				if (thisNavDiv.style.display == '') {
					this.revertLink(i);
					if (leftNavInfo.effect == 'yes') {
						new Effect.SlideUp('nav' + i, { queue: 'front' });
					} else {
						thisNavDiv.style.display = 'none';
					}
				}
			} else {
				if (thisNavDiv.style.display == '') {
					this.revertLink(i);
					if (leftNavInfo.effect == 'yes') {
						new Effect.SlideUp('nav' + i, { queue: 'front' });
					} else {
						thisNavDiv.style.display = 'none';
					}
				} else {
					this.changeLink(i);
					if (leftNavInfo.effect == 'yes') {
						new Effect.SlideDown('nav' + i, { queue: 'end' });
					} else {
						thisNavDiv.style.display = '';
					}
				}
			}
		} /*else {
			if (i != divnumber) {
				this.revertLink(i);
			} else {
				if (thisNavDiv.style.display == '') {
					this.revertLink(i);
				} else {
					this.changeLink(i);
				}
			}
		}*/
	}
}

leftNav.prototype.changeLink = function(linkNum){
	thisLink = document.getElementById('Link' + linkNum);
	thisLink.style.cssText = "background: url('" + brand.returnServerURL() + "images/nav/leftNav_open.gif') no-repeat 0px 1px; font-weight: bold;"; 
}

leftNav.prototype.revertLink = function (linkNum){
	thisLink = document.getElementById('Link' + linkNum);
	thisLink.style.cssText = "background: url('" + brand.returnServerURL() + "images/nav/leftNav.gif') no-repeat 0px 1px;; font-weight: normal;"; 
}
