var chan = 0;
var help = 0;
var loopcontrols = 0;
var comment = "";
//----loop stuff
var looping = true;
var loopLvl = 1;
var loopNdx = 1;
var loop2Ndx = 1;
var vidloop2;

function dummy() {return}

function Home() {
	Channel(0);
	StartLoop();
}
function Contact() {
	looping=false;
	HideComment();
	document.getElementById("tvframe").src="contact.html";
	loopNdx=loopNdx-1;
}
function EndVid() {
	HideComment();
	document.getElementById("chantxt"+chan).style.display = "block";
}

function ShowComment(id,id2) {
if (document.getElementById(id)) {
	commentid = id
} else {
	commentid = id2
}
if (document.getElementById(commentid)) {
	HideComment();
	comment = commentid;
	document.getElementById(commentid).style.display = "block";
}
}
function HideComment() {
if(document.getElementById(comment)) { 
	document.getElementById(comment).style.display = "none";
}
}
function PlayVid(vid) {
vidloop2=vid.split("/");
if (vidloop2.length==0) { return; }
if (vidloop2.length==1) {
	loopLvl = 1;
	document.getElementById("chantxt"+chan).style.display = "none";
	ShowComment(vidloop2[0],vidloop2[0]);
	if (looping == true) {
		tvframe.loadNewVideo(vidloop2[0], "0");
	} else {
		looping = true
		document.getElementById("tvframe").src="mplayer.asp?v=" + vidloop2[0];		
	}
} else {
	loopLvl = 2;
	loop2Ndx=0;
	LoopVid();
}
}

function LoopVid() {
document.getElementById("chantxt"+chan).style.display = "none";
if (loopLvl == 1) {
	setCookie('htvt',loopNdx,365);
	ShowComment(vidloop[loopNdx],vidloop[loopNdx]);
	tvframe.loadNewVideo(vidloop[loopNdx], "0");
	document.getElementById("loopposition").innerHTML = (loopNdx+1) + " of " + (vidloop.length);
	loopNdx = loopNdx+1;
	if(loopNdx>vidloop.length-1) {loopNdx = 0}
} else {
	ShowComment(vidloop2[loop2Ndx],vidloop2[0]);
	if (looping == true) {
		tvframe.loadNewVideo(vidloop2[loop2Ndx], "0");
	} else {
		looping = true
		document.getElementById("tvframe").src="mplayer.asp?v=" + vidloop2[loop2Ndx];		
	}
	loop2Ndx = loop2Ndx+1;
	if(loop2Ndx>vidloop2.length) {
		loopLvl = 1;
		LoopVid();		
	}
}
}

function StartLoop() {
if (looping == true) { return; }
looping=true;
ShowComment(vidloop[loopNdx],vidloop[loopNdx]);
document.getElementById("tvframe").src="mplayer.asp?v=" + vidloop[loopNdx];
loopNdx=loopNdx+1;
}
function StopLoop() {
if (looping == false) { return; }
looping=false;
HideComment();
//document.getElementById("tvframe").src="slides/slides.asp";
//loopNdx=loopNdx-1;
document.getElementById("tvframe").src="loop.asp";
}
function NextLoop() {
	if (looping == false) { return; }
	loopLvl = 1;
	LoopVid();
}
function PrevLoop() {
	if (looping == false) { return; }
	if (loopNdx == 0) { loopNdx = vidloop.length; }
	loopNdx = loopNdx - 2;
	if (loopNdx < 0) { loopNdx = vidloop.length - 1; }
	loopLvl = 1
	LoopVid();
}
function FirstLoop() {
	if (looping == false) { return; }
	loopNdx = 0;
	loopLvl = 1;
	LoopVid();
}
function LastLoop() {
	if (looping == false) { return; }
	loopNdx = vidloop.length - 1;
	loopLvl = 1;
	LoopVid();
}
function GoLoop() {
	if (looping == false) { return; }
	var val=document.getElementById("loopgo").value
	if (val = parseInt(val)) {loopNdx = parseInt(document.getElementById("loopgo").value)-1;}
	if (loopNdx > vidloop.length) { loopNdx = vidloop.length-1; }
	if (loopNdx < 0) { loopNdx = 0; }
	loopLvl = 1;
	LoopVid();
}

