

axe.AudioSidePanel = function(inits){
	
	axe.AudioSidePanel.superclass.constructor.call(this, inits);
	this.container = document.createElement("div");
	this.container.className = "sideContainer";
	this.HTML.appendChild(this.container);

}
YAHOO.lang.extend(axe.AudioSidePanel,axe.SidePanel);
axe.AudioSidePanel.prototype.refreshView = function(){
	this.HTML.removeChild(this.container);
	this.container = document.createElement("div");
	this.container.className = "sideContainer";
	this.HTML.appendChild(this.container);		
	tags = this.panel.DOM.documentElement.childNodes;

	for (i in tags){
		if ((tags[i])&&(tags[i].getAttribute)){
			time = tags[i].getAttribute("absolute");
	
			timeTag = document.createElement("div");
			timeTag.appendChild(document.createTextNode(tags[i].getAttribute("xml:id") + " : " + time));
			YAHOO.util.Event.addListener(timeTag,"click",function(e,obj){
				
				linkObj = {obj: obj}
				axe.tagClicked.fire(linkObj);
			},tags[i]);
			this.container.appendChild(timeTag);
			}

	}
	
}




axe.AudioPanel = function(inits){
	axe.AudioPanel.superclass.constructor.call(this, inits);	
	
	this.wrapper = document.createElement("div");	

	this.audioBox = document.createElement("div");
	this.audioBox.className="audioBox";
	this.wrapper.className="audioWrapper";	
	this.wrapper.appendChild(this.audioBox);
	this.content.HTML.appendChild(this.wrapper);
	this.objectHTML = document.createElement("object");
	this.objectHTML.id=YAHOO.util.Dom.generateId(this,"audioObj");
	this.objectHTML.className = "audioObject";
	this.objectHTML.width="400";
	this.objectHTML.height="390";
	this.objectHTML.setAttribute("classid","clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B");
	this.objectHTML.setAttribute("codebase","http://www.apple.com/qtactivex/qtplugin.cab");
	this.DOM = inits["DOM"];
	
	
	
	this.movieParam = document.createElement("param");
	this.movieParam.name="src";
	this.movieParam.value=this.url;

	this.objectHTML.appendChild(this.movieParam);
	
	this.autoplayParam = document.createElement("param");
	this.autoplayParam.name="autoplay";
	this.autoplayParam.value="false";
	this.objectHTML.appendChild(this.autoplayParam);
	
	this.embedHTML = document.createElement("embed");
	this.embedHTML.name=this.objectHTML.id;
	this.embedHTML.setAttribute("autoplay","false");
	this.embedHTML.src=this.url;
	this.embedHTML.setAttribute("enablejavascript","true");
	this.embedHTML.setAttribute("plugsinspage","http://www.apple.com/quicktime/download");
	this.embedHTML.type="video/quicktime"
	this.embedHTML.width="400";
	this.embedHTML.height="20";
	this.objectHTML.appendChild(this.embedHTML);
	this.audioBox.appendChild(this.objectHTML);
	this.embedHTML.className = "audioEmbed"
	
	sideinits = {sidebar: this.desktop.sideBar, panel: this};
	this.sidePanel = new axe.AudioSidePanel(sideinits);
	this.desktop.sideBar.addPanel(this.sidePanel);
	this.controls = new axe.AudioControls(this);
	this.audioBox.appendChild(this.controls.HTML);	
	
	this.viewButton = new axe.panelButton("./theme/images/icon_xml.png","view",this);
this.header.HTML.insertBefore(this.viewButton.HTML,this.closeButton.HTML);
YAHOO.util.Event.addListener(this.viewButton.HTML,"click",this.showXML,this);
}

YAHOO.lang.extend(axe.AudioPanel,axe.panel);

