var LOADED = false;
window.onload = function () {
	
	if (document.getElementById('nav')) {
		tabs = document.getElementById('nav').getElementsByTagName('a');
		for(i=0; i<tabs.length; i++) {
			if (tabs[i]) {
				if (String(tabs[i].id).length > 0) {
					tabs[i].onmouseover = ShowSubNav;
				}
			}
		}
		if (document.getElementById(page)) {
			ShowSubNav(document.getElementById(page));
		} else {
			ShowSubNav(document.getElementById('company'));	
		}
	}
	
	if (document.getElementById('showcase')) {
		tiles = document.getElementById('showcase').getElementsByTagName('a');
		for(i=0; i<tiles.length; i++) {
			if (tiles[i]) {
				tiles[i].onmouseover = PopUpImage;
			}
		}
	}
	
	if (document.getElementById('map')) {
		LoadMap();	
	}
	
	LOADED = true;
	
	
	cProcess = new cProcess(true);
	
}

function HighLightField(e) {
	targ = GetTarget(e);
	targ.className = 'highlight';
}
function UnHighLightField(e) {
	targ = GetTarget(e);
	targ.className = '';
}

var CurrentSub;
var CurrentTab;
function ShowSubNav(e) {
	targ = GetTarget(e);
	if (targ) { } else { targ = e; }
	subNav = targ.parentNode.getElementsByTagName('ul');
	if (CurrentSub) {
		CurrentSub.className = '';
		CurrentTab.className = 'tab_off';
	}
	if (subNav[0]) {
		subNav[0].className = 'show';
		CurrentTab = targ;
		CurrentSub = subNav[0];
		targ.className = 'tab_on';
	} else if (document.getElementById(page)) {
		targ.onmouseout = function() { ShowSubNav(document.getElementById(page)); }
	}
}

//IMAGE POPUP CORE//
var image_width = 320;
var offsetfrommouse=[15,-125] //image x,y offsets from cursor position in pixels. Enter 0,0 for no offset

function truebody(){
return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function followmouse(e){
if (PopUp) {
	var xcoord=offsetfrommouse[0];
	var ycoord=offsetfrommouse[1];
	if (typeof e != "undefined"){
		xcoord+=e.pageX;
		ycoord+=e.pageY;
	}
	else if (typeof window.event !="undefined"){
		xcoord+=truebody().scrollLeft+event.clientX;
		ycoord+=truebody().scrollTop+event.clientY;
	}
	PopUp.style.left=xcoord+"px";
	PopUp.style.top=ycoord+"px";
}
}

var PopUp;
function PopUpImage(e) {
	targ = GetTarget(e);
	
	targ.onmouseout = ClosePopUp;
	document.onmousemove = followmouse;
	
	if (!PopUp) {
		PopUp = document.createElement('div');
		PopUp.className = 'PopUp';
		document.body.appendChild(PopUp);
	}
	PopUp.style.display = 'block';	
	PopUp.innerHTML = "<img src=\"/i/portfolio/"+targ.parentNode.id.substr(1)+".jpg\">";
}
function PopUpImageLarge(targ, pid) {
	if (LOADED) {		
		targ.onmouseout = ClosePopUp;
		document.getElementById('container').onmousemove = followmouse;
		
		if (!PopUp) {
			PopUp = document.createElement('div');
			PopUp.className = 'PopUp';
			document.body.appendChild(PopUp);
		}
		PopUp.style.display = 'block';	
		PopUp.innerHTML = "<img src=\"/i/portfolio/"+pid+"_large.jpg\">";
	}
}
function ClosePopUp() {
	if (PopUp) {
		PopUp.style.display = 'none';
	}
}
//IMAGE POPUP CORE//

function GetTarget(e) {
	var targ;
	if (!e) var e = window.event;
	if (e.target) targ = e.target;
	else if (e.srcElement) targ = e.srcElement;
	if (targ) {
		if (targ.nodeType == 3) // defeat Safari bug
			targ = targ.parentNode;
	}
	return targ;
}

var TempValue;
function ClearLabel(field, label) {
	TempValue = label;
	if (field.value == label) {
		field.value = '';
	}
	field.onblur = CheckLabel;
}
function CheckLabel(e) {
	field = GetTarget(e);
	if (field.value.length < 1 || field.value == 'undefined' || field.value == '') {
		field.value = TempValue;	
	}
	TempValue = '';
}

function toggleBlog(id) {
	teaser = document.getElementById('teaser_'+id);
	if (teaser) {
		if (teaser.style.display == 'block') {
			teaser.style.display = 'none';
			document.getElementById('icon_'+id).className = 'plusIcon';
		} else {
			teaser.style.display = 'block';
			document.getElementById('icon_'+id).className = 'minusIcon';
		}
	}
}
