/*

function _parseNav(loc) {
    // parse current location...
    if(!loc) {return false;}
    var currLocation = loc.toString().split('/');
    currLocation = currLocation[(currLocation.length-1)];
    // split the raw string
    var toNav = currLocation.split('_');
    var nav = [];
    for(i=0; i<toNav.length; i++) {
        // push all integer values to the navigation array
        var add = true;
        if(parseInt(toNav[i])!=0 || toNav[i]=='0') {
           // if(toNav[i].indexOf('.')!=-1) {add = false;}
            if(toNav[i].length > 1 && parseInt(toNav[i]).toString()=='NaN') {add = false;}
            if(add) {nav.push(toNav[i]);}
        }
    }
	nav = currLocation;
    return nav;
}

$().ready(function() {
    // grab current location to identify active navigation element
    var currNav = _parseNav(location.href);
	alert("currNav: "+ currNav);
	// loop through all navigation elements in navigation box
    $('#Navigation a').each(function(){
        // get the navigation array for each element
        var _cloc = _parseNav($(this).attr("href"));
        if(_cloc) {
            // compare
            if(_cloc[0]!=currNav[0]) {
                // hide all inactive elements
                if($('ul',this.parentNode).size()>0) {$('ul',this.parentNode).hide();}
            } else if((_cloc[1]==currNav[1] && _cloc[2]==currNav[2]) 
                || (_cloc[1]==currNav[1] && _cloc[2]==1)) {
                    // highlight...
                    $(this).addClass('active');
             }
         }
    });
    $('#Footer a').each(function(){
        // get the navigation array for each element
        var _cloc = _parseNav($(this).attr("href"));
        // highlight
        if(_cloc[0]==currNav[0] && _cloc[1]==currNav[1]) {
            $(this).addClass('active');
        }
    });
    
    $('.contentnav a').each(function(){
        // get the navigation array for each element
        var _cloc = _parseNav($(this).attr("href"));
        // highlight
        if(_cloc.length==3) {
            if(_cloc[2]==currNav[2]) {
                $(this).addClass('active');
            }
        } else if(_cloc.length==2) {
            if(_cloc[1]==currNav[1]) {
                $(this).addClass('active');
            }
        }
    });
    
});
*/

function getFileName(loc) {
	if(!loc) {return false;}
	var currentLocation_array = loc.toString().split('/');
	var file_str = (currentLocation_array[(currentLocation_array.length - 2)] + "/" + currentLocation_array[(currentLocation_array.length - 1)]).toString();;
	//alert ("file: "+ file_str);
	return file_str;
}
function getFolderNames(loc){
	if(!loc) {return false;}
	var currentLocation_array = loc.toString().split('/');
	var folder_str = (currentLocation_array[(currentLocation_array.length - 3)] + "/" + currentLocation_array[(currentLocation_array.length - 2)]).toString();
	//alert ("file: "+ file_str);
	return folder_str;
}

$().ready(function() {
	/**
	* manipulate the navigation to hilite the current page:
	*/
	
	var currentNavItem = getFileName(location.href);
	var currentFolderNames = getFolderNames(location.href);
	//  make current element active:
	var link_found = 0;
	$('#Navigation a').each(function(){
        // get the filename each element
		var curr_href = $(this).attr("href");
        var curr_loc = getFileName(curr_href);
		var curr_folder = getFolderNames(curr_href);
        if(curr_loc) {
            // compare each link with current file
            if(curr_loc == currentNavItem) {
				// link to current file found, add css-class:
				$(this).addClass('active');
				link_found++;
				if($('ul',this.parentNode).size()>0) {
					$('ul',this.parentNode).show();
					$('ul',this.parentNode).addClass('active');
				} else if($('ul',this.parentNode.parentNode.parentNode).size()>0) {
					// show all links belonging to site section:
					$('ul',this.parentNode.parentNode.parentNode).show();
					// highlight the main link to site section:
					$('a + ul',this.parentNode.parentNode.parentNode).parent().children().eq(0).addClass('active');
				}
			}
			else {
				//hide all sub-elements:
				if($('ul',this.parentNode).size()>0) {
					$('ul',this.parentNode).hide();
				}	
			}
		}
    });
	// fallback, if current page is not in main navigation check the folder structure and hilite the 'parent' link
	if (link_found < 1) {
		$('#Navigation a').each(function(){
			var curr_href = $(this).attr("href");
        	var curr_loc = getFileName(curr_href);
			var curr_folder = getFolderNames(curr_href);
			if(curr_loc) {
				// check folder names:
				//var indexF = currentFolderNames.indexOf(curr_folder);
				if (currentFolderNames.indexOf(curr_folder) >= 0) {
					// folder string was found
					// check for index page in directory:
					if (curr_href.indexOf("index.htm") >= 0) {
						// add css-class to index link:
						$(this).addClass('active');
					}
					if($('ul',this.parentNode).size()>0) {
						$('ul',this.parentNode).show();
						$('ul',this.parentNode).addClass('active');
					} else if($('ul',this.parentNode.parentNode.parentNode).size()>0) {
						// show all links belonging to site section:
						$('ul',this.parentNode.parentNode.parentNode).show();
						//highlight the main link to site section:
						$('a + ul',this.parentNode.parentNode.parentNode).parent().children().eq(0).addClass('active');
					}
				}
			}
		});
	}
	$('#Footer a').each(function(){
        // get the filename each element
		var curr_href = $(this).attr("href");
        var curr_loc = getFileName(curr_href);
		var curr_folder = getFolderNames(curr_href);
		
        if(curr_loc) {
            // compare
            if(curr_loc == currentNavItem) {
				// link to current file found:
				$(this).addClass('active');
			}
		}
    });
	$('.contentnav a').each(function(){
        // get the filename each element
		var curr_href = $(this).attr("href");
        var curr_loc = getFileName(curr_href);
		var curr_folder = getFolderNames(curr_href);
		
        if(curr_loc) {
            // compare
            if(curr_loc == currentNavItem) {
				// link to current file found:
				$(this).addClass('active');
			}
		}
    });
});