function HideDiv(d) {
if(d.length < 1) { return; }
document.getElementById(d).style.display = "none";
}
function ShowDiv(d) {
if(d.length < 1) { return; }
HideDiv("home");
HideDiv("advertisers");
HideDiv("behindthescenes");
HideDiv("onthescene");
HideDiv("hometowntips");
HideDiv("specialprograms");
HideDiv("thefrontporch");
HideDiv("onthewater");
HideDiv("localsports");
HideDiv("seasonalevents");
document.getElementById(d).style.display = "block";
}
function Channel(d) {
	HideComment();
	document.getElementById("chan"+chan).style.display = "none";
	document.getElementById("chantxt"+chan).style.display = "none";
	document.getElementById("chan"+d).style.display = "block";
	document.getElementById("chantxt"+d).style.display = "block";
	comment = "chantxt"+d;
	chan = d;
}
function ChannelChg(d) {
	HideComment();
	document.getElementById("chan"+chan).style.display = "none";
	document.getElementById("chantxt"+chan).style.display = "none";
	if(d==0) {chan=chan-1} else {chan=chan+1} 
	if(chan<0) {chan=10}
	if(chan>10) {chan=0}
	document.getElementById("chan"+chan).style.display = "block";
	document.getElementById("chantxt"+chan).style.display = "block";
}
function VolumeChg(d) {
	var volume = tvframe.getVolume();
	if(d==0) {volume=volume-15} else {volume=volume+15} 
	tvframe.setVolume(volume);
}
function SeekChg(d) {
	var seek = tvframe.getCurrentTime();
	if(d==0) {seek=seek-5} else {seek=seek+5} 
	tvframe.seekTo(seek);
}
function PauseTog() {
	var state = tvframe.getPlayerState();
	if(state==1) {tvframe.pause();}
	if(state==2) {tvframe.play();}
}
function HelpTog() {
if(help==0) {   
	document.getElementById("controlbanner").style.display = "none";
	document.getElementById("rotobanner").style.display = "none";
	document.getElementById("statbanner").style.display = "block";
	document.getElementById("help1").style.display = "block"; 
	document.getElementById("help2").style.display = "block";
	document.getElementById("help3").style.display = "block";
	document.getElementById("help4").style.display = "block";
	document.getElementById("help5").style.display = "block";
	document.getElementById("help6").style.display = "block";
	help = 1;} else {HelpOff();}
}
function HelpOff() {
	help = 0;
	document.getElementById("help1").style.display = "none";
	document.getElementById("help2").style.display = "none";
	document.getElementById("help3").style.display = "none";
	document.getElementById("help4").style.display = "none";
	document.getElementById("help5").style.display = "none";
	document.getElementById("help6").style.display = "none";
	document.getElementById("controlbanner").style.display = "none";
	document.getElementById("statbanner").style.display = "none";
	document.getElementById("rotobanner").style.display = "block";
}
function ControlTog() {
	if(loopcontrols==0) {
		document.getElementById("rotobanner").style.display = "none";
		document.getElementById("controlbanner").style.display = "block";
		loopcontrols=1;
	} else {
		document.getElementById("controlbanner").style.display = "none";
		document.getElementById("rotobanner").style.display = "block";
		loopcontrols=0;
	}
}
function ledTog(s) {
if(s==0) {
	document.getElementById("led").className = "leds blueoff"; 
	document.getElementById("led2").className = "leds redoff";
	}
if(s==1) {
	document.getElementById("led").className = "leds blueon"; 
	document.getElementById("led2").className = "leds redon";
	}
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}

function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function checkCookie()
{
lno=getCookie('htvt');
if (lno!=null && lno!="")
  {
  lpcnt = parseInt(lno);
  if(lpcnt>vidloop.length-1) {loopNdx=0} else {loopNdx = lpcnt}
  }
else
  {
  loopNdx = 1;
  }
}
