



function addControls(e,second,obj){
	//alert(second+" "+obj.objectHTML.id);
	if (second == obj.objectHTML.id) {
		
		obj.wrapper.appendChild(obj.controls.HTML);
	}
}
axe.videoLoaded = new YAHOO.util.CustomEvent("videoLoaded");
axe.VideoSidePanel = function(inits){
	
	axe.VideoSidePanel.superclass.constructor.call(this, inits);
	this.container = document.createElement("div");
	this.container.className = "sideContainer";
	this.HTML.appendChild(this.container);
	this.DOM = inits["DOM"];
}
YAHOO.lang.extend(axe.VideoSidePanel,axe.SidePanel);
axe.VideoSidePanel.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);
			}

	}
}
function sendVideoID(id){
	alert(id);
}

function sendReady(me){
	axe.videoLoaded.fire(me);
	
}
function getFlashMovieObject(movieName)
{
  if (window.document[movieName]) 
  {
    return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1)
  {
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName]; 
  }
  else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
  {
    return document.getElementById(movieName);
  }
}

/*
function getFlashMovieObject(movieName)
{

  if (eval(document.movieName)) 
  {
    return eval(document.movieName);
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1)
  {
    if (document.embeds && eval(document.movieName))
      return eval(document.movieName); 
  }
  else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
  {
    return eval(document.movieName);
  }
}
*/
/*
function getTime(line) {
var flashMovie = getFlashMovieObject("LyricCreate");
	
	if (flashMovie.SetVariable) {
		var time = flashMovie.SetVariable("requestTime", true);
		//var points = flashMovie.SetVariable("requestPoints", true);
		var lineId = flashMovie.SetVariable("requestId", line);
	}

}*/
function getPoints(line,videoID) {
	
	var flashMovie = getFlashMovieObject(videoID);
	

	if (flashMovie.SetVariable) {
		
		var points = flashMovie.SetVariable("requestPoints", true);
		var lineId = flashMovie.SetVariable("requestId", line);
		
	}
	else{
	
		object = document.getElementById(videoID).parentNode;
		par = object.parentNode;
		newobj = object.cloneNode(true);
		par.replaceChild(newobj,object);
		
		
	}
}

function sendTime(time, id) {
	input_time = document.getElementById("time_"+id); 
	input_time.value = time;
}
function sendBoth(time, id, points) {
	input_time = document.getElementById("time_"+id); 
	input_time.value = time;
	input_points = document.getElementById("points_"+id);
	input_points.value = points;
}


function sendPoints(time, points, id, videoID) {
	
	input_time = document.getElementById("time_"+id);
	if (input_time=="undefined"){
		
	}
	if (input_time) {
	
		input_time.value = time;
	}
	input_points = document.getElementById("points_"+id);
	if (input_points) {
		input_points.value = points;
	}
	
}


// below:
// testing things for the playback component


function beginCue(id) {
	writeToStatus('beginning id# '+id);
}

function endCue(id) {
	writeToStatus('ending id# '+id);
}

function writeToStatus(msg) {
	status = document.getElementById('status');
	status.value += msg+"\n";
	status.scrollTop = status.scrollHeight;
}

function myMovie_DoFSCommand(command, args) {
	if (command == "beginCue") {
		writeToStatus("begin: "+args);
	} else if (command == "endCue") {
		writeToStatus("end  : "+args);
	}
}

