//Create pointer image of tooltip
imgPointer=document.createElement("img");

//Create empty tooltip div element 
tipDiv= document.createElement("div");

//Create div which holds content of tooltip
content = document.createElement("div");

//Create paragraph element
para=document.createElement("p");

function startUp(){
imgPointer.className="noprint";
imgPointer.style.visibility="hidden";
imgPointer.style.zindex="40";
imgPointer.style.position="absolute";
document.body.appendChild(imgPointer);

tipDiv.className="noprint";
tipDiv.style.position = "absolute";
tipDiv.style.visibility = "hidden";
tipDiv.style.zindex=41;

//tipDiv.style.height="52px";
tipDiv.style.width="300px";


content.className="noprint";
content.style.width ="280px";

content.style.position = "relative";
content.style.left="4px";
content.style.visibility = "hidden";


para.style.fontSize="9pt";
para.className="noprint";
para.style.position="relative";
para.style.left="0px";

//For some reason, the paragraph offset differs between browsers and web pages. We use id="specialCase" in table in walk.html which houses navigation buttons.
//First check if we have a special case
var tablElems=document.getElementsByTagName("table");
var lenTables = tablElems.length;
var specCase=false;
for(var i=0; i<lenTables;i++){
if(tablElems[i].getAttribute("id")=="specialCase"){
specCase=true;
i=lenTables;
} //end if
} //end for


var corxn=0;//first set 0 for all browsers
if((!document.all)&&(!specCase)){//Opera,Mozilla,Firefox not on walks.html
var corxn = -12;
}
if((document.documentMode==8)&&(!specCase)){//IE8 not on walks.html
var corxn= -12;
}
para.style.top=corxn +"px"; 
content.style.top="5px";

tipText="";
if(!document.createTextNode) return false;
tipNode = document.createTextNode(tipText);

tipTxt = new Array();
hRef = new Array();
linkElems= new Array();

//Get elements 'a' with class-name "hasTip" using function in global.js
linkElems=getElemsByClassName("hasTip","a");
lenLinks=linkElems.length;
for(var i=0; i<lenLinks;i++){
var fullHref=linkElems[i].href;

//Split the full href into its various sections, (separated by "/") and keep the last section.
var bitsHref=fullHref.split("/");
hRef[i]=bitsHref[bitsHref.length-1];


// Get message to display in tooltip
if(hRef[i] == "index.html"){tipTxt[i]="Your likely starting point. The date latest update/s were made. Links to local weather forecasts.";
}else if(hRef[i] == "intro.html"){tipTxt[i]="Reasons to join Ramblers. Penrith Group's catchment area. Brief info on web site content.";
}else if(hRef[i] == "walk.html"){tipTxt[i]="Latest walks' programme + facilities for walk location, finding which map/s to use and printing."; 
}else if(hRef[i] == "update.html"){tipTxt[i]="Updates to forthcoming walks. Info for group's members. Adverts of interest to ramblers.";
}else if(hRef[i] == "guide.html"){tipTxt[i]="Walk Grades. Countryside code. Tips for leaders. Advice on dogs, accidents, obstructions, etc.";
}else if(hRef[i] == "contacts.html"){tipTxt[i]="Where to meet. Contacting secretaries, walk co-ordinators and leaders. Joining 'Ramblers'.";
}else if(hRef[i] == "news.html"){tipTxt[i]="Read the latest Penrith Ramblers newsletter, which is provided in both HTML and PDF formats.";
}else if(hRef[i] == "thumbpg.html"){tipTxt[i]="Photographs provided by members of Penrith rambling group. View singly or as a slide show.";
}else if(hRef[i] == "dales.html"){tipTxt[i]="Yorkshire Dales - its location, a brief account of its topography and tourist facilities with photos.";
}else if(hRef[i] == "eden.html"){tipTxt[i]="The Eden Valley - its location, topography and info on its many tourist facilities plus photos.";
}else if(hRef[i] == "howgill.html"){tipTxt[i]="The Howgills - its location with a description of its geology and topography with photographs.";
}else if(hRef[i] == "lake.html"){tipTxt[i]="The Lake District - a diagram with lists of lakes, mountains and tourist facilities plus photos";
}else if(hRef[i] == "pennine.html"){tipTxt[i]="The western Pennines - a brief account of the topography and tourist facilities with photos";
}else if(hRef[i] == "gear.html"){tipTxt[i]="Advice on basic walking gear plus suggested extras for serious fell walking in cold and ice.";
}else if(hRef[i] == "compass.html"){tipTxt[i]="Ordnance Survey grid references. How to use a compass. An insight into GPS use.";
}else if(hRef[i] == "medical.html"){tipTxt[i]="Recognising, strokes, cardiac arrest and heart attacks. Preventing aches and Lyme disease.";
}else if(hRef[i] == "site.html"){tipTxt[i]="Info. on facilities on web site with javascript ON. Aims of site. Diary. Web host. Web master, etc.";
}else if(hRef[i] == "photoHelp.html"){tipTxt[i]="Submitting photos, help viewing photos, printing photos, corrupted photos.";
 // }else if(hRef[i] == "walk.html#"){tipTxt[i]="Walk grades In rising severity are E=Easy, M=Moderate, H=Hard, D=Demanding. See Grades in 'Guide Lines to walks'."; 

}else{tipTxt[i]="";

} //end else
} //end for

divhasTip=new Array();
idTxt=new Array();

//Get elements 'div' with class-name "hasTip" using function in global.js This is for tooltips to do with facilities on Walks' Programme page
divhasTip=getElemsByClassName("hasTip","div");
lenDivhasTip= divhasTip.length;

for(var i=0; i<lenDivhasTip;i++){
idTxt[i]=divhasTip[i].id;
if(idTxt[i]=="printButton"){tipTxt[i+lenLinks]="This facility enables the printing of a choice of monthly programmes of walks, selected using a check box. (No navigation bars should appear.) Included are instructions on setting up your printer dialogue box to prevent wasted output.";
}else if(idTxt[i]=="WalkPlaceButton"){tipTxt[i+lenLinks]="This facility adds a column labelled M to the tables. Clicking M in the row of a walk plots the region of the walk on one of four maps. A second button, 'OS maps for walks' appears, which if clicked shows the OS maps for that region.";
}else{tipTxt[i]="";
}// end if
} //end for

return[hRef],[idTxt];
} //eof startUp


