//Function for nav
function swapimage(navImagePath,image, state) {
	var imPath = navImagePath;
	if (document.images) {
		switch (state) {
			case 'preload':
				image = new Image();
				image.src = imPath + image + ".gif";
				break;
			case '_hi':
				document[image].src = imPath + image + "_hi.gif";
				break;
			case '':
				document[image].src = imPath + image + ".gif";
				break;
		}		
	}
}

//Function for non nav
function swapImage(e,dir){
	if(dir == "preload") {
		var newSrc = e.src.replace('.gif','_o.gif').replace('.jpg','_o.jpg');
		var newim = new Image;
		newim .src =newSrc;
		return true;
	} 
	if(!e) e = window.event;
	if(e.target){
		im = e.target
	} else if (e.srcElement) {
		im = e.srcElement;
	}
	if (dir == "over") {
		var newSrc = im.src.replace('.gif','_o.gif').replace('.jpg','_o.jpg');
		im.src=newSrc;
	} else { 
		var newSrc = im.src.replace('_o','');
		im.src=newSrc;
	}
}

//popup
var wind = null;

function popUp(image) {
	if(!wind || wind.closed){
		wind = window.open(image, "newWin", "scrollbars=no, width=760, height=580, menubar=no, toolbar=no, resizeable=no");
	} 
	wind.focus();
	return false;
}

function popUpImg(image) {
	if(!wind || wind.closed){
		wind = window.open(image, "newWin", "scrollbars=no, width=760, height=507, menubar=no, toolbar=no, resizeable=no");
	} 
	wind.focus();
	return false;
}


function showimage(width,height,src){
	im = document.getElementById("bigimage");
	im.width = width;
	im.height = height;
	im.src = src;
//	alert(width + "," +  height);
}


function init (rooturl){
	swapimage(rooturl,'images/nav/home_hi.gif',"preload");
	swapimage(rooturl,'images/nav/about_us_hi.gif',"preload");
	swapimage(rooturl,'images/nav/accommodation_hi.gif',"preload");
	swapimage(rooturl,'images/nav/gallery_hi.gif',"preload");
	swapimage(rooturl,'images/nav/fishing_hi.gif',"preload");
	swapimage(rooturl,'images/nav/other_attractions_hi.gif',"preload");
	swapimage(rooturl,'images/nav/webcam_hi.gif',"preload");
	swapimage(rooturl,'images/nav/home.gif',"preload");
	swapimage(rooturl,'images/nav/about_us.gif',"preload");
	swapimage(rooturl,'images/nav/accommodation.gif',"preload");
	swapimage(rooturl,'images/nav/gallery.gif',"preload");
	swapimage(rooturl,'images/nav/fishing.gif',"preload");
	swapimage(rooturl,'images/nav/other_attractions.gif',"preload");
	swapimage(rooturl,'images/nav/webcam.gif',"preload");
	swapimage(rooturl,'images/nav/reservations.gif',"preload");
	swapimage(rooturl,'images/nav/rivercam_home.gif',"preload");
}

function initrollovers(){
	var ims = document.getElementsByTagName("img");
	for(var x=0;x< ims.length;x++){
		if(ims[x].className.substr(0,9) == "swapimage"){
			if(document.addEventListener){
				ims[x].addEventListener ("mouseover", swapover, true);
				ims[x].addEventListener ("mouseout", swapout, true);
			} else if (document.attachEvent){
				ims[x].attachEvent("onmouseover", swapover, true);
				ims[x].attachEvent("onmouseout", swapout, true);
			} else {
				ims[x].onmouseover = swapover;
				ims[x].onmouseout = swapout;
			}
			swapImage(ims[x],"preload");
			// uncomment this line for debugging 
			// ims[x].style.border="1px solid red;"
		}
	}
}

function swapover(e){
	swapImage(e,"over");
}

function swapout(e){
	swapImage(e,"out");
}

addEvent(window,"load",initrollovers);

// Utility function to add an event listener
// thanks to ..........
// Author: Matt Kruse <matt@mattkruse.com>
// WWW: http://www.mattkruse.com/

function addEvent(o,e,f){
	if (o.addEventListener){ 
		o.addEventListener(e,f,true); 
		return true; 
	} else if (o.attachEvent){ 
		return o.attachEvent("on"+e,f); 
	} else { 
		return false;
	}
}