axe.AudioPanel.prototype.hideObject = function(){
	this.objectHTML.style.display="none";
}
axe.AudioPanel.prototype.showObject = function(){
	this.objectHTML.style.display="block";
}
axe.AudioPanel.prototype.constructXML = function(panel){

	panel.DOM.documentElement.setAttribute("origin",panel.DOM.documentElement.firstChild.getAttribute("xml:id"));
	xmlstring = (XMLtoString(panel.DOM.documentElement));
	return xmlstring;
}
axe.AudioPanel.prototype.showXML=function(e,obj){
	
 	xmlout = window.open('','xmlout',''); 
	txt = obj.constructXML(obj);
	html = "<textarea rows=500 cols=200>"+txt+"</textarea>";
	xmlout.document.write(html);
	xmlout.document.close();

} 


axe.AudioControls = function(panel){
	this.id = YAHOO.util.Dom.generateId(this, "audioControls");
	this.panel = panel;
	this.HTML = document.createElement("div");
	this.HTML.id = this.id;
	this.HTML.className = "audioControls";
	this.tags = [];
	this.lastTime = null;
	this.globalPlayButton = document.createElement("span");
		this.globalPlayButton.className = "audioButton";
	this.gpbImg = document.createElement("img");
	this.gpbImg.src = "./theme/images/icon_audio_play.png";
this.globalPlayButton.appendChild(this.gpbImg);
	
	
	//this.globalPlayButton.appendChild(document.createTextNode("Play "));
	this.HTML.appendChild(this.globalPlayButton);
	YAHOO.util.Event.addListener(this.globalPlayButton,"click",function(e,obj){
		
		eval("document." + obj.panel.objectHTML.id + ".Play();")
	},this);
		
		this.globalPauseButton = document.createElement("span");
			this.globalPauseButton.className = "audioButton";
		this.gpbImg = document.createElement("img");
	this.gpbImg.src = "./theme/images/icon_audio_pause.png";
this.globalPauseButton.appendChild(this.gpbImg);
	
	//this.globalPauseButton.appendChild(document.createTextNode("Pause "));
	this.HTML.appendChild(this.globalPauseButton);
	YAHOO.util.Event.addListener(this.globalPauseButton,"click",function(e,obj){
		
		eval("document." + obj.panel.objectHTML.id + ".Stop();")
	},this);
	this.globalRecordButton = new axe.GlobalRecordButton(this);

	this.HTML.appendChild(this.globalRecordButton.HTML);

	this.newTag();
}
axe.AudioControls.prototype.saveTag=function(obj){
	phpCall("saveAudioTag.php","?tagName="+obj["tagName"]+"&id="+id+"&offset="+obj["offset"]+"&length="+obj["length"],"GET");	
}
axe.AudioControls.prototype.newTag=function(){

	tag = new axe.AudioTag(this);
	this.HTML.appendChild(tag.HTML);
	this.tags[tag.id] = tag;
	this.lastTime = tag;
	return tag;
	
}
axe.GlobalRecordButton = function(loc){
	this.loc = loc;
	this.HTML = document.createElement("span");
	this.globRecButton = document.createElement("img");
	this.globRecButton.className = "audioButton;"
	this.globRecButton.src = "./theme/images/icon_audio_record.png";
	this.HTML.appendChild(this.globRecButton);
	//this.HTML.appendChild(document.createTextNode("Record"));
	YAHOO.util.Event.addListener(this.HTML,"click",this.recordAndNewTag,this.loc.panel); 
}
axe.GlobalRecordButton.prototype.recordAndNewTag=function(e,obj){
		controls = obj.controls;
		
		controls.lastTime.RecordTime(e,controls.lastTime);
}
axe.AudioTag = function(loc){
	
	this.id = YAHOO.util.Dom.generateId(this,"audioTag");
	this.XML = null;
	this.loc = loc;
	this.HTML = document.createElement("div");
	this.HTML.id = this.id;
	this.HTML.className ="audioTag";
	this.time = document.createElement("input");
	this.time.type="text";
	this.time.width='5';
	this.time.id = this.id+"_timeBox";
	this.recordButton = document.createElement("span");
	this.recordButton.className = "audioButton";
	this.rbImg = document.createElement("img");
	this.rbImg.src="./theme/images/icon_audio_record.png";
	//this.recordButton.appendChild(document.createTextNode("record"));
	this.recordButton.appendChild(this.rbImg);
	
	
	
	this.deleteButton = document.createElement("span");
	this.deleteButton.className = "audioButton";
		this.delImg = document.createElement("img");
	this.delImg.src="./theme/images/icon_audio_delete.png";
	//this.recordButton.appendChild(document.createTextNode("record"));
	this.deleteButton.appendChild(this.delImg);
	
	
	this.playButton = document.createElement("span");
	//this.playButton.appendChild(document.createTextNode("Play From Here"));
	this.playButton.className = "audioButton";
		this.pImg = document.createElement("img");
	this.pImg.src="./theme/images/icon_audio_play.png";
	//this.recordButton.appendChild(document.createTextNode("record"));
	this.playButton.appendChild(this.pImg);
	
	this.HTML.appendChild(this.time);
	this.HTML.appendChild(this.recordButton);
	this.HTML.appendChild(this.deleteButton);
	this.HTML.appendChild(this.playButton);
	YAHOO.util.Event.addListener(this.recordButton,"click",this.RecordTime,this);
	YAHOO.util.Event.addListener(this.playButton,"click",this.PlayFrom,this);
	YAHOO.util.Event.addListener(this.deleteButton,"click",this.remove,this);
}	
	

axe.AudioTag.prototype.remove = function(e,obj){
	// Remove obj.loc.tags[obj.id]
	//obj.locs.tags[obj.id]=null;
	//----
	if (obj.time.value.length > 0) {
		obj.loc.HTML.removeChild(obj.HTML);
		obj.xml.parentNode.removeChild(obj.xml);
		phpCall("deleteAudioTag.php","?id="+obj.id,"GET");	
	}
	obj.loc.panel.sidePanel.refreshView();
}
axe.AudioTag.prototype.RecordTime=function(e,obj) 
{ 

	commandString = "document."+obj.loc.panel.objectHTML.id+".GetTime();";
	time = eval(commandString);
	obj.time.value = time;
	if (obj.id == obj.loc.lastTime.id) {
		obj.loc.lastTime = obj.loc.newTag();
		
		var dom = obj.loc.panel.DOM;
		var newXMLTag = dom.createElement("when");
		newXMLTag.setAttribute("xml:id",obj.id);
		newXMLTag.setAttribute("absolute",time);
		obj.xml = newXMLTag;
		dom.documentElement.appendChild(newXMLTag);
		saveObj = {obj: newXMLTag};
		axe.tagCreated.fire(saveObj);
	}
	else{
		obj.xml.setAttribute("absolute",time);
	}
	phpCall("saveAudioTag.php","?id="+obj.id+"&time="+time,"GET");
	

	obj.loc.panel.sidePanel.refreshView();
}


axe.AudioTag.prototype.Stop = function(){
	commandString = "document."+this.loc.panel.objectHTML.id+".Stop();";
	eval(commandString);
}
axe.AudioTag.prototype.Play = function(){
	commandString = "document."+this.loc.panel.objectHTML.id+".Play();";
	eval(commandString);
}
axe.AudioTag.prototype.SetStartTime = function(st){
	commandString = "document."+this.loc.panel.objectHTML.id+".SetStartTime("+st+");";
	eval(commandString);
}
axe.AudioTag.prototype.Rewind = function(){
	commandString = "document."+this.loc.panel.objectHTML.id+".Rewind();";
	eval(commandString);
}

axe.AudioTag.prototype.PlayFrom=function(e,obj) 
{ 
	startTime = obj.time.value;
	obj.Stop();
	obj.SetStartTime(startTime);
	obj.Rewind();
	obj.Play();
	obj.SetStartTime(0);
	
}
function loadSound(){
   document.movie1.SetURL(document.getElementById("filename").value);
}


