window.onload = init; 

function init() {
	// SET HEIGHT OF PANELS
	var linksPanel = document.getElementById('linksPanel'); 
	var linksPanelHeight = linksPanel.offsetHeight; 

	if (document.getElementById('picsPanel')) {
		var content = document.getElementById('content'); 
		var picsPanel = document.getElementById('picsPanel'); 
		var contentHeight = content.offsetHeight; 
	
		picsPanel.style.height = linksPanelHeight - contentHeight - 11 + 'px'; 
	} else if (document.getElementById('projectMenu')) {						// project pages
		var projectMenu = document.getElementById('projectMenu'); 
		var content_left = document.getElementById('content_left'); 
		var picsPanel_right = document.getElementById('picsPanel_right'); 
		var projectMenuHeight = projectMenu.offsetHeight; 

		picsPanel_right.style.height = content_left.style.height = linksPanelHeight - projectMenuHeight - 11 -14 + 'px'; 
	} else {											// contact page
		var content_left = document.getElementById('content_left'); 
		var picsPanel_right = document.getElementById('picsPanel_right'); 

		picsPanel_right.style.height = content_left.style.height = linksPanelHeight - 14 + 'px'; 
	}

	// SET POSITION OF PANEL BOTTOM EDGES (REQUIRED FOR IE6)
	var imgArray = document.getElementsByTagName('img'); 

	for (var i = 0; i < imgArray.length; i++) {
		if (imgArray[i].className == 'edge_bottom') {
			imgArray[i].style.bottom = 0; 
		}
	}

	// SET HEIGHT OF IMAGES
	var divArray = document.getElementsByTagName('div'); 

	for (var i = 0; i < divArray.length; i++) {
		if (divArray[i].className == 'picCol' || divArray[i].className == 'picCol_1-2' || divArray[i].className == 'picCol_1-3') {
			if (document.getElementById('projectMenu')) {
				divArray[i].style.height = linksPanelHeight - projectMenuHeight - 10 + 'px'; 
			} else {
				divArray[i].style.height = linksPanelHeight - contentHeight - 10 + 'px'; 
			}
		} else if (divArray[i].className == 'picCol_1-2-2') {
			divArray[i].style.height = (linksPanelHeight - 10) / 2 + 'px'; 
		}
	}

	// ADD EVENT LISTENERS FOR ARROWS
	if (document.getElementById('arrow_left')) { 
		var arrow_left = document.getElementById('arrow_left'); 

		if (!document.addEventListener) {	// FOR IE
			arrow_left.onclick = move_left; 
		} else {
			arrow_left.addEventListener(
				'click', 
				move_left, 
				false
			)
		}
	}

	if (document.getElementById('arrow_right')) {
		var arrow_right = document.getElementById('arrow_right'); 

		if (!document.addEventListener) {	// FOR IE
			arrow_right.onclick = move_right; 
		} else {
			arrow_right.addEventListener(
				'click', 
				move_right, 
				false
			)
		}
	}

	// ADD EVENT LISTENERS FOR PROJECT MENU PICS
	var imgArray = document.getElementsByTagName('img'); 

	for (var i = 0; i < imgArray.length; i++) {
		if (imgArray[i].className == 'thumbBox_img') {
			if (!document.addEventListener) {	// FOR IE
				imgArray[i].onclick = displayImage; 
			} else {
				imgArray[i].addEventListener('click', displayImage, false); 
			}
		}
	}

	/* PRELOAD PROJECT MENU PICS
	* taken out for now because the images are many and varied
	* if this is a problem will need to be reinstated in some form
	**
	if (document.getElementById('projectMenu')) {
		new Image().src = 'graphics/projectMenu_0_0.jpg'; 
		new Image().src = 'graphics/projectMenu_0_1.jpg'; 
		new Image().src = 'graphics/projectMenu_0_2.jpg'; 
		new Image().src = 'graphics/projectMenu_0_3.jpg'; 
		new Image().src = 'graphics/projectMenu_0_4.jpg'; 
		new Image().src = 'graphics/projectMenu_0_5.jpg'; 
		new Image().src = 'graphics/projectMenu_0_6.jpg'; 
		new Image().src = 'graphics/projectMenu_0_7.jpg'; 
	}
	*/
	
	// ADD EVENT LISTENERS FOR MOUSEOVERS
	if (document.getElementById('bn_contact')) {
		var bn_contact = document.getElementById('bn_contact'); 
	}
	
	if (document.getElementById('arrow_left')) {
		var arrow_left = document.getElementById('arrow_left'); 
		var arrow_right = document.getElementById('arrow_right'); 
	}

	if (!document.addEventListener) {	// FOR IE
		if (document.getElementById('bn_contact')) {
			bn_contact.onmouseover = mouseover; 
		}
		
		if (document.getElementById('arrow_left')) {
			arrow_left.onmouseover = mouseover; 
			arrow_right.onmouseover = mouseover; 
		}
	} else {
		if (document.getElementById('bn_contact')) {
			bn_contact.addEventListener('mouseover', mouseover, false); 
		}
		
		if (document.getElementById('arrow_left')) {
			arrow_left.addEventListener('mouseover', mouseover, false); 
			arrow_right.addEventListener('mouseover', mouseover, false); 
		}
	}

	if (!document.addEventListener) {	// FOR IE
		if (document.getElementById('bn_contact')) {
			bn_contact.onmouseout = mouseout; 
		}
		
		if (document.getElementById('arrow_left')) {
			arrow_left.onmouseout = mouseout; 
			arrow_right.onmouseout = mouseout; 
		}
	} else {
		if (document.getElementById('bn_contact')) {
			bn_contact.addEventListener('mouseout', mouseout, false); 
		}
		
		if (document.getElementById('arrow_left')) {
			arrow_left.addEventListener('mouseout', mouseout, false); 
			arrow_right.addEventListener('mouseout', mouseout, false); 
		}
	}

	// PRELOAD MOUSEOVER PICS
	if (document.getElementById('bn_contact')) {
		new Image().src = 'graphics/bn_submit_mouseover.gif'; 
	}


	if (document.getElementById('arrow_left')) {
		new Image().src = 'graphics/arrow_left_mouseover.gif'; 
		new Image().src = 'graphics/arrow_right_mouseover.gif'; 
	}
	
	// EXTERIOR LINKS
	var aArray = document.getElementsByTagName('a'); 
	
	for (var i = 0; i < aArray.length; i++) {
		if (aArray[i].className == 'exteriorLink') {
			aArray[i].onclick = function() {
				window.open(this.getAttribute('href')); 
				return false;
			}
		}
	}
}

