////////////////////
// GENERAL
////////////////////
// supress any and all js errors
function stopError(sMsg,sUrl,sLine) {
	//alert("Error: "+ sMsg + " : " + sLine);
	return true;
}
window.onerror = stopError;

////////////////////
// GENERAL
////////////////////
getScrollTop = function(){
	var y = 0;
	if(window.pageYOffset){
		// Netscape, Gecko
		y = window.pageYOffset;
	}else if(document.documentElement && document.documentElement.scrollTop){
		// Explorer 6 strict
		y = document.documentElement.scrollTop;
	}else if(document.body && document.body.scrollTop){
		// Explorer quirks
		y = document.body.scrollTop;
	}
	return y;
};

getMouseY = function(evt){
	var y = 0;
	if(window.event){
		y = window.event.clientY + getScrollTop();
	}else{
		y = evt.pageY;
	}
	return y;
};

function popTour(){
	xWindow.openCenter("/virtualtour.php","tourpop",375,400);
}
function popDirections(){
	xWindow.openCenterScroll("/directions.php","tourpop",385,500);
}

function noSpam(recip,domain){
	var mail = "mailto:" + recip + "@" + domain;
	window.location.href = mail;
}

function dreamHome(){
	window.open("/media/dreamhome/index.php");
}


// IMAGE GALLERY SCRIPT
function nextImage(){
	if((currentimage+1) > maximage){
		currentimage = 0;
	}else{
		currentimage = currentimage + 1;
	}
	getImage();
}

function prevImage(){
	if((currentimage-1) < 0){
		currentimage = maximage;
	}else{
		currentimage = currentimage - 1;
	}
	getImage();
}

function getImage(){
	document.gallery_image.src = "/images/galleries/"+imageprefix+"/"+imageprefix+"_"+currentimage+".jpg";
	document.getElementById("imagenumber").innerHTML = (currentimage+1) + " of " + (maximage+1) + " images";	
}


// featured project popup script
function popImage(img){
	xWindow.openCenter("/viewimage.php?img="+img,"featured",510,380);
}

// featured project popup script
function popSuperSash(){
	xWindow.openCenterScroll("/supersash.php","ss",650,490);
}
////////////////////
// XSWAP
////////////////////
xSwap = function(name){
	this.name = name;
	this.images = {};
	this.restoresrc = null;
	this.nest = "undefined";
};
xSwap.prototype.add = function(state,src){
	this.images[state] = new Image();
	this.images[state].src = src;
};
xSwap.prototype.swap = function(state){
	var img = this.getImage();
	this.restoresrc = img.src;
	img.src = this.images[state].src;
};
xSwap.prototype.restore = function(){
	if(this.restoresrc){
		this.getImage().src = this.restoresrc;
		this.restoresrc = null;
	}
};
xSwap.prototype.getImage = function(){// Private
	if(document.layers && this.nest == "undefined") this.nest = this.getLayer();
	if(document.layers && this.nest != false){
		return this.nest.document.images[this.name];
	}else{
		return document.images[this.name];
	}
};
xSwap.prototype.getLayer = function(root){// Private
	var i, k, layer, found = false;
	if(!root) root = window;
	for(i = 0; i < root.document.layers.length; i++){
		layer = root.document.layers[i];
		for(k = 0; k < layer.document.images.length; k++){
			if(layer.document.images[k].name == this.name){
				return layer;
			}
		}
		if(layer.document.layers.length) found = this.getLayer(layer);
		if(found) return found;
	}
	return false;
};
////////////////////
// NAVIGATION
////////////////////
// ROLLOVERS
home_obj = new xSwap ("home_btn");
home_obj.add ("over","/images/navigation/home_on.gif");

about_obj = new xSwap ("about_btn");
about_obj.add ("over","/images/navigation/about_on.gif");

services_obj = new xSwap ("services_btn");
services_obj.add ("over","/images/navigation/services_on.gif");

news_obj = new xSwap ("news_btn");
news_obj.add ("over","/images/navigation/news_on.gif");

showcase_obj = new xSwap ("showcase_btn");
showcase_obj.add ("over","/images/navigation/showcase_on.gif");

tools_obj = new xSwap ("tools_btn");
tools_obj.add ("over","/images/navigation/tools_on.gif");

contact_obj = new xSwap ("contact_btn");
contact_obj.add ("over","/images/navigation/contact_on.gif");

// HEADER ROLLOVERS
dh_obj = new xSwap ("dreamhome_btn");
dh_obj.add ("over","/images/header/btn_dreamhome_o.gif");

