var animateImage = true;

// Sets the actions for elements base on specific class names
function setActions(mainDivId) {
	
	// Get known elements with specific class names
	var actionElements = $(mainDivId).getElementsBySelector(
		'a.omToggle',
		'a.omRollover',
		'a.omNewWindow'
	);
	
	// If no elements are found, return
	if (!actionElements) {
		return;
	}
	
	// Traverse through the elements
	for (var a = 0; a < actionElements.length; a++) {
		
		// Switch through the types of elements
		switch (actionElements[a].nodeName.toLowerCase()) {
			case 'a':
				// Rollover events
				if (actionElements[a].hasClassName('omRollover')) {
					actionElements[a].onmouseover = function (evt) { omRollover(evt, this); };
					actionElements[a].onmouseout = function (evt) { omRollover(evt, this); };
				}
				// Toggle events
				if (actionElements[a].hasClassName('omToggle')) {
					actionElements[a].onclick = function () { omToggle(this); return false; };
				}
				// New Window events
				if (actionElements[a].hasClassName('omNewWindow')) {
					actionElements[a].onclick = function () { omNewWindow(this); return false; };
				}
				break;
		}
		
	}
	
}

// Produces a sprite base omRollover effect
function omRollover(evt, linkObj) {
	if (!evt) {
		evt = window.event;
	}
	if (evt.type == 'mouseover') {
		bgPos = '0 -' + $(linkObj).getHeight() + 'px';
		$(linkObj).setStyle({ backgroundPosition: bgPos });
	} else {
		$(linkObj).setStyle({ backgroundPosition: '0 0' });
	}
}

// Toggles a div base on the link id, the toggle link should have the same id div suffixed with _Toggle
function omToggle(link) {
	
	// Get the id of the related div
	relatedDiv = link.id.replace('_Toggle', '');
	// Toggle the div
	new Effect.toggle(relatedDiv, 'blind',{duration: 0.5});
	
	if (link.style.backgroundImage.match('_On')) {
		link.style.backgroundImage = link.style.backgroundImage.replace('_On', '_Off');
	} else {
		link.style.backgroundImage = link.style.backgroundImage.replace('_Off', '_On');
	}
	
}

// Opens a link in a new window
function omNewWindow(link) {
	if (link.rel == 'contact') {
		window.open(link.href, 'name', 'width=620,height=500,location=false,menubar=false');
	} else {
		window.open(link.href);
	}
}

// Resizes the current window
function resizeWindow(width, height) {
	window.resizeTo(width, height);
	var ix = false;
	var iy = false;
	var ex = false;
	var ey = false;
	if (window.innerWidth && window.innerHeight) {
		ix = window.innerWidth;
		iy = window.innerHeight;
		ex = window.outerWidth;
		ey = window.outerHeight;
	} else if (document.documentElement && document.documentElement.clientWidth && document.documentElement.clientHeight) {
		ix = document.documentElement.clientWidth;
		iy = document.documentElement.clientHeight;
		ex = width;
		ey = height;
	} else if (document.body) {
		ix = document.body.clientWidth;
		iy = document.body.clientHeight;
		ex = width;
		ey = height;
	}
	if (ix && iy && ex && ey) {
		var dx = (ex - ix);
		var dy = (ey - iy);
		var rx = (width + dx);
		var ry = (height + dy);
		window.resizeTo(rx, ry);
	}
}