startList = function() {
  if (document.all&&document.getElementById) {
    navRoot = document.getElementById("menu");
    for (i=0; i<navRoot.childNodes.length; i++) {
      node = navRoot.childNodes[i];
      if (node.nodeName=="LI") {
        node.onmouseover=function() {
          this.className+=" over";
        }
        node.onmouseout=function() {
          this.className=this.className.replace(" over", "");
        }
      }
    }
  }
}

init = function(){
	// stars
	var l = $('news').getElementsByTagName('li');
	for(var i=0;i<l.length;i++){
		var s = l[i].getElementsByTagName('a');
		for(var j=0;j<s.length;j++){
				Event.observe(s[j],'click',star,false);
		}
	}
	
	// left column h1 links
	var h = $('links').getElementsByTagName('h1');
	for(var i=0;i<h.length;i++){
		var s = h[i].getElementsByTagName('a')[0];
		Event.observe(s,'click',toggleLeftColumn,false);
	}
}
toggleLeftColumn = function(e){
	new Effect.toggle(this.parentNode.nextSibling,'blind');
	//alert(this.parentNode.nextSibling.tagName);
}

star = function(e){
	var t = window.event ? window.event.srcElement : e ? e.target : null;
	if (!t) return;
	// send to db

	// toggle
	var img = document.createElement('img');
	img.src='/images/sm-star_2.gif';
	
	t.style.marginLeft = '-18px';
	t.style.marginTop = '-17px';
	
	var l =t.parentNode.parentNode;
	l.insertBefore(img,t.parentNode);
	
	new Effect.Fade(t, {duration:.3});
}

getNodeValue = function(node, tagName){
	return node.getElementsByTagName(tagName)[0].childNodes[0].nodeValue;
}


/* Talking Broadway */
var tb = {
	xmlDoc:	false,
	list:	false,
	init: function(){
		tb.list = $('talkingBroadway').getElementsByTagName('ul')[0];
		
		if (document.implementation && document.implementation.createDocument){
			tb.xmlDoc = document.implementation.createDocument("", "", null);
			Event.observe(tb.xmlDoc,'load',tb.loadList,false);
		}
		else if (window.ActiveXObject){
			tb.xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
			tb.xmlDoc.onreadystatechange = function(){if (tb.xmlDoc.readyState == 4) tb.loadList()};
		}
		else{
			alert('Your browser can\'t handle this script');
			return;
		}
		tb.xmlDoc.load("/talkingbroadway/tb.xml");		
	},
	loadList: function(){
		var items = tb.xmlDoc.getElementsByTagName('item');
		if(items.length < 1){return;}
		tb.clearList();
		
		for(var i=0;i<items.length;i++){
			new Insertion.Bottom(tb.list, '<li><a href="'+getNodeValue(items[i],'link')+'">'+getNodeValue(items[i],'title')+' '+ getNodeValue(items[i],'pubDate') +'</a></li>');
		}
	},
	clearList: function(){
		if(!tb.list){return;}
		while(tb.list.childNodes[0]){ tb.list.removeChild(tb.list.childNodes[0]); }
	}
}


Event.observe(window,'load',startList,false);
Event.observe(window,'load',init,false);

Event.observe(window,'load',tb.init,false);