ml_obj = new xSwap ("mailinglist_btn");
ml_obj.add ("over","/images/header/btn_mailinglist_o.gif");

sm_obj = new xSwap ("sitemap_btn");
sm_obj.add ("over","/images/header/btn_sitemap_o.gif");

// SUBNAVIGATION
var nav_array = new Array();
nav_array[0] = "home";
nav_array[1] = "about";
nav_array[2] = "services";
nav_array[3] = "news";
nav_array[4] = "showcase";
nav_array[5] = "tools";
nav_array[6] = "contact";
nav_array[7] = "privacy";
nav_array[8] = "sitemap";
nav_array[9] = "error";
nav_array[10] = "credits";
nav_array[11] = "additional";

//menu methods
function hideSubNavs(itm){
	for (var i=0; i< nav_array.length; i++){
		if(itm == false){
			var sn = document.getElementById("subnav_"+nav_array[i]);
			sn.style.display="none";
		}else{
			var sn = document.getElementById("subnav_"+nav_array[i]);
			if(!sn){
				//alert(i + " : " + sn);
				return;
			}
			if(itm != nav_array[i]){
				sn.style.display="none";
			}else{
				sn.style.display="block";
			}
		}
	}
}

//menu constructor
function showSubNav(itm){
	hideSubNavs(false);
	var sn = document.getElementById("subnav_"+itm);
	sn.style.display = "block";
}

// getMouseY function in general.js
function resetSubNavs(evt){
	if(getMouseY(evt) < 100 || getMouseY(evt) > 200){
		hideSubNavs(currentsection);
	}
}


function navInit(){
	showSubNav(currentsection);
}
document.onmousemove = resetSubNavs;

////////////////////
// xscreen
////////////////////
if(typeof(xScreen) == "undefined") xScreen = {};

xScreen.getWidth = function(){
	return window.screen ? window.screen.availWidth : 0;
};
xScreen.getHeight = function(){
	return window.screen ? window.screen.availHeight : 0;
};



////////////////////
// xwindowopen
////////////////////
// Requires: xscreen.js
if(typeof(xScreen) == "undefined") alert("xScreen Required");

// ||||||||||||||||||||||||||||||||||||||||||||||||||

if(typeof(xWindow) == "undefined") xWindow = {};

xWindow.open = function(url,name,width,height,xpos,ypos,chrome,scroll,fullscreen){
	var x, y, w, h, moveX=0, moveY=0, features="";
	chrome = chrome ? "yes" : "no";
	scroll = scroll ? "yes" : "no";
	features += "toolbar="+chrome;
	features += ",menubar="+chrome;
	features += ",location="+chrome;
	features += ",status="+chrome;
	features += ",scrollbars="+scroll;
	features += ",resizable="+scroll;
	if(width) features += ",width="+width;
	if(height) features += ",height="+height;
	if(fullscreen) features += ",fullscreen=yes";
	if(xpos){
		w = xScreen.getWidth();
		width = parseInt(width);
		switch(xpos){
			case "left": x = 0; break;
			case "center": x = Math.round((w-width)/2); break;
			case "right": x = w-width; break;
			default: x = xpos;
		}
		features += ",screenX="+x+",left="+x;
		var moveX = x;
	}
	if(ypos){
		h = xScreen.getHeight();
		height = parseInt(height);
		switch(ypos){
			case "top": y = 0; break;
			case "middle": y = Math.round((h-height)/2); break;
			case "bottom": y = h-height; break;
			default: y = ypos;
		}
		features += ",screenY="+y+",top="+y;
		var moveY = y;
	}
	xWindowOpenReference = window.open(url,name,features);
	if(moveX || moveY){
		if(xWindowOpenReference != null && !xWindowOpenReference.closed){
			// position the window for browsers that don't recognize screenX, screenY
			xWindowOpenReference.moveTo(moveX,moveY);
		}
	}
};
xWindow.openScroll = function(url,name,width,height){
	this.open(url,name,width,height,false,false,false,"scroll");
};
xWindow.openCenter = function(url,name,width,height){
	this.open(url,name,width,height,"center","middle");
};
xWindow.openCenterScroll = function(url,name,width,height){
	this.open(url,name,width,height,"center","middle",false,"scroll");
};
xWindow.openFull = function(url,name){
	this.open(url,name,xScreen.getWidth(),xScreen.getHeight(),"0","0",false,false);
};
xWindow.openKiosk = function(url,name){
	this.open(url,name,xScreen.getWidth(),xScreen.getHeight(),"0","0",false,false,true);
};