axe.VideoPanel = function(inits){
	axe.VideoPanel.superclass.constructor.call(this, inits);
	videoFile = inits["url"];
	videoXML = inits["xml"];	
	this.DOM = inits["DOM"];
	this.id =YAHOO.util.Dom.generateId(this,"videoPanel");
	this.wrapper = document.createElement("div");	
	
	this.videoBox = document.createElement("div");
	this.videoBox.className="videoBox";
	//this.videoBox.appendChild(this.objectHTML);

	this.wrapper.className="videoWrapper";	

	this.wrapper.appendChild(this.videoBox);

	
this.content.HTML.appendChild(this.wrapper);

 this.objectHTML = document.createElement("object");
	
	this.objectID = YAHOO.util.Dom.generateId(this.objectHTML,"video");;
	this.objectHTML.setAttribute("videoID",this.objectID);
	this.objectHTML.width="400";
	this.objectHTML.height="390";
	this.objectHTML.setAttribute("classid","clsid:D27CDB6E-AE6D-11cf-96B8-444553540000");
	this.objectHTML.setAttribute("codebase","http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0");
	
	
	
	this.movieParam = document.createElement("param");
	this.movieParam.name="movie";
	this.movieParam.value="./video/videoTagger_v02.swf";

	this.objectHTML.appendChild(this.movieParam);
	
	this.qualityParam = document.createElement("param");
	this.qualityParam.name="quality";
	this.qualityParam.value="high";
	
	this.fileParam = document.createElement("param");
	this.fileParam.name = "FlashVars";
	this.fileParam.value = "video="+videoFile;

	this.xmlParam = document.createElement("param");
	this.xmlParam.name = "FlashVars";
	this.xmlParam.value = "xml="+videoXML;
	this.idParam = document.createElement("param");
	this.idParam.name = "FlashVars";
	this.idParam.value = "videoID="+this.objectID;
	
	
	this.objectHTML.appendChild(this.qualityParam);
	this.objectHTML.appendChild(this.fileParam);
	this.objectHTML.appendChild(this.xmlParam);
	this.objectHTML.appendChild(this.idParam);
	this.embedHTML = document.createElement("embed");
	this.embedHTML.name=this.objectID;
	this.embedHTML.setAttribute("swfLiveConnect","true");
	this.embedHTML.src="./video/videoTagger_v02.swf";
	this.embedHTML.setAttribute("quality","high");
	this.embedHTML.setAttribute("plugsinspage","http://www.macromedia.com/go/getflashplayer");
	this.embedHTML.type="application/x-shockwave-flash"
	this.embedHTML.width="400";
	this.embedHTML.height="390";
	this.embedHTML.setAttribute("FlashVars","video="+videoFile+"&videoID="+this.objectID);
	
	this.objectHTML.appendChild(this.embedHTML);
	this.videoBox.appendChild(this.objectHTML);
	this.controls = new axe.VideoControls(this);
	//this.wrapper.appendChild(this.controls.HTML);
	sideinits = {sidebar: this.desktop.sideBar, panel: this};
	this.sidePanel = new axe.VideoSidePanel(sideinits);
	axe.videoLoaded.subscribe(addControls,this);
	YAHOO.util.Event.onAvailable(this.HTML.id,function(obj){
	

},this);
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.VideoPanel,axe.panel);

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


} 

axe.VideoControls = function(panel){
	this.id = YAHOO.util.Dom.generateId(this, "videoControls");
	this.panel = panel;
	this.HTML = document.createElement("div");
	this.HTML.id = this.id;
	this.HTML.className = "videoControls";
	this.tags = [];
	this.lastTime = null;
	
	this.GlobalRecordVideo = new axe.GlobalRecordVideo(this);
	this.HTML.appendChild(this.GlobalRecordVideo.HTML);

	
	
}

