/////////// TUBERADIO OBJECT /////////////////////////////
function TubeRadio () {
	this.pl = '0';
	this.curPl = undefined;
	this.lastPlid = undefined;
	this.lastPl = undefined;
	this.lastSearchPl = undefined;
	this.curVid = undefined;
	this.curVidNo = 0;
	this.lastVid = undefined;
	this.lastPlayedClass = '';
	this.curPlayPl = undefined;
	this.curYtVid = undefined;
	this.lastYtVid = undefined;
	this.curYtVidNo = undefined;
	this.lastPlayedClassYt = '';
	this.so = 't_seq';
	this.command = '';
	this.mode = 'playlist';
	this.smode = '';
	this.playMode = 'paused';
	this.playType = '';
	this.menuMode = '';
	this.shuffle = false;
	this.mute = false;
	this.repeat = false;
	this.lastSearch = '';
	this.startIndex = 1;
	this.pubStartIndex = 1;
	this.initSearch = '';
	this.maxResults = 30;
	this.pubMaxResults = 30;
	this.searchTerms = new Array('','','',''); 
	this.findReplacement = 0;
	this.playlists = new Playlists();
	this.youtuberesults = new YouTubeResults();
	this.discs = new Discs();
	this.templates = new Templates();
	this.references = new References();
	this.tabgroup = new TabGroup();
	this.infotabs = new InfoTabs();
	this.curTab = this.infotabs.get(0);
	this.curTabNo = 0;
	this.pubPl = undefined;
	this.curPubPl = undefined;
	this.publicplaylists = new Playlists();
	this.action = '';
	this.actionvalue='';
	this.curMenu = '';
	this.curMenuId = 0;
	this.menuMode = '';
	this.fireHideMenus = true;
	this.editVidId = 0;
	this.curTimeoutId = undefined;
	this.lastTg = 'tgtuberadio';
	this.browseMode = 'player';
	this.amazonRedirect = false;
	this.curKey = '';
	this.dragMode = '';
	this.dragTimeoutId = undefined;
	this.dragId = 0;
	this.dragName = '';
	this.mouseOffset = 0;
	this.doubleClickTimeoutId = undefined;
	this.clickId = 0;
	this.curSh = 0;
	this.shTimeoutId = undefined;
	this.dragSnapTimeoutId = undefined;
	
	this.init();
}
TubeRadio.prototype.init = function () {
	this.references.add("phprev", g("phprev"));
	this.references.add("phplay", g("phplay"));
	this.references.add("phnext", g("phnext"));
	this.references.add("phshuffle", g("phshuffle"));
	this.references.add("phmute", g("phmute"));
	this.references.add("phrepeat", g("phrepeat"));
	this.references.add("search", g("search"));
	this.references.add("smyoutube", g("smyoutube"));
	this.references.add("smdisc", g("smdisc"));
	this.references.add("smpl", g("smpl"));
	this.references.add("smpub", g("smpub"));
	this.references.add("sloader", g("sloader"));
	this.references.add("appwait", g("appwait"));
	this.references.add("playlists", g("playlists"));
	this.references.add("nlin", g("nlin"));	
	this.references.add("playgridheader", g("playgridheader"));
	this.references.add("ytgridheader", g("ytgridheader"));
	this.references.add("publicheader", g("publicheader"));
	this.references.add("playgriddiv", g("playgriddiv"));
	this.references.add("youtubediv", g("youtubediv"));
	this.references.add("discdiv", g("discdiv"));
	this.references.add("publicdiv", g("publicdiv"));
	this.references.add("trackinfo", g("trackinfo"));
	this.references.add("tabwait", g("tabwait"));
	this.references.add("releases", g("releases"));
	this.references.add("lyrics", g("lyrics"));
	this.references.add("bio", g("bio"));
	this.references.add("similar", g("similar"));
	this.references.add("col1", g("col1"));
	this.references.add("col2", g("col2"));
	this.references.add("col3", g("col3"));
	this.references.add("col4", g("col4"));
	this.references.add("sortimg1", g("sortimg1"));
	this.references.add("sortimg2", g("sortimg2"));
	this.references.add("sortimg3", g("sortimg3"));
	this.references.add("sortimg4", g("sortimg4"));
	this.references.add("tcol2", g("tcol2"));
	this.references.add("tcol3", g("tcol3"));
	this.references.add("tcol4", g("tcol4"));
	this.references.add("myplaylists", g("myplaylists"));
	this.references.add("sharedplaylists", g("sharedplaylists"));
	this.references.add("togglemyplaylists", g("togglemyplaylists"));
	this.references.add("togglesharedplaylists", g("togglesharedplaylists"));	
	this.references.add("optrate", g("optrate"));
	this.references.add("optnext", g("optnext"));
	this.references.add("optprev", g("optprev"));	
	this.references.add("optbacktopl", g("optbacktopl"));
	this.references.add("optbacktosearch", g("optbacktosearch"));
	this.references.add("optshare", g("optshare"));
	this.references.add("optpubprev", g("optpubprev"));
	this.references.add("optpubnext", g("optpubnext"));
	this.references.add("optprevsep", g("optprevsep"));
	this.references.add("optsharesep", g("optsharesep"));
	this.references.add("optsubscribe", g("optsubscribe"));
	this.references.add("optbacktopublic", g("optbacktopublic"));
	this.references.add("optaddalbums", g("optaddalbums"));
	this.references.add("star1", g("star1"));
	this.references.add("star2", g("star2"));
	this.references.add("star3", g("star3"));
	this.references.add("star4", g("star4"));
	this.references.add("star5", g("star5"));
	this.references.add("ycol2", g("ycol2"));
	this.references.add("ycol3", g("ycol3"));	
	this.references.add("ytc2", g("ytc2"));
	this.references.add("ytc3", g("ytc3"));		
	this.references.add("finfo", g("finfo"));	
	this.references.add("hinfo", g("hinfo"));	
	this.references.add("dialog", g("dialog"));
	this.references.add("pubcol2", g("pubcol2"));
	this.references.add("pubcol3", g("pubcol3"));
	this.references.add("pubcol4", g("pubcol4"));
	this.references.add("pubcol5", g("pubcol5"));
	this.references.add("pubc2", g("pubc2"));
	this.references.add("pubc3", g("pubc3"));
	this.references.add("pubc4", g("pubc4"));
	this.references.add("pubc5", g("pubc5"));
	this.references.add("menu", g("menu"));
	this.references.add("alert", g("alert"));
	this.references.add("plname", g("plname"));
	this.references.add("albuminfotitle", g("albuminfotitle"));
	this.references.add("albuminfo", g("albuminfo"));
	this.references.add("contentdiv", g("contentdiv"));
	this.references.add("content", g("content"));
	this.references.add("player", g("player"));
	this.references.add("tabgroup", g("tabgroup"));
	this.references.add("tabspacer", g("tabspacer"));
	this.references.add("tabprev", g("tabprev"));
	this.references.add("tabnext", g("tabnext"));
	this.references.add("searchsection", g("searchsection"));
	this.references.add("miniplay", g("miniplay"));
	this.references.add("minipl", g("minipl"));
	this.references.add("miniav", g("miniav"));
	this.references.add("tabsep1", g("tabsep1"));
	this.references.add("tabsep2", g("tabsep2"));
	this.references.add("tabsep3", g("tabsep3"));
	this.references.add("tabsep4", g("tabsep4"));
	this.references.add("tabsep5", g("tabsep5"));
	this.references.add("tab1", g("tab1"));
	this.references.add("tab2", g("tab2"));
	this.references.add("tab3", g("tab3"));
	this.references.add("tab4", g("tab4"));
	this.references.add("trlogo", g("trlogo"));
	this.references.add("tgtuberadio", g("tgtuberadio"));
	this.references.add("trtabspacer", g("trtabspacer"));
	this.references.add("dragdiv", g("dragdiv"));
	this.references.add("searchhint", g("searchhint"));

	//this.pl = readCookie('pl');
	if (this.pl == null) {this.pl = '0'}	
		
	com ("func.asp?c=templates", parseTemplates);
	com ("func.asp?c=loadpls", parseXML);

	if (this.references.get('nlin') != undefined) {
		this.tabgroup.add(new Tab("tgchart", "CHART", "tr.loadContent('tgchart','chart.asp')", true));
		this.tabgroup.add(new Tab("tgsignup", "SIGN UP", "tr.loadContent('tgsignup','signup.asp')", true));
		this.tabgroup.add(new Tab("tglogin", "LOGIN", "tr.showDialog('login')", true));
		this.tabgroup.add(new Tab("tgtandc", "TERMS", "tr.loadContent('tgtandc','termsandconditions.asp')", true));	
		this.tabgroup.add(new Tab("tgfaq", "FAQ", "tr.loadContent('tgfaq','faq.asp')", true));	
		this.tabgroup.add(new Tab("tgcontact", "CONTACT", "tr.loadContent('tgcontact','contact.asp')", true));
	} else {
		this.tabgroup.add(new Tab("tgchart", "CHART", "tr.loadContent('tgchart','chart.asp')", true));
		this.tabgroup.add(new Tab("tgprofile", "PROFILE", "tr.loadContent('tgprofile','profile.asp')", true));
		this.tabgroup.add(new Tab("tgtandc", "TERMS", "tr.loadContent('tgtandc','termsandconditions.asp')", true));
		this.tabgroup.add(new Tab("tgcontact", "CONTACT", "tr.loadContent('tgcontact','contact.asp')", true));
		this.tabgroup.add(new Tab("tgfaq", "FAQ", "tr.loadContent('tgfaq','faq.asp')", true));	
		this.tabgroup.add(new Tab("tglogout", "LOGOUT", "document.location.href='logout.asp'", true));
	}
	
}
TubeRadio.prototype.setMode = function (newmode) {

	if (this.mode != newmode) {
		this.mode = newmode;
		
		if (newmode == 'playlistsearch' && this.lastSearchPl != undefined) {
			tr.curPl = tr.lastSearchPl;
			tr.curPl.display();	
		}

		if (newmode == 'playlist' && this.lastPlid != undefined) {
			this.playlists.load(this.lastPlid);
		}
		
		switch (newmode) {
			case 'youtube':				
				//SHOW-HIDE THE RELEVANT DIVS
				this.references.get('playgriddiv').style.display='none';
				this.references.get('playgridheader').style.display='none';
				this.references.get('youtubediv').style.display='block';
				this.references.get('ytgridheader').style.display='block';					
				this.references.get('publicheader').style.display='none';
				this.references.get('publicdiv').style.display='none';					
				this.references.get('discdiv').style.display='none';				
							
				if (this.curPl.shared == '1') {
					this.playlists.unselect(this.pl);	
				} else {
					//ENSURE THE PLAYLIST IS SELECTED
					this.playlists.select(this.pl);
					
					if (this.youtuberesults.count > 0) {
						if (g('plarrow' + this.pl) != undefined) {g('plarrow' + this.pl).style.display = 'block'};
						
						if (this.youtuberesults.forceRedisplay) {
							//REFRESH THE YOUTUBE RESULTS 
							//#### COMMENTED OUT AS CALLED GLOABALLY BELOW
							//this.youtuberesults.display();
						}
					}
				}
				
				this.youtuberesults.display();
		
				//SET THE BUTTON STATES
				this.references.get('optbacktopl').style.display='block';
				this.references.get('optbacktopl').src=imagePath + 'opt_backtoplaylist.png';
				this.references.get('optbacktosearch').style.display='none';
				this.references.get('optshare').style.display='none';
				this.references.get('optpubprev').style.display='none';
				this.references.get('optpubnext').style.display='none';				
				this.references.get('optprev').style.display='block';
				this.references.get('optnext').style.display='block';
				this.references.get('optprevsep').style.display='block';			
				this.references.get('optsharesep').style.display='none';	
				this.references.get('optsubscribe').style.display='none';			
				this.references.get('optbacktopublic').style.display='none';	
				this.references.get('optrate').style.display='none';	
				this.references.get('optaddalbums').style.display='none';
				this.references.get('search').focus();
				this.references.get('search').select();
				resizeClient();
				break;
			
			case 'playlist':				
			case 'playlistsearch':
				//RESET THE FIND REPLACEMENT VIDEO ID
				this.findReplacement = 0;
				//SHOW-HIDE THE RELEVANT DIVS
				this.references.get('youtubediv').style.display='none';
				this.references.get('ytgridheader').style.display='none';					
				this.references.get('playgriddiv').style.display='block';
				this.references.get('playgridheader').style.display='block';
				this.references.get('publicheader').style.display='none';
				this.references.get('publicdiv').style.display='none';		
				this.references.get('discdiv').style.display='none';				
				//HIDE THE ARROW
				if (g('plarrow' + this.pl) != undefined) {g('plarrow' + this.pl).style.display = 'none'};
				//SET THE BUTTON STATES
				if (this.mode == 'playlistsearch') {
					this.references.get('optbacktopl').style.display='block';
					this.references.get('optbacktopl').src=imagePath + 'opt_backtoplaylist.png';
					this.references.get('optbacktosearch').style.display='none';
					this.references.get('optshare').style.display='none';	
					this.references.get('optsharesep').style.display='none';		
				
				} else {
					this.references.get('optshare').style.display='block';				
					this.references.get('optshare').src=imagePath + 'opt_sharethisplaylist.png';				
					this.references.get('optsharesep').style.display='block';							
					this.references.get('optbacktopl').style.display='none';
					this.references.get('optbacktosearch').style.display='block';
					if (this.lastSearch.length > 0) {
						this.references.get('optbacktosearch').src=imagePath + 'opt_backtosearch.png';
						this.references.get('optbacktosearch').style.cursor='pointer';
					} else {
						this.references.get('optbacktosearch').src=imagePath + 'opt_backtosearch_grey.png';
						this.references.get('optbacktosearch').style.cursor='default';
					}
					
					//RESELECT THE CURRENT PLAYLIST IF IT WAS RESELECTED FROMA YOUTUBE SEARCH
					if (this.curPl != undefined && this.curPl.shared == '1') {this.playlists.select(this.pl)};
					
				}
				
				this.references.get('optpubprev').style.display='none';
				this.references.get('optpubnext').style.display='none';				
				this.references.get('optprev').style.display='none';
				this.references.get('optnext').style.display='none';
				this.references.get('optprevsep').style.display='none';
				this.references.get('optsubscribe').style.display='none';			
				this.references.get('optbacktopublic').style.display='none';
				this.references.get('optaddalbums').style.display='none';
				//IF ITS A SHARED PLAYLIST THEN SHOW THE RATING
				if (this.curPl.shared == '1') {
					this.setRating (this.curPl.userrating);
					this.references.get('optrate').style.display='block';	
				} else {
					this.references.get('optrate').style.display='none';	
				}
								
				//IF ITS FIREFOX THEN REFRESH THE DISPLAY
				//THIS GETS ROUND THE STRANGE BUG WHERE THE SELECTED TUNE RUINS THE FORMATTING
				if (this.curPl.forceRedisplay) {
					this.curPl.display();
					this.curPl.forceRedisplay = false;
				}
				resizeClient();
				break;
							
			case 'disc':				
				//RESET THE FIND REPLACEMENT VIDEO ID
				this.findReplacement = 0;				
				this.references.get('playgriddiv').style.display='none';
				this.references.get('playgridheader').style.display='none';
				this.references.get('youtubediv').style.display='none';
				this.references.get('ytgridheader').style.display='none';	
				this.references.get('publicheader').style.display='none';
				this.references.get('publicdiv').style.display='none';
				this.references.get('discdiv').style.display='block';
				//HIDE THE ARROW
				if (g('plarrow' + this.pl) != undefined) {g('plarrow' + this.pl).style.display = 'none'};				
				
				this.references.get('optbacktopl').style.display='block';
				this.references.get('optbacktopl').src=imagePath + 'opt_backtoplaylist.png';
				this.references.get('optbacktosearch').style.display='none';				
				this.references.get('optshare').style.display='none';
				this.references.get('optpubprev').style.display='none';
				this.references.get('optpubnext').style.display='none';				
				this.references.get('optprev').style.display='none';
				this.references.get('optnext').style.display='none';
				this.references.get('optprevsep').style.display='none';
				this.references.get('optsharesep').style.display='none';	
				this.references.get('optsubscribe').style.display='none';			
				this.references.get('optbacktopublic').style.display='none';	
				this.references.get('optrate').style.display='none';	
				this.references.get('optaddalbums').style.display='block';
				if (this.discs.selCount > 0) {
					this.references.get('optaddalbums').src=imagePath + 'opt_addalbums.png';
				} else {
					this.references.get('optaddalbums').src=imagePath + 'opt_addalbums_grey.png';
				}
				resizeClient();			
				break;
							
			case 'public':				
				//RESET THE FIND REPLACEMENT VIDEO ID
				this.findReplacement = 0;				
				this.references.get('playgriddiv').style.display='none';
				this.references.get('playgridheader').style.display='none';
				this.references.get('youtubediv').style.display='none';
				this.references.get('ytgridheader').style.display='none';	
				this.references.get('publicheader').style.display='block';
				this.references.get('publicdiv').style.display='block';	
				this.references.get('discdiv').style.display='none';								
				//HIDE THE ARROW
				if (g('plarrow' + this.pl) != undefined) {g('plarrow' + this.pl).style.display = 'none'};				
				
				this.references.get('optbacktopl').style.display='block';
				this.references.get('optbacktopl').src=imagePath + 'opt_backtoplaylist.png';
				this.references.get('optbacktosearch').style.display='none';				
				this.references.get('optshare').style.display='none';
				this.references.get('optpubprev').style.display='block';
				this.references.get('optpubnext').style.display='block';				
				this.references.get('optprev').style.display='none';
				this.references.get('optnext').style.display='none';
				this.references.get('optprevsep').style.display='block';
				this.references.get('optsharesep').style.display='none';	
				this.references.get('optsubscribe').style.display='none';			
				this.references.get('optbacktopublic').style.display='none';	
				this.references.get('optrate').style.display='none';	
				this.references.get('optaddalbums').style.display='none';								
				resizeClient();
				break;

			case 'publicplaylist':				
				//RESET THE FIND REPLACEMENT VIDEO ID
				this.findReplacement = 0;				
				//SHOW-HIDE THE RELEVANT DIVS
				this.references.get('youtubediv').style.display='none';
				this.references.get('ytgridheader').style.display='none';					
				this.references.get('playgriddiv').style.display='block';
				this.references.get('playgridheader').style.display='block';
				this.references.get('publicheader').style.display='none';
				this.references.get('publicdiv').style.display='none';	
				this.references.get('discdiv').style.display='none';								
				//HIDE THE ARROW
				if (g('plarrow' + this.pl) != undefined) {g('plarrow' + this.pl).style.display = 'none'};
				//SET THE BUTTON STATES
				this.references.get('optbacktopl').style.display='none';
				this.references.get('optbacktosearch').style.display='none';

				if (this.playlists.inPlaylists(this.pubPl)) {
					this.references.get('optsubscribe').src = imagePath + 'opt_unsubscribe.png';
				} else {
					this.references.get('optsubscribe').src = imagePath + 'opt_subscribe.png';
				};				
				
				this.references.get('optbacktopl').style.display='none';
				this.references.get('optbacktosearch').style.display='none';
				this.references.get('optshare').style.display='none';
				this.references.get('optshare').src=imagePath + 'opt_sharethisplaylist.png';
				this.references.get('optpubprev').style.display='none';
				this.references.get('optpubnext').style.display='none';				
				this.references.get('optprev').style.display='none';
				this.references.get('optnext').style.display='none';
				this.references.get('optprevsep').style.display='none';
				this.references.get('optsharesep').style.display='block';	
				this.references.get('optsubscribe').style.display='block';			
				this.references.get('optbacktopublic').style.display='block';		
				this.references.get('optrate').style.display='none';	
				this.references.get('optaddalbums').style.display='none';				
				resizeClient();
				break;				
		}
	}	
}
TubeRadio.prototype.setSearchMode = function (newmode) {

	switch (newmode) {
		case 'youtube':
			this.smode='youtube';
			if (this.lastSearch.length == 0) {
				this.initSearch = 'Search You Tube here to add new videos to "' + this.curPl.name + '"';
				this.references.get('search').value = this.initSearch;
			} else {
				if (this.lastSearch != this.searchTerms[0]) {
					this.search(this.smode, this.lastSearch)
				} else {
					this.setMode('youtube');
				};
			}
			
			this.references.get('search').focus();
			this.references.get('search').select();
			this.references.get('smyoutube').src=imagePath + 'search_youtube_down.png';
			this.references.get('smdisc').src=imagePath + 'search_discography.png';
			this.references.get('smpl').src=imagePath + 'search_myplaylists.png';
			this.references.get('smpub').src=imagePath + 'search_publicplaylists.png';	
			break;
			
		case 'disc':
			this.smode ='disc';
			if (this.lastSearch.length == 0) {
				this.initSearch = 'Enter the full name of an artist and Tuberadio will build a playlist for you';
				this.references.get('search').value = this.initSearch;
			} else {
				if (this.lastSearch != this.searchTerms[1]) {
					this.search(this.smode, this.lastSearch)
				} else {
					this.setMode('disc');
				};
			}

			this.references.get('search').focus();
			this.references.get('search').select();				
			this.references.get('smyoutube').src=imagePath + 'search_youtube.png';
			this.references.get('smdisc').src=imagePath + 'search_discography_down.png';
			this.references.get('smpl').src=imagePath + 'search_myplaylists.png';
			this.references.get('smpub').src=imagePath + 'search_publicplaylists.png';	
			break;			
		
		case 'playlistsearch':
			this.smode='playlistsearch';
			if (this.lastSearch.length == 0) {
				this.initSearch = 'Search for videos across all your playlists';
				this.references.get('search').value = this.initSearch;
			} else {
				this.search (this.smode, this.lastSearch);
			}

			this.references.get('search').focus();
			this.references.get('search').select();				
			this.references.get('smyoutube').src=imagePath + 'search_youtube.png';
			this.references.get('smdisc').src=imagePath + 'search_discography.png';
			this.references.get('smpl').src=imagePath + 'search_myplaylists_down.png';
			this.references.get('smpub').src=imagePath + 'search_publicplaylists.png';	
			break;			
		
		case 'publicsearch':
			this.smode='publicsearch';
			if (this.lastSearch.length == 0) {
				this.initSearch = 'Search for videos in public playlists';
				this.references.get('search').value = this.initSearch;
			} else {
				this.search(this.smode, this.lastSearch);
			}
						
			this.references.get('search').focus();
			this.references.get('search').select();				
			this.references.get('smyoutube').src=imagePath + 'search_youtube.png';
			this.references.get('smdisc').src=imagePath + 'search_discography.png';
			this.references.get('smpl').src=imagePath + 'search_myplaylists.png';
			this.references.get('smpub').src=imagePath + 'search_publicplaylists_down.png';	
			break;			
	}
}
TubeRadio.prototype.startVidDrag = function (id) {

}
TubeRadio.prototype.play = function (id, isHuman) {
	var sameTune = false;
	var refreshTab = false;
	
	this.playType = 'playlist';
	
	if (this.curVid != undefined) {
		this.lastVid = this.curVid;
		if (g('t'+this.curVid.id+'c1') != undefined) {
			this.curVid.unselect(true);
		}
	}
	//HIDE THE CURRENT PLAYLIST PLAYING ICON
	if (this.curPlayPl != undefined) {
		if(g('plplay' + this.curPlayPl.id) != undefined) {
			g('plplay' + this.curPlayPl.id).style.display = 'none';
		}
	}	
	if (isHuman) {
		//IF THE PLAY REQUEST CAME FROM A PLAYGRID CLICK (NOT A NEXT , PREV OR SHUFFLE REQ) THEN SET THE CURRENT PLAYLIST
		this.curPlayPl = this.curPl;			
	}	
	this.curVid = this.curPlayPl.get(id);
	if (this.curVid.id == id) {sameTune = true};
	this.curVid.selectPlay()
	//SHOW THE CURRENT PLAYLIST PLAYING ICON
	g('plplay' + this.curPlayPl.id).style.display = 'block';	
	createCookie('curVid',id,31);
	//GET THE VIDEO NUMBER
	this.curVidNo = this.curPlayPl.getVidNo(id);
	this.curVid.played = '1';
	if (this.curVid.artist.length > 0) {
		this.references.get('albuminfotitle').innerHTML = this.curVid.artist;
	} else {
		this.references.get('albuminfotitle').innerHTML = this.curVid.name;
	}	

	//LOAD THE AMAZON DATA
	if (this.curVid != undefined) {
		vol.getAmazonInfo(this.curVid.album, this.curVid.artist, this.curVid.name);
	}
	//LOAD THE CURRENT TAB AND LOG THE PLAY	
	this.loadInfo(this.curTabNo, this.curVid.artist, this.curVid.name, true);
	
	if (this.curVid != undefined) {		
		if (this.curTimeoutId != undefined) {clearTimeout(this.curTimeoutId)};
		this.curTimeoutId = setTimeout('swf.loadVideoById(\'' + this.curVid.videoid + '\', 0);', 1000);
	}
	this.changePlayerState ('playing');
}
TubeRadio.prototype.playNext = function () {
var vid; //THE NEXT VID TO PLAY
	switch(this.playType) {
		case "youtube":
			if (this.curYtVidNo < 29) {
				this.curYtVidNo = parseInt(this.curYtVidNo) + 1;
			} else {
				this.curYtVidNo = 0;
			}
			this.playYoutube(this.curYtVidNo);
			break;
			
		case "playlist": 
		
			if (this.curVid != undefined) {
				this.scrobble(this.curVid, swf.getCurrentTime());
			}
		
		
			if (this.repeat != true) {
			
				if (this.playlists.q.length>0 && this.pl == this.playlists.qPl) {
					g('t' + this.playlists.q[0] + 'c1').innerHTML = '';
					this.play(this.playlists.q.shift());	
					this.playlists.displayQ();
					return false;
				} else {

					if (this.shuffle) {
						this.curVidNo = Math.floor(Math.random()*this.curPlayPl.count);
						vid = this.curPlayPl.videos[this.curVidNo].id;
					
					} else {						
						//WORK OUT WHICH TUNE IS NEXT
						if (this.curVidNo < this.curPlayPl.count - 1) {
							this.curVidNo += 1;
							vid = this.curPlayPl.videos[this.curVidNo].id;
						} else {
							this.curVidNo = 0;
							vid = this.curPlayPl.videos[0].id;
						}
					}
				}				
			} else {
				vid = this.curVid.id;
			}
			this.play(vid, false);	
			break;
			
		case "publicplaylist": 			
			break;
	
	}

}
TubeRadio.prototype.playPrev = function () {
var vid;

	switch(this.playType) {
		case "youtube":
			if (this.curYtVidNo > 0) {
				this.curYtVidNo = parseInt(this.curYtVidNo) - 1;
			} else {
				this.curYtVidNo = 29;
			}
			this.playYoutube(this.curYtVidNo);
			break;

		case "playlist": 
		
			if (this.curVid != undefined) {
				this.scrobble(this.curVid, swf.getCurrentTime());
			}		
		
			if (this.repeat != true) {
				if (this.shuffle) {
					this.curVidNo = Math.floor(Math.random()*this.curPlayPl.count);
					vid = this.curPlayPl[this.curVidNo].id;
				
				} else {
			
					//WORK OUT WHICH TUNE IS PREV
					if (this.curVidNo > 0) {
						this.curVidNo -= 1;
						vid = this.curPlayPl.videos[this.curVidNo].id;
					} else {
						this.curVidNo = this.curPlayPl.count - 1;
						vid = this.curPlayPl.videos[this.curVidNo].id;
					}
				}
			
			} else {
				vid = this.curVid;
			}
			this.play(vid, false);
			
		case "publicplaylist":
			break;
	}

}
TubeRadio.prototype.playYoutube = function (id) {

	this.playType = 'youtube';

	if (this.curYtVidNo != undefined) {
		if (g('yt'+this.curYtVid.id+'c1') != undefined) {	
			this.youtuberesults.unselect(this.curYtVid.id);
			this.lastYtVid = this.curYtVid;
		}
	}
	this.curYtVidNo = id;
	this.curYtVid = this.youtuberesults.get(id);
	
	this.infotabs.clearYt();
	
	if (this.youtuberesults.select(id)) {	
		createCookie('curYtVid',id,31);
		if (this.curTimeoutId != undefined) {clearTimeout(this.curTimeoutId)};
		this.curTimeoutId = setTimeout('swf.loadVideoById(\'' + this.curYtVid.videoid + '\', 0);', 1000);		
		this.changePlayerState ('playing');			
	}	
	
	
	
}
TubeRadio.prototype.setPlayerState = function (newState) {
	switch (newState) {
		case 'play':
			this.changePlayerState('playing');
			swf.playVideo();
			this.playMode = 'playing';
			break;

		case 'pause':
			this.changePlayerState('paused');
			swf.pauseVideo();
			this.playMode = 'paused';			
			break;
		
	}	
}
TubeRadio.prototype.changePlayerState = function (newState) {
	switch (newState) {
		case 'playing':
			if (this.curPlayPl != undefined) {
				if (g('plplay' + this.curPlayPl.id) != undefined) {
					g('plplay' + this.curPlayPl.id).style.display = 'block';
				}
			}
			this.references.get('phplay').src= imagePath + 'btn_pause.png';
			break;
			
		case 'paused':
			if (this.curPlayPl != undefined) {
				if (g('plplay' + this.curPlayPl.id) != undefined) {
					g('plplay' + this.curPlayPl.id).style.display = 'none';
				}	
			}
			this.references.get('phplay').src=imagePath + 'btn_play.png';
			break;
			
	}
	this.playMode = newState;
}
TubeRadio.prototype.setShuffle = function (newstate) {

	if (newstate) {
		this.references.get('phshuffle').src = imagePath + 'btn_shuffle_down.png';
		createCookie('shuffle','1',31);
		this.shuffle = true;	
	} else {
		this.references.get('phshuffle').src = imagePath + 'btn_shuffle.png';
		createCookie('shuffle','0',31);
		this.shuffle = false;		
	}

}
TubeRadio.prototype.toggleShuffle = function () {
	if (this.shuffle) {
		this.setShuffle(false);
	} else {
		this.setShuffle(true);
	}

}
TubeRadio.prototype.setMute = function (newstate) {

	if (newstate) {
		if (swf != undefined) {swf.mute()};
		this.references.get('phmute').src = imagePath + 'btn_mute_down.png';
		createCookie('mute','1',31);
		this.mute = true;	
	} else {
		if (swf != undefined) {swf.unMute()};
		this.references.get('phmute').src = imagePath + 'btn_mute.png';
		createCookie('mute','0',31);
		this.mute = false;		
	}

}
TubeRadio.prototype.toggleMute = function () {
	if (this.mute) {
		this.setMute(false);
	} else {
		this.setMute(true)
	}
}
TubeRadio.prototype.setRepeat = function (newstate) {

	if (newstate) {
		this.references.get('phrepeat').src = imagePath + 'btn_repeat_down.png';
		createCookie('repeat','1',31);
		this.repeat = true;	
	} else {
		this.references.get('phrepeat').src = imagePath + 'btn_repeat.png';
		createCookie('repeat','0',31);
		this.repeat = false;		
	}

}
TubeRadio.prototype.toggleRepeat = function () {
	if (this.repeat) {
		this.setRepeat(false);
	} else {
		this.setRepeat(true);
	}

}
TubeRadio.prototype.showDialog = function (name) {
	var t = this.templates.get(name);

	switch (name) {
		case 'addalbumstopl':
			this.references.get('dialog').innerHTML = tr.templates.get('dialog').replace(/-content-/g, t);
	
			var select = g('aaplid');			
			select.innerHTML = '';
			var n = select.appendChild(document.createElement("OPTION"));
			n.text = 'Select Playlist...';
			n.value = '0';		
			for (var i=0;i<this.playlists.count;i++) {
				if (this.playlists.playArr[i].shared != '1') {
					var n = select.appendChild(document.createElement("OPTION"));
					n.text = this.playlists.playArr[i].name;
					n.value = this.playlists.playArr[i].id;
				}
			}
			g('aaname').value = '';
			this.references.get('dialog').style.width = '330px';
			this.references.get('dialog').style.top = (parseInt(yMousePos) - 38) + 'px';
			this.references.get('dialog').style.left = centerDiv(330) + 'px';	
			this.references.get('dialog').style.display='block';
			g('aaname').focus();
			g('aaname').select();		
			break;
		
		case 'addalbumsmonitor':
			this.references.get('dialog').innerHTML = tr.templates.get('dialog').replace(/-content-/g, t);
			g('aaclose').style.display = 'none';
			g('aacancel').style.display = 'block';
			this.references.get('dialog').style.width = '330px';
			this.references.get('dialog').style.top = (parseInt(yMousePos) - 38) + 'px';
			this.references.get('dialog').style.left = centerDiv(330) + 'px';
			this.references.get('dialog').style.display='block';
			break;
			
		case 'editvid':
			this.references.get('dialog').innerHTML = tr.templates.get('dialog').replace(/-content-/g, t);		
			this.editVidId=this.actionvalue;
			if (this.curPl.inSel(this.editVidId) == false) {
				this.curPl.clearSel();
				this.curPl.addSel(this.editVidId);
				this.curPl.get(this.editVidId).select();
			}			
			var v = this.curPl.get(this.editVidId);
			if (this.curPl.selCount > 1) {
				g('tname').value = 'Multiple Selection';
				g('tname').style.fontStyle = 'italic';
				g('tname').disabled = true;
				
				var art = v.artist;
				var sameart = true;
				for (var i=0;i<this.curPl.selCount;i++) {
					if (this.curPl.get(this.curPl.sel[i]).artist != art) {
						sameart = false;
						break;
					}
				}
				if (sameart) {
					g('tartist').value=unescape(v.artist);
				} else {
					g('tartist').value = '';
				}				
			} else {
				g('tname').style.fontStyle = 'normal';
				g('tname').value=unescape(v.name);
				g('tartist').value=unescape(v.artist);
			}

			g('talbum').value=unescape(v.album);			
			this.references.get('dialog').style.width = '330px';
			this.references.get('dialog').style.top = (parseInt(yMousePos) - 38) + 'px';
			this.references.get('dialog').style.left = centerDiv(330) + 'px';
			this.references.get('dialog').style.display='block';
			g('tname').focus();
			g('tname').select();
			break;
			
		case 'sendq':
			if (this.playlists.q.length > 0) {
				this.references.get('dialog').innerHTML = tr.templates.get('dialog').replace(/-content-/g, t);

				var select = g('sendqplid');
				select.innerHTML = '';					
				var n = select.appendChild(document.createElement("OPTION"));
				n.text = 'Select Playlist...';
				n.value = '0';		
				for (var i=0;i<this.playlists.count;i++) {	
					if (this.playlists.playArr[i].id != this.pl && this.playlists.playArr[i].shared != '1') {
						var n = select.appendChild(document.createElement("OPTION"));
						n.text = this.playlists.playArr[i].name;
						n.value = this.playlists.playArr[i].id;
					}
				}
				g('sendqname').value = '';
				this.references.get('dialog').style.width = '330px';
				this.references.get('dialog').style.top = (parseInt(yMousePos) - 38) + 'px';
				this.references.get('dialog').style.left = centerDiv(330) + 'px';
				this.references.get('dialog').style.display='block';
				g('sendqname').focus();
				g('sendqname').select();
			}	
			break;
			
		case 'login':
			this.references.get('dialog').innerHTML = this.templates.get('dialog').replace(/-content-/g, t);
			this.references.get('dialog').style.width = '330px';
			this.references.get('dialog').style.top = '10px';
			this.references.get('dialog').style.left = centerDiv(330) + 'px';
			this.references.get('dialog').style.display='block';			
			com('login.asp', handleResponse, undefined, 'trlogindiv');
			break;
			
		case 'miniplsel':
			this.references.get('dialog').innerHTML = this.templates.get('dialog').replace(/-content-/g, t);
			var str = this.templates.get('miniplrowtemplate');
			var outArr = new Array();
			for (var i=0;i<this.playlists.count;i++) {
				t = str;
				t = t.replace(/-id-/g, this.playlists.playArr[i].id);
				t = t.replace(/-name-/g, this.playlists.playArr[i].name);
				if (this.playlists.playArr[i].shared == '1') {
					t = t.replace(/-username-/g, ' - ' + this.playlists.playArr[i].username);
				} else {
					t = t.replace(/-username-/g, '');
				}
				outArr.push(t);
			}
			g('miniplsel').innerHTML = '<table cellpadding=0 cellspacing=0 border=0 width="100%" style="background-image:url(' + imagePath + 'alternating_blue_white.gif)" >' + outArr.join('') + '</table>';
			this.references.get('dialog').style.width = '330px';
			this.references.get('dialog').style.top = '10px';
			this.references.get('dialog').style.left = centerDiv(330) + 'px';
			this.references.get('dialog').style.display='block';
			break;
			
		case 'miniavsel':
			this.references.get('dialog').innerHTML = this.templates.get('dialog').replace(/-content-/g, t);
			var str = this.templates.get('miniavrowtemplate');
			var outArr = new Array();
			for (var i=0;i<this.curPl.count;i++) {
				t = str;
				t = t.replace(/-id-/g, this.curPl.videos[i].id);
				t = t.replace(/-name-/g, this.curPl.videos[i].name);
				outArr.push(t);
			}
			g('miniavsel').innerHTML = '<table cellpadding=0 cellspacing=0 border=0 width="100%" style="background-image:url(' + imagePath + 'alternating_blue_white.gif)" >' + outArr.join('') + '</table>';
			this.references.get('dialog').style.width = '330px';
			this.references.get('dialog').style.top = '10px';
			this.references.get('dialog').style.left = centerDiv(330) + 'px';
			this.references.get('dialog').style.display='block';
			break;
			
		case 'shareplaylist':
			this.references.get('dialog').innerHTML = this.templates.get('dialog').replace(/-content-/g, t);
			this.references.get('dialog').style.width = '330px';
			this.references.get('dialog').style.top = '10px';
			this.references.get('dialog').style.left = centerDiv(330) + 'px';
			this.references.get('dialog').style.display='block';			
			break;
			
		case 'selectpl':
			this.references.get('dialog').innerHTML = this.templates.get('dialog').replace(/-content-/g, t);
			var select = g('selplid');
			select.innerHTML = '';

			for (var i=0;i<this.playlists.count;i++) {
				if (this.playlists.playArr[i].shared != '1') {
					var n = select.appendChild(document.createElement("OPTION"));
					n.text = this.playlists.playArr[i].name;
					n.value = this.playlists.playArr[i].id;
				}
			}		
		
			this.references.get('dialog').style.width = '330px';
			this.references.get('dialog').style.top = '10px';
			this.references.get('dialog').style.left = centerDiv(330) + 'px';
			this.references.get('dialog').style.display='block';			
			break;	

		case 'welcome':
			this.references.get('dialog').innerHTML = this.templates.get('dialog').replace(/-content-/g, t);
			this.references.get('dialog').style.width = '450px';
			this.references.get('dialog').style.top = '10px';
			this.references.get('dialog').style.left = centerDiv(450) + 'px';
			this.references.get('dialog').style.display='block';			
			break;
		case 'addvidtopl':	
			this.references.get('dialog').innerHTML = tr.templates.get('dialog').replace(/-content-/g, t);

			var select = g('addvidtoplplid');
			select.innerHTML = '';					
			var n = select.appendChild(document.createElement("OPTION"));
			n.text = 'Select Playlist...';
			n.value = '0';		
			for (var i=0;i<this.playlists.count;i++) {	
				if (this.playlists.playArr[i].id != this.pl && this.playlists.playArr[i].shared != '1') {
					var n = select.appendChild(document.createElement("OPTION"));
					n.text = this.playlists.playArr[i].name;
					n.value = this.playlists.playArr[i].id;
				}
			}
			g('addvidtoplplname').value = '';
			this.references.get('dialog').style.width = '330px';
			this.references.get('dialog').style.top = (parseInt(yMousePos) - 38) + 'px';
			this.references.get('dialog').style.left = centerDiv(330) + 'px';
			this.references.get('dialog').style.display='block';
			g('addvidtoplplname').focus();
			g('addvidtoplplname').select();
			break;
		
	}
}
TubeRadio.prototype.hideDialog = function (name) {
	tr.references.get('appwait').style.display='none';
	tr.references.get('dialog').style.display='none';
}
TubeRadio.prototype.showTip = function (strURL, left) {
	this.references.get('appwait').style.display = 'block';
	this.references.get('dialog').innerHTML = tr.templates.get('dialog').replace(/-content-/g, '<div id="dialogcontent"></div>');	
	this.references.get('dialog').style.top = '10px';
	if (left != undefined) {
		this.references.get('dialog').style.left = '10px';
	} else {
		this.references.get('dialog').style.left = centerDiv(464) + 'px';
	}
	this.references.get('dialog').style.display='block';	
	com(strURL, handleResponse, undefined, 'dialogcontent');
}
TubeRadio.prototype.hideTip = function () {
	this.references.get('appwait').style.display = 'none';
	g('dialog').style.display = 'none';
}
TubeRadio.prototype.addDiscs = function () {
	var n = '';
	var plid = '0';
	var str = '';

	//VALIDATE
	if (g('aaplid').value == '0') {
		if (g('aaname').value.length == 0) {
			//NO NAME SUPPLIED
			g('aaname').style.backgroundColor = 'FFD3D3';
			g('aaname').focus();
			g('aaname').select();			
		
			return false;
		} else {
			n = g('aaname').value;
		}
	} else {
		plid = g('aaplid').value;
	}

	this.hideDialog()
	this.references.get('appwait').style.display = 'block';
	this.showDialog('addalbumsmonitor');

	if (n.length > 0) {
		updateAddAlbumStatus ('Creating your new playlist', '', 1);
		com('func.asp?c=adddisc&n=' + escape(n), parseXML);

	} else {
		this.doAddDiscs(plid);
	}
}
TubeRadio.prototype.doAddDiscs = function (plid) {
var outArr = new Array();

	for (var i=0; i<this.discs.count; i++) {
		if (this.discs.d[i].sel) {
			outArr.push(this.discs.d[i].mbid);
		}
	}	
	vol.addAlbumsToPlaylist(plid, outArr.join(","))
}
TubeRadio.prototype.loadInfo = function (tabno, artist, track, logPlay) {
	if (this.playType == 'youtube') {
		this.infotabs.clearYt();
	} else {
		this.references.get('tabwait').style.width=tr.references.get('trackinfo').offsetWidth + 'px';
		this.references.get('tabwait').style.height=tr.references.get('trackinfo').offsetHeight + 'px';
		this.references.get('trackinfo').style.overflow='hidden';
		this.references.get('tabwait').style.display='block';	
		switch (tabno) {
			case 1: //LYRICS
				this.infotabs.load(tabno, artist, track, logPlay);
				break;
			default:
				this.infotabs.load(tabno, artist, undefined, logPlay);
				break;
		}
	}

}
TubeRadio.prototype.selectInfoTab = function (tabno) {

	this.curTabNo = tabno;
	this.curTab = this.infotabs.get(tabno);
	
	//LASTFM LOGO
	if (tabno == 1) {	
		g('lastfmlogo').style.display = 'none';
	} else {
		g('lastfmlogo').style.display = 'block';
	}
	
	switch (tabno) {
		case 0: //RELEASES
			this.references.get('tabsep3').className = 'tabsep';
			this.references.get('tabsep4').className = 'tabsep';			
			this.references.get('tabsep5').className = 'tabsep';			
			this.references.get('tab2').className = '';
			this.references.get('tab3').className = '';
			this.references.get('tab4').className = '';
			this.references.get('tabsep1').className = 'tableftsel';
			this.references.get('tab1').className = 'tabstretchsel';
			this.references.get('tabsep2').className = 'tabrightsel';
			
			this.references.get('releases').style.display = 'block';
			this.references.get('lyrics').style.display = 'none';
			this.references.get('bio').style.display = 'none';
			this.references.get('similar').style.display = 'none';			
			
			if (this.curVid != undefined) {this.loadInfo(tabno, this.curVid.artist, this.curVid.name)}			
			break;
			
		case 1: //LYRICS
			this.references.get('tabsep1').className = 'tabsep';
			this.references.get('tabsep4').className = 'tabsep';			
			this.references.get('tabsep5').className = 'tabsep';			
			this.references.get('tab1').className = '';
			this.references.get('tab3').className = '';
			this.references.get('tab4').className = '';
			this.references.get('tabsep2').className = 'tableftsel';
			this.references.get('tab2').className = 'tabstretchsel';
			this.references.get('tabsep3').className = 'tabrightsel';	

			this.references.get('releases').style.display = 'none';
			this.references.get('lyrics').style.display = 'block';
			this.references.get('bio').style.display = 'none';
			this.references.get('similar').style.display = 'none';				
		
			if (this.curVid != undefined) {this.loadInfo(tabno, this.curVid.artist, this.curVid.name)}		
			break;
	
		case 2: // BIO
			this.references.get('tabsep1').className = 'tabsep';
			this.references.get('tabsep2').className = 'tabsep';			
			this.references.get('tabsep5').className = 'tabsep';			
			this.references.get('tab1').className = '';
			this.references.get('tab2').className = '';
			this.references.get('tab4').className = '';
			this.references.get('tabsep3').className = 'tableftsel';
			this.references.get('tab3').className = 'tabstretchsel';
			this.references.get('tabsep4').className = 'tabrightsel';		
			
			this.references.get('releases').style.display = 'none';
			this.references.get('lyrics').style.display = 'none';
			this.references.get('bio').style.display = 'block';
			this.references.get('similar').style.display = 'none';	
			
			if (this.curVid != undefined) {this.loadInfo(tabno, this.curVid.artist, this.curVid.name)}		
			break;		
		
		case 3: // SIMILAR
			this.references.get('tabsep1').className = 'tabsep';
			this.references.get('tabsep2').className = 'tabsep';			
			this.references.get('tabsep3').className = 'tabsep';			
			this.references.get('tab1').className = '';
			this.references.get('tab2').className = '';
			this.references.get('tab3').className = '';
		
			this.references.get('tabsep4').className = 'tableftsel';
			this.references.get('tab4').className = 'tabstretchsel';
			this.references.get('tabsep5').className = 'tabrightsel';	

			this.references.get('releases').style.display = 'none';
			this.references.get('lyrics').style.display = 'none';
			this.references.get('bio').style.display = 'none';
			this.references.get('similar').style.display = 'block';	
			
			if (this.curVid != undefined) {this.loadInfo(tabno, this.curVid.artist, this.curVid.name)}			
			break;			

	}


}
TubeRadio.prototype.search = function (stype, str) {
	if (this.smode != stype) {this.setSearchMode(stype); return false};
	this.shHide();
	if (str.length > 0 && this.references.get('search').value != this.initSearch) {		
		//this.lastSearch = this.references.get('search').value;
		this.lastSearch = str;
		
		switch (stype) {	
			case "youtube":	
				this.setMode('youtube');
				if (this.lastSearch != this.searchTerms[0]) {	
					this.references.get('sloader').style.display = 'block';				
					tr.references.get('youtubediv').innerHTML = '<table cellpadding=0 cellspacing=0 border=0 style="background-image:url(' + imagePath + 'alternating_blue_white.gif)" width="100%" height="100%" >' + tr.templates.get('ytrowformat') + '</table>';					
					this.startIndex = 1;			
					this.searchTerms[0] = this.lastSearch;					
					this.youtuberesults.clear();
					vol.queryYouTube(encodeURI(this.searchTerms[0]), this.startIndex, this.maxResults);
					tr.references.get('search').blur();
				}
				break;

			case 'disc':
				this.setMode('disc');
				if (this.lastSearch != this.searchTerms[1]) {			
					//CLEAR DOWN THE ARRAY
					this.references.get('sloader').style.display = 'block';
					tr.references.get('discdiv').innerHTML = '<table style="background-color:262626" cellpadding=20 cellspacing=0 border=0 width="100%" height="100%" ><tr><td valign="top" class="ftextwhite" ></td></tr></table>';			
					this.discs.clear();
					this.searchTerms[1] = this.lastSearch;
					//alert(encodeUTF8(this.searchTerms[1]))
					vol.getDiscography(encodeURI(this.searchTerms[1]));
					tr.references.get('search').blur();				
				}
				break;						
				
			case "playlistsearch":
				if (this.mode != 'playlistsearch') {this.setMode('playlistsearch')};	
				this.references.get('sloader').style.display = 'block';				
				tr.references.get('playgriddiv').innerHTML = '<table id="tunegrid" cellpadding=0 cellspacing=0 border=0 style="background-image:url(' + imagePath + 'alternating_blue_white.gif)" width="100%" height="100%" >' + tr.templates.get('plrowformat') + '</table>';
				this.searchTerms[2] = this.lastSearch;
				this.playlists.unselect(this.curPl.id);
				if (this.curPl.id.length > 0) {this.lastPlid = this.curPl.id};
				this.curPl = new Playlist();
				//DESELECT THE CURRENT PLAYLIST		
				com('func.asp?c=loadpl&s=' + escape(this.searchTerms[2]), parseXML);
				this.references.get('search').blur();	
				break;
			
			case "publicsearch":
				//this.lastPlid = this.curPl.id;
				if (this.mode != 'public') {this.setMode('public')};
				this.references.get('sloader').style.display = 'block';
				tr.references.get('publicdiv').innerHTML = '<table cellpadding=0 cellspacing=0 border=0 style="background-image:url(' + imagePath + 'alternating_blue_white.gif)" width="100%" height="100%" >' + tr.templates.get('pubrowformat') + '</table>';
				this.pubStartIndex = 1;
				this.searchTerms[3] = this.lastSearch;
				this.playlists.unselect(this.curPl.id);
				com('func.asp?c=loadpls&s=' + escape(this.searchTerms[3]) + '&si=' + this.pubStartIndex + '&mr=' + this.pubMaxResults, parseXML);
				this.references.get('search').blur();	
				break;				
		}
				
	}
}
TubeRadio.prototype.nextYtResults = function () {
	this.youtuberesults.clear();
	this.startIndex += this.maxResults;
	vol.queryYouTube(this.searchTerms[0], this.startIndex, this.maxResults);
}
TubeRadio.prototype.prevYtResults = function () {
	if (this.startIndex > 1) { 
		this.startIndex -= this.maxResults;
		this.youtuberesults.clear();
		vol.queryYouTube(this.searchTerms[0], this.startIndex, this.maxResults);
	}
}
TubeRadio.prototype.nextPubResults = function () {
	this.pubStartIndex += this.pubMaxResults;
	com('func.asp?c=loadpls&s=' + this.searchTerms[3] + '&si=' + this.pubStartIndex + '&mr=' + this.pubMaxResults, parseXML);
}
TubeRadio.prototype.prevPubResults = function () {
	if (this.pubStartIndex > 1) {
		this.pubStartIndex -= this.pubMaxResults;
		com('func.asp?c=loadpls&s=' + this.searchTerms[3] + '&si=' + this.pubStartIndex + '&mr=' + this.pubMaxResults, parseXML);		
	}
}
TubeRadio.prototype.captureKeypress = function (e, callback) {
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;

	if (keycode == 13) {
		eval(callback);
		return false;			

	}
}
TubeRadio.prototype.captureKeydown = function (e) {
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;

	switch (keycode) {
		case 38: //UP
			if (this.curSh > 1) {
				if (g('sh' + this.curSh) != undefined) {
					g('sh' + this.curSh).style.backgroundColor='';
				}			
				this.curSh -= 1;
				if (g('sh' + this.curSh) != undefined) {
					g('sh' + this.curSh).style.backgroundColor='EFF3F9';
					if (this.curSh != 0) {this.references.get('search').value = HtmlDecode(g('sh' + this.curSh).innerHTML)};
				}
			}
			return false;
			break;
	
		case 40: //DOWN
			if (this.curSh < 9) {
				if (g('sh' + this.curSh) != undefined) {
					g('sh' + this.curSh).style.backgroundColor='';
				}			
				this.curSh += 1;
				if (g('sh' + this.curSh) != undefined) {
					g('sh' + this.curSh).style.backgroundColor='EFF3F9';
					if (this.curSh != 0) {this.references.get('search').value = HtmlDecode(g('sh' + this.curSh).innerHTML)};
				}
			}
			return false;
			break;

		case 37: //LEFT
		case 39: //RIGHT
			break;
			
		case 8: //BACKSPACE
			
			
		default:
			tr.getSearchHint(this.references.get("search").value + keycode);
		
		
	}
		
}
TubeRadio.prototype.setRating = function (rating) {
	for (var i=1;i<6;i++) {
		if (i <= rating) {
			this.references.get('star' + i).src=imagePath + 'opt_rate_star_over.png';
		} else {
			this.references.get('star' + i).src=imagePath + 'opt_rate_star.png';
		}
	}
}
TubeRadio.prototype.rate = function (id, rating) {
	this.setRating(rating);
	this.playlists.get(id).userrating = rating;
	com('func.asp?c=rate&pl=' + this.pl + '&ra=' + rating, noCallback);
}
TubeRadio.prototype.toggleMyPlaylists = function () {
	if (tr.references.get('myplaylists').style.display == 'block') {
		this.hideMyPlaylists();
	} else {
		this.showMyPlaylists();
	}	
}
TubeRadio.prototype.toggleSharedPlaylists = function () {
	if (tr.references.get('sharedplaylists').style.display == 'block') {
		this.hideSharedPlaylists();
	} else {
		this.showSharedPlaylists();
	}	
}
TubeRadio.prototype.showMyPlaylists = function () {
	tr.references.get('togglemyplaylists').src = imagePath + 'playlist_arrow_expanded.png';
	tr.references.get('myplaylists').style.display = 'block';	
}
TubeRadio.prototype.hideMyPlaylists = function () {
	tr.references.get('togglemyplaylists').src = imagePath + 'playlist_arrow_collapsed.png';
	tr.references.get('myplaylists').style.display = 'none';	
}
TubeRadio.prototype.showSharedPlaylists = function () {
	tr.references.get('togglesharedplaylists').src = imagePath + 'playlist_arrow_expanded.png';
	tr.references.get('sharedplaylists').style.display = 'block';	
}
TubeRadio.prototype.hideSharedPlaylists = function () {
	tr.references.get('togglesharedplaylists').src = imagePath + 'playlist_arrow_collapsed.png';
	tr.references.get('sharedplaylists').style.display = 'none';	
}
TubeRadio.prototype.loadMiniPl = function (id) {
	this.playlists.load(id);
	var p = this.playlists.get(id)
	this.references.get('minipl').innerHTML = '<nobr>' + brief(p.name, 30);
	if (p.count > 0) {
		this.references.get('miniav').innerHTML = brief(p.videos[0].artist + ' - ' + p.videos[0].name, 30);
		this.play(p.videos[0].id, true);
	} else {
		this.references.get('miniav').innerHTML = '<nobr>Select...';
	}
	this.hideDialog();
}
TubeRadio.prototype.loadMiniAv = function (id) {
	this.play(id, true);
	var t = this.curPl.get(id)
	this.references.get('miniav').innerHTML = '<nobr>' + brief(t.artist + ' - ' + t.name, 30);
	this.hideDialog();
}
TubeRadio.prototype.loadPublicPl = function (id) {	
	this.pubPl = id;
	tr.references.get('playgriddiv').innerHTML = '<table id="tunegrid" cellpadding=0 cellspacing=0 border=0 style="background-image:url(' + imagePath + 'alternating_blue_white.gif)" width="100%" height="100%" >' + tr.templates.get('pubplrowformat') + '</table>';
	tr.setMode('publicplaylist');
	this.curPubPl = this.publicplaylists.get(id);	
	com("func.asp?c=loadpubpl&pl=" + id, parseXML);
	//loadXML('tr_pl.asp?pl=' + plid);
}
TubeRadio.prototype.showMenu = function (menu, id) {
	this.curMenu = menu;
	this.curMenuId = id;
	this.actionvalue = id;

	switch (this.curMenu) {
		case 'playlists':
		case 'plsplaylists':
		
			if (this.curMenu == 'playlists') {
				this.references.get('menu').innerHTML = tr.templates.get('menu').replace(/-content-/g, this.templates.get('options'));
			} else {
				this.references.get('menu').innerHTML = tr.templates.get('menu').replace(/-content-/g, this.templates.get('plsoptions'));
			}
		
			this.references.get('menu').style.top = (parseInt(yMousePos) - 38) + 'px';
			this.references.get('menu').style.left = (parseInt(xMousePos) + 10) + 'px';
			this.references.get('menu').style.display = 'block';	
			
			//DISABLE UNSUBSCRIBING FOR THE TUBERADIO PLAYLIST
			if (tr.actionvalue == '1' && this.curMenu == 'plsplaylists') {
				g('unsubscribediv').style.display = 'none';
			}
			
			//CHANGE THE OPTIONS IMAGE
			switch(g('plRow' + id).className) {
				case 'playlistentry':
				case 'playlistentryover':
					g('ploptimg' + id).src = imagePath + 'btn_optionicon_down.png';
					//RESET THE CLASSNAME TO GET AROUND IT STAYING 
					//IN THE MOUSEOVER STATE WHEN THE MENU APPEARS				
					g('plRow' + id).className = 'playlistentry';
					break;		
				case 'playlistentrysel':
					g('ploptimg' + id).src = imagePath + 'btn_optionicon_down.png';
					break;
				
			}
			break;
			
		case 'tunes':
		case 'shtunes':
			if (this.curMenu == 'shtunes') {
				this.references.get('menu').innerHTML = tr.templates.get('menu').replace(/-content-/g, this.templates.get('shoptions'));
			} else {
				this.references.get('menu').innerHTML = tr.templates.get('menu').replace(/-content-/g, this.templates.get('toptions'));
			}
		
			if (this.playlists.q.length > 0 && this.playlists.qPl == this.curPl.id) {
				g('qoptions').style.display = 'block';
			} else {
				g('qoptions').style.display = 'none';		
			}
			
			this.references.get('menu').style.top = (parseInt(yMousePos) - 38) + 'px';
			this.references.get('menu').style.left = (parseInt(xMousePos) + 10) + 'px';
			this.references.get('menu').style.display = 'block';	

			if (g('t'+id+'i2').className == 'tuneentrydisabled') {
				g('topt' + id).style.backgroundImage  = 'url(' + imagePath + 'btn_missing_over.png)';	
			} else {
				g('topt' + id).style.backgroundImage = 'url(' + imagePath + 'btn_optionicon_white_down.png)';
			}	

			break;
			
		case 'download':
			var t = tr.templates.get('menu').replace(/-content-/g, this.templates.get('download'));
			t = t.replace(/-dalbumname-/g, id);
			this.references.get('menu').innerHTML = t;
			this.references.get('menu').style.top = (parseInt(yMousePos) - 97) + 'px';
			this.references.get('menu').style.left = (parseInt(xMousePos) - 65) + 'px';
			this.references.get('menu').style.display = 'block';
			break;
	}

}
TubeRadio.prototype.hideMenus = function () {
	this.references.get('menu').style.display = 'none';	
	this.references.get('alert').style.display = 'none';	
		
	if (this.menuMode == 'rename') {
		this.cancelRename();
	}
		
	switch (this.curMenu) {
		case 'playlists':
		case 'plsplaylists':
			g('ploptimg' + this.curMenuId).src = imagePath + 'btn_optionicon.png';
			break;
		case 'tunes':
		case 'shtunes':
			g('topt' + this.curMenuId).style.backgroundImage = 'url(' + imagePath + 'btn_optionicon_white.png)';
			break;
	}
	
	this.curMenu = '';
	this.curMenuId = 0;		
}
TubeRadio.prototype.showAlert = function (alname) {
	this.references.get('alert').innerHTML = tr.templates.get('alert').replace(/-content-/g, this.templates.get(alname));
	this.references.get('alert').style.top = this.references.get('menu').style.top;
	this.references.get('alert').style.left = this.references.get('menu').style.left;
	this.references.get('alert').style.display = 'block';
}
TubeRadio.prototype.startRename = function () {
	this.hideMenus();
	this.menuMode = 'rename';
	g('plname'+this.actionvalue).style.display='none';
	g('changepl'+this.actionvalue).style.display='block';
	g('changepl'+this.actionvalue).focus();
	g('changepl'+this.actionvalue).select();
}
TubeRadio.prototype.cancelRename = function () {
	var tpl = this.playlists.get(this.actionvalue);
	if (g('changepl' + this.actionvalue).value != tpl.name && g('changepl' + this.actionvalue).value.length > 0) {
		this.menuMode = '';	
		g('plname'+this.actionvalue).style.display='block';
		g('changepl'+this.actionvalue).style.display='none';			
		g('plname'+this.actionvalue).innerHTML = g('changepl'+this.actionvalue).value;
		//UPDATE THE ARRAY VALUE	
		tpl.name = g('changepl' + this.actionvalue).value;	
		com('func.asp?c=renamepl&pl=' + this.actionvalue + '&n=' + tpl.name, noCallback);
	} else {		
		g('plname'+this.actionvalue).style.display='block';
		g('changepl'+this.actionvalue).style.display='none';
		this.menuMode = '';	
	}
}
TubeRadio.prototype.addPlaylist = function () {
	if (tr.references.get('plname').value.length > 0 && tr.references.get('plname').value != 'Start a new playlist...') {	
		this.showMyPlaylists();
		com('func.asp?c=addpl&n=' + tr.references.get('plname').value, parseXML);
		tr.references.get('plname').value = 'Start a new playlist...';
		tr.references.get('plname').blur();
	}	
}
TubeRadio.prototype.deletePlaylist = function (id) {
	if (this.playlists.myPlCount == 1) {
		alert('You must have at least 1 playlist');
		return false;
	} else {
		if (this.curPl.id == id) {	
			for (var i=0;i<this.playlists.count;i++) {
				if (this.playlists.playArr[i].id == parseInt(id)) {
					if ((i+1) == this.playlists.count) {
						this.playlists.load(this.playlists.playArr[0].id);
					} else {
						this.playlists.load(this.playlists.playArr[i+1].id);
					}
					break;
				}	
			}
		}
		this.playlists.del(id);
		removeRow('plRow' + id);
		com('func.asp?c=delpl&pl=' + id, noCallback)
	}
}
TubeRadio.prototype.saveEditVid = function () {
	if (this.curPl.selCount > 1) {	
		var art = g('tartist').value;
		var alb = g('talbum').value;
		for (i=0;i<this.curPl.selCount;i++) {
			var v = this.curPl.get(this.curPl.sel[i]);
			
			if (art.length > 0) {
				v.artist = art;
				g('t' + this.curPl.sel[i] + 'i3').innerHTML = art
			}
			v.album = alb;
			g('t' + this.curPl.sel[i] + 'i4').innerHTML = alb;
		}
		this.curPl.sort(this.so);
		this.curPl.display();			
		this.hideDialog();
		com('func.asp?c=editvids&v=' + this.curPl.sel.join(",") + '&a=' + escape(art) + '&al=' + escape(alb), noCallback);
	} else {
		var v = this.curPl.get(this.editVidId);
		if (g('tname').value.length > 0) {		
			v.name = g('tname').value;
			v.artist = g('tartist').value;
			v.album = g('talbum').value;		
			g('t' + this.editVidId + 'i2').innerHTML = v.name;
			g('t' + this.editVidId + 'i3').innerHTML = v.artist;
			g('t' + this.editVidId + 'i4').innerHTML = v.album;
			this.curPl.sort(this.so);
			this.curPl.display();
			com('func.asp?c=editvid&t=' + this.editVidId + '&n=' + escape(v.name) + '&a=' + escape(v.artist) + '&al=' + escape(v.album), noCallback);
			this.hideDialog();
		} else {
			//NO NAME SUPPLIED
			g('tname').value = unescape(v.name);
			g('tname').style.backgroundColor = 'FFD3D3';
			g('tname').focus();
			g('tname').select();
		}
	}
}
TubeRadio.prototype.clearSort = function () {
	//PUTS THE PLAYGRID IN CUSTOM SORT MODE
	this.so = 't_seq'; //CUSTOM SORT
	createCookie('so',this.so,31);
	
	for (var i=1;i<5;i++) {
		this.references.get('sortimg' + i).src = imagePath + 'sort_arrow_custom.gif';
		this.references.get('col' + i).className = 'playgridcolheader';		
	}
	
	this.curPl.highlightSel();
}
TubeRadio.prototype.doSort = function (colname) {	
	var temp;
	var newimg;
	var newclass;

	if (colname == 'name') {temp = 1};
	if (colname == 'artist') {temp = 2};
	if (colname == 'album') {temp = 3};
	if (colname == 'duration') {temp = 4};
	
	if (this.so == colname + ' desc') {
		this.so = 't_seq'; //CUSTOM SORT
		newimg = 'sort_arrow_custom.gif';
		newclass = 'playgridcolheader';
	} else if (this.so == colname) {
		this.so = colname + ' desc'; // DESCENDING
		newimg = 'sort_arrow_down.gif';
		newclass = 'playgridcolheadersel';	
	} else {
		this.so = colname;
		newimg = 'sort_arrow_up.gif';
		newclass = 'playgridcolheadersel';			
	}
	
	for (var i=1;i<5;i++) {
		if (temp == i) {
			this.references.get('sortimg' + i).src = imagePath + newimg;
			this.references.get('col' + i).className = newclass;			
		} else {
			this.references.get('sortimg' + i).src = imagePath + 'sort_arrow_custom.gif';
			this.references.get('col' + i).className = 'playgridcolheader';		
		}
	}	

	createCookie('so',this.so,31);
	if (this.mode == 'publicplaylist') {
		this.curPubPl.sort(this.so);
		this.curPubPl.display();
	} else {
		this.curPl.sort(this.so);
		this.curPl.display();
	}
	
	this.curPl.highlightSel();
	
}
TubeRadio.prototype.showTabLoader = function () {
	this.references.get('tabwait').style.width=this.references.get('trackinfo').offsetWidth + 'px';
	this.references.get('tabwait').style.height=this.references.get('trackinfo').offsetHeight + 'px';
	this.references.get('trackinfo').style.overflow='hidden';
	this.references.get('tabwait').style.display='block';
}
TubeRadio.prototype.loadContent = function (id, src) {
	//UNSELECT THE LAST TAB
	var o = this.tabgroup.get(this.lastTg);
	if (o != false) {	
		this.tabgroup.unselect(this.lastTg);
		if (o.stat != true) {g('tgi' + this.lastTg).src = imagePath + 'tg_close.png'};	
		if (this.lastTg == this.tabgroup.tabs[0].id) {this.references.get('tabspacer').style.display ='none'}
		g(o.id + 'sep').style.display = 'block';
		if (this.lastTg != this.tabgroup.tabs[0].id) {
			//SHOW THE LEFT SEPARATOR
			g(this.tabgroup.tabs[this.tabgroup.getTabNo(this.lastTg) -1].id + 'sep').style.display = 'block';		
		}
		if (this.lastTg != 'tgtuberadio') {g(this.lastTg).className = 'tabgroup'};
	}
	
	if (this.lastTg == 'tgtuberadio') {
		this.references.get('tgtuberadio').style.backgroundImage = 'url(' + imagePath + 'tg.gif)';
		this.references.get('trlogo').src = imagePath + 'icon_logo.png';
	}
	
	if (id == 'tgtuberadio') {
	
		//LASTFM LOGO
		if (this.curTabNo == 1) {	
			g('lastfmlogo').style.display = 'none';
		} else {
			g('lastfmlogo').style.display = 'block';
		}	
	
		this.browseMode = 'player';
		this.references.get('contentdiv').style.display = 'none';
		this.references.get('player').style.height = '100%';
		this.references.get('miniplay').style.display = 'none';
		this.references.get('searchsection').style.display = 'block';
		this.references.get('minipl').value = '<nobr>' + brief(this.curPl.name, 30);
		this.references.get('tgtuberadio').style.backgroundImage = 'url(' + imagePath + 'tg_sel.gif)';
		this.references.get('trlogo').src = imagePath + 'icon_logo_sel.png';
		this.references.get('trtabspacer').style.display = 'block';
		if (this.mode == 'disc') {this.references.get('discdiv').style.display = 'block'};
		if (this.curVid != undefined) {
			this.references.get('miniav').value = '<nobr>' + brief(this.curVid.name, 30);
		}
		
		if (this.playlists.forceReload) {
			this.playlists.clear();
			this.references.get('sharedplaylists').innerHTML = '';
			com ("func.asp?c=loadpls", parseXML);	
			this.playlists.forceReload = false;
		}
		
		if (this.curPl.cached != true) {
			this.playlists.load(this.pl);
		}
		
	} else {	
	
		//LASTFM LOGO
		g('lastfmlogo').style.display = 'none';	
	
		//SELECT THE NEW TAB
		g(id).className = 'tabgroupsel';
		
		this.references.get('trtabspacer').style.display = 'none';
		
		var o = this.tabgroup.get(id);
		if (o != false) {
			this.tabgroup.select(id);
			if (o.stat != true) {g('tgi' + id).src = imagePath + 'tg_close_sel.png'};
			if (id == this.tabgroup.tabs[0].id) {this.references.get('tabspacer').style.display ='block'}
			g(o.id + 'sep').style.display = 'none';
			if (id != this.tabgroup.tabs[0].id) {
				//HIDE THE LEFT SEPARATOR
				g(this.tabgroup.tabs[this.tabgroup.getTabNo(id) -1].id + 'sep').style.display = 'none';
			}
		}
		
		if (this.curPl != undefined) {
				var t = this.curPl
				this.references.get('minipl').innerHTML = '<nobr>' + brief(t.name, 30);			
		
				if (this.curVid != undefined) {
					var t = this.curVid
					this.references.get('miniav').innerHTML = '<nobr>' + brief(t.artist + ' - ' + t.name, 30);		
				}
		}		
		
		this.tabgroup.ensureVisible(id);
		this.browseMode = 'content';
		this.references.get('player').style.height = '1px';
		this.references.get('miniplay').style.display = 'block';
		this.references.get('searchsection').style.display = 'none';		
		this.references.get('discdiv').style.display = 'none';
		this.references.get('contentdiv').style.display = 'block';
		this.references.get('content').src = src;
	}
	this.lastTg = id;
	resizeClient();
}
TubeRadio.prototype.loadTG = function (id, name, click) {
	//this.tabgroup.unselect(this.lastTg);
	//g(this.lastTg).className = 'tabgroup';
	
	var t = new Tab();
	t.id = id;
	t.name = name;
	t.click = click;
	var o = this.tabgroup.get(t.id);
	if (o == false) {
		this.tabgroup.add(t);
		o = this.tabgroup.tabs[this.tabgroup.count];
	}
	this.displayTG();
	
	//this.tabgroup.select(id);
	//g(id).className = 'tabgroupsel';
	//g('tgi' + id).src = imagePath + 'tg_close_sel.png';
	//this.browseMode = 'content';
	//this.references.get('player').style.height = '1px';
	//this.references.get('contentdiv').style.display = 'block';
	eval(click);
	//this.references.get('content').src = src;
	
	//this.lastTg = id;
	//resizeClient();	
}
TubeRadio.prototype.displayTG = function () {
	var outArr = new Array();
	outArr.push('<table cellpadding="0" cellspacing="0" border="0" height=23 ><tr>');
	for (var i=0;i<this.tabgroup.count;i++) {
		if (this.tabgroup.tabs[i].stat) {var t=this.templates.get('tgstat')} else {var t=this.templates.get('tg')}
		t = t.replace(/-id-/g, this.tabgroup.tabs[i].id);
		t = t.replace(/-src-/g, this.tabgroup.tabs[i].src);	
		t = t.replace(/-name-/g, this.tabgroup.tabs[i].name);	
		t = t.replace(/-click-/g, this.tabgroup.tabs[i].click);	
		outArr.push(t);
	}
	outArr.push('</tr></table>');
	this.references.get('tabgroup').innerHTML = outArr.join('');
	this.tabgroup.calcWidths();
}
TubeRadio.prototype.closeTG = function (id) {
	if (this.tabgroup.curTab == id) {
		var t = this.tabgroup.get(id);
		this.tabgroup.curTab = this.tabgroup.tabs[t.tabno - 1].id;
		if (this.tabgroup.curTab == 'tglogout') {
			this.tabgroup.curTab = this.tabgroup.tabs[t.tabno - 2].id;
		}
	}
	this.tabgroup.del(id);
	this.displayTG();
	eval(this.tabgroup.get(this.tabgroup.curTab).click);
}
TubeRadio.prototype.prevTG = function (id) {
	var t = this.tabgroup.get(this.tabgroup.curTab);
	this.tabgroup.curTab = this.tabgroup.tabs[t.tabno - 1].id;
	eval(this.tabgroup.get(this.tabgroup.curTab).click);
	

}
TubeRadio.prototype.nextTG = function (id) {
	var t = this.tabgroup.get(this.tabgroup.curTab);
	//alert(t.tabno + ' ' + t.count);
	if (t.tabno + 1 < this.tabgroup.count) {
		this.tabgroup.curTab = this.tabgroup.tabs[t.tabno + 1].id;
		eval(this.tabgroup.get(this.tabgroup.curTab).click);
	}
}
TubeRadio.prototype.login = function (id) {
	com('login.asp?c=login', handleResponse, g('trloginfrm'), 'trlogindiv');
}
TubeRadio.prototype.buyFromAmazon = function (alb, art) {
	this.amazonRedirect = true;
	vol.getAmazonInfo(alb, art, '');
}
TubeRadio.prototype.share = function (opt) {

	if (this.actionvalue.length == 0) {
		this.actionvalue = this.pl;
	}

	switch (opt) {
		case "0":
			g('shtext').style.display='none';
			g('shfriends').style.display='none';
			g('shshare').style.display='none';		
		
			break
	
		case "1": //FRIENDS AND FANS
			g('shtext').style.display='none';
			g('shfriends').style.display='block';
			g('shshare').style.display='block';
			com('shfriends.asp', handleResponse, undefined, 'shfriends');
			
			break;
	
		case "2": //EMAIL
			g('shtext').style.display='block';
			g('shfriends').style.display='none';
			g('shshare').style.display='none';
			g('embed').value='I wanted to share this Tuberadio playlist with you: http://www.tuberadio.fm/?pl=' + this.actionvalue;
			g('embedins').innerHTML = 'Copy the text below to a new email if it hasn\'t been done automatically';

			var email = "";
			var subject = "Tuberadio Playlist: " + this.playlists.get(this.actionvalue).name;
			var link = "http://www.tuberadio.fm/?pl=" + this.actionvalue;
			var body = 'I wanted to share this Tuberadio playlist with you: ' + link;

			var mailto_link = 'mailto:?subject='+subject+'&body='+body;

			var win = window.open(mailto_link,'emailWindow');
			if (win && win.open &&!win.closed) win.close();			
			
			
			break;
			
		case "3": //LINK
			g('shtext').style.display='block';
			g('shfriends').style.display='none';
			g('shshare').style.display='none';
			g('embed').value='http://www.tuberadio.fm/?pl=' + this.actionvalue;
			g('embedins').innerHTML = 'Copy the link below to share this playlist';			
			break;
			
		case "4": //EMBED
			g('shtext').style.display='block';
			g('shfriends').style.display='none';
			g('shshare').style.display='none';
			var str = g('embedtext').value;
			t = str.replace(/-pl-/g, this.actionvalue);			
			g('embed').value=t;
			g('embedins').innerHTML = 'Paste the code below to embed in your site / blog';			
			break;
			
		case "5": //TWITTER
			g('shtext').style.display='none';
			g('shfriends').style.display='none';
			g('shshare').style.display='none';
			var ext_link = 'http://twitter.com/home?status=' + encodeURIComponent('Check out my #TubeRadio.fm "' + brief(this.playlists.get(this.actionvalue).name, 60) + '" playlist: http://www.tuberadio.fm/?pl=' + this.actionvalue);
			var win = window.open(ext_link,'extWindow');	
			break;	

		case "6": //FACEBOOK
			g('shtext').style.display='none';
			g('shfriends').style.display='none';
			g('shshare').style.display='none';
			var ext_link = 'http://www.facebook.com/sharer.php?u=' + encodeURIComponent('http://www.tuberadio.fm/?pl=' + this.actionvalue) + '&t=' + encodeURIComponent('Check out my TubeRadio.fm "' + this.playlists.get(this.actionvalue).name + '" playlist!');
			var win = window.open(ext_link,'extWindow');	
			break;	
			
	}
}
TubeRadio.prototype.scrobble = function (vid, curTime) {
	//LASTFM SCROBBLE
	var dur = convDurToSecs(vid.duration);
	if (scrobble && (dur > 30) && ((curTime >= (dur / 2)) || (curTime >= 240))) {	
		vol.scrobble (lfmu, lfmkey, vid.name, vid.artist, dur)		
	}
}
TubeRadio.prototype.startVidDrag = function (id) {
	tr.dragMode = 'vid';
}
TubeRadio.prototype.vidMouseDown = function (id) {

	deselect();
	document.onmouseup = tr.vidMouseUp;

	switch (tr.curKey) {
		case 'ctrl':
			if (this.curPl.inSel(id) == false) {
				this.curPl.addSel(id);
				this.curPl.get(id).select();
			} else {
				this.curPl.delSel(id);
				this.curPl.get(id).unselect();			
			}
			this.dragId = 0;
			break;
			
		case 'shift':
			if (this.curPl.inSel(id) == false) {
				
				if (this.curPl.selCount > 0) {
					var selecting = false
					var lastVid = false;
					for (var i=0;i<this.curPl.count; i++) {
						
						if (this.curPl.videos[i].id == id || this.curPl.inSel(this.curPl.videos[i].id)) {
							if (selecting) {selecting = false;lastVid = true} else {selecting = true};
						}
						
						if (selecting || lastVid) {
							if (this.curPl.inSel(this.curPl.videos[i].id) == false) {this.curPl.addSel(this.curPl.videos[i].id)};
							this.curPl.videos[i].select();
							if (lastVid) {break;}
						} else {
							this.curPl.videos[i].unselect();
						}
					}
				} else {
					this.curPl.addSel(id);
					this.curPl.get(id).select();		
				}
			}		
			this.dragId = 0;
			break;			
		
		default:
			
			if (this.curPl.inSel(id) == false) {
				this.curPl.clearSel();
				this.curPl.addSel(id);
				this.curPl.get(id).select();		

			}
			this.dragId = id;
			this.mouseOffset = yMousePos % 1;			
			this.dragTimeoutId = setTimeout('tr.startVidDrag();', 300);
	}
	
	document.body.focus(); 
	document.onselectstart = function () { return false; }; 
	//target.ondragstart = function() { return false; };  	
	document.ondragstart = function () {return false};
	return false;

}
TubeRadio.prototype.vidMouseUp = function (id) {	
	
	deselect();
	
	if (id != undefined) {tr.vidDoubleClick(id)}
	document.onmouseup = mup;
	document.body.style.cursor='default';
	if (tr.dragTimeoutId != undefined) {clearTimeout(tr.dragTimeoutId)};
		
	if (tr.so != "t_seq") {hideInfo()};
	
	if (xMousePos < 250) {
		
		if (yMousePos > (120 - tr.references.get('playlists').scrollTop) && yMousePos < (120 + tr.references.get('myplaylists').offsetHeight - tr.references.get('playlists').scrollTop)) {	
					
			var pos = Math.round((yMousePos - 120 + tr.references.get('playlists').scrollTop) / 20);
			
			var j = 0;
			for (var i=0;i<tr.playlists.count;i++) {
				if (tr.playlists.playArr[i].shared != 1) {j+=1};
				if (j == pos) {
					var dropPl = tr.playlists.playArr[i];
					break;
				};
			}
			
			if (dropPl != undefined) {			
				g('dragdiv').innerHTML = "Adding...";
				setTimeout("g('dragdiv').style.display = 'none'", 500);
				if (dropPl.id != tr.curPl.id) {
					if (browser != 'ff' || browser == 'ff' && id != undefined) { //PREVENT FF FROM FIRING THE EVENT TWICE
						dropPl.cached = false;
						com ("func.asp?c=sendq", noCallback, undefined, undefined, "enqplid=" + dropPl.id + "&enqlist=" + tr.curPl.sel.join(","));					
					}
				}
			} else {
				g('dragdiv').style.display = 'none';
			}
		} else {
			g('dragdiv').style.display = 'none';
		}
	} else {
	
		g('dragdiv').style.display = 'none';
		
		if (this.curPl.shared != 1) {
		
			var pgOffset = 0;
			if (g('nlin') != undefined) {pgOffset = g('nlin').offsetHeight};
		
			if (yMousePos > 109 && yMousePos < (109 + tr.references.get('playgriddiv').offsetHeight + pgOffset)) {
		
				var pos = Math.round((((yMousePos - 109 + tr.references.get('playgriddiv').scrollTop - pgOffset)) / 17 + tr.mouseOffset));
					
				if (pos < (tr.curPl.count - 1) && pos >= 0) {
					id = tr.curPl.videos[pos].id;
				} else {
					if (pos < 0) {
						id = tr.curPl.videos[0].id;
					} else {		
						id = tr.curPl.videos[tr.curPl.count - 1].id;
					}
				}
				
				if (tr.dragTimeoutId != undefined) {clearTimeout(tr.dragTimeoutId)};

				if (tr.dragMode == 'vid' && tr.dragId != id && tr.so == 't_seq') {
					tr.curPl.moveSel(id);
					tr.curPl.display();
					tr.curPl.highlightSel();

				} else {
					if (tr.curPl.inSel(id) && tr.curPl.selCount > 0) {
						tr.curPl.get(id).select()
					};
				}	
				
			}
		}
	}
	
	tr.dragMode = '';
	tr.dragId = 0;	
	document.onselectstart = null; 
	document.ondragstart = null;

}
TubeRadio.prototype.vidMouseMove = function (id) {
	//deselect();
	document.body.style.cursor='pointer';
	
	if (xMousePos < 250) {
		
		if (yMousePos <= (120  - tr.references.get('playlists').scrollTop) || yMousePos >= (120 + this.references.get('myplaylists').offsetHeight  - tr.references.get('playlists').scrollTop)) {
			if (tr.so != "t_seq") {
				hideInfo();
			} else {
				this.references.get('dragdiv').style.left = xMousePos - 100 + 'px';
				this.references.get('dragdiv').style.top = yMousePos + 'px';
				this.references.get('dragdiv').innerHTML = this.curPl.selCount + ' items';
				this.references.get('dragdiv').style.backgroundImage = 'url(' + imagePath + 'drag.png)';
				if (this.references.get('dragdiv').style.display != 'block') {
					this.references.get('dragdiv').style.display = 'block';
				}	
			}
			if (this.dragSnapTimeoutId != undefined) {clearTimeout(this.dragSnapTimeoutId)};
			
		} else {	
		
			if (this.dragSnapTimeoutId != undefined) {	
				this.references.get('dragdiv').style.left = xMousePos - 100 + 'px';
				this.references.get('dragdiv').style.top = yMousePos + 'px';	
				clearTimeout(this.dragSnapTimeoutId);
				this.dragSnapTimeoutId = setTimeout("tr.dragSnap('pl')", 250);
			} else {
				this.dragSnapTimeoutId = setTimeout("tr.dragSnap('pl')", 250);
			}
		
			if (this.references.get('dragdiv').style.display != 'block') {
				this.references.get('dragdiv').style.display = 'block';
			}		
			
			var pos = Math.round((yMousePos - 120 + this.references.get('playlists').scrollTop) / 20) - 1;
			
			if (this.playlists.playArr[pos] != undefined) {
				if (this.playlists.playArr[pos].id != this.curPl.id) {str = '[<b>+</b>] ' + this.curPl.selCount + ' Items'} else {str = 'Current Playlist!'};
				this.references.get('dragdiv').style.backgroundImage = 'url(' + imagePath + 'drag_sel.png)';				
				this.references.get('dragdiv').innerHTML = str;
			}
		}
		
	} else {
		
		var pgOffset = 0;
		if (g('nlin') != undefined) {pgOffset = g('nlin').offsetHeight};
	
		if (yMousePos < 109 || yMousePos > (109 + this.references.get('playgriddiv').offsetHeight + pgOffset)) {
			if (tr.so != "t_seq") {hideInfo()};
			if (this.references.get('dragdiv').style.display != 'none') {
				this.references.get('dragdiv').style.display = 'none';
			}
			if (this.dragSnapTimeoutId != undefined) {clearTimeout(this.dragSnapTimeoutId)};
			
		} else {	
		
			if (tr.so != "t_seq") {
				showInfo("Change to custom sort mode to move videos.<br>Click the sorted column until it turns grey!");
				return false;
			}
			this.references.get('dragdiv').style.backgroundImage = 'url(' + imagePath + 'drag_sel.png)';
			this.references.get('dragdiv').style.left = xMousePos + 20 + 'px';
			this.references.get('dragdiv').style.top = yMousePos + 'px';			
			
			if (this.dragSnapTimeoutId != undefined) {clearTimeout(this.dragSnapTimeoutId)};
			this.dragSnapTimeoutId = setTimeout("tr.dragSnap('vid')", 250);

			if (this.references.get('dragdiv').style.display != 'block') {
				this.references.get('dragdiv').style.display = 'block';
			}		
		}	
		if (this.curPl.shared != 1) {
			this.references.get('dragdiv').innerHTML = 'Moving ' + this.curPl.selCount + ' Items';
		} else {
			this.references.get('dragdiv').innerHTML = 'Not Your Playlist!';
		}
		
	}	
}
TubeRadio.prototype.vidDoubleClick = function (id) {
	if (this.doubleClickTimeoutId != undefined && id == this.clickId) {	
		clearTimeout(this.doubleClickTimeoutId);
		deselect();
		this.curPl.clearSel();
		this.dragMode = '';
		this.dragId = 0;
		this.play(id, true);
	} else {
		this.clickId = id;
		clearTimeout(this.doubleClickTimeoutId);
		this.doubleClickTimeoutId = setTimeout("tr.cancelDoubleClick();", 300);
	}
}
TubeRadio.prototype.cancelDoubleClick = function () {
	this.clickId = 0;
	if (this.doubleClickTimeoutId != undefined) {clearTimeout(this.doubleClickTimeoutId)};

}
TubeRadio.prototype.dragSnap = function (t) {
	deselect();
	this.dragSnapTimeoutId = undefined;
	
	switch (t) {
		case 'vid':	
			var pgOffset = 0;
			if (g('nlin') != undefined) {pgOffset = g('nlin').offsetHeight};		
			this.references.get('dragdiv').style.left = xMousePos + 20 + 'px';
			var pos = 109 + pgOffset + Math.round((yMousePos - 109 - pgOffset) / 17) * 17;
			this.references.get('dragdiv').style.top = pos + 'px';
			break;
			
		case 'pl':
			this.references.get('dragdiv').style.left = xMousePos - 100 + 'px';
			var pos = 120 + Math.round((yMousePos - 120) / 20) * 20 - 7;			
			this.references.get('dragdiv').style.top = pos + 'px';		
			break;
	
	}
}
TubeRadio.prototype.startPlDrag = function (id) {
	tr.dragMode = 'pl';
}
TubeRadio.prototype.plMouseDown = function (id) {
	deselect();
	document.onmouseup = tr.plMouseUp;
	
	this.dragId = id;
	this.dragName = brief(tr.playlists.get(id).name,10);
	this.mouseOffset = yMousePos % 1;			
	this.dragTimeoutId = setTimeout('tr.startPlDrag();', 300);
	
	document.body.focus(); 
	document.onselectstart = function () { return false; }; 
	document.ondragstart = function () {return false};
	return false;	
}	
TubeRadio.prototype.plMouseUp = function (id) {	
	deselect();
	document.onmouseup = mup;
	document.body.style.cursor='default';	
	if (tr.dragTimeoutId != undefined) {clearTimeout(tr.dragTimeoutId)};
	
	//alert(tr.dragId + ' ' + id)
	
	g('dragdiv').style.display = 'none';
	
	if (tr.dragMode == 'pl') {
	
		if (xMousePos < 250) {
					
			if (yMousePos > (120 - tr.references.get('playlists').scrollTop) && yMousePos < (120 + tr.references.get('myplaylists').offsetHeight - tr.references.get('playlists').scrollTop)) {	
						
				var pos = Math.round((yMousePos - 120 + tr.references.get('playlists').scrollTop) / 20) + 1;
		
				//alert(pos)
		
				var j = 0;
				for (var i=0;i<tr.playlists.count;i++) {
					if (tr.playlists.playArr[i].shared != 1) {j+=1};
					if (j == pos) {
						var dropPl = tr.playlists.playArr[i];
						break;
					};
				}
									
				if (dropPl != undefined) {			
					if (dropPl.id != tr.dragId) {
						if (browser != 'ff' || browser == 'ff' && id != undefined) { //PREVENT FF FROM FIRING THE EVENT TWICE
							tr.playlists.move (dropPl.id, tr.dragId);
							tr.playlists.display();						
							com("func.asp?c=movepl&pl=" + tr.dragId + "&tpl=" + dropPl.id, noCallback);
						}
					}

				}
			}
		}
		
	} else {
		tr.playlists.load(id);
	}
	
	tr.dragMode = '';
	tr.dragId = 0;	
	document.onselectstart = null; 
	document.ondragstart = null;	
	
}
TubeRadio.prototype.plMouseMove = function (id) {
	document.body.style.cursor='pointer';
	
	if (xMousePos < 250) {
		
		if (yMousePos <= (120 - this.references.get('playlists').scrollTop) || yMousePos >= (120 + this.references.get('myplaylists').offsetHeight  - this.references.get('playlists').scrollTop)) {

			this.references.get('dragdiv').style.left = xMousePos - 100 + 'px';
			this.references.get('dragdiv').style.top = yMousePos + 'px';
			this.references.get('dragdiv').innerHTML = 'Can\'t Move Here';
			this.references.get('dragdiv').style.backgroundImage = 'url(' + imagePath + 'drag.png)';
			if (this.references.get('dragdiv').style.display != 'block') {
				this.references.get('dragdiv').style.display = 'block';
			}	
			
		} else {	
		 
			var pos = 120 + Math.round((yMousePos - 120) / 20) * 20;			
			this.references.get('dragdiv').style.top = pos + 'px';			
		
			this.references.get('dragdiv').style.left = xMousePos - 100 + 'px';
			this.references.get('dragdiv').style.top = pos + 'px';	
		
			if (this.references.get('dragdiv').style.display != 'block') {
				this.references.get('dragdiv').style.display = 'block';
			}		
			
			var pos = Math.round((yMousePos - 120 + this.references.get('playlists').scrollTop) / 20) - 1;
			
			if (this.playlists.playArr[pos] != undefined) {
				//if (this.playlists.playArr[pos].id != this.curPl.id) {str = 'Moving ' + tr.dragName} else {str=''};
				str = 'Moving ' + tr.dragName;
				this.references.get('dragdiv').style.backgroundImage = 'url(' + imagePath + 'drag_sel.png)';				
				this.references.get('dragdiv').innerHTML = str;
			}
		}
		
	} else {
		this.references.get('dragdiv').innerHTML = 'Can\'t Move Here';
		this.references.get('dragdiv').style.backgroundImage = 'url(' + imagePath + 'drag.png)';
		this.references.get('dragdiv').style.left = xMousePos + 20 + 'px';
		this.references.get('dragdiv').style.top = yMousePos + 'px';			
	
		if (this.references.get('dragdiv').style.display != 'block') {
			this.references.get('dragdiv').style.display = 'block';
		}			

	}
}
TubeRadio.prototype.startPlsDrag = function (id) {
	tr.dragMode = 'pls';
}
TubeRadio.prototype.plsMouseDown = function (id) {
	deselect();
	document.onmouseup = tr.plsMouseUp;

	this.dragId = id;
	this.dragName = brief(tr.playlists.get(id).name,10);
	this.mouseOffset = yMousePos % 1;			
	this.dragTimeoutId = setTimeout('tr.startPlsDrag();', 300);
	
	document.body.focus(); 
	document.onselectstart = function () { return false; }; 
	document.ondragstart = function () {return false};
	return false;
}	
TubeRadio.prototype.plsMouseUp = function (id) {	
	deselect();
	document.onmouseup = mup;
	document.body.style.cursor='default';	
	if (tr.dragTimeoutId != undefined) {clearTimeout(tr.dragTimeoutId)};
	
	//alert(tr.dragId + ' ' + id)
	
	g('dragdiv').style.display = 'none';
	
	if (tr.dragMode == 'pls') {
	
		if (xMousePos < 250) {
					
			if (yMousePos > ((140 + tr.references.get('myplaylists').offsetHeight) - tr.references.get('playlists').scrollTop) && yMousePos < (140 + tr.references.get('myplaylists').offsetHeight  + tr.references.get('sharedplaylists').offsetHeight - tr.references.get('playlists').scrollTop)) {	
						
				var pos = Math.round((yMousePos - 140 + tr.references.get('playlists').scrollTop) / 20) + 1;
		
				var j = 0;
				for (var i=0;i<tr.playlists.count;i++) {
					j+=1;
					if (j == pos) {
						var dropPl = tr.playlists.playArr[i];
						break;
					};
				}
									
				if (dropPl != undefined) {			
					if (dropPl.id != tr.dragId) {
						if (browser != 'ff' || browser == 'ff' && id != undefined) { //PREVENT FF FROM FIRING THE EVENT TWICE
							tr.playlists.move (dropPl.id, tr.dragId);
							tr.playlists.display();								
							com("func.asp?c=movepls&pl=" + tr.dragId + "&tpl=" + dropPl.id, noCallback);
						}
					}

				}
			}
		}
		
	} else {
		tr.playlists.load(id);
	}
	
	tr.dragMode = '';
	tr.dragId = 0;	
	document.onselectstart = null; 
	document.ondragstart = null;	
	
}
TubeRadio.prototype.plsMouseMove = function (id) {
	document.body.style.cursor='pointer';
	
	if (xMousePos < 250) {
		
		if (yMousePos <= ((140 + this.references.get('myplaylists').offsetHeight) - this.references.get('playlists').scrollTop) || yMousePos >= (140 + this.references.get('myplaylists').offsetHeight + this.references.get('sharedplaylists').offsetHeight - this.references.get('playlists').scrollTop)) {

			this.references.get('dragdiv').style.left = xMousePos - 100 + 'px';
			this.references.get('dragdiv').style.top = yMousePos + 'px';
			this.references.get('dragdiv').innerHTML = 'Can\'t Move Here';
			this.references.get('dragdiv').style.backgroundImage = 'url(' + imagePath + 'drag.png)';
			if (this.references.get('dragdiv').style.display != 'block') {
				this.references.get('dragdiv').style.display = 'block';
			}	
			
		} else {
		 
			var pos = 140 + Math.round((yMousePos - 140) / 20) * 20;			
			this.references.get('dragdiv').style.top = pos + 'px';			
		
			this.references.get('dragdiv').style.left = xMousePos - 100 + 'px';
			this.references.get('dragdiv').style.top = pos + 'px';	
		
			if (this.references.get('dragdiv').style.display != 'block') {
				this.references.get('dragdiv').style.display = 'block';
			}		
			
			var pos = Math.round((yMousePos - 140 + this.references.get('playlists').scrollTop) / 20) - 1;
			
			if (this.playlists.playArr[pos] != undefined) {
				//if (this.playlists.playArr[pos].id != this.curPl.id) {str = 'Moving ' + tr.dragName} else {str=''};
				str = 'Moving ' + tr.dragName;
				this.references.get('dragdiv').style.backgroundImage = 'url(' + imagePath + 'drag_sel.png)';				
				this.references.get('dragdiv').innerHTML = str;
			}
		}
		
	} else {
		this.references.get('dragdiv').innerHTML = 'Can\'t Move Here';
		this.references.get('dragdiv').style.backgroundImage = 'url(' + imagePath + 'drag.png)';
		this.references.get('dragdiv').style.left = xMousePos + 20 + 'px';
		this.references.get('dragdiv').style.top = yMousePos + 'px';			
	
		if (this.references.get('dragdiv').style.display != 'block') {
			this.references.get('dragdiv').style.display = 'block';
		}			

	}
}
TubeRadio.prototype.getSearchHint = function (s) {
	if (s.length > 2) {
		this.references.get('searchhint').style.top = '48px';
		this.references.get('searchhint').style.left = '319px';
		this.references.get('searchhint').style.width = this.references.get('search').offsetWidth + 'px';
		this.references.get('searchhint').style.innerHTML = '';
		this.curSh = 0;
		this.references.get('searchhint').style.display = 'block';
		if (this.shTimeoutId != undefined) {clearTimeout(this.shTimeoutId)};
		this.shTimeoutId = setTimeout("com('searchhint.asp?s=" + s.replace(/\'/g,'\'')  + "', handleResponse, undefined, 'searchhint')", 300);
	} else {
		this.shHide();
	}
}
TubeRadio.prototype.shHighlight = function (id) {
	if (g('sh' + this.curSh) != undefined) {
		g('sh' + this.curSh).style.backgroundColor='';
	}			
	this.curSh = id;
	if (g('sh' + this.curSh) != undefined) {
		g('sh' + this.curSh).style.backgroundColor='EFF3F9';
		this.references.get('search').value = HtmlDecode(g('sh' + this.curSh).innerHTML);
	}
}
TubeRadio.prototype.shHide = function () {
	this.curSh = 0;
	if (this.shTimeoutId != undefined) {clearTimeout(this.shTimeoutId)};
	tr.references.get('searchhint').innerHTML = '';
	tr.references.get('searchhint').style.display = 'none';
}
/////////// PLAYLISTS OBJECT /////////////////////////////
function Playlists () {
	this.playArr = new Array();
	this.count = 0;
	this.myPlCount = 0;
	this.q = new Array;
	this.qPl = 0;
	this.forceReload = false;
}
Playlists.prototype.get = function (id) {

	for (var i=0; i<this.count; i++) {
		if (this.playArr[i].id == id) {
			return this.playArr[i];
			break;
		}
	}
	return false;
}
Playlists.prototype.clear = function () {
	this.playArr = [];
	this.count = 0;
	this.myPlCount = 0;
}
Playlists.prototype.add = function (newplaylist) {
	this.playArr.push(newplaylist);
	this.count = this.playArr.length;
	
	this.myPlCount = 0
	for (var i=0;i<this.count;i++) {
		if (this.playArr[i].shared != '1') {
			this.myPlCount += 1;
		}
	}
}
Playlists.prototype.load = function (id) {	
	tr.curPl.clearSelArr();
	this.select(id);
	tr.setMode('playlist');

	//LOADS A PLAYLIST BY ID
	if (tr.curPl.cached) {
		tr.curPl.sort(tr.so);
		tr.curPl.display();
	} else {	
		tr.references.get('playgriddiv').innerHTML = '<table id="tunegrid" cellpadding=0 cellspacing=0 border=0 style="background-image:url(' + imagePath + 'alternating_blue_white.gif)" width="100%" height="100%" >' + tr.templates.get('plrowformat') + '</table>';
		g('plload' + id).style.display = 'block';		
		com("func.asp?c=loadpl&pl=" + tr.pl, parseXML);
	}
	
}
Playlists.prototype.display = function () {
var outArr = new Array();
var outArr2 = new Array();
var toggle = 0;

	var str = tr.templates.get('plsrowtemplate');
	var str2 = tr.templates.get('plssharedrowtemplate');

	for (var i=0;i<tr.playlists.count;i++) {
		var res = tr.playlists.playArr[i];

		//DISPLAY THE RESULTS
		toggle += 1;
		if (tr.curPl.id == res.id) {
			var plclass = "playlistentrysel"
		} else {
			var plclass="playlistentry"
		}
					
		if (res.shared == "0") {
			//NOT IN THE SHARED PLAYLISTS LIST
			var t = str;
			t = t.replace(/-i-/g, i);
			t = t.replace(/-id-/g, res.id);
			t = t.replace(/-name-/g, res.name);
			t = t.replace(/-plclass-/g, plclass);
			t = t.replace(/<tbody>/g, '');
			t = t.replace(/<\/tbody>/g, '');
								
			outArr.push(t);
		} else {
			//IN THE SHARED PLAYLISTS LIST
			var t = str2;
			t = t.replace(/-i-/g, i);
			t = t.replace(/-id-/g, res.id);
			t = t.replace(/-name-/g, res.name);
						
			if (res.username.length > 0) {
				t = t.replace(/-username-/g, ' - ' + res.username);
			} else {
				t = t.replace(/-username-/g, '');
			};
			t = t.replace(/-plclass-/g, plclass);
			t = t.replace(/<tbody>/g, '');
			t = t.replace(/<\/tbody>/g, '');
								
			outArr2.push(t);						

		}

	}

	tr.references.get('myplaylists').innerHTML = '<table cellpadding=0 cellspacing=0 border=0 width="100%" >' + outArr.join('') + '</table>';		
	tr.references.get('sharedplaylists').innerHTML = '<table cellpadding=0 cellspacing=0 border=0 width="100%" >' + outArr2.join('') + '</table>';			
	
}
Playlists.prototype.cache = function (id) {



}
Playlists.prototype.select = function (id) {
	//UNSELECT THE PREVIOUS
	this.unselect(tr.pl)
	//SELECT THIS ONE
	tr.pl = id;
	tr.curPl = this.get(id);
	g('plRow' + id).className = 'playlistentrysel';
	g('plarrow' + id).style.display='none';
}
Playlists.prototype.unselect = function (id) {
	if (g('plRow' + id) != undefined) {
		g('plRow' + id).className = 'playlistentry';
		g('plarrow' + id).style.display='none';	
		g('plload' + id).style.display = 'none';			
	}
}
Playlists.prototype.del = function (id) {
	for (var i=0;i<this.count;i++) {
		if (this.playArr[i].id == id) {
			if (this.playArr[i].shared != '1') {this.myPlCount -= 1};
			this.playArr.splice(i,1);	
			this.count = this.playArr.length;
		}
	}
}
Playlists.prototype.rename = function (id) {



}
Playlists.prototype.subscribe = function (id) {
	tr.showSharedPlaylists();
	g('pub' + id + 'sub').src = imagePath + 'btn_unsubscribe.png';
	this.add(new CloneObject(tr.publicplaylists.get(id)));
	this.get(id).shared = '1';
	this.display();
	com('func.asp?c=subscribe&pl=' + id, noCallback);
}
Playlists.prototype.unsubscribe = function (id) {
	if (g('pub' + id + 'sub') != null) {
		g('pub' + id + 'sub').src = imagePath + 'btn_subscribe.png';
	}
	for (var i=0;i<this.count;i++) {
		if (this.playArr[i].id == id) {
			this.playArr.splice(i,1);
			this.count = this.playArr.length;
		}
	}		
	this.display();
	com('func.asp?c=unsubscribe&pl=' + id, noCallback);
}
Playlists.prototype.rate  = function (id, rating) {



}
Playlists.prototype.inPlaylists = function (id) {
	for (var i=0;i<this.count;i++) {
		if (this.playArr[i].id == id) {
			return true;
		}
	}
	return false;
}
Playlists.prototype.enQ = function (id) {
	var inEnq = false;
	if (parseInt(tr.pl) != parseInt(this.qPl)) {
		//THIS IS A NEW PLAYLIST SO CLEAR THE ENQUEUE
		this.q = [];
		this.qPl = tr.pl;
	} 
	//CHECK IF THIS TUNE IS ALREADY IN THE LIST
	inEnq = this.delFromQ(id);

	if (inEnq != true) {
		this.q.push(id);
		g('t' + id + 'c1').innerHTML = '<div style="width:17;text-align:center;line-height:17px;font-weight:bold;">' + this.q.length + '</div>';
		
	}
}
Playlists.prototype.displayQ = function (id) {
	if (tr.pl == this.qPl) {
		for (var i=0; i<this.q.length; i++) {
			g('t' + this.q[i] + 'c1').innerHTML = '<div style="width:17;text-align:center;line-height:17px;font-weight:bold;">' + (i + 1) + '</div>';
		}
	}
}
Playlists.prototype.delFromQ = function (id) {
	//CHECK IF THIS TUNE IS ALREADY IN THE LIST
	for (var i=0; i<this.q.length; i++) {
		if (this.q[i] == id) {
			this.q.splice(i,1);
			g('t' + id + 'c1').innerHTML = '';
			this.displayQ();
			return true;
		}
	} 	
	return false;
}
Playlists.prototype.sortByQ = function (id) {
	if (this.q.length > 0) {
		tr.clearSort();
		tr.curPl.cached = false;
		var s = 'enqlist=' + this.q.join(',');
		com('func.asp?c=sortbyq&pl=' + this.qPl, parseXML, undefined, undefined, s);
	}
}
Playlists.prototype.sendQ = function () {
	//VALIDATE
	if (g('sendqplid').value == '0') {
		if (g('sendqname').value.length == 0) {
			//NO NAME SUPPLIED
			g('sendqname').style.backgroundColor = 'FFD3D3';
			g('sendqname').focus();
			g('sendqname').select();			
		
			return false;
		} else {
			g('enqplname').value = g('sendqname').value;
		}
	} else {
		g('enqplid').value = g('sendqplid').value;
	}

	if (this.q.length > 0) {
		if (g('sendqplid').value != '0') {this.get(g('sendqplid').value).cached = false};
		var s='enqplname=' + g('sendqname').value + '&enqplid=' + g('sendqplid').value + '&enqlist=' + this.q.join(",")
		com('func.asp?c=sendq', parseXML, undefined,undefined, s);
	}
	tr.hideDialog();
}
Playlists.prototype.clearQ = function (id) {
	if (tr.pl == this.qPl) {
		for (var i=0; i<this.q.length; i++) {
			g('t' + this.q[i] + 'c1').innerHTML = '';
		}
	}
	this.q = [];
}
Playlists.prototype.addVidToPl = function () {
	//VALIDATE
	if (g('addvidtoplplid').value == '0') {
		if (g('addvidtoplplname').value.length == 0) {
			//NO NAME SUPPLIED
			g('addvidtoplplname').style.backgroundColor = 'FFD3D3';
			g('addvidtoplplname').focus();
			g('addvidtoplplname').select();			
		
			return false;
		} else {
			g('addvidplname').value = g('addvidtoplplname').value;
		}
	} else {
		g('addvidplid').value = g('addvidtoplplid').value;
	}

	if (g('addvidplid').value != '0') {this.get(g('addvidplid').value).cached = false};
	var s='addvidplname=' + g('addvidplname').value + '&addvidplid=' + g('addvidplid').value + '&addvidid=' + tr.actionvalue;
	com('func.asp?c=addvidtopl', parseXML, undefined,undefined, s);
	
	tr.hideDialog();
}
Playlists.prototype.move = function (aboveplid, id) {
	var pl = undefined;

	//MOVE THE PLAYLIST
	for (var i=0;i<this.playArr.length;i++) {
		if (this.playArr[i].id == id) {
			pl = new CloneObject(this.playArr[i]);
			this.playArr.splice(i, 1);
			break;
		}
	}
	for (var i=0;i<this.playArr.length;i++) {
		if (this.playArr[i].id == aboveplid) {
			this.playArr.splice(i,0,pl);
			break;
		}
	}

}
/////////// PLAYLIST OBJECT /////////////////////////////
function Playlist () {
	this.id = '';
	this.name = '';
	this.shared = '';
	this.rating = 0; //THE OVERALL RATING FOR THIS PLAYLIST
	this.ttlvids = 0;
	this.username = 0;
	this.userrating=0; //WHAT THE CURRENT USER RATED THIS PLAYLIST
	this.uid=0;	
	this.cached = false;
	this.sortorder = 'seq';
	this.videos = new Array() 
	this.count = 0; 
	this.forceRedisplay = false;
	this.publicpl=false;
	this.sel = new Array();
	this.selCount = 0;

}
Playlist.prototype.get = function (id) {
	for (var i=0; i<this.count; i++) {
		if (this.videos[i].id == id) {
			return this.videos[i];
			break;
		}
	}

}
Playlist.prototype.getByVidId = function (vidid) {
	for (var i=0; i<this.count; i++) {
		if (this.videos[i].videoid == vidid) {
			return this.videos[i];
			break;
		}
	}

}
Playlist.prototype.getVidNo = function (id) {
	for (var i=0; i<this.count; i++) {
		if (this.videos[i].id == id) {
			return i;
			break;
		}
	}
}
Playlist.prototype.update = function (id) {



}
Playlist.prototype.del = function (id) {
	removeRow('t' + id);
	
	//REMOVE THE VID FROM THE CURRENT VIDARR AND ENQUEUE
	for (var i=0;i<this.count;i++) {
		if (this.videos[i].id == id) {
			this.videos.splice(i,1);
			this.count = this.videos.length;
			tr.playlists.delFromQ(id);
			tr.playlists.displayQ();
			break;
		}	
	}
	if (tr.mode != 'youtube') {tr.youtuberesults.forceRedisplay = true};
	if (tr.mode != 'playlist') {tr.curPl.forceRedisplay = true};
	com('func.asp?c=delvid&v=' + id, noCallback);
	resizeClient();
}
Playlist.prototype.delByVidId = function (vid) {
	var res = this.getByVidId(vid);
	this.del(res.id);
}
Playlist.prototype.delSelVids = function (id) {
	
	var s = this.sel.join(",");
	var str = ',' + s + ',';
	for (var i=0;i<this.count;i++) {
		if (str.search(',' + this.videos[i].id + ',') != -1) {
			this.videos.splice(i,1);
			i -= 1;
			this.count = this.videos.length;
			tr.playlists.delFromQ(id);
		}
	}		
	tr.playlists.displayQ();
	this.clearSelArr();
	this.display();
	
	com('func.asp?c=delvids', noCallback, undefined, undefined, "v=" + s);
}
Playlist.prototype.replace = function (id) {



}
Playlist.prototype.findReplacement = function (id) {
	tr.hideMenus();
	tr.findReplacement = id;
	tr.setSearchMode('youtube');
	var v = this.get(id);
	var str = v.artist + String.fromCharCode(32) + v.name;
	tr.references.get('search').value = str;
	tr.search('youtube',str);
}
Playlist.prototype.clear = function () {
	this.videos = [];
}
Playlist.prototype.add = function (video) {
	this.videos.push(video);
	this.count = this.videos.length;
}
Playlist.prototype.addToPlaylist = function (id) {
	var res = tr.youtuberesults.get(id);

	if (this.shared == '1') {
		tr.showDialog('selectpl');
		tr.actionvalue = id;
		return false;
	}
	this.forceRedisplay = true;
	
	if (tr.findReplacement != 0) {
		g('appwait').style.display='block';
	} else {
		g('yt' + id + 'add').src = imagePath + 'btn_removefrompl_white.png';
	}
	
	var title = res.title.replace(/&quot;/g, '');
	vol.getBackgroundInfo(title, res.swf, res.videoid, res.desc, res.thumbimg, res.seconds, tr.pl); //GETS THE BACKGROUND INFO 
}
Playlist.prototype.display = function () {
	var tclass;
	var trclass;
	var txtclass;
	var timg;
	var tcolor;

	//IF ITS A SHARED PLAYLIST THEN SHOW THE RATING	
	if (this.shared == '1') {
		tr.references.get('optrate').style.display='block';	
		tr.setRating (this.userrating);
	} else {
		tr.references.get('optrate').style.display='none';	
	}
	
	//TUNES
	var toggle = 0
	if (this.publicpl) {var str = tr.templates.get('pubplrowtemplate')} else {var str = tr.templates.get('plrowtemplate')};
	var outstr = '';
	var outArr = new Array();
	
	for (i=0;i<this.count;i++) {			
		var res = this.videos[i];
		
		//DISPLAY THE RESULTS
		toggle += 1;

		if (toggle == 2) {
			tclass = 'tuneentry2';
			trclass = 'tunerow2';
			txtclass = 'tuneentryi';
			timg = 'white';
			tcolor = 'ffffff';
			toggle = 0;
		} else {
			tclass = 'tuneentry1';
			trclass = 'tunerow1';
			txtclass = 'tuneentryi';
			timg = 'ltblue';
			tcolor = 'eff4fa';
		}
		
		if (res.played == '0') {txtclass = 'tuneentryibold'};						
		if (res.disabled == '1') {
			optimage = 'btn_missing.png'
			txtclass = 'tuneentrydisabled';
		} else {
			optimage='btn_optionicon_white.png'
		};
		
		var t = str;
		t = t.replace(/-i-/g, i);
		t = t.replace(/-id-/g, res.id);
		t = t.replace(/-name-/g, res.name);
		t = t.replace(/-artist-/g, res.artist);
		t = t.replace(/-album-/g, res.album);
		t = t.replace(/-duration-/g, res.duration);
		t = t.replace(/-tclass-/g, tclass);
		t = t.replace(/-trclass-/g, trclass);
		t = t.replace(/-txtclass-/g, txtclass);
		t = t.replace(/-optimage-/g, optimage);
		t = t.replace(/-timg-/g, timg);
		t = t.replace(/-tcolor-/g, tcolor);
		t = t.replace(/<tbody>/gi, '');
		t = t.replace(/<\/tbody>/gi, '');

		outArr.push(t);

	}
	
	if (this.publicpl) {
		tr.references.get('playgriddiv').innerHTML = '<table id="tunegrid" cellpadding=0 cellspacing=0 border=0 style="background-image:url(' + imagePath + 'alternating_blue_white.gif)" width="100%" height="100%" >' + outArr.join('') + tr.templates.get('pubplrowformat') + '</table>';
	} else {
		tr.references.get('playgriddiv').innerHTML = '<table id="tunegrid" cellpadding=0 cellspacing=0 border=0 style="background-image:url(' + imagePath + 'alternating_blue_white.gif)" width="100%" height="100%" >' + outArr.join('') + tr.templates.get('plrowformat') + '</table>';
	}
	
	tr.playlists.displayQ();
	
	resizeClient();	
	if (tr.curVid != undefined) {tr.curVid.selectPlay()};	

}
Playlist.prototype.sort = function (sortorder) {
var sortFunc;

	tr.so = sortorder;

	switch (sortorder) {
		case 't_seq desc':
		case 't_seq': //CUSTOM
			sortFunc = function (a,b) {
				return (a.seq - b.seq);
			}			
			break;
		
		case 'name':
			sortFunc = function (a,b) {
				var A = a.name.toLowerCase();
				var B = b.name.toLowerCase();
				if (A < B) return -1;
				if (A > B) return 1;
				return 0;
			}
			break;
			
		case 'artist':
			sortFunc = function (a,b) {
				var A = a.artist.toLowerCase();
				var B = b.artist.toLowerCase();
				if (A < B) return -1;
				if (A > B) return 1;
				return 0;
			}
			break;			
						
		case 'album':
			sortFunc = function (a,b) {
				var A = a.album.toLowerCase();
				var B = b.album.toLowerCase();
				if (A < B) return -1;
				if (A > B) return 1;
				return 0;
			}			
			break;				
	
		case 'duration':
			sortFunc = function (a,b) {
				var A = a.duration.toLowerCase();
				var B = b.duration.toLowerCase();
				if (A < B) return -1;
				if (A > B) return 1;
				return 0;
			}		
			break;

		case 'name desc':
			sortFunc = function (a,b) {
				var A = a.name.toLowerCase();
				var B = b.name.toLowerCase();
				if (A < B) return 1;
				if (A > B) return -1;
				return 0;
			}
			break;
			
		case 'artist desc':
			sortFunc = function (a,b) {
				var A = a.artist.toLowerCase();
				var B = b.artist.toLowerCase();
				if (A < B) return 1;
				if (A > B) return -1;
				return 0;
			}
			break;			
						
		case 'album desc':
			sortFunc = function (a,b) {
				var A = a.album.toLowerCase();
				var B = b.album.toLowerCase();
				if (A < B) return 1;
				if (A > B) return -1;
				return 0;
			}			
			break;				
	
		case 'duration desc':
			sortFunc = function (a,b) {
				var A = a.duration.toLowerCase();
				var B = b.duration.toLowerCase();
				if (A < B) return 1;
				if (A > B) return -1;
				return 0;
			}		
			break;
	}	
		
	this.videos.sort(sortFunc);
	
	//IF THIS IS THE CURRENTLY PLAYING PLAYLIST THEN UPDATE THE CURPLAYARR
	if (tr.curPlayPl != undefined) {
		if (tr.curPl.id == tr.curPlayPl.id) {
			tr.curPlayPl = tr.curPl;
			//UPDATE THE CURVIDNO TO REFLECT THE NEW POSITION OF THE CURRENT TUNE SELECTION
			if (tr.curVid != undefined) {
				for (var i=0;i<tr.curPlayPl.length;i++) {
					if (tr.curVid.id == tr.curPlayPl[i].id) {
						tr.curVidNo = i;
					}
				}
			}
			
		}
	}
}
Playlist.prototype.disable = function (id) {
	g('t' + id + 'i2').className = 'tuneentrydisabled';
	g('t' + id + 'i3').className = 'tuneentrydisabled';
	g('t' + id + 'i4').className = 'tuneentrydisabled';
	g('t' + id + 'i5').className = 'tuneentrydisabled';
	g('topt' + id).style.backgroundImage = 'url(' + imagePath + 'btn_missing.png)';	
	this.get(id).disabled = '1';
	com('func.asp?c=disablevid&t=' + id, noCallback);
}
Playlist.prototype.inPlaylist = function (vidid) {
	for (var i=0;i<this.count;i++) {
		if (this.videos[i].videoid == vidid) {
			return true;
			break;
		}
	}
	return false;
}
Playlist.prototype.addSel = function (vidid) {
	this.sel.push(vidid);
	this.selCount = this.sel.length;
}
Playlist.prototype.delSel = function (vidid) {
	for (var i=0;i<this.selCount;i++) {
		if (this.sel[i] == vidid) {
			this.sel.splice(i,1);
			this.selCount = this.sel.length;
			break;
		}	
	}
}
Playlist.prototype.clearSel = function (vidid) {
	var str = ',' + this.sel.join(',') + ',';
	for (var i=0;i<this.count;i++) {
		if (str.search(',' + this.videos[i].id + ',') != -1) {
			this.videos[i].unselect();
		}
	}

	this.sel = [];
	this.selCount = 0;
}
Playlist.prototype.clearSelArr = function (vidid) {
	this.sel = [];
	this.selCount = 0;
}
Playlist.prototype.inSel = function (vidid) {
	var inSel = false;
	
	for (var i=0;i<this.selCount;i++) {
		if (this.sel[i] == vidid) {	
			inSel = true;
			break;
		}
	}
	return inSel;
}
Playlist.prototype.moveSel = function (abovevidid) {
	//vidid is the video that was clicked when the drag started
	//abovevidid is the vidid from the vidrow onmouseup
	
	if (this.inSel(abovevidid) == false) {	
		var aboveVidIdPos = 0;
		var vids = new Array();

		//MOVE THE SELECTION
		for (var i=0;i<this.count;i++) {
			if (this.inSel(this.videos[i].id) ) {
				vids.push(new CloneObject(this.videos[i]));
				this.videos.splice(i, 1);
				i -= 1;
				this.count -= 1;
			}
		}

		//CALC THE NEW TARGET VID POSITION
		for (var i=0;i<this.count;i++) {
			if (this.videos[i].id == abovevidid) {aboveVidIdPos = i};
		}	
		
		//INSERT THE VIDS
		var mv = new Array();
		for (var i=0;i<vids.length;i++) {
			this.videos.splice(aboveVidIdPos, 0, vids[i]);
			aboveVidIdPos += 1;
			mv.push(vids[i].id)
		}

		this.count = this.videos.length;
			
		this.reSeq();
		
		com ("func.asp?c=movevids&pl=" + this.id + "&tv=" + abovevidid, noCallback, undefined, undefined, "mv=" + mv.join(","));
		
	}
	
}
Playlist.prototype.highlightSel = function () {
	for (var i=0;i<this.selCount;i++) {
		this.get(this.sel[i]).select();
	}
}
Playlist.prototype.reSeq = function () {
	for (var i=0;i<this.count;i++) {
		this.videos[i].seq = i;
	}
}
/////////// VIDEO OBJECT /////////////////////////////
function Video () {
	this.id = '';
	this.videoid = '';
	this.name = '';
	this.artist = '';
	this.album = '';
	this.duration = '';
	this.played	 = '';
	this.seq = '';
	this.hasreleases = 0;
	this.haslyrics = 0;
	this.hasbio = 0;
	this.hassimilar = 0;
	this.disabled = false;
}
Video.prototype.select = function () {
	if (g('t'+this.id+'c2') != undefined) {
		var playId = 0;
		if (tr.curVid != undefined) {playId = tr.curVid.id};	
	
		if (playId != this.id) {
			tr.lastPlayedClass = g('t'+this.id+'c2').className;
		
			g('t'+this.id+'c1').className = 'tuneentrysel';
			g('t'+this.id+'c2').className = 'tuneentrysel';
			g('t'+this.id+'c3').className = 'tuneentrysel';
			g('t'+this.id+'c4').className = 'tuneentrysel';
			g('t'+this.id+'c5').className = 'tuneentrysel';
			g('topt'+this.id).className = 'toptsel';
			
			if (g('t'+this.id+'i2').className == 'tuneentryibold' || g('t'+this.id+'i2').className == 'tuneentryiselbold' ) {
				g('t'+this.id+'i2').className = 'tuneentryiselbold';
				g('t'+this.id+'i3').className = 'tuneentryiselbold';
				g('t'+this.id+'i4').className = 'tuneentryiselbold';	
				g('t'+this.id+'i5').className = 'tuneentryiselbold';
			} else {
				g('t'+this.id+'i2').className = 'tuneentryisel';
				g('t'+this.id+'i3').className = 'tuneentryisel';
				g('t'+this.id+'i4').className = 'tuneentryisel';	
				g('t'+this.id+'i5').className = 'tuneentryisel';
			}
			
			return true;
		}

	}

	return false;
}
Video.prototype.selectPlay = function () {
	if (g('t'+this.id+'c2') != undefined) {
		//IF THE TRACK IS OUT OF VIEW THEN SCROLL THE PLAYDIV
		//getObj('playgriddiv').scrollTop = getObj('t'+id).offsetTop;
		tr.lastPlayedClass = g('t'+this.id+'c2').className;
	
		g('t'+this.id+'c1').className = 'tuneentryplay';
		g('t'+this.id+'c2').className = 'tuneentryplay';
		g('t'+this.id+'c3').className = 'tuneentryplay';
		g('t'+this.id+'c4').className = 'tuneentryplay';
		g('t'+this.id+'c5').className = 'tuneentryplay';
		g('topt'+this.id).className = 'toptplay';
		
		g('t'+this.id+'i2').className = 'tuneentryisel';
		g('t'+this.id+'i3').className = 'tuneentryisel';
		g('t'+this.id+'i4').className = 'tuneentryisel';	
		g('t'+this.id+'i5').className = 'tuneentryisel';
		
		return true;

	}

	return false;
}
Video.prototype.unselect = function (forceUnselect) {
	var playId = 0;
	if (tr.curVid != undefined) {playId = tr.curVid.id};

	if (playId != this.id || forceUnselect != undefined) {

		g('t'+this.id+'c1').className = 'tuneentry1';
		g('t'+this.id+'c2').className = 'tuneentry1';
		g('t'+this.id+'c3').className = 'tuneentry1';
		g('t'+this.id+'c4').className = 'tuneentry1';
		g('t'+this.id+'c5').className = 'tuneentry1';
		g('topt'+this.id).className = 'topt';
		
		//alert(g('t'+this.id+'i2').className)
		
		if (g('t'+this.id+'i2').className == 'tuneentryiselbold' || g('t'+this.id+'i2').className == 'tuneentryibold') {
			g('t'+this.id+'i2').className = 'tuneentryibold';
			g('t'+this.id+'i3').className = 'tuneentryibold';
			g('t'+this.id+'i4').className = 'tuneentryibold';	
			g('t'+this.id+'i5').className = 'tuneentryibold';	
		} else {
			g('t'+this.id+'i2').className = 'tuneentryi';
			g('t'+this.id+'i3').className = 'tuneentryi';
			g('t'+this.id+'i4').className = 'tuneentryi';	
			g('t'+this.id+'i5').className = 'tuneentryi';
		}
		
	}
}
/////////// YOUTUBERESULTS OBJECT /////////////////////////////
function YouTubeResults () {
	this.yt = new Array();
	this.count =0;
	this.forceRedisplay = false;
	this.totalYtResults = 0;
}
YouTubeResults.prototype.get = function (id) {
	return this.yt[id];
}
YouTubeResults.prototype.add = function (ytresult) {
	this.yt.push(ytresult);
	this.count = this.yt.length;
}
YouTubeResults.prototype.select = function (id) {
	if (id != undefined) {
		tr.lastPlayedClassYt = g('yt'+id+'c2').className;
		g('yt'+id+'c1').className = 'tuneentryplay';
		g('yt'+id+'c2').className = 'tuneentryplay';		
		g('yt'+id+'i2').className = 'tuneentryisel';
		g('yt'+id+'c3').className = 'tuneentryplay';		
		g('yt'+id+'i3').className = 'tuneentryisel';		
		
		return true;
	}

	return false;	
}
YouTubeResults.prototype.unselect = function (id) {
	g('yt'+id+'c1').className = tr.lastPlayedClassYt;
	g('yt'+id+'c2').className = tr.lastPlayedClassYt;
	g('yt'+id+'i2').className = 'tuneentryi';
	g('yt'+id+'c3').className = tr.lastPlayedClassYt;
	g('yt'+id+'i3').className = 'tuneentryi';	
}
YouTubeResults.prototype.display = function (id) {
	var outArr = new Array();
	var curYtVidInResults = false;
	
	if (tr.curPl.shared == '0') {
		if (g('plarrow' + tr.pl) != undefined) {g('plarrow' + tr.pl).style.display = 'block'};						
	}	
	
	var toggle = 0;
	var str = tr.templates.get('ytrowtemplate');
	for (var i=0;i<this.count;i++) {
		var res = this.yt[i];
		toggle += 1;
		if (toggle == 2) {
			tclass = 'tuneentry2';
			tcolor = 'ffffff';
			if (tr.curPl.inPlaylist(res.videoid)) {icolor = 'btn_removefrompl_white'} else {icolor='btn_addplaylist_white'};
			toggle = 0;
		} else {
			tclass = 'tuneentry1';
			tcolor = 'eff4fa';
			if (tr.curPl.inPlaylist(res.videoid)) {icolor = 'btn_removefrompl_white'} else {icolor = 'btn_addplaylist_white'};
		}
		if (tr.findReplacement != 0) {icolor = 'btn_replacevideo'}
		if (tr.curPl.shared == '1') {icolor = 'btn_addplaylist_white'};
		
		if (tr.playType == 'youtube') {
			if (tr.curYtVid.videoid == res.videoid) {curYtVidInResults = true};
		}
		
		var t = str;
		t = t.replace(/-i-/g, i);						
		t = t.replace(/-title-/g, res.title);
		t = t.replace(/-duration-/g, res.duration);
		t = t.replace(/-thumbimg-/g, res.thumbimg);
		t = t.replace(/-tclass-/g, tclass);
		t = t.replace(/-tcolor-/g, tcolor);
		t = t.replace(/-icolor-/g, icolor);
		t = t.replace(/<tbody>/g, '');
		t = t.replace(/<\/tbody>/g, '');
		
		outArr.push(t);
	}
	
	tr.references.get('youtubediv').innerHTML = '<table cellpadding=0 cellspacing=0 border=0 style="background-image:url(' + imagePath + 'alternating_blue_white.gif)" width="100%" height="100%" >' + outArr.join('') + tr.templates.get('ytrowformat') + '</table>';
	resizeClient();
	
	if (tr.playType == 'youtube' && curYtVidInResults) {this.select(tr.curYtVid.id)};
	
	//SET THE NEXT AND PREV BUTTONS
	var ttl = this.totalYtResults;
	
	if (ttl > (tr.startIndex + tr.maxResults)) {
		if (tr.references.get('optnext').src.indexOf('_over') != -1) {
			tr.references.get('optnext').src = imagePath +'opt_next_over.png';
		} else {
			tr.references.get('optnext').src = imagePath +'opt_next.png';
		}
	} else {
		tr.references.get('optnext').src = imagePath +'opt_next_grey.png';
	}
	
	if (tr.startIndex > 1) {
		if (tr.references.get('optprev').src.indexOf('_over') != -1) {
			tr.references.get('optprev').src = imagePath +'opt_prev_over.png';
		} else {
			tr.references.get('optprev').src = imagePath +'opt_prev.png';
		}
	} else {
		tr.references.get('optprev').src = imagePath +'opt_prev_grey.png';	
	}	

}
YouTubeResults.prototype.clear = function () {
	this.yt = [];
	this.count = 0;
	this.totalYtResults = 0;
}
/////////// YOUTUBERESULT OBJECT /////////////////////////////
function YouTubeResult () {
	this.id = 0;
	this.title = '';
	this.swf = '';
	this.desc = '';
	this.videoid = '';
	this.thumbimg = '';
	this.duration = '';
	this.seconds = '';
}
/////////// DISCS OBJECT /////////////////////////////
function Discs () {
	this.d = new Array(); //ARRAY OF ALBUMS
	this.count = 0; //NUMBER OF ALBUMS IN THE ARRAY
	this.selCount = 0;
}
Discs.prototype.get = function (id) {
	return this.d[id];
}
Discs.prototype.select = function (id) {
	var r = this.get(id);
	if (r.sel == false) {
		//SELECT THE ALBUM
		this.selCount += 1;
		r.sel = true;
		g('asel' + id).style.display = 'block';
		g('optaddalbums').src=imagePath + 'opt_addalbums.png';	
	} else {
		//DESELECT THE ALBUM
		r.sel = false;
		this.selCount -= 1;
		g('asel' + id).style.display = 'none';
		
		//CHECK TO SEE IF THERE IS MORE THAN ONE ALBUM SELECTED
		if (this.selCount == 0) {
			tr.references.get('optaddalbums').src=imagePath + 'opt_addalbums_grey.png';	
		}
	}
}
Discs.prototype.clear = function () {
	this.d = [];
	this.count = 0;
	this.selCount = 0;
}
Discs.prototype.add = function (obj) {
	this.d.push(obj);
	this.count = this.d.length;
}
/////////// DISC OBJECT /////////////////////////////
function Disc () {
	this.mbid = '';
	this.name = '';
	this.img = '';
	this.sel = false; //FLAG FOR WHETHER AN ALBUM IS SELECTED
}
/////////// TEMPLATES OBJECT /////////////////////////////
function Templates () {
	this.temps = new Array(); //ARRAY OF ALBUMS
	this.count = 0; //NUMBER OF ALBUMS IN THE ARRAY
}
Templates.prototype.get = function (name) {
	for (var i=0; i<this.count; i++) {
		if (this.temps[i].name == name) {
			return this.temps[i].str;
			break;
		}
	}
	return false;
}
Templates.prototype.add = function (name, str) {
	var t = new Template;
	t.name = name;
	t.str = str;
	this.temps.push(t);
	this.count = this.temps.length;
}
/////////// TEMPLATE OBJECT /////////////////////////////
function Template () {
	this.name = '';
	this.str = ''; //THE TEMPLATE STRING
}
/////////// INFOTABS OBJECT /////////////////////////////
function InfoTabs () {
	this.tabs = new Array(); //ARRAY OF INFOTAB
	this.count = 0; //NUMBER OF TAB IN THE ARRAY
	
	this.tabs.push(new InfoTab(0));
	this.tabs.push(new InfoTab(1));
	this.tabs.push(new InfoTab(2));
	this.tabs.push(new InfoTab(3));
	this.count = this.tabs.length;
}
InfoTabs.prototype.get = function (id) {
	return this.tabs[id];
}
InfoTabs.prototype.load = function (tabno, artist, track, logPlay) {

	var a = artist.toLowerCase();
	if (track != undefined) {var t = track.toLowerCase()};
	//SCROLL THE TRACKINFO DIV TO THE TOP
	tr.references.get('trackinfo').scrollTop = 0;
	
	for (var i=0;i<this.tabs[tabno].count;i++) {
		if (track != undefined) {
			//LYRICS
			if (this.tabs[tabno].cachedata[i].artist.toLowerCase() == a && this.tabs[tabno].cachedata[i].track.toLowerCase() == t) {
				//THE DATA IS ALREADY CACHED
				this.display(tabno, this.tabs[tabno].cachedata[i]);
				if (logPlay != undefined) {com('func.asp?c=play&tid=' + tr.curVid.id, noCallback)}
				return false;
				break;
			}	
			
		} else {	
			
			if (this.tabs[tabno].cachedata[i].artist.toLowerCase() == a) {
				//THE DATA IS ALREADY CACHED
				this.display(tabno, this.tabs[tabno].cachedata[i]);
				if (logPlay != undefined) {com('func.asp?c=play&tid=' + tr.curVid.id, noCallback)}
				return false;
				break;
			}
		}
	}
	//THE DATA IS NOT CACHED - CHECK THE SERVER
	//alert('func.asp?c=getinfo&tab=' + tabno + '&a=' + artist + '&t=' + track)
	if (logPlay == undefined) {
		com('func.asp?c=getinfo&tab=' + tabno + '&a=' + escape(artist) + '&t=' + escape(track), parseXML);	
	} else {
		//LOG THE PLAY		
		com('func.asp?c=getinfologplay&tab=' + tabno + '&a=' + escape(artist) + '&t=' + escape(track) + '&tid=' + tr.curVid.id, parseXML);	
	}
}
InfoTabs.prototype.select = function (id) {
	
	
}
InfoTabs.prototype.clear = function (id) {
	//CLEARS THE TABS
	//USED WHEN PLAYING A YOUTUBE VID
	
}
InfoTabs.prototype.clearYt = function () {
	tr.references.get('releases').innerHTML = '<table cellpadding=0 cellspacing=0 border=0 style="background-image:url(images/large_blue_white.gif)" height="100%" width="100%" ><tr><td align="center" class="ftext" >Add this video to your playlist for info</td></tr></table>';
	tr.references.get('lyrics').innerHTML = '<table cellpadding=0 cellspacing=0 border=0 height="100%" width="100%" ><tr><td align="center" class="ftext" >Add this video to your playlist for info</td></tr></table>';
	tr.references.get('bio').innerHTML = '<table cellpadding=0 cellspacing=0 border=0 height="100%" width="100%" ><tr><td align="center" class="ftext" >Add this video to your playlist for info</td></tr></table>';	
	tr.references.get('similar').innerHTML = '<table cellpadding=0 cellspacing=0 border=0 style="background-image:url(images/large_blue_white.gif)" height="100%" width="100%" ><tr><td align="center" class="ftext" >Add this video to your playlist for info</td></tr></table>';	
}
InfoTabs.prototype.display = function (tabno,obj) {
	var outArr = new Array();

	cframe = '';
	if (hasChromeFrame == false || true) {			
		cframe = '<table cellpadding=0 cellspacing=0 border=0 width="100%" style="height:30;color:c96800" bgcolor="ffffe5" class="chromeframetext" >';
		cframe += '<tr><td align="center" ><b>Make TubeRadio run stupidly fast with a free Google plug-in for Internet Explorer. <nobr><a onclick="'
		cframe += 'tr.loadTG(\'tggetchromeframe\',\'Faster TubeRadio...\',\'tr.loadContent(\\\'tggetchromeframe\\\',\\\'getchromeframe.asp\\\')\')'
		cframe += '" class="sbarlink">Click here for the low down.</a></b></td>';
		cframe += '</tr></table><div style="height:1;width:100%;background-color:f5e082"><table cellpadding=0 cellspacing=0 border=0><tr><td><img src="clear.gif" border=0 width=1 height="1"></td></tr></table></div>';
		
		cframe = '<table cellpadding=0 cellspacing=0 border=0 width="100%" style="height:30;color:c96800" bgcolor="ffffe5" class="chromeframetext" >';
		cframe += '<tr><td align="center" ><b><a href="http://bit.ly/atsO9d" ';
		cframe += '" target="_blank" class="sbarlink">7 Minutes that will change your life FOREVER!</a></b><br>It couldn\'t be easier...</td>';
		cframe += '</tr></table><div style="height:1;width:100%;background-color:f5e082"><table cellpadding=0 cellspacing=0 border=0><tr><td><img src="clear.gif" border=0 width=1 height="1"></td></tr></table></div>';		
	}	

	if (tabno == 1) {	
		var logostr = '<table cellpadding=0 cellspacing=0 border=0 width="100%" class="biotext" >';
		logostr += '<tr><td align="center"><a target="_blank" href="http://lyricsfly.com/search/correction.php?' + obj.checksum + '&id=' + obj.songid + '" class="slink" >Click here to correct these lyrics</a>';
		logostr += '</td></tr>';
		logostr += '</table><br>';
	}
	
	switch (tabno) {
		case 0: // RELEASES
			var toggle = 0
			var str = tr.templates.get('relrowtemplate');
	
			for (i=0;i<obj.count;i++) {	
				var o = obj.rel[i];
				
				//DISPLAY THE RESULTS
				toggle += 1;
				if (toggle == 2) {
					tclass = 'tuneentry2';
					trclass = 'tunerow2';
					txtclass = 'tuneentryi';
					timg = 'white';
					tcolor = 'ffffff';
					toggle = 0;
				} else {
					tclass = 'tuneentry1';
					trclass = 'tunerow1';
					txtclass = 'tuneentryi';
					timg = 'ltblue';
					tcolor = 'eff4fa';
				}					
				var t = str;
				t = t.replace(/-art-/g, unescape(obj.artist));
				t = t.replace(/-n-/g, unescape(o.name));
				t = t.replace(/-img-/g, unescape(o.img));
				outArr.push(t);
			}
			tr.references.get('releases').innerHTML = cframe + '<table cellpadding=0 cellspacing=0 border=0 style="background-image:url(' + imagePath + 'large_blue_white.gif)" width="100%" >' + outArr.join('') + '</table>' ;
			tr.references.get('tabwait').style.display = 'none';
			tr.references.get('trackinfo').style.overflow='auto';
			return true;
			break;
			
		case 1: // LYRICS
			var t = tr.templates.get('lyrowtemplate');
			var lyrics = obj.lyrics;
			
			if (lyrics != null) {
				if (lyrics.length > 0) {
					t = t.replace(/-lyrics-/g, lyrics);					
					outArr.push(t);		
					tr.references.get('lyrics').innerHTML = cframe + outArr.join('') + logostr;
				} else {
					tr.references.get('lyrics').innerHTML = '<table cellpadding=0 cellspacing=0 border=0 class="ftext" width="100%" height="100%" ><tr><td align="center" valign="middle" >Lyrics not found</td></tr></table>';
				}
			} else {
				tr.references.get('lyrics').innerHTML = '<table cellpadding=0 cellspacing=0 border=0 class="ftext" width="100%" height="100%" ><tr><td align="center" valign="middle" >Lyrics not found</td></tr></table>';
			}
			tr.references.get('tabwait').style.display = 'none';
			tr.references.get('trackinfo').style.overflow='auto';
			return true;		
			break;
			
		case 2: // BIO
			var t = tr.templates.get('biorowtemplate');
			var bio = obj.bio;
			
			if (bio != null) {			
				if (bio.length > 0) {
					bio = HtmlDecode(bio);
					t = t.replace(/-bio-/g, bio);
					t = t.replace(/href/g, ' target="_blank" href');
					t = t.replace(/\r/g, '<br>');

					outArr.push(t);
					tr.references.get('bio').innerHTML = cframe + outArr.join('');
				} else {
					tr.references.get('bio').innerHTML = '<table cellpadding=0 cellspacing=0 border=0 class="ftext" width="100%" height="100%" ><tr><td align="center" valign="middle" >Bio not found</td></tr></table>';
				}
			} else {
				tr.references.get('bio').innerHTML = '<table cellpadding=0 cellspacing=0 border=0 class="ftext" width="100%" height="100%" ><tr><td align="center" valign="middle" >Bio not found</td></tr></table>';
			}
			tr.references.get('tabwait').style.display = 'none';
			tr.references.get('trackinfo').style.overflow='auto';
			return true;				
			break;
			
		case 3: //SIMILAR
			var str = tr.templates.get('simrowtemplate');
		
			for (i=0;i<obj.count;i++) {				
				var o = obj.artists[i];
			
				var t = str;
				t = t.replace(/-n-/g, o.name);
				t = t.replace(/-img-/g, o.img);
									
				outArr.push(t);
			}
			
			tr.references.get('similar').innerHTML = cframe + '<table cellpadding=0 cellspacing=0 border=0 style="background-image:url(' + imagePath + 'large_blue_white.gif)" width="100%" >' + outArr.join('') + '</table>';
			tr.references.get('tabwait').style.display = 'none';
			tr.references.get('trackinfo').style.overflow='auto';			
			return true;
			break;

	}

}
/////////// INFOTAB OBJECT /////////////////////////////
function InfoTab (id) {
	this.id = id
	this.artist = '';
	this.str = '';
	this.cached = false;
	this.maxCache = 10;
	this.cachedata = new Array();
	this.count = 0;
	this.sel;
}
InfoTab.prototype.addCacheData = function (obj) {
	this.cachedata.push(obj);
	this.count = this.cachedata.length;
	if (this.count > this.maxCache) {
		this.cachedata.shift();
		this.count = this.cachedata.length;
	}
}
/////////// RELEASES OBJECT /////////////////////////////
function Releases () {
	this.artist = '';
	this.rel = new Array();
	this.count = 0;
}
Releases.prototype.add = function (r) {
	this.rel.push(r);
	this.count = this.rel.length;
}
/////////// LYRICS OBJECT /////////////////////////////
function Lyrics () {
	this.artist = '';
	this.track = '';
	this.lyrics = '';
	this.checksum = '';
	this.songid = '';
}
/////////// BIO OBJECT /////////////////////////////
function Bio () {
	this.artist = '';
	this.bio = '';
}
/////////// SIMILAR OBJECT /////////////////////////////
function Similar () {
	this.artist = '';
	this.artists = new Array();
	this.count = 0;
}
Similar.prototype.add = function (a) {
	this.artists.push(a);
	this.count = this.artists.length;
}
/////////// ARTIST OBJECT /////////////////////////////
function Artist () {
	this.name = '';
	this.img = '';
}
/////////// RELEASE OBJECT /////////////////////////////
function Release () {
	this.name = '';
	this.mbid = '';
	this.img = '';
}
/////////// INFOTAB OBJECT /////////////////////////////
function TabGroup () {
	this.tabs = new Array();
	this.count = 0;
	this.curTab = '';
	this.width = 0;
	this.tabno = 0
}
/////////// TABGROUP OBJECT /////////////////////////////
TabGroup.prototype.get = function (id) {
	for (var i=0;i<this.count;i++) {
		if (this.tabs[i].id == id) {
			return this.tabs[i];
			break;
		}
	}
	return false;
}
TabGroup.prototype.getTabNo = function (id) {
	for (var i=0;i<this.count;i++) {
		if (this.tabs[i].id == id) {
			return i;
			break;
		}
	}
	return false;
}
TabGroup.prototype.add = function (t) {
	this.tabs.push(t);
	this.count = this.tabs.length;	
	t.tabno = this.count - 1;
}
TabGroup.prototype.del = function (id) {
	var ttl = 0;
	for (var i=0;i<this.count;i++) {
		if (this.tabs[i].id == id) {
			this.tabs.splice(i,1);
			this.count = this.tabs.length;
			break;
		}
	}
	for (var i=0;i<this.count;i++) {	
		this.tabs[i].tabno = i;
	}	
}
TabGroup.prototype.unselect = function (id) {
	this.get(id).sel = false;
	this.curTab = '';
}
TabGroup.prototype.select = function (id) {
	this.get(id).sel = false;
	this.curTab = id;
}
TabGroup.prototype.ensureVisible = function (id) {
	var c = getClientSize();
	c.width -= 191;
	var t = this.get(id);
	if (t.tabno == 0) {c.width -= 10};

	var rightX = t.rightX;
	var ttl = t.rightX;
	var larrow = false;
	var rarrow = false;
	for (var i=0;i<this.count;i++) {
		if (ttl > c.width) {
			g(this.tabs[i].id).style.display = 'none';
			g(this.tabs[i].id + 'sep').style.display = 'none';	
			ttl -= this.tabs[i].width;
			if (this.tabs[i].tabno < t.tabno) {larrow = true};
			
			
		} else {
			g(this.tabs[i].id).style.display = 'block';
			if (this.tabs[i].tabno != t.tabno) {
				g(this.tabs[i].id + 'sep').style.display = 'block';
			} else {
				g(this.tabs[i].id + 'sep').style.display = 'none';
			}
			if (this.tabs[i].tabno > t.tabno) {rightX += this.tabs[i].width}
		}
		
		if (i+1 == t.tabno) {
			g(this.tabs[i].id + 'sep').style.display = 'none';
		}
	}	
	
	if (rightX > c.width) {rarrow = true};
	if (larrow) {tr.references.get('tabprev').src=imagePath + 'toolbar_arrow_left.gif'} else {tr.references.get('tabprev').src=imagePath + 'toolbar_arrow_left_grey.gif'};
	if (rarrow) {tr.references.get('tabnext').src=imagePath + 'toolbar_arrow_right.gif'} else {tr.references.get('tabnext').src=imagePath + 'toolbar_arrow_right_grey.gif'};
}
TabGroup.prototype.calcWidths = function () {
	var ttl = 0;
	for (var i=0;i<this.count;i++) {
		if (i != 0) {
			this.tabs[i].width = g(this.tabs[i].id).offsetWidth + 1;
			ttl += this.tabs[i].width;
			this.tabs[i].rightX = ttl;
		}
	}
	this.width = ttl;
}
TabGroup.prototype.getTabWidth = function (from,to) {
	var ttl=0;
	for (var i=from;i<to;i++) {
		ttl += g(this.tabs[i].id).offsetWidth + 1;
	}
	return ttl;
}
TabGroup.prototype.getTtlWidth = function () {
	var ttl=0;
	for (var i=0;i<this.count;i++) {
		ttl += g(this.tabs[i].id).offsetWidth + 1;
	}	
	return ttl;
}
TabGroup.prototype.getVisibleWidth = function () {
	var ttl=0;
	for (var i=0;i<this.count;i++) {
		if (g(this.tabs[i].id).style.visible != 'none') {ttl += g(this.tabs[i].id).offsetWidth + 1};
	}	
	return ttl;
}
/////////// TAB OBJECT /////////////////////////////
function Tab (id, name, click, stat) {
	this.id = id;
	this.name = name
	this.click = click;
	this.stat = stat;
	this.width = 0;
	this.rightX = 0;
	this.sel = false;
}

/////////// REFERENCES OBJECT /////////////////////////////
function References () {
	this.r = new Array();
	this.count = 0;
}
References.prototype.add = function (name, obj) {
	var ref = new Reference();
	ref.name = name;
	ref.obj = obj;
	
	this.r.push(ref);
	this.count = this.r.length;
}
References.prototype.get = function (name) {
	for (var i=0;i<this.r.length;i++) {
		if (this.r[i].name == name) {
			return this.r[i].obj;
			break;
		}
	}
	return undefined;
}
/////////// REFERENCE OBJECT /////////////////////////////
function Reference () {
	this.name = '';
	this.obj = undefined;
}