function move_left() {
	var divArray = document.getElementsByTagName('div'); 

	for (var i = 0; i < divArray.length; i++) {
		if (divArray[i].className == 'thumbBox') {
			var pos = divArray[i].offsetLeft; 
			divArray[i].style.left = pos + 100 + 'px'; 
		}
	}
}

function move_right() {
	var divArray = document.getElementsByTagName('div'); 

	for (var i = 0; i < divArray.length; i++) {
		if (divArray[i].className == 'thumbBox') {
			var pos = divArray[i].offsetLeft; 
			divArray[i].style.left = pos - 100 + 'px'; 
		}
	}
}

function displayImage() {
	var imgSrc = this.src; 

	imgSrcArray = imgSrc.split('?'); 
	var queryString = imgSrcArray[1]; 

	queryStringArray = queryString.split('&'); 
	var imageDir = queryStringArray[0].substring(9); 
	var image = queryStringArray[1].substring(6); 

	var projectMenuPic = document.getElementById('projectMenuPic'); 

	projectMenuPic.style.background = 'url(graphics/projects/' + imageDir + '/' + image + ')'; 
	projectMenuPic.style.backgroundPosition = 'center'; 
	projectMenuPic.style.backgroundRepeat = 'no-repeat'; 
}

function rollover() {
	alert('rollover'); 
}

function mouseover() {
	var id = this.getAttribute('id'); 

	if (id == 'bn_contact') {
		this.src = 'graphics/bn_submit_mouseover.gif'; 
	} else if (id == 'arrow_left') {
		this.src = 'graphics/projectMenu_arrow_left_mouseover.gif'; 
	} else if (id == 'arrow_right') {
		this.src = 'graphics/projectMenu_arrow_right_mouseover.gif'; 
	}
}

function mouseout() {
	var id = this.getAttribute('id'); 

	if (id == 'bn_contact') {
		this.src = 'graphics/bn_submit.gif'; 
	} else if (id == 'arrow_left') {
		this.src = 'graphics/projectMenu_arrow_left.gif'; 
	} else if (id == 'arrow_right') {
		this.src = 'graphics/projectMenu_arrow_right.gif'; 
	}
}

// FONT REPLACEMENT
var glypha = { src: 'glypha.swf' };

sIFR.activate(glypha);

sIFR.replace(glypha, {
  selector: 'h1, .project h2',
  css: '.sIFR-root { background-color: #8c8272; color: #FFFFFF; }', 
  transparent: true
});
