
// ############ Variables ##############
var refreshInterval=11; // minutes
var initialRefresh=1;   // minutes



// ############ Functions ##############

function titleImg() {
  // Font is Monotype Corsiva
  var text="<H1><A HREF='http://www.pointuk.com'><IMG SRC='title.gif' WIDTH='220' HEIGHT='98' ALIGN='BOTTOM' BORDER='0' ";
  text+="ALT='The Point, Rhoscolyn, Anglesey' TITLE='The Point, Rhoscolyn, Anglesey'></A></H1>";
  return text;
}

function navigation(loc,subLoc) {
  var navBlock="";
  if(subLoc!=0) navBlock+="<A NAME='"+subLoc+"'></A>";
  navBlock+="<TABLE BORDER='0' CELLSPACING='0' CELLPADDING='4'>";
  navBlock+="<TR><TD ALIGN='LEFT' NOWRAP BGCOLOR='#5C4F48'>";
  navBlock+="<IMG SRC='nothing.gif' WIDTH='122' HEIGHT='1' BORDER='0'><BR>";
  for(var n in nav) {
    navBlock+="<SPAN CLASS='navLink'><FONT";
    if(loc==n) navBlock+=" style='BACKGROUND-COLOR: #AD8668'";
    d=dest[n][0];
    newWindow="";
    if(d.indexOf(">")>-1) {
      d=d.substring(1);
      newWindow=" TARGET='_blank'";
    }
    navBlock+="><A HREF='"+d+"'>"+nav[n][0]+"</A></FONT></SPAN><BR>";
    if(loc==n) {
      for(var nn in nav[n]) {
        if(nn!=0) {
          navBlock+="&nbsp;&nbsp;&nbsp;<SPAN CLASS='navSubLink'><FONT";
          if(subLoc==nn) navBlock+=" style='BACKGROUND-COLOR: #AD8668'";
          d=dest[n][nn];
          newWindow="";
          if(d.indexOf(">")>-1) {
            d=d.substring(1);
            newWindow=" TARGET='_blank'";
          }
          navBlock+="><A HREF='"+d+"'"+newWindow+">"+nav[n][nn]+"</A></FONT></SPAN><BR>";
        }
      }   
    }
  }
  navBlock+="</TD>";
  //navBlock+="<TD BGCOLOR='#5C4F48'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>";
  navBlock+="<TD>&nbsp;</TD></TR></TABLE>";
  return navBlock;
}

var navIncludes=new Array();
navIncludes[0]="home";
navIncludes[1]="availability";
navIncludes[2]="contact";
navIncludes[3]="location";
navIncludes[4]="weather";
navIncludes[5]="webcamBeach";
navIncludes[6]="webcamSea";
navIncludes[7]="links";

function navLine(loc,includes) {
  var navLine="<BR>";
  for(i=0; i<includes.length; i++) {
    navLine+="<SPAN CLASS='navLink'><FONT";
    if(loc==includes[i]) navLine+=" style='BACKGROUND-COLOR: #AD8668'";
    d=dest[includes[i]][0];
    newWindow="";
    if(d.indexOf(">")>-1) {
      d=d.substring(1);
      newWindow=" TARGET='_blank'";
    }
    navLine+=">[<A HREF='"+d+"'>"+nav[includes[i]][0]+"</A>]</FONT></SPAN>&nbsp;&nbsp;";
  }

  navLine+="<BR>&COPY; All content on this website is copyright. Please contact us for details.";

  return navLine;
}

function testCookie() {
  var expiredate=new Date();
  expiredate.setTime(expiredate.getTime()+30000)
  document.cookie="testCookie=test;expires="+expiredate.toGMTString();
  if(findCookie("testCookie")=="test") return true;
  else return false;
}

function setRefreshCookie(milliseconds) {
  // set cookie to current time with expiry in milliseconds mS
  var now=new Date();
  var expiredate=new Date();
  expiredate.setTime(expiredate.getTime()+milliseconds)
  var now_mS=now.getTime();
  document.cookie="refreshCookie="+now_mS+";expires="+expiredate.toGMTString();
  if(""+now_mS==findCookie("refreshCookie")) return true;
  else return false;
}

function findCookie(v) {
  //alert(document.cookie);
  var found="";
  if(document.cookie) {
    var docCook=new Array();
    var tempArray=new Array();
    var cookArray=document.cookie.split(";");
    for(var f=0; f<cookArray.length; f++) {
      tempArray=cookArray[f].split("=");
      while(tempArray[0].substring(0,1)==" ")
        {tempArray[0]=tempArray[0].substring(1,tempArray[0].length)}
      docCook[tempArray[0]] = tempArray[1];
    }
    if(docCook[v]) {
      found=docCook[v];
      found=unescape(found);
    }
  }
  return found
}

function timedRefresh(refreshPeriod) {
   setTimeout("self.location.reload(true);",refreshPeriod);
}

function refreshPage() {
  // start timed refresh periods
  timedRefresh(60000*refreshInterval);
  
  // refresh now if not done recently
  var lastRefresh=findCookie("refreshCookie");
  var lastRefresh_mS=0;
  if(lastRefresh!="") lastRefresh_mS=parseInt(lastRefresh);
  var now_mS=new Date().getTime();
  if(testCookie() && lastRefresh_mS<(now_mS-initialRefresh*60000) ) {
    if(setRefreshCookie(initialRefresh*60000)) self.location.reload(true);
  }
}

function webcamDataExists() {
  return (window.dayFolder && window.numPics && window.albumTitle && window.photo && window.caption);
}

function charReplace(test, out, replace) {
  if(out==replace) return test;
  pos=test.indexOf(out);
  while(pos>-1) {
    test=test.substring(0,pos) + replace + test.substring(pos+out.length,test.length);
    pos=test.indexOf(out,pos+replace.length);
  }
  return test;
}

function mail() {
  // returns <HREF TAG   (ie no closing '> )
  em1="k.com";
  em3="<A HRE";
  em4="F='mailt";
  em5="oi";
  em6="ntu";
  em7="o:sal";
  em8="ly@p";
  return em3+em4+em7+em8+em5+em6+em1;
}
function phoneNumber() {
  em1="1";
  em3="014";
  em4="7";
  em5="30";
  em6="1";
  em7="7 ";
  em8="53";
  return em3+em4+em7+em8+em5+em6+em1;
}
function contactName() {
  em1="e";
  em3="S";
  em4="a";
  em5="D";
  em6="yk";
  em7="ll";
  em8="y ";
  return em3+em4+em7+em8+em5+em6+em1;
}

var artPics=new Array();
artPics[0]="art_IMG_4750_130.jpg";
artPics[1]="art_P1000194_130.jpg";
artPics[2]="art_P1000212_130.jpg";
artPics[3]="art_P1000235cas_130.jpg";
artPics[4]="art_P1000340_130.jpg";
artPics[5]="art_P1000390_130.jpg";
artPics[6]="art_P1000399_130.jpg";
artPics[7]="art_P1000463.jpg";
var nextArt=Math.floor(artPics.length*Math.random());

function getNextArt() {
  nextArt++;
  if(nextArt>=artPics.length) nextArt=0;
  return "<IMG SRC='"+artPics[nextArt]+"' WIDTH='130' HEIGHT='200' ALIGN='BOTTOM' BORDER='0'>";
}
