if ( !steno ) {
	var steno=new Object();
	steno.quotes=new Array();
	steno.hasWindow=false;
	steno.window="";
	steno.alt=false;
}

steno.init=function() {
	var form,list,window,i;
	form=document.getElementById("add-quote");
	steno.form=form;
	
	dojo.event.connect(form,"onsubmit",function(evt) {
		steno.add(evt)
		return false;
	});
	
	list=document.getElementById("conversation");
	steno.list=list;
}

steno.add=function(evt) {
	var speaker=dojo.byId("speaker"),quote=dojo.byId("quote"),li=document.createElement("li"),cite=document.createElement("cite"),bq=document.createElement("blockquote"),a=document.createElement("a");
	
	if ( speaker.value.length < 1 || quote.value.length < 1 ) {
		alert("Can't add an empty quote.  Please try again.");
		return;
	}
	
	dojo.dom.textContent(cite,speaker.value);
	dojo.dom.textContent(bq,quote.value);
	
	a.appendChild(document.createTextNode("x"));
	a.setAttribute("href","#add-quote");
	a.setAttribute("class","x");
	
	dojo.event.connect(a,"onclick",function(evt) {
	   steno.x(evt)
	}) 
	
	li.appendChild(a);
	li.appendChild(cite);
	li.appendChild(bq);
	
	steno.list.insertBefore(li,steno.list.firstChild);

	steno.quotes[steno.quotes.length]=new Object({'speaker':speaker,'quote':quote});

	steno.alternate(steno.list);
	
	quote.value="";
	speaker.value="";
	speaker.focus();
//	steno.updateWindow();
}

steno.openWindow=function() {
	var stenoWindow=window.open("remote.html",'stenoWindow','width=800,height=600,resizable=yes,scrollbars=yes,toolbar=no');
	steno.window=stenoWindow;	
	steno.hasWindow=true;
//	steno.updateWindow();
}

steno.updateWindow=function() {
	if ( steno.hasWindow ) {
		var w=steno.window, list=dojo.byId("conversation");items=list.getElementsByTagName("li"),remoteList=w.document.getElementById("conversation");
	dojo.dom.removeChildren(remoteList);
	
		for ( i=0;i<items.length;i++ ) {
			remoteList.appendChild(items[i].cloneNode(true));
		}	
	}
}

steno.alternate=function(list) {
	var i,items=list.getElementsByTagName("li"),item;
	alt=0;
	for ( i=0;i<items.length;i++) {
		item=items[i];
		if ( alt<1 ) {
			item.className="";
			alt=1;
		} else {
			item.className="alt";
			alt=0;
		}
	}
}

steno.x=function(evt) {
    var a=evt.currentTarget;
    var li=a.parentNode;
    li.parentNode.removeChild(li);
}

steno.n=function() {}

steno.openPrint=function() {
	var printW=window.open('print.html','printW','width=800,height=600');
}

dojo.event.connect(window,"onload",steno.init);