function tip(thisLink){
if(prntNote.on||mapDisplay.on){ return false;} // switch off tooltips when 'Print Information' or mapping of walks is displayed
//if(document.all){
if(thisLink.getAttribute("className")){ //IE before IE8
classText = thisLink.getAttribute("className");
}else{classText = thisLink.getAttribute("class"); //Mozilla Firefox, Opera and IE8+
}
if (classText != "hasTip"){ return false; } // Return if the link  has no tooltip associated with it

var posn=new Array();
posn=findPos(thisLink);
xLink=posn[0];
yLink=posn[1];

if((thisLink.href==undefined)&&(thisLink.id=="")){return false; }// return if function tip is activated without tags href or id present.

//Consider tag href. This is involved with tooltips to links to other pages.
if(thisLink.href!=undefined){
pointCorrxn=0; //a coorrection for the position of the point relative to the tooltip window
var fullHref=thisLink.href;
var hrefBits=fullHref.split("/");
ourHref=hrefBits[hrefBits.length-1];
for(i=0;i<lenLinks;i++){
if(hRef[i]==ourHref){
tipText=tipTxt[i];
i=lenLinks;
} //end if
} // end for

//Get horizontal position of tipDiv and imgPointer, depending on whether button is on L.H.S. or R.H.S. of page 
if(xLink>500){ //tooltip on right hand side of page
var x=xLink-360;
imgPointer.setAttribute("src","images/pointer2.gif");
imgPointer.style.left=xLink-53 +"px";
tipDiv.className= "tooltipShadow2";

}else{  //tooltip on lefthand side of page
var x=xLink+197;// value of tipDiv.style.left
imgPointer.setAttribute("src","images/pointer1.gif");
imgPointer.style.left=xLink +145 +"px";
tipDiv.className= "tooltipShadow1";
}

//Set up depth and colour of border of tooltips for links to other pages
tipDiv.style.height="52px";
content.style.height="30px";
tipDiv.style.backgroundColor = "#8f8";
setupTip(tipText,"#000","#ffffdd");
} //end if

//Consider tag id. This is involved with tooltips to facilities on same page, in particulat the Walks Programme page
if(thisLink.id!=""){ 
pointCorrxn= 22; //A deeper tooltip window means that the pointer needs to be lowered relative to it.
var idee=thisLink.id;
for(i=0;i<lenDivhasTip;i++){
if( idee==idTxt[i]){
tipText=tipTxt[i+lenLinks];
i=lenDivhasTip;
} //end if
} //end for

//Get horizontal position of tipDiv and imgPointer, depending on whether 'facility' button is on L.H.S. or R.H.S. of page 
if(xLink>500){ //tooltip on right hand side of page
var x=xLink-357;
imgPointer.setAttribute("src","images/pointer2.gif");
imgPointer.style.left=xLink-50 +"px";
 tipDiv.className= "tooltipShadow2";

}else{ //tooltip on left hand side of page
var x=xLink+270;// value of tipDiv.style.left
imgPointer.setAttribute("src","images/pointer1.gif");
imgPointer.style.left=xLink +218 +"px";
tipDiv.className= "tooltipShadow1";
}

//Set up depth and colour of border of tooltips for facilities on same page. These are deeper than tooltips for links to other pages.
tipDiv.style.height="94px";
content.style.height="72px";
tipDiv.style.backgroundColor = "#f88";
setupTip(tipText,"#000","#ddffdd");
} //end if

content.className = "tooltipContent";
tipDiv.style.left=x + "px";

if(document.all){ //for I.E.
tipDiv.style.top=yLink -16+"px"; 
imgPointer.style.top=yLink+pointCorrxn-6 +"px";
}else{ // For non I.E.
tipDiv.style.top=yLink -22 +"px"; 
imgPointer.style.top=yLink-12+ pointCorrxn+"px";
}

tipDiv.style.visibility = "visible";
content.style.visibility="visible";
content.appendChild(para);
tipDiv.appendChild(content);
document.body.appendChild(tipDiv);
imgPointer.style.visibility="visible";
} //eof tip


function setupTip(tipText,col, bgCol){
content.style.backgroundColor=bgCol;
content.style.color=col;
tipNode=document.createTextNode(tipText);
para.appendChild(tipNode);
} //eof setupTip


 function hide(thisLink){
 //Cancel action if para.firstChild does not exist, because 'Print Notice' or mapping of walk is on display.
 if(para.firstChild!=tipNode){return false;}
 para.removeChild(tipNode);
 tipDiv.style.visibility = "hidden";
 content.style.visibility="hidden";
 imgPointer.style.visibility="hidden";
 return;
 } //eof hide
 
 
 function findPos(obj){
 var topCoor=leftCoor=0;
 while(obj!=null)
 {topCoor+=obj.offsetTop;
 leftCoor+=obj.offsetLeft;
 obj=obj.offsetParent;}
 return [leftCoor,topCoor] ; //return left and top co-ordinates in an array.
 } //eof findPos

addLoadEvent(startUp);