// webcam code by jovino, ©2001, all rights reserved

var camImage = '/_img/livecam1.jpg';
var camImage2 = '/_img/livecam2.jpg';
var refreshIntervalSeconds = 15;

var secondsLeft = refreshIntervalSeconds;

function startClock() {
  if (secondsLeft > 0) {
    if (secondsLeft < 10) {
      document.webCam.timer.value = '0' + secondsLeft;
    } else {
      document.webCam.timer.value = secondsLeft;
    }
    secondsLeft = secondsLeft - 1
    timerID = setTimeout('startClock()', 1000);
  } else {
  date = new Date();
  imageNumber = date.getTime();
  document.webCamImage1.src = camImage + '?' + imageNumber;
  document.webCamImage2.src = camImage2 + '?' + imageNumber;
  secondsLeft = refreshIntervalSeconds;
  startClock();
  }
}

// popups code courtesy of Már Örlygsson
// http://mar.anomy.net/entry/2004/02/09/12.17.47/

window.onload = initPage;  
// Make sure that no other javscripts assign a fuction to window.onload
// There can be only one window.onload at a time

function initPage() {
  var isWebCam = document.getElementById("webCam");
  initPopupLinks();
  if (isWebCam != null) {
  	startClock();
  }
}

function initPopupLinks()
{
  if (!document.getElementsByTagName) return true;
  var pageLinks = document.getElementsByTagName("a");
  for (var i = 0; i < pageLinks.length; i++) 
  {
    if (((pageLinks[i].className != null) && 
         (pageLinks[i].className != "")) ||
        ((pageLinks[i].parentNode.className != null) && 
         (pageLinks[i].parentNode.className != "")))
    {
      var linkClass = " " + pageLinks[i].className + " ";
      if ((linkClass == "  ") && (pageLinks[i].parentNode.className != ""))
      {
        linkClass = " " + pageLinks[i].parentNode.className + " ";
      }
      for (var theKey in popupLinkConfig) 
      {
        if (linkClass.indexOf(" " + theKey + " ") > -1)
        {
          if ((pageLinks[i].target == "") || (pageLinks[i].target == null))
          {
            pageLinks[i].target = (popupLinkConfig[theKey][0] != "") ? popupLinkConfig[theKey][0] : theKey;
          }
          pageLinks[i].settings = popupLinkConfig[theKey][1];
          pageLinks[i].onclick = popUp;
        }
      }
    }
  }
  return true;
}

function popUp()
{
  newWin = window.open(this.href, this.target, this.settings);
  newWin.focus();
  return false;
}

var popupLinkConfig = new Array;
// Delete/copy/modify the following lines to configure your popup windows.
popupLinkConfig["popup"] = new Array ( "", "width=350,height=450,scrollbar=yes,menubar=yes");
popupLinkConfig["listenlive"] = new Array ( "listenlive", "width=550,height=350,resizable=no,scrollbars=no");

function getObject(name) {
   var ns4 = (document.layers) ? true : false;
   var w3c = (document.getElementById) ? true : false;
   var ie4 = (document.all) ? true : false;

   if (ns4) return eval('document.' + name);
   if (w3c) return document.getElementById(name);
   if (ie4) return eval('document.all.' + name);
   return false;
}

// site-specific code
function navswitch(id) {
	var nav_items = Array('default', 'listenlive', 'news', 'music', 'events', 'forums', 'contact', 'about');
	for(i=0;i<nav_items.length;i++) {
		ob = getObject('nav_'+nav_items[i]);
		if(ob) ob.style.display = 'none';

		ob = getObject(nav_items[i]);
		if(ob) ob.className = '';
	}
	
	ob = getObject(id);
	if(ob) ob.className = 'current';
	
	ob = getObject('nav_'+id);
	if(ob) ob.style.display = 'block';

	var pos = '';
	switch(id) {
		case 'listenlive':	pos = '57'; break;
		case 'news':		pos = '150'; break;
		case 'music':		pos = '217'; break;
		case 'events':		pos = '285'; break;
		case 'forums':		pos = '357'; break;
		case 'contact':		pos = '435'; break;
		case 'about':		pos = '505'; break;
		default:			pos = '-200'; break;
	}
	
	ob = getObject('navsubwrapper');
	ob.style.backgroundPosition = pos+'px -1px';
}

function clearSearch(f) {
	if(f.defaultValue==f.value) {
		f.value = '';
	}
}

function restoreSearch(f) {
	if(f.value=='') {
		f.value = f.defaultValue;	
	}
}

