//Warn of links opening in new window
function externalLinks() { 
 if (!document.getElementsByTagName) return; 
 var anchors = document.getElementsByTagName("a"); 
 for (var i=0; i<anchors.length; i++) { 
   var anchor = anchors[i]; 
   if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") { 
    anchor.target = "_blank"; 
    anchor.title = (anchor.title != "") ? anchor.title+" (Opens in a new window)" : "opens in a new window"; 
    anchor.className = (anchor.className != '') ? anchor.className+' external' : 'external'; 
}
 } 
} 
window.onload = externalLinks;

function swap(targetId){
  
  if (document.getElementById)
        {
        target = document.getElementById(targetId);
        
            if (target.style.display == "none")
                {
                target.style.display = "";
                } 
            
            else 
                {
                target.style.display = "none";
                }
                
        }
}


/***********************************************
* AnyLink Vertical Menu- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

//Contents for mountains
var mountains=new Array()
mountains[0]='<a href="http://snowdonia.tupence.co.uk/mountains/advice.htm">Advice</a>'
mountains[2]='<a href="http://snowdonia.tupence.co.uk/mountains/glyders.htm">Glyders</a>'
mountains[1]='<a href="http://snowdonia.tupence.co.uk/mountains/snowdon.htm">Snowdon</a>'
mountains[3]='<a href="http://snowdonia.tupence.co.uk/mountains/tryfan.htm">Tryfan</a>'

//Contents for history
var hist=new Array()
hist[0]='<a href="http://snowdonia.tupence.co.uk/history/romans.htm">Romans</a>'
hist[1]='<a href="http://snowdonia.tupence.co.uk/history/dark.htm">Dark Ages</a>'
hist[2]='<a href="http://snowdonia.tupence.co.uk/history/medieval.htm">Medieval</a>'
hist[3]='<a href="http://snowdonia.tupence.co.uk/history/rhuddlan.htm">Post Rhuddlan</a>'

//Contents for medieval
var medieval=new Array()
medieval[0]='<a href="http://snowdonia.tupence.co.uk/history/owain.htm">Owain Gwynedd</a>'
medieval[1]='<a href="http://snowdonia.tupence.co.uk/history/llyw1.htm">Llywelyn Fawr</a>'
medieval[2]='<a href="http://snowdonia.tupence.co.uk/history/daf1.htm">Dafydd ap Llywelyn</a>'
medieval[3]='<a href="http://snowdonia.tupence.co.uk/history/llyw2.htm">Llywelyn ap Gruffydd</a>'
medieval[4]='<a href="http://snowdonia.tupence.co.uk/history/daf2.htm">Dafydd ap Gruffydd</a>'

//Contents for castles
var castles=new Array()
castles[0]='<a href="http://snowdonia.tupence.co.uk/castles/roman.htm">Roman Forts</a>'
castles[1]='<a href="http://snowdonia.tupence.co.uk/cstles/welsh.htm">Welsh Castles</a>'
castles[2]='<a href="http://snowdonia.tupence.co.uk/castles/norman.htm">Norman Castles</a>'

//Contents for galleries
var galleries=new Array()
galleries[0]='<a href="http://snowdonia.tupence.co.uk/galleries/mountains.htm">Mountains</a>'
galleries[1]='<a href="http://snowdonia.tupence.co.uk/galleries/lakes.htm">Lakes</a>'
galleries[2]='<a href="http://snowdonia.tupence.co.uk/galleries/castles.htm">Castles</a>'
galleries[3]='<a href="http://snowdonia.tupence.co.uk/galleries/others.htm">Others</a>'
galleries[4]='<a href="http://postacrds.tupence.co.uk/snowdonia.htm">Old Postcards</a>'

//Contents for trains
//var trains=new Array()
//trains[0]='<a href="http://snowdonia.tupence.co.uk/trains/smr.htm">Snowdon Mountain Railway</a>'
//trains[1]='<a href="http://snowdonia.tupence.co.uk/trains/ffest.htm">Ffestiniog</a>'
//trains[2]='<a href="http://snowdonia.tupence.co.uk/trains/whr.htm">Welsh Highland</a>'
//trains[3]='<a href="http://snowdonia.tupence.co.uk/trains/llanberis.htm">Llanberis Lake</a>'


var disappeardelay=250  //menu disappear speed onMouseout (in miliseconds)
var horizontaloffset=2 //horizontal offset of menu from default location. (0-5 is a good value)

/////No further editting needed

var ie4=document.all
var ns6=document.getElementById&&!document.all

if (ie4||ns6)
document.write('<div id="dropmenudiv" style="visibility:hidden;width: 160px" onMouseover="clearhidemenu()" onMouseout="dynamichide(event)"></div>')

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}


function showhide(obj, e, visible, hidden, menuwidth){
if (ie4||ns6)
dropmenuobj.style.left=dropmenuobj.style.top=-500
dropmenuobj.widthobj=dropmenuobj.style
dropmenuobj.widthobj.width=menuwidth
if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
obj.visibility=visible
else if (e.type=="click")
obj.visibility=hidden
}

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
var edgeoffset=0
if (whichedge=="rightedge"){
var windowedge=ie4 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
if (windowedge-dropmenuobj.x-obj.offsetWidth < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure+obj.offsetWidth
}
else{
var topedge=ie4 && !window.opera? iecompattest().scrollTop : window.pageYOffset
var windowedge=ie4 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure){ //move menu up?
edgeoffset=dropmenuobj.contentmeasure-obj.offsetHeight
if ((dropmenuobj.y-topedge)<dropmenuobj.contentmeasure) //up no good either? (position at top of viewable window then)
edgeoffset=dropmenuobj.y
}
}
return edgeoffset
}

function populatemenu(what){
if (ie4||ns6)
dropmenuobj.innerHTML=what.join("")
}


function dropdownmenu(obj, e, menucontents, menuwidth){
if (window.event) event.cancelBubble=true
else if (e.stopPropagation) e.stopPropagation()
clearhidemenu()
dropmenuobj=document.getElementById? document.getElementById("dropmenudiv") : dropmenudiv
populatemenu(menucontents)

if (ie4||ns6){
showhide(dropmenuobj.style, e, "visible", "hidden", menuwidth)
dropmenuobj.x=getposOffset(obj, "left")
dropmenuobj.y=getposOffset(obj, "top")
dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+obj.offsetWidth+horizontaloffset+"px"
dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+"px"
}

return clickreturnvalue()
}

function clickreturnvalue(){
if (ie4||ns6) return false
else return true
}

function contains_ns6(a, b) {
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
}

function dynamichide(e){
if (ie4&&!dropmenuobj.contains(e.toElement))
delayhidemenu()
else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
delayhidemenu()
}

function hidemenu(e){
if (typeof dropmenuobj!="undefined"){
if (ie4||ns6)
dropmenuobj.style.visibility="hidden"
}
}

function delayhidemenu(){
if (ie4||ns6)
delayhide=setTimeout("hidemenu()",disappeardelay)
}

function clearhidemenu(){
if (typeof delayhide!="undefined")
clearTimeout(delayhide)
}

/***********************************************
* Image Thumbnail viewer- © Dynamic Drive (www.dynamicdrive.com)
* Visit http://www.dynamicdrive.com/dynamicindex4/thumbnail.htm for full source code
***********************************************/
var ie=document.all
var ns6=document.getElementById&&!document.all

function ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat" && !window.opera)? document.documentElement : document.body
}

function enlarge(which, e, position, imgwidth, imgheight){
if (ie||ns6){
crossobj=document.getElementById? document.getElementById("showimage") : document.all.showimage
if (position=="center"){
pgyoffset=ns6? parseInt(pageYOffset) : parseInt(ietruebody().scrollTop)
horzpos=ns6? pageXOffset+window.innerWidth/2-imgwidth/2 : ietruebody().scrollLeft+ietruebody().clientWidth/2-imgwidth/2
vertpos=ns6? pgyoffset+window.innerHeight/2-imgheight/2 : pgyoffset+ietruebody().clientHeight/2-imgheight/2
if (window.opera && window.innerHeight) //compensate for Opera toolbar
vertpos=pgyoffset+window.innerHeight/2-imgheight/2
vertpos=Math.max(pgyoffset, vertpos)
}
else{
var horzpos=ns6? pageXOffset+e.clientX : ietruebody().scrollLeft+event.clientX
var vertpos=ns6? pageYOffset+e.clientY : ietruebody().scrollTop+event.clientY
}
crossobj.style.left=horzpos+"px"
crossobj.style.top=vertpos+"px"

crossobj.innerHTML='<div align="right" id="dragbar"><span id="closetext" onClick="closepreview()">Close</span> </div><img src="'+which+'">'
crossobj.style.visibility="visible"

return false
}
else //if NOT IE 4+ or NS 6+, simply display image in full browser window
return true
}

function closepreview(){
crossobj.style.visibility="hidden"
}

function drag_drop(e){
if (ie&&dragapproved){
crossobj.style.left=tempx+event.clientX-offsetx+"px"
crossobj.style.top=tempy+event.clientY-offsety+"px"
}
else if (ns6&&dragapproved){
crossobj.style.left=tempx+e.clientX-offsetx+"px"
crossobj.style.top=tempy+e.clientY-offsety+"px"
}
return false
}

function initializedrag(e){
if (ie&&event.srcElement.id=="dragbar"||ns6&&e.target.id=="dragbar"){
offsetx=ie? event.clientX : e.clientX
offsety=ie? event.clientY : e.clientY

tempx=parseInt(crossobj.style.left)
tempy=parseInt(crossobj.style.top)

dragapproved=true
document.onmousemove=drag_drop
}
}

document.onmousedown=initializedrag
document.onmouseup=new Function("dragapproved=false")


