//Unique pop-up for personal supports

function new_window(url_of_window) {
	newWindowObj = window.open (url_of_window,'asl_videos','width=290,height=430,scrollbars=yes,resizable=yes');
	newWindowObj.focus();
}

function init(){

	menuItems = document.getElementsByTagName("UL");
	for(var i=0; i< menuItems.length;i++ ){

		if(menuItems[i].className =='sub-nav') {
			menuItems[i].style.display='none';
		}
	}
}

function formatLeftNavReal(elementPath) {
		var elementPath = window.location.href;
		elementPath = elementPath.substring(7,elementPath.length);			
		elementPath = elementPath.substring(elementPath.indexOf('/'), elementPath.length);

		if(elementPath.indexOf("mediagallery") == -1 &&
			elementPath.lastIndexOf('/') == elementPath.length-1){
			elementPath = elementPath + "index.html";
		}

		if(elementPath.indexOf("/mediagallery") != -1){
			var context;
			var parameterName = "context=";
			// Find the beginning of the string
			begin = elementPath.indexOf ( parameterName );
			// If the parameter name is not found, skip it, otherwise return the value
			if ( begin != -1 ) {
				// Add the length (integer) to the beginning
				begin += parameterName.length;
				// Multiple parameters are separated by the "&" sign
				end = elementPath.indexOf ( "&" , begin );
				if ( end == -1 ) {
					end = elementPath.length;
				}
				
				context = elementPath.substring ( begin, end ) ;
			}
                  var pathPrefix = elementPath.substring(elementPath.indexOf("owner=")+6,elementPath.length);
                  elementPath = pathPrefix + "photos/" + context + ".html";
		}
	


		if(elementPath !=null && elementPath.length>1) {
			init();
		}

		mediagalleryElement = document.getElementById("ID_media_gallery");
		if(elementPath=="" && mediagalleryElement !=null ){
			toggleNav(mediagalleryElement);
		}

		// get rid of the leading / and last .html
		var path = elementPath.substring(1, elementPath.length-5);

		var elementList = path.split("/");

		var activeElementID;
		var activeElement;
		var headerActiveElement;
		if (elementList.length == 1) {
			// root level element, no expansion.
			if(elementList[0] == "index"){
				activeElement = document.getElementById("ID_home");
			} else {
				activeElement = document.getElementById("ID_" + elementList[0]);
			}
		} else {
			var i =0 ;
			var slen = elementList.length-1;
			while (i < slen){
				if(elementList[i] =='speeches' || elementList[i] =='audio' || 
					elementList[i]=='photos' || elementList[i]=='events' || elementList[i] =='enewsletters'){
					expandElement = document.getElementById("ID_" + elementList[i]);
					if(expandElement!=null && expandElement.className!=null &&
						(expandElement.className.indexOf('collapsed')>=0 || 
						 expandElement.className.indexOf('expanded')>=0 )){
						toggleNav(expandElement);
					}


					if (elementList[i+1] != 'index' && elementList[i+1].length==4){
						expandElement = document.getElementById("ID_"+elementList[i]+ '_'+elementList[i+1]);
						toggleNav(expandElement);
						activeElementID = elementList[i]+ '_'+elementList[i+1] + '_' + elementList[i+2];
						i=slen;
					}
					i=slen;
				} else {
				expandElement = document.getElementById("ID_" + elementList[i]);
				if(expandElement!=null && expandElement.className!=null &&
					(expandElement.className.indexOf('collapsed')>=0 || 
					 expandElement.className.indexOf('expanded')>=0 )){
					toggleNav(expandElement);
				}
				if(elementList[i] == 'media_gallery'){
					expandElement = document.getElementById("ID_"+elementList[i-1]);
					toggleNav(expandElement);
				}
				i++;
				}
			}
			// if the last element is index, then active element id should be 
			// second to last.
			if(activeElementID ==null){
				if(elementList[0]=='residents' || elementList[0]=='business'){
					activeElementID=elementList[0];
				} else {
					activeElementID = elementList[elementList.length-1];
				}
			}
			if(activeElementID=="index"){
				activeElementID = elementList[elementList.length-2];
			}
			if(activeElementID=="current"){
				activeElementID = elementList[elementList.length-3];				
			}

			activeElement = document.getElementById("ID_"+activeElementID);
			headerActiveElement=document.getElementById("HEADER_"+elementList[0]);
		}
		if(activeElement!=null){
			if(activeElement.className ==null) {
				activeElement.className="active";
			} else {
				activeElement.className = activeElement.className + " active"; 
			}
		}

		if(headerActiveElement!=null){
			headerActiveElement.className="active";
		} else {
			if(document.getElementById("search-scope") !=null) {
				headerActiveElement = document.getElementById("HEADER_ministries");
				if(headerActiveElement!=null) {
					headerActiveElement.className="active";
				}
			}
		}

}
function formatLeftNav(elementPath ){
		initFontSize();
		externalLinks();

}

function toggleNav(node) {
	// Need to traverse 2 nodes to deal with whitespace that is treated as a node
	if (node.nextSibling.nextSibling.style.display == 'none') {
		
		/* Need to check and see if this is the 'Reports and Publications' link in the Premier's left nav. We need to do this becuase the 'Reports and Publications' link doesn't go to a new page, so the left nav doesn't get re-rendered and any open sub-menus don't get closed. Therefore, we handle this link below by hiding any open sub-menus if the 'Reports and Publications' link is clicked. */
		if (node.id == "ID_ReportsAndPublications") { // If it's the 'Reports And Publications' link
			var lists = document.getElementById("primary").getElementsByTagName("ul"); // Find all lists elements in the primary nav
			var links = document.getElementById("primary").getElementsByTagName("a"); // Find all links in the primary nav
			for (i=0;i<lists.length;i++) {
				if (lists[i].className == "sub-nav") { // get all sub-nav lists
					lists[i].style.display = "none"; // hide them
				}
			}
			for (i=0;i<links.length;i++) {
				if (links[i].className == "expanded") { // get all sub-nav links (unactive)
					links[i].className = "collapsed"; // collapse them
				}
				else if (links[i].className == "expanded active") { // get all sub-nav links (active)
					links[i].className = "collapsed active"; // collapse them
				}
			}
		} 
		
		node.className = "expanded";
		node.nextSibling.nextSibling.style.display = 'block';
	}
	else if (node.nextSibling.nextSibling.style.display == 'block') {
		node.className = "collapsed";
		node.nextSibling.nextSibling.style.display = 'none';
	}
}

