



$(document).ready(function() {
  showCurrentSub('left');
});


function showCurrentSub(id) {
	// identify which top level link in #id is current page and show sub nav
	// or which sub level link in #id is current page and show its nav
	
	var here = findHere();
	$('#'+id).find('a').each(function() {
		// is this link the current page?
		// do some prep on the link
		// split the protocol off
		var there = $(this).attr('href');
		there = there.toLowerCase();
		// strip any #<name> from the end
		there = there.replace(new RegExp("#.*"),"");        
		// strip /index.htm or last / from the end
		there = there.replace(new RegExp("/index\.htm"),"");
		there = there.replace(new RegExp("/$"),"");      
		// split the domain name from the front
		there = there.substring(there.indexOf('/'));		

		if (pathMatch(here, there, 1, 1)) {
			// this is the page, if we have subnav then show it, if we are sub nav show us
			$(this).parent().children('ul').slideDown(500);
			$(this).parent().parent().children('ul').slideDown(500);			
		}
	})
}


function findHere() {
    var here = "" + window.location;
    // strip any #<name> from the end
    here = here.replace(new RegExp("#.*"),"");  
    // strip /index.htm or last / from the end
    here = here.replace(new RegExp("/index\.htm"),"");
    here = here.replace(new RegExp("/$"),"");
    // split the protocol off
    here = here.toLowerCase().split('//')[1];
    // split the domain name off
    here = here.substring(here.indexOf('/'));
		return here;
}

function pathMatch(here, there, folderMatch, n) {
  if (here==there) {
    if (((here=='') && (n==1)) || (here!='')) {
      return 1;
    }
    else {
      return 0;
    }  
  }
  else if ((folderMatch == 1) && (here != '')) {
    here  = here.substring(0,here.lastIndexOf('/'));
    return pathMatch(here, there, folderMatch, n+1);
  }
	return 0;
}

function queryVal(key) {
	var params = window.location.search.substring(1);
	params = params.split('&');
	for (i=0;i<params.length;i++) {
		var p = params[i].split('=');
		if (p[0] == key) {
			return p[1];
		}
	}
	return 0;
}


