var host = "http://" + document.location.host;
var dev = false;
// hack
if (host == 'http://192.168.0.6') {
	host += "/healthcomm";
	dev = true;
}

function initMenu() {
/*
since WP assigns ids for pages  and not string reps, this will be different eveytime. yay.

kind of a fix - create the wp page and store the id in one of the vars below
when the page loads, loop through the a tags and if the rel attribute matches
set the page id.

It's still not entirely dynamic but its better
*/

	var loc  = document.location.toString();
	// parent nav items
	var boosters = 7;
	var students = 3;
	var alumni = 4;
	var share = 5;
	var resources = 6;
	var contact =8;
	
	// child nav items
	var boosters_1 = 9;
	var boosters_2 = 10;
	var students_1 = 11;
	var students_2 = 12;
	var students_3 = 13;
	var alumni_1 = 14;
	var alumni_2 = 15;
	var share_1 = 16;
	var share_2 = 17;
	
	
	if (!document.getElementsByTagName) return;
	
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++){
		var anchor = anchors[i];
	
		if (anchor.getAttribute("href")){
			switch(anchor.getAttribute("rel")) {	
			// parents items
				case "boosters":
					anchor.setAttribute("href", host+"/?page_id="+boosters);
					break;	
				case "students":
					anchor.setAttribute("href", host+"/?page_id="+students);
					break;	
				case "alumni":
					anchor.setAttribute("href", host+"/?page_id="+alumni);
					break;	
				case "share":
					anchor.setAttribute("href", host+"/?page_id="+share);
					break;	
				case "resources":
					anchor.setAttribute("href", host+"/?page_id="+resources);
					break;	
				case "contact":
					anchor.setAttribute("href", host+"/?page_id="+contact);
					break;	
			// child items
				case "boosters_1":
					anchor.setAttribute("href", host+"/?page_id="+boosters_1);
					break;	
				case "boosters_2":
					anchor.setAttribute("href", host+"/?page_id="+boosters_2);
					break;	
				case "students_1":
					anchor.setAttribute("href", host+"/?page_id="+students_1);
					break;	
				case "students_2":
					anchor.setAttribute("href", host+"/?page_id="+students_2);
					break;						
				case "students_3":
					anchor.setAttribute("href", host+"/?page_id="+students_3);
					break;						
				case "alumni_1":
					anchor.setAttribute("href", host+"/?page_id="+alumni_1);
					break;	
				case "alumni_2":
					anchor.setAttribute("href", host+"/?page_id="+alumni_2);
					break;						
				case "share_1":
					anchor.setAttribute("href", host+"/?page_id="+share_1);
					break;	
				case "share_2":
					anchor.setAttribute("href", host+"/?page_id="+share_2);
					break;						
	
			}
			
			
			
		}
	}
	
	// get the id to see what page we're on and highlight the appropriate nav item
	var id = parseInt(loc.split('=')[1]);
	
	if (isNaN(id)) {
		id = -1;
	}


	switch (id) {
		case boosters:
			document.getElementById('boosters').firstChild.className = 'active';
			document.getElementById('footer_boosters').firstChild.className = 'active';
			break;
		case boosters_1:
			document.getElementById('boosters').firstChild.className = 'active';
			document.getElementById('boosters_1').firstChild.className = 'active';
			document.getElementById('footer_boosters').firstChild.className = 'active';
			break;
		case boosters_2:
			document.getElementById('boosters').firstChild.className = 'active';
			document.getElementById('boosters_2').firstChild.className = 'active';
			document.getElementById('footer_boosters').firstChild.className = 'active';
			break;
		case students:
			document.getElementById('students').firstChild.className = 'active';
			document.getElementById('footer_students').firstChild.className = 'active';
			break;			
		case students_1:
			document.getElementById('students').firstChild.className = 'active';
			document.getElementById('students_1').firstChild.className = 'active';
			document.getElementById('footer_students').firstChild.className = 'active';
			break;
		case students_2:
			document.getElementById('students').firstChild.className = 'active';
			document.getElementById('students_2').firstChild.className = 'active';
			document.getElementById('footer_students').firstChild.className = 'active';
			break;
		case students_3:
			document.getElementById('students').firstChild.className = 'active';
			document.getElementById('students_3').firstChild.className = 'active';
			document.getElementById('footer_students').firstChild.className = 'active';
			break;
		case alumni:
			document.getElementById('alumni').firstChild.className = 'active';
			document.getElementById('footer_alumni').firstChild.className = 'active';
			break;			
		case alumni_1:
			document.getElementById('alumni').firstChild.className = 'active';
			document.getElementById('alumni_1').firstChild.className = 'active';
			document.getElementById('footer_alumni').firstChild.className = 'active';
			break;
		case alumni_2:
			document.getElementById('alumni').firstChild.className = 'active';
			document.getElementById('alumni_2').firstChild.className = 'active';
			document.getElementById('footer_alumni').firstChild.className = 'active';
			break;
		case share:
			document.getElementById('share').firstChild.className = 'active';
			document.getElementById('footer_share').firstChild.className = 'active';
			break;				
		case share_1:
			document.getElementById('share').firstChild.className = 'active';
			document.getElementById('share_1').firstChild.className = 'active';
			document.getElementById('footer_share').firstChild.className = 'active';
			break;		
		case share_2:
			document.getElementById('share').firstChild.className = 'active';
			document.getElementById('share_2').firstChild.className = 'active';
			document.getElementById('footer_share').firstChild.className = 'active';
			break;
		case resources:
			document.getElementById('resources').firstChild.className = 'active';
			document.getElementById('footer_resources').firstChild.className = 'active';
			document.getElementById('SideBarContainer').style.display = 'none';
			break;
		case contact:
			document.getElementById('contact').firstChild.className = 'active';
			document.getElementById('footer_contact').firstChild.className = 'active';
			//document.getElementById('SideBarContainer').style.display = 'none';
			break;
		
		// if someone monkeys with the qString and there is no case go back to the start	
		default:
			//document.location = host;
			break;
	}
	
}