
function cueNewVideo(id, startSeconds) {
	   debug("cueing new video "+id);
//alert(cueNewVideo);
		
		if (!onWebsite)
		{
	   // try to find title
	   title = '';
		for (i=0; i<videos.length; i++ )
			{
			if (videos[i]['youtube_id'] == id)
				{
				title = videos[i]['title'];
				break;
				}
			}
		
		if (title == '')
			{
			title = lCustomPlaying;
			}
		if (id == 'Ce9hzex8gvA')
			{
			title = 'Alice TV';
			}

		status(title);
		}
		

		// start playing
          if (ytplayer) {
		  //alert(id);
		  //alert(startSeconds);
		 // clearVideo();
            ytplayer.loadVideoById(id, startSeconds);
          }
	}


function clickPlay(itsMe)
{
if (sIHaveRemote || !itsMe)
	{
	abtn='/template/alicetv/images/play_n.gif'; 
	clk(); 
	document.getElementById('btn1').src='/template/alicetv/images/play_a.gif';
	play();
	if (itsMe)
		{
		sendAction('PLAY');
		}
	}
if (itsMe)
	{
	track('Clicked play button');
	}
}

function clickPause(itsMe)
{
if (sIHaveRemote || !itsMe)
	{
	abtn='/template/alicetv/images/pause_n.gif'; 
	clk(); 
	document.getElementById('btn2').src='/template/alicetv/images/pause_a.gif'; 
	pause();
	if (itsMe)
		{
		sendAction('PAUSE');
		}
	}
if (itsMe)
	{
	track('Clicked pause button');
	}
}

function clickStop(itsMe)
{
if (sIHaveRemote || !itsMe)
	{
	stop();
	sendAction('STOP');
	}
if (itsMe)
	{
	track('Clicked stop button');
	}
}

function clickNext()
{
if ((sIHaveRemote || !itsMe) && currentvideonr != -1)
	{
	if (onWebsite)
		{
		sel = document.videoselectform.videoSelect;
		newnr = sel.selectedIndex + 1;
		if (newnr <= sel.options.length-1)
			{
			zapOnSite(newnr);
			}
		}
	else
		{
		if (videoOpen)
			{
			switchVideo();
			}
		if (catOpen)
			{
			switchCat();
			}
		if (channelOpen)
			{
			switchChannel();
			}
		currentvideonr = currentvideonr + 1;
		
		if (currentvideonr > videos.length-1)
			{
			currentvideonr = 0;
			}
		setCatTitle(videos[currentvideonr]['category']);
		setChannelTitle(videos[currentvideonr]['channel']);
		setVideoTitle(videos[currentvideonr]['title']);
		zap(videos[currentvideonr]['youtube_id']);
		}
	track('Clicked next button');
	}
}

function clickPrev()
{
if ((sIHaveRemote || !itsMe) && currentvideonr != -1)
	{
	if (onWebsite)
		{
		sel = document.videoselectform.videoSelect;
		newnr = sel.selectedIndex - 1;
		if (newnr >= 0)
			{
			zapOnSite(newnr);
			}
		}
	else
		{
		if (videoOpen)
			{
			switchVideo();
			}
		if (catOpen)
			{
			switchCat();
			}
		if (channelOpen)
			{
			switchChannel();
			}
		currentvideonr = currentvideonr - 1;
		
		if (currentvideonr  == -1)
			{
			currentvideonr = videos.length-1;
			}
		setCatTitle(videos[currentvideonr]['category']);
		setChannelTitle(videos[currentvideonr]['channel']);
		setVideoTitle(videos[currentvideonr]['title']);
		zap(videos[currentvideonr]['youtube_id']);
		}
	track('Clicked previous button');
	}
}


function zap(newVideoId)
{

if (sIHaveRemote)
	{
	clickPlay(0);
	sendAction('ZAP:'+newVideoId);
	cueNewVideo(newVideoId, 0);
	}
}

var abtn="/template/alicetv/images/play_n.gif";
var aspkr=false;

function out(id,filename)
{
	if(abtn!=filename) id.src=filename;
}

function clk()
{
		document.getElementById("btn1").src="/template/alicetv/images/play_n.gif";
		document.getElementById("btn2").src="/template/alicetv/images/pause_n.gif";
		document.getElementById("btn3").src="/template/alicetv/images/backward_n.gif";
		document.getElementById("btn4").src="/template/alicetv/images/forward_n.gif";
 
}

function clkspkr(id)
{
	
	if(aspkr==false)
	{
		mute();
		id.src="/template/alicetv/images/mute_a.gif";
		aspkr="/template/alicetv/images/mute_a.gif";
	}
	else
	{
		unMute();
		id.src="/template/alicetv/images/mute_n.gif";
		aspkr=false;
	}
}

function overspkr(id)
{
	
	 
	if(!aspkr) id.src='/template/alicetv/images/mute_a.gif';
	else  id.src='/template/alicetv/images/mute_n.gif';


}

function outspkr(id)
{
	if(!aspkr) id.src='/template/alicetv/images/mute_n.gif';
	else  id.src='/template/alicetv/images/mute_a.gif';
}


function status(msg)
{
document.getElementById('status').innerHTML = msg;
debug("STATUS:  "+msg);
}


function zapOnSite(nr)
{
newID = document.videoselectform.videoSelect.options[nr].value;
newTitle = document.videoselectform.videoSelect.options[nr].text;
document.videoselectform.videoSelect.selectedIndex = nr;
status(newTitle);
cueNewVideo(newID, 0);
}
