new Track("","","","");
Track.prototype.SelectItem = Track_SelectItem;
Track.prototype.FocusItem = Track_FocusItem;
Track.prototype.UnselectItem = Track_UnselectItem;
Track.prototype.GetItem = Track_GetItem;
Track.prototype.SetItem = Track_SetItem;
Track.prototype.PlayItem = Track_PlayItem;
Track.prototype.ClearPlayItem = Track_ClearPlayItem;
var tracks = null;

function test()
{
	alert("listen up dragon");	
}
// Track Object
function Track(name,tUrl,tClassname,id)
{
	this.name = name;
	this.id = id;
	this.url = tUrl;
	this.itype = "i";
	this.itemObj = document.createElement("li");
	this.iid = this.itype+id;  // holds the item span id
	// Configure whether roles should be set
	if(UseRoles==true)
	{
		this.itemObj.setAttribute("role","option");
	}
	this.itemObj.className=tClassname;
	this.itemObj.setAttribute("id",id);
	this.itemObj.setAttribute("url",tUrl);
	this.itemObj.setAttribute("title",this.name);
	this.playSpan = document.createElement("span");
//  TODO Investigate
//	this.playSpan.setAttribute("class","playColumn");
	this.deleteSpan = document.createElement("span");
	this.itemSpan = document.createElement("span");
	this.deleteSpan.setAttribute("class","deleteColumn");
	text = document.createTextNode(this.name);
	// TODO this is new
	this.itemSpan.appendChild(text);
//	var co = document.getElementById("CONFIG");

	this.itemObj.appendChild(this.playSpan);
	this.itemObj.appendChild(this.itemSpan);
	this.itemObj.appendChild(this.deleteSpan);
}

function Track_SetItem(itemObj)
{
	this.itemObj = itemObj;	
}

function Track_GetItem()
{	
	return this.itemObj;
}

function Track_PlayItem()
{	
	if(UseRelationships==true)
	{
		this.itemObj.setAttribute("aria-describedby","lblPlay");
	}
	this.playSpan.setAttribute("class","playIcon");

//	userControlled=true;
	var songUrl = this.itemObj.getAttribute("url");
	loadNewVideo(songUrl);
//	IsNewSong=true;
//	updatePauseUI();
}

function Track_ClearPlayItem()
{	
	//TODO
	this.UnselectItem();
	if(UseRelationships==true)
	{
		this.itemObj.removeAttribute("aria-describedby");
	}
	this.playSpan.setAttribute("class","");
}

function Track_SelectItem()
{
	out("SelectItem called");
	if(UseKeyboard)
	{
	this.itemObj.setAttribute("tabindex","0");
	}
	// Updated tabindex code
	//this.itemObj.setAttribute("tabindex","-1");
	if(UseStates==true)
	{
		this.itemObj.setAttribute("aria-selected","true");

	}
}

function Track_FocusItem()
{

//	console.log("Track FocusItem Called" + this.itemObj);
//	var focusObj = axs.id(this.id);
	//console.log(this.itemObj);
	window.setTimeout(function () {this.itemObj.focus();},0);  // focusItem must be in scope
}

function Track_UnselectItem()
{
	out("UnselectItem called");
	if(UseKeyboard)
	{
	this.itemObj.setAttribute("tabindex","-1");
	}
//	this.itemObj.removeAttribute("tabindex");
	if(UseStates==true)
	{
		this.itemObj.setAttribute("aria-selected","false");
	}
}


/**
 * Processing Functions
 */

function SanitizeText(text)
{
	artistName = axs.id("editArtist").value;
	var pos = artistName.indexOf("The");
	if(pos==-1)
	{
		pos = artistName.indexOf("the");
	}
	if (pos >= 0 && pos < 4)
	{
		m = new RegExp(artistName,"gi");	
		text = text.replace(m,"");
		artistName=artistName.substring(3,artistName.length);
		m = new RegExp(artistName,"gi");	
		text = text.replace(m,"");
	}
	else
	{
		m = new RegExp("The " + artistName,"gi");		
		text = text.replace(m,"");
		m = new RegExp(artistName,"gi");		
		text = text.replace(m,"");
	}
	

	text = text.replace(" - ","");
	text = text.replace('"',"");
	text = text.replace('"',"");
	text = text.replace("- ","");
	text = text.replace(".mpg","");
	text = text.replace(": ","");
	text = text.replace("(music video","");
	text = text.replace("music video","");
	text = $.trim(text);
	if(text.length > 32)
	{
		text = text.substr(0,33);
		text = text+"...";
	}
	return text;
}