var orchestraMenu;
var names = new Array();
var urls = new Array();
var leftMenuTxt = new String("<div style='text-align: center;'><b>2007/2008</b></div><br>");
var leftOffsetHeight = 100;

// ###########################
// ######  Change menu structure below
// ###########################

	MenuTopic('About');
		MenuItem('Home', 'index.html');
		MenuItem('Eckstein Orchestras', 'orchestras.html');
		MenuItem('Recent Repertoire', 'repertoire.html');
		MenuItem('Volunteer Opportunities', 'volunteer.html');
	MenuTopic('Calendar');
		MenuItem('2007/2008', 'calendar_all.html');
	MenuTopic('Recent News');
		MenuItem('10/4/2007 Newsletter', 'news/10012007.pdf');
	MenuTopic('Forms/Event Info');
		MenuItem('Concert Attire', 'concertattire.html');
		MenuItem('Event Info/Forms', 'eventinfo.html');
	MenuTopic('Techniques');
		MenuItem('Intonation', 'playintune.html');;
		MenuItem('Spiccato', 'spiccato.html');;
		MenuItem('Vibrato', 'vibrato.html');

// ###########################
// ######  End menu structure
// ###########################


// ###########################
// ######  Change left menu structure below
// ######  Syntax is: LeftMenuItem("First Row Text", "Second Row Text", "link");
// ###########################

	LeftMenuItem("April 21-25", "5th Grade Interviews", "calendar_all.html");
	LeftMenuItem("May 12-16", "Musical Rehearsals", "musical.html");
	LeftMenuItem("May 16/17", "Musical", "calendar_all.html#musical");
	LeftMenuItem("May 20", "Junior/Wedgewood Concert", "calendar_all.html#junior_concert");
	LeftMenuItem("June 12", "Spring Concert", "calendar_all.html#spring_concert");
	
// ###########################
// ######  End left menu
// ###########################

function myonload() {
}

function adjustcontent() {
  // Add img tag at top 
  var imgdiv = document.getElementById('logo');
  var wrap = document.getElementById('container');
  if (imgdiv) {
  } else if (wrap) {
	  imgdiv = document.createElement('div');
	  imgdiv.setAttribute('id','logo');
	  wrap.insertBefore(imgdiv, wrap.childNodes.item(0));
  }
  
	try {
		var content = document.getElementById('content');
		//Detect IE6 and before doesn't display background
		//correctly (block back, doesn't work with png24)
		ieVer = 7;
		if (navigator.appVersion.indexOf("MSIE")!=-1){
			temp=navigator.appVersion.split("MSIE")
			ieVer=parseFloat(temp[1])
		}
		if (content && ieVer >= 7) {
			// non ie or >=7
			content.style.backgroundImage = 'url(images/violin-background.png)';
		}
	} catch (e) {
		alert("Failed to set background\n" + e);
	}
}

function LeftMenuItem(dateTxt, itemTxt, linkTxt) {
	var itemHtml = '<b>' + dateTxt + '</b><br><a href="' + linkTxt + '">&nbsp;' + itemTxt + '</a><br><br>';
	leftMenuTxt = leftMenuTxt + itemHtml;
}

function MenuTopic(txt) {
	names.push(txt);
	urls.push("invalid");
	if (document.all) {
		txt = '<div style="width:170px;">' + txt + "&nbsp;&nbsp;&nbsp;</div>";
	}
	return txt;
}

function MenuItem(txt, url) {
	names.push(txt);
	urls.push(url);
	if (document.all) {
		txt = "<div style='width:160px;'>" + txt + "&nbsp;&nbsp;&nbsp;</div>";
	}
	retVal = [txt, null, null];
	return retVal;
}

var COOL_TREE_FORMAT =
[
//0. left position
	10,
//1. top position
	10,
//2. show +/- buttons
	false,
//3. couple of button images (collapsed/expanded/blank)
	["/img/b.gif", "/img/b.gif", "/img/b.gif"],
//4. size of images (width, height,ident for nodes w/o children)
	[0,0,0],
//5. show folder image
	false,
//6. folder images (closed/opened/document)
	["/img/b.gif", "/img/b.gif", "/img/b.gif"],
//7. size of images (width, height)
	[0,0],
//8. identation for each level [0/*first level*/, 16/*second*/, 32/*third*/,...]
	[4,20],
//9. tree background color ("" - transparent)
	"",
//10. default style for all nodes
	"topMenu",
//11. styles for each level of menu (default style will be used for undefined levels)
	["topMenu", "subMenu"],
//12. true if only one branch can be opened at same time
	true,
//13. item pagging and spacing
	[0,0],
];

function createTheMenu() {
	window.location = "http://ecksteineagles.org/orchestra/";
	// Determine which node will be expanded 
	var menuToExpand = -1;
	var lastTop = 0;
	for (i=0; i<urls.length; i++) {
		if (urls[i] == "invalid") {
			// toplevel
			lastTop = i;
		} else if (document.location.pathname.lastIndexOf(urls[i]) != -1) {
			// have menu, get out.
			menuToExpand = lastTop;
			break;
		}
	}
	orch_menu = new Array();
	curmenu = new Array();
	for (i=0; i<urls.length; i++) {
		if (urls[i] == "invalid") {
			// toplevel
			curmenu = new Array(names[i], null, null);
			if (i == menuToExpand) {
				curmenu.push({format:{expanded:true}});
			}
			orch_menu.push(curmenu);
		} else {
			curmenu.push(new Array(names[i], urls[i], null));
		}
	}
	orchestraMenu = new COOLjsTreePRO("orchestraMenu", orch_menu, COOL_TREE_FORMAT);
	orchestraMenu.init();
	RedrawAllTrees();

	loadLeftPanel();
	loadFooter();
	
	adjustcontent();

	window.onresize = handleResize;
	handleResize();
}

function loadLeftPanel() {
	var html = '<img src="images/ltopper.gif" alt="news" style="vertical-align: bottom;">' +
			   '<div class="leftcontent">' + leftMenuTxt + '</div>';
	var leftdiv = document.getElementById('leftpanel');
	if (leftdiv) {} else {
		leftdiv = document.createElement('div');
		leftdiv.setAttribute('id','leftpanel');
	}
	leftdiv.innerHTML = html;
	document.body.appendChild(leftdiv);
	var c2 = document.getElementById('leftpanel');
	if (c2  && c2.offsetHeight) {
		leftOffsetHeight = c2.offsetHeight;
	}
}
function getW(){
	var w;
	if(document.innerWidth){ 
		w=document.innerWidth;
	} else if(document.documentElement.clientWidth){ 
		w=document.documentElement.clientWidth;
	} else if(document.body){ 
		w=document.body.clientWidth; 
	}
	return w;
}
function handleResize() {
	var cr = document.getElementById('container');
	if (!cr) {/* Get out if not supported or no container */ 
		return;
	}
	if (getW() - cr.offsetLeft > 1000) {
		// max is 1000 pixels
		cr.style.width = "1000px";
	} else if ((getW() - cr.offsetLeft) < 500) {
		// min is 500 pixels
		cr.style.width = "500px";
	} else  {
		cr.style.width = "";
	}
	var c1 = document.getElementById('content');
	var c2 = document.getElementById('leftpanel');
	var c3 = document.getElementById('textend');
	if (c1 && c2 && c3 && c1.offsetHeight && leftOffsetHeight) {
		if (c1.offsetHeight < leftOffsetHeight) {
			// pad right side
			var rheight = (leftOffsetHeight - c1.offsetHeight - 2);
			if (navigator.userAgent.toLowerCase().indexOf("msie") != -1) {
				// add ltopper.gif for IE
				rheight += 32;
			}
			c3.style.height = rheight + "px";
			// ensure left side is still at min value, 32 is for ltopper.gif
			c2.style.height = (leftOffsetHeight-32) + "px";
		} else {
			c3.style.height = "1px";
			c2.style.height = (c1.offsetHeight - 32) + "px";
		}
	}
}
	
function loadFooter() {
	var txt = '<table cellpadding="8"><tr>' +
			  '<td><a href="index.html">Orchestra Home</a></td>' +
	          '<td><a href="http://www.eckstein.seattleschools.org/">&copy; 2007-2008 Eckstein Middle School</a></td>' +
	          '<td><a href="http://www.eckstein.seattleschools.org/cuescobedo/index.htm">Eckstein Band</a></td>' +
			  '<td><a href="mailto:curley@blarg.net">Webmaster</a></td>' +
			  '</tr></table>';
	var wrap = document.getElementById('container');

	var tempdiv = document.createElement('div');
	tempdiv.setAttribute('id','textend');
	// IE gives height to empty divs, fix with this:
	tempdiv.appendChild(document.createComment("IE BUG FIX"));
	if (wrap) {
		wrap.appendChild(tempdiv);
	} else {
		document.body.appendChild(textend);
	}

	var footdiv = document.createElement('div');
	footdiv.setAttribute('id','footer');
	footdiv.innerHTML = txt;
	if (wrap) {
		wrap.appendChild(footdiv);
	} else {
		document.body.appendChild(footdiv);
	}
}