axe.VideoControls.prototype.newTag=function(){
	
	tag = new axe.VideoTag(this);
	this.HTML.appendChild(tag.HTML);
	this.tags[tag.id] = tag;
	
	/*if ((this.lastTime) ){
		alert(this.lastTime.time.value);
		this.lastTime.RecordTime(null,this.lastTime);
	}*/
	this.lastTime = tag;
	/*
	
	YAHOO.util.Event.onAvailable(tag.id,function(obj){
		getTime(obj.id);
	getPoints(obj.id);
	obj.loc.panel.sidePanel.refreshView();
	
	},tag);*/
	
	return tag;
	
}
axe.GlobalRecordVideo = function(loc){
	this.loc = loc;
	this.HTML = document.createElement("span");
	this.HTML.appendChild(document.createTextNode("New Tag"));
	YAHOO.util.Event.addListener(this.HTML,"click",this.recordAndNewTag,this.loc.panel); 
}
axe.GlobalRecordVideo.prototype.recordAndNewTag=function(e,obj){
	controls = obj.controls;
	
		tag = controls.newTag();
		
		
	
		
}
axe.VideoTag = function(loc){
	
	this.id = YAHOO.util.Dom.generateId(this,"videoTag");
	
	this.loc = loc;

	this.HTML = document.createElement("div");
	this.HTML.id = this.id;
	this.HTML.className ="videoTag";
	this.time = document.createElement("input");
	this.time.type="text";
	this.time.width='8';
	this.time.id = "time_"+this.id;
	
	this.points = document.createElement("input");
	this.points.type="text";
	this.points.width='15';
	this.points.id = "points_"+this.id;
	
	this.recordButton = document.createElement("span");
	this.recordButton.className = "videoButton";
	//this.recordButton.appendChild(document.createTextNode("record"));
		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 = "videoButton";
	//this.deleteButton.appendChild(document.createTextNode(" delete"));
 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.saveButton = document.createElement("span");
	this.saveButton.className = "videoButton";
	this.saveButton.appendChild(document.createTextNode(" save"));
	
	
	
	
	this.HTML.appendChild(this.time);
	this.HTML.appendChild(this.points);
	this.HTML.appendChild(this.recordButton);
	
	this.HTML.appendChild(this.deleteButton);
	this.HTML.appendChild(this.saveButton);
this.time.value = getPoints(this.id,this.loc.panel.objectID);
var dom = this.loc.panel.DOM;
		this.XML  = dom.createElement("when");
		var xmlid = YAHOO.util.Dom.generateId(this.XML, "videoTag");
		this.XML.setAttribute("xml:id", xmlid);
		dom.documentElement.appendChild(this.XML);
	YAHOO.util.Event.addListener(this.recordButton,"click",this.RecordTime,this);

	YAHOO.util.Event.addListener(this.saveButton,"click",this.updateTime,this);
	YAHOO.util.Event.addListener(this.deleteButton,"click",this.removeTag,this);
}	

axe.VideoTag.prototype.updateTime=function(e,obj){

		obj.XML.setAttribute("absolute", obj.time.value);
		obj.XML.setAttribute("points", obj.points.value);
		tagString = "?id=" + obj.id + "&time=" + obj.time.value + "&points=" + obj.points.value;
		
	
		phpCall("saveVideoTag.php", tagString, "GET");
		obj.loc.panel.sidePanel.refreshView();
			axe.tagCreated.fire({
				obj: obj.XML
			});
}
axe.VideoTag.prototype.removeTag = function(e, obj){
	obj.XML.parentNode.removeChild(obj.XML);
	obj.HTML.parentNode.removeChild(obj.HTML);
	phpCall("removeAudioTag.php","?id="+obj.id);
	obj.loc.panel.sidePanel.refreshView();
	obj=null;
}
axe.VideoTag.prototype.RecordTime=function(e,obj) 
{ 
	
		/*tagObj = {
			id: obj.id,
			time: obj.time.value,
			points: obj.points.value
		};*/

		//	getTime(obj.id);
		getPoints(obj.id,obj.loc.panel.objectID);
		//		getVideoID(obj.id);

		//obj.updateTime(e,obj);
		/*
		obj.XML.setAttribute("absolute", obj.time.value);
		obj.XML.setAttribute("points", obj.points.value);
		tagString = "?id=" + obj.id + "&time=" + obj.time.value + "&points=" + obj.points.value;
		
		axe.tagCreated.fire(obj.XML);
		phpCall("saveVideoTag", tagString, "GET");
		
	*/
		
	
}