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

//xWindow.openCenter("/virtualtour.php","tourpop",375,400);
//xWindow.openCenterScroll("/supersash.php","ss",650,490);


////////////////////
// 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 noSpam(recip,domain){
	var mail = "mailto:" + recip + "@" + domain;
	window.location.href = mail;
}



////////////////////
// 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
hom_obj = new xSwap ("hom_btn");
hom_obj.add ("over","/images/navigation/nav_hom_o.gif");

arch_obj = new xSwap ("arch_btn");
arch_obj.add ("over","/images/navigation/nav_arch_o.gif");

too_obj = new xSwap ("too_btn");
too_obj.add ("over","/images/navigation/nav_too_o.gif");

con_obj = new xSwap ("con_btn");
con_obj.add ("over","/images/navigation/nav_con_o.gif");

sho_obj = new xSwap ("sho_btn");
sho_obj.add ("over","/images/navigation/nav_sho_o.gif");

new_obj = new xSwap ("new_btn");
new_obj.add ("over","/images/navigation/nav_new_o.gif");

ctc_obj = new xSwap ("ctc_btn");
ctc_obj.add ("over","/images/navigation/nav_ctc_o.gif");

prod_obj = new xSwap ("prod_btn");
prod_obj.add ("over","/images/navigation/nav_prod_o.gif");

// SUBNAVIGATION
var nav_array = new Array();
nav_array[0] = "hom";
nav_array[1] = "arch";
nav_array[2] = "too";
nav_array[3] = "con";
nav_array[4] = "sho";
nav_array[5] = "new";
nav_array[6] = "ctc";
nav_array[7] = "oth";
nav_array[8] = "prod";


//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){
				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) < 80 || 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);
};




////////////////////
// XBROWSER
////////////////////
xBrowser = function(){
	this.agent = navigator.userAgent.toLowerCase();
	// Platform
	this.mac = this.agent.indexOf("mac")!=-1;
	this.win = this.agent.indexOf("win")!=-1;
	this.win32 = this.win && this.agent.indexOf("16bit")==-1;
	this.unix = this.agent.indexOf("x11")!=-1 || this.agent.indexOf("linux")!=-1;
	// Browser
	this.w3c = document.getElementById ?true:false;
	this.iex = document.all ?true:false;
	this.ie4 = this.iex && !this.w3c;
	this.ie5up = this.iex && this.w3c;
	this.ns4 = document.layers ?true:false;
	this.ns6up = !this.iex && !this.ns4 && this.w3c;
	this.nsx = this.ns4 || this.ns6up;
};
xBrowser.prototype.dump = function(){
	var html = "";
	for(i in this) if(typeof(this[i]) != "function") html += i+" = "+this[i]+"<br>";
	document.write(html);
};
xBrowser = new xBrowser();



////////////////////
// XFLASH
////////////////////

// Requires: xbrowser.js
if(typeof(xBrowser) == "undefined") alert("xBrowser Required");

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

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

xFlash.currentVersion = 8;// This variable will need to be updated as new Flash versions are released.
xFlash.versionInstalled = 0;
xFlash.getVersion = function(){
	if(navigator.plugins != null && navigator.plugins.length > 0){
		var plugin = navigator.plugins["Shockwave Flash"];
		if(typeof plugin == "object"){
			for(i=3; i<= this.currentVersion; i++){
				if(plugin.description.indexOf(i+".") != -1){
					this.versionInstalled = i;
				}
			}
		}else if(navigator.plugins["Shockwave Flash 2.0"]){
			this.versionInstalled = 2;
		}
	}else if(xBrowser.iex && xBrowser.win32){
		document.write('<'+'script language="VBScript"'+'> \n');
			document.write('set xFlashObj = Nothing \n');
			document.write('on error resume next \n');
			document.write('For i = '+this.currentVersion+' to 3 step -1 \n');
				document.write('set xFlashObj = CreateObject("ShockwaveFlash.ShockwaveFlash." & i) \n');
				document.write('If (Not(xFlashObj is Nothing)) Then \n');
					document.write('xFlash.versionInstalled = i \n');
					document.write('Exit For \n');
				document.write('End If \n');
			document.write('Next \n');
		document.write('<'+'\/script'+'> \n');

	}else if(xBrowser.agent.indexOf("webtv/2.5") != -1){
		this.versionInstalled = 3;
	}else if(xBrowser.agent.indexOf("webtv") != -1){
		this.versionInstalled = 2;
	}else{
		this.versionInstalled = -1;
	}
};
xFlash.getVersion();

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

xFlash.redirect = function(required, upgradeFlash, noFlash, failedCheck){
	if(this.versionInstalled < required  && location.search.indexOf("skipcheck=true") == -1){
		var url;
		if(this.versionInstalled == -1){
			if(!failedCheck) failedCheck = upgradeFlash;
			url = failedCheck;
		}else if(this.versionInstalled == 0){
			if(!noFlash) noFlash = upgradeFlash;
			url = noFlash;
		}else{
			url = upgradeFlash;
		}
		window.location.href = url;
	}
};

xFlash.replace = function(required, name, width, height, bgcolor, quality, menu, noFlash, flashVars){
	if(this.versionInstalled >= required){
		flashVars = flashVars!=null ? flashVars : "";
		var swf = '';
		swf += '<object';
		swf += ' width="'+width+'"';
		swf += ' height="'+height+'"';
		swf += ' classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';
		swf += ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+required+',0,0,0">';
		swf += '<param name="movie" value="'+name+'?'+flashVars+'">';
		swf += '<param name="FlashVars" value="'+flashVars+'">';
		swf += '<param name="bgcolor" value="'+bgcolor+'">';
		swf += '<param name="quality" value="'+quality+'">';
		swf += '<param name="menu" value="'+menu+'">';
			swf += '<embed src="'+name+'?'+flashVars+'"';
			swf += ' FlashVars="'+flashVars+'"';
			swf += ' width="'+width+'"';
			swf += ' height="'+height+'"';
			swf += ' bgcolor="'+bgcolor+'"';
			swf += ' quality="'+quality+'"';
			swf += ' menu="'+menu+'"';
			swf += ' type="application/x-shockwave-flash"';
			swf += ' pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">';
			swf += '<\/embed>';
		swf += '<\/object>';
		document.write(swf);
	}else{
		document.write(noFlash);
	}
};


////////////////////
// Search
////////////////////
function doSearch(){
	var st = document.getElementById("sterm").value;
	document.location = "http://www.google.com/search?rls=en&ie=UTF-8&oe=UTF-8&q="+st+"+site:www.classicconservatories.com";
}




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

////////////////////
// VIRTUAL TOURS
////////////////////
function popTour(mov){
	xWindow.openCenter("/virtual-tours_pop.php?mov="+mov,"vtour",700,500);
}

////////////////////
// FEATURED PROJECT
////////////////////
function popFeatured(img){
	xWindow.openCenter("/image.php?fn="+img,"featureimg",500,380);
	xWindowOpenReference.focus();
}