function nw (link)

{
				 
	//alert(link)
	window.open(link.href);
 	return false;
}


function focusOnField(field)
{
//alert(field)
document.forms[0][field].focus()
document.forms[0][field].select()
}




window.onload = function(){
	
	setupMainMenuLinks();
	checkSlideshowSupport()	
	prepareGallery()	
	
}


window.onunload = function(){
	
	/* run this function if we have a page running the slideshow - just to ensure we have cleared all the memory timers
	
	if(!document.getElementsByTagName) return false;
	if(!document.getElementById) return false;
	if(!document.getElementById("slideshow")) return false;
		
	clearInterval(initialImageFadeout)	
	
	clearInterval(image1FadeIn)

	clearInterval(image1FadeOut)	
	
	clearInterval(newBackgroundImage)	*/
	
}


function setupMainMenuLinks()	{

	
	
	/* check the browser is capable of recognising the DOM objects
	   we need to implement the script - otherwise return false and allow the normal link to be executed */
	   
	if(!document.getElementsByTagName) return false;
	if(!document.getElementById) return false;
	if(!document.getElementById("mainnav")) return false;

		if(document.getElementById("Contact_Me")) {
			
			
			document.getElementById("Contact_Me").onclick = function() {
				
				return showContactTime()
			
			}
		}
		
		
function showContactTime() {


	if(document.getElementById("contactTime").style.display == "none")	{

		document.getElementById("contactTime").style.display = "block"
		document.getElementById("preferredTime").style.display = "block"					
					

	}	
	
	else	{
		document.getElementById("contactTime").style.display = "none"
		document.getElementById("preferredTime").style.display = "none"					
	
	}
			
}			

	/* get the reference to the mainnav object and then create an array 
	   of all the <li> tags found in the array. To each tag assign a function to
	   the onmouseover and onmouseout methods. */
	   
	
	var links = document.getElementById("mainnav").getElementsByTagName("li");
	
	
	for(i = 0; i < links.length; i++) {

		links[i].onmouseover = function() {
		
			
			return setMenuBackground(this);	
			
		}
		
		
		links[i].onmouseout = function() {
			
				return resetMenuBackground(this);	
		
		}
	
	}
	
	
}

function setMenuBackground(menuItem) {
	

	/* only if the parentnode is mainnav do we replace the background image */
	
if (menuItem.parentNode.getAttribute("id") == "mainnav") {
	
	
	
	menuItem.style.backgroundImage = "url(images/menu_background.gif)"	
	menuItem.style.backgroundRepeat = "no-repeat"	
	
	}	
}


function resetMenuBackground(menuItem) {
	
	
menuItem.style.backgroundImage = "none"	
	
}





var slideCounter = 1

function checkSlideshowSupport()	{
	
	/* check the browser is capable of recognising the DOM objects
	   we need to implement the script - otherwise return false and abandom the slideshow */
	   
	if(!document.getElementsByTagName) return false;
	if(!document.getElementById) return false;
	if(!document.getElementById("slideshow")) return false;
	
	initialImageFadeout = setInterval("FadeOpacity('slideshow', 100, 0, 1500, 10)", 4500)
	
	setInterval("displaySequentialSlideshow()", 8000)
	
	

}


function displayRandomSlideshow()	{	
	
	
	var showThisImage = "library/" + js_slideShowGallery + "/" + slideshowPics[Math.round(Math.random() * (slideshowPics.length-1))] 

	document.getElementById("slideshow").src = showThisImage

	
}



function displaySequentialSlideshow()	{	
	
	
	setTimeout("clearInterval(initialImageFadeout)", 500)

	var showThisImage = "library/" + js_slideShowGallery + "/" + slideshowPics[slideCounter]
	document.getElementById("slideshow").src = showThisImage
	
	image1FadeIn = setInterval("FadeOpacity('slideshow', 0, 100, 1500, 15)", 1500)
	setTimeout("clearInterval(image1FadeIn)", 1800)

	image1FadeOut = setInterval("FadeOpacity('slideshow', 100, 0, 1500, 15)", 6000)
	setTimeout("clearInterval(image1FadeOut)", 7900)	
	

	newBackgroundImage = setInterval("newBackground()", 5000)	
	setTimeout("clearInterval(newBackgroundImage)", 5300)

	
	var showNextImage = "library/" + js_slideShowGallery + "/" + slideshowPics[slideCounter+1]
	
	
	
		if(slideCounter < slideshowPics.length-2) {
	
				slideCounter = (slideCounter + 2)
		}
		
		else	{
			
		slideCounter = 0
		
		}


}


function newBackground() {
	
	
	
	 document.getElementById("slideShowContainer").style.backgroundImage = "url(library/" + js_slideShowGallery + "/" + slideshowPics[slideCounter+1] + ")"

}

function prepareGallery()	{

	/* check the browser is capable of recognising the DOM objects
	   we need to implement the script - otherwise return false and allow the normal link to be executed */
	   
	if(!document.getElementsByTagName) return false;
	if(!document.getElementById) return false;
	if(!document.getElementById("thumbnails")) return false;

	
	/* get the reference to the thumbnails object and then create an array 
	   of all the <a> tags found in the array. To each tag assign a function to
	   the onclick method - which calls the showPic function. */
	   
	var gallery = document.getElementById("thumbnails");
	var links = gallery.getElementsByTagName("a");
	
	for(i = 0; i < links.length; i++) {
		
		links[i].onclick = function() {
			
			//alert(this)

			return showPic(this);
	/* If the showPic function returns true then the normal link will be followed,
	   if it returns false the normal link will be cancelled and the img src is the only
	    element on the page to be updated */
		}
		
	}
	
	
}


function showPic(whichPic)  {
	
	/* If we don't find an image with the unique id then exit the function */
	if(!document.getElementById("displayImage")) return true;	
	
	/* get the name attribute which contains the actual image filename we want to display,
	   and then get the reference to the actual image object itself */
	   
	var source = whichPic.getAttribute("name");
	var displayImage = document.getElementById("displayImage")
	
	/* finally go get the new image and change the src attribute, returning false to prevent the
	   normal link from being executed */
	displayImage.setAttribute("src", "dynamic/house_match/" + source);
	
	return false;
	
}



