
/*
----------------------------------------------------------
  
  Copyright 2009 Crusader Ltd
  
  Website: Three Fives media
  Author:  Stephen Last
  
----------------------------------------------------------
*/

/* Add load events
----------------------------------------------------------*/
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function () {
			oldonload();
			func();
		}
	}
}

/* Get element by id shortcut
----------------------------------------------------------*/
function $(s) {
	return document.getElementById(s);
}

/* Convert e-mail address (anti-spam)
----------------------------------------------------------*/
function convertEmail() {
	var a = document.getElementsByTagName("a");
	if (a) {
		for (var i=0; i<a.length; i++) {
			var href = a[i].getAttribute("href");
			if (href) {
				if (href.indexOf("mailto:")!=-1) {
					var new_mail = href;
					new_mail = new_mail.replace("-at-","@");
					new_mail = new_mail.replace("-dot-",".");
					new_mail = new_mail.replace("-dot-",".");
					a[i].setAttribute("href",new_mail);
					a[i].childNodes[0].nodeValue = new_mail.replace("mailto:","");
				}
			}
		}
	}
}
addLoadEvent(convertEmail);

/* Tabs
----------------------------------------------------------*/
function hideBoxes(state) {
	// Hide all content boxes
	var box = $("tab_box");
	if (box) {
		var div = box.getElementsByTagName("div");
		for (var i=0; i<div.length; i++) {
			if (state=="load" && i==0) {
				// If its page load time and the first loop, show it
				if (div[i].className=="content") { div[i].style.display="block"; }
			} else {
				// Hide all others
				if (div[i].className=="content") { div[i].style.display="none"; }
			}
		}
	}
}
function tabsOff() {
	// Tab links
	var box = $("tab_box");
	if (box) {
		var a = box.getElementsByTagName("a");
		for (var i=0; i<a.length; i++) {
			a[i].className="";
		}
	}
}
function tabs() {
	hideBoxes("load");
	var box = $("tab_box");
	if (box) {
		// Build content box array
		var div = box.getElementsByTagName("div");
		var div_count = 0;
		for (var i=0; i<div.length; i++) {
			if (div[i].className=="content") {
				div[i].setAttribute("id","content_box_"+div_count);
				div_count++;
			}
		}
		// Tab links
		var a = box.getElementsByTagName("a");
		for (var i=0; i<a.length; i++) {
			a[i].i=i;
			a[i].l=a[i];
			a[i].onclick = function() {
				// Hide boxes
				hideBoxes("clicked");
				// Show the clicked on box
				var id = $("content_box_"+this.i);
				id.style.display="block";
				// Tabs off
				tabsOff();
				// This tab on
				this.l.className="on";
				// Stop the normal link
				return false;
			}
		}
	}
}
addLoadEvent(tabs);








