var rot13map;

function rot13init() {
	var map = new Array();
	var s   = "abcdefghijklmnopqrstuvwxyz";
	for (i=0; i<s.length; i++)
		map[s.charAt(i)] = s.charAt((i+13)%26);
	for (i=0; i<s.length; i++)
		map[s.charAt(i).toUpperCase()]	= s.charAt((i+13)%26).toUpperCase();
	return map;
}

function rot13(a) {
	if (!rot13map)
		rot13map=rot13init();
	s = "";
	for (i=0; i<a.length; i++) {
		var b = a.charAt(i);
		s += (b>='A' && b<='Z' || b>='a' && b<='z' ? rot13map[b] : b);
	}
	return s;
}

function changelink(picName,imgName)
 {
   if (document.images)
    {
      imgOn=eval(imgName + ".src");
      var showimage = document.getElementById(picName);
      if (showimage != null)
      {
	showimage.src = imgOn;
      }
      imgLink=eval(imgName + "link");
      var imgMap = document.getElementsByName("maplink");
      if (imgMap != null)
      {
        if (imgLink != "null")
        {
          imgMap[0].innerHTML = "<area shape=\"rect\" coords=\"250,175,300,225\" href=\"" + imgLink + "\" rel=\"lightbox\" alt=\"Click to open link...\" />";
        } else {
          imgMap[0].innerHTML = "";
        }
      }
    }
 }

function showhover(text)
{
	var theSpans = document.getElementsByTagName('span');
	for(var i = 0; i < theSpans.length; i++)
	{
		if(theSpans[i].id.search('showhover') == 0)
		{
			theSpans[i].style.display = 'none';
		}
	}
	document.getElementById('showhover'+text).style.display = 'inline';
}

function show(text)
{
	var theDivs = document.getElementsByTagName('div');
	for(var i = 0; i < theDivs.length; i++)
	{
		if(theDivs[i].id.search('show') == 0)
		{
			theDivs[i].style.display = 'none';
		}
	}
	document.getElementById('show'+text).style.display = 'block';
      var imgShow = document.getElementById('showimage');
      if (imgShow != null)
	{
		var imgName = 'showimg'+text;
		changelink('showimage',imgName);
	}
      var imgSlideShow = document.getElementById('roomslides');
      if (imgSlideShow != null)
	{
		if (text == '1')
		{
			var mygallery=new fadeSlideShow({
				wrapperid: "roomslides", //ID of blank DIV on page to house Slideshow
				dimensions: [300, 225], //width/height of gallery in pixels. Should reflect dimensions of largest image
				imagearray: [
					["images/photos/room03t.jpg", "images/photos/room03.jpg", "lightbox", "King Size 4 Poster Bed in Great Gable Room"],
					["images/photos/room05t.jpg", "images/photos/room05.jpg", "lightbox", "Twin or Superking Bed in Castle Crag Room"],
					["images/photos/room07t.jpg", "images/photos/room07.jpg", "lightbox", "Twin or Superking Bed in Scafell Room"],
					["images/photos/room08t.jpg", "images/photos/room08.jpg", "lightbox", "Scafell Room"] //<--no trailing comma after very last image element!
				],
				displaymode: {type:'auto', pause:3500, cycles:0, wraparound:false},
				persist: false, //remember last viewed slide and recall within same session?
				fadeduration: 750, //transition duration (milliseconds)
				descreveal: "ondemand",
				togglerid: ""
			})
		}
		if (text == '2')
		{
			var mygallery=new fadeSlideShow({
				wrapperid: "roomslides", //ID of blank DIV on page to house Slideshow
				dimensions: [300, 225], //width/height of gallery in pixels. Should reflect dimensions of largest image
				imagearray: [
					["images/photos/roomSCt.jpg", "images/photos/roomSC.jpg", "lightbox", "Self Catering cottage at Hazel Bank"],
					["images/photos/room06t.jpg", "images/photos/room06.jpg", "lightbox", "Hazel Bank Country House in surroundings."] //<--no trailing comma after very last image element!
				],
				displaymode: {type:'auto', pause:3500, cycles:0, wraparound:false},
				persist: false, //remember last viewed slide and recall within same session?
				fadeduration: 750, //transition duration (milliseconds)
				descreveal: "ondemand",
				togglerid: ""
			})
		}
	}	
}

function popup(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=600,height=450');");
}

window.onload = function()
{
	var noscript = document.getElementById('noscript');
	if (noscript != null)
	{
		noscript.style.display = 'none';
	}
	var theSpans = document.getElementsByTagName('span');
	for(var j = 0; j < theSpans.length; j++)
	{
		if(theSpans[j].id.search('showhover') != -1)
		{
			theSpans[j].style.display = 'none';
		}
		if(theSpans[j].id.search('rotate') != -1)
		{
			SpanContent = theSpans[j].innerHTML;
			SpanContent = SpanContent.replace(/\&lt;/g,'<').replace(/\&gt;/g,'>').replace(/\&amp;/g,'@');
			theSpans[j].innerHTML = rot13(SpanContent);
			theSpans[j].style.display = 'inline';
		}
	}
	var showhoverzero = document.getElementById('showhover0');
	if (showhoverzero != null)
	{
		showhoverzero.style.display = 'inline';
	}
	var theDivs = document.getElementsByTagName('div');
	for(var j = 0; j < theDivs.length; j++)
	{
		if(theDivs[j].id.search('show') != -1)
		{
			theDivs[j].style.display = 'none';
		}
	}
	var showzero = document.getElementById('show0');
	if (showzero != null)
	{
		showzero.style.display = 'block';
	}
}
