var chan = "main";
var maxchan = 11;
var help = 0;
var loopcontrols = 0;
var comment = "chantxt0";
var cookiename = "mtntv"
//----loop stuff
var looping = true;
var loopLvl = 1;
var loopNdx = 1;
var loop2Ndx = 1;
var vidloop2;

function dummy() {return}

function Home() {
	Channel("main");
	StartLoop();
}
function Contact() {
	looping=false;
	HideComment();
	document.getElementById("contactus").style.display = "block";
	comment="contactus";
	document.getElementById("tvframe").src="contact.html";
	loopNdx=loopNdx-1;
}
function ShowCam(cam) {
	looping=false;
	HideComment();
	comment="contactus";
	if (cam=="camWPTown.html") {comment="camWPTown"}
	if (cam=="camWPSunspot.html") {comment="camWPSunspot"}
	if (cam=="camGrandlake.html") {comment="camGrandLake"}
	if (cam=="camGrandlake2.html") {comment="camGrandLake2"}
	if (cam=="http://74.93.225.123/popup.html?0") {comment="camSolVista"}
	document.getElementById(comment).style.display = "block";
	document.getElementById("tvframe").src=cam;
}
function ShowWeather(zip) {
	looping=false;
	HideComment();
	comment="weather";
	document.getElementById(comment).style.display = "block";
	document.getElementById("tvframe").src="http://weather.netfrontage.com/TVweather.asp?zip=" + zip;
}
function ShowSki() {
	looping=false;
	HideComment();
	comment="skiwinterpark";
	document.getElementById(comment).style.display = "block";
	document.getElementById("tvframe").src="http://www.weather.netfrontage.com/skiconditions.asp";
}
function Arcade(game) {
	looping=false;
	HideComment();
	comment="contactus";
	if (game=="pacman") {comment="pacman"}
	if (game=="mspacman") {comment="mspacman"}
	if (game=="invaders") {comment="invaders"}
	if (game=="hexxagon") {comment="hexxagon"}
	if (game=="poux") {comment="poux"}
	if (game=="tetris") {comment="tetris"}
	if (game=="spider") {comment="spider"}
	if (game=="simon_game") {comment="simon_game"}
	if (game=="scrabble") {comment="scrabble"}
	
	document.getElementById(comment).style.display = "block";
	document.getElementById("tvframe").src="http://98.130.183.216/arcade.asp?g="+game;
}
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(cookiename,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";
document.getElementById("tvframe").src="images/bgtv.jpg";
loopNdx=loopNdx-1;
}
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 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(chan=='main') {chan=0}
	
	if(d==0) {
		chan=chan-1
	} else {
		chan=chan+1
	} 
	if(chan<0) {chan=maxchan}
	if(chan>maxchan) {chan=0}
	if(chan==0) {chan='main'}
	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(cookiename);
if (lno!=null && lno!="")
  {
  lpcnt = parseInt(lno);
  if(lpcnt>vidloop.length-1) {loopNdx=0} else {loopNdx = lpcnt}
  }
else
  {
  loopNdx = 1;
  }
}
