// JavaScript Document

function disguisedText()
{
	//Check if DOM is supported
	if(!document.getElementById){return;}
	
	//Get the div where the content will be added
	var contentArea=document.getElementById("primaryContent");
	
	//Create text node, append to paragraph element; then append para to div
	var text=document.createTextNode("Telephone: +44 (0)1582 751042");
	var newElem=document.createElement("p");
	newElem.appendChild(text);
	contentArea.appendChild(newElem);
	
	//Create and append text node for email address
	var text=document.createTextNode("Email: ");
	var newElem=document.createElement("p");
	newElem.appendChild(text);	
	contentArea.appendChild(newElem);
	
	//Create the email anchor element
	var text=document.createTextNode("contact@chevronb4.co.uk");
	var anchorElem=document.createElement("a");
	anchorElem.setAttribute("href", "mailto:contact@chevronb4.co.uk");
	anchorElem.appendChild(text);
	
	//Get the last paragraph element
	var para=document.getElementById("primaryContent").lastChild;
	
	//Firefox fix to prevent selection of whitespace
	while (para.nodeType!=1)
	{
		para=para.nextSibling;
	}	
	
	//append the email address to the paragraph
	para.appendChild(anchorElem);
	return;
}


/*	Get amount of X and Y scrolling to maintain page position when viewing gallery pics 
	Requiries page to contain a form called 'scrollAmt' containing a hidden field called
	'scrollAmt' */

function getScroll(linkClicked)
{
  var xScroll = 0;
  var yScroll = 0;
  
  if(typeof(window.pageYOffset) == 'number' )
  {
    //Netscape
    yScroll = window.pageYOffset;
    xScroll = window.pageXOffset;
  }
  
  else if(document.body && (document.body.scrollLeft || document.body.scrollTop ))
  {
    //DOM compliant
    yScroll = document.body.scrollTop;
    xScroll = document.body.scrollLeft;
  }
  
  else if(document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop))
  {
    //IE6
    yScroll = document.documentElement.scrollTop;
    xScroll = document.documentElement.scrollLeft;
  }
  
  var data=xScroll+","+yScroll;
  
  // If the user clicked the 'Next' link
  if(linkClicked=="nextLink")
  {
	  //assign the scroll data to the 'Next Page' hidden form field
	  document.scrollAmtNextPage.scrollAmt.value=data;
	  
	  //submit the 'next page' form
	  document.scrollAmtNextPage.submit();
  }
  
  //If the user clicked the previous link
  if(linkClicked=="previousLink")
  {
	 document.scrollAmtPreviousPage.scrollAmt.value=data;
	 document.scrollAmtPreviousPage.submit();
  }
  
 
}


function scrollWindow()
{
	window.scrollTo(xScroll, yScroll);
}



/* Function to attach the getScroll function to the 'Next' and 'Previous' links 
and scroll window to same position as previous image viewed*/

function attachScriptAndScroll()
{
	//Check if DOM is supported
	if(!document.getElementById) {return;}
	
	//grab all the anchor elements within the 'expandedImageNav' div
	//var targetElems=document.getElementById("expandedImageNav").getElementsByTagName("a");
	var targetElem1=document.getElementById("nextLink");
	var targetElem2=document.getElementById("previousLink");
	
	//Check if the target element exists
	if(!targetElem1 || !targetElem2) {return;}

	//Attach the 'getScroll' function to the onclick handler of the navigation links
	targetElem1.onclick=function()
	{
			getScroll(this.id);
			return false;
	}

	targetElem2.onclick=function()
	{
			getScroll(this.id);
			return false;
	}
	//scroll the window
		
	scrollWindow();

	return;
	
}