var myrules = {
/*	'.imgbtn' : function(element){
		element.onmousedown = function(){
			this.src = "http://muledesign.com/images/" + this.id + "-on.gif";
			alert('got here!');
		}
		element.onmouseup = function(){
			this.src = "http://muledesign.com/images/" + this.id + ".gif";
		}
	},
	'.personname' : function(element) {
		element.onmouseover = function() {
			var person = this.parentNode.id;
			var popup = document.getElementById(person + '-pop');
			var others = getElementsByClass('personinfo',document,'*');
			var x
			for (x in others) {
				if (others[x].style.display == 'block') {
					others[x].style.display = 'none';
				}
			}
			if(popup.style.display != 'block') {
				popup.style.display = 'block';
			}
		}
	},
	'.personinfo' : function(element) {
		element.onclick = function() {
			this.style.display = 'none';
		}
	},
	'#directions-content .toggle' : function(element) {
		element.onclick = function() {
			var m = document.getElementById(this.id + "-link");
			var d = document.getElementById(this.id + "-dir");
			if (m.style.visibility == 'hidden'){
				this.style.fontWeight = 'bold';
				this.style.textDecoration = 'none';
				this.style.color = '#805a17';
				this.style.backgroundImage = 'url(/images/v3-expand-down.gif)';
				m.style.visibility = 'visible';
				d.style.display = 'block';
			} else {
				this.style.fontWeight = 'normal';
				this.style.textDecoration = 'underline';
				this.style.color = '#c90';
				this.style.backgroundImage = 'url(/images/v3-expand-up.gif)';
				m.style.visibility = 'hidden';
				d.style.display = 'none';
			}
		}
	},*/
	'#directions' : function(element) {
		element.onclick = function() {
			document.getElementById("directions-content").style.display = 'block';
			this.className = "tab-toggle active";
			document.getElementById("photos-content").style.display = 'none';
			document.getElementById("photos").className = "tab-toggle inactive";
			return false;
		}
	},
	'#photos' : function(element) {
		element.onclick = function() {
			document.getElementById("photos-content").style.display = 'block';
			this.className = "tab-toggle active";
			document.getElementById("directions-content").style.display = 'none';
			document.getElementById("directions").className = "tab-toggle inactive";
			return false;
		}
	}
};
Behaviour.register(myrules);

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

function closePersonPop(popup) {
	if (document.getElementById(popup).style.display == 'block') {
		document.getElementById(popup).style.display = 'none';
	}
}

function altComments() {
	var comments = getElementsByClass('comment',document,'div');
	for(i = 0; i < comments.length; i++){          
	//alternate colors
		if(i % 2 == 0) {
			comments[i].className = "comment comment-alt";
		} else {
			comments[i].className = "comment";
		}      
	}
}

function addLoadEvent(func) {
	var oldonload = window.onload;
	if(typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

function insertAfter(newElement,targetElement) {
  var parent = targetElement.parentNode;
  if (parent.lastChild == targetElement) {
    parent.appendChild(newElement);
  } else {
    parent.insertBefore(newElement,targetElement.nextSibling);
  }
}

function showHide(id) {
	var c = document.getElementById(id);
	if(c.style.display != 'block'){
		c.style.display = 'block';
	} else {
		c.style.display = 'none';
	}
	return false;
}

function changeProfile(direction) {
	var direction = direction;
	var allHidden = getElementsByClass('slide-hidden',document,'*');
	var hideThis = getElementsByClass('slide-visible',document,'*');
	hideThis[0].className = "slide-hidden";
	var totalSlides = hideThis.length + allHidden.length;
	if (direction == "prev") { 
		var showThis = Number(hideThis[0].id.substring(5));
		if (showThis == 1) {
			showThis = totalSlides;
		} else {
			showThis = showThis - 1;
		}
	} else if (direction == "next") { 
		var showThis = Number(hideThis[0].id.substring(5));
		if (showThis == totalSlides) {
			showThis = 1;
		} else {
			showThis = showThis + 1;
		}
	}
	showThisStr = "slide" + String(showThis);
	document.getElementById(showThisStr).className = "slide-visible";
	document.getElementById("currentSlide").innerHTML = showThis;
//	alert(showThis);
//	document.getElementById("current-slide").innerHTML = showThis;
//	document.getElementById("total-slides").innerHTML = totalSlides;
}

function validateContactForm() {
	var f = document.forms["contactform"];
	var e = document.forms["contactform"]["email"];
	var em = document.getElementById('emailerror');
	var m = document.forms["contactform"]["message"];
	var mm = document.getElementById('messageerror');
	if (e.value == "") {
		e.className+=e.className?' error':'error';
		em.innerHTML = "Please enter an e-mail address.";
		var oops = true;
	}
	if (m.value == "") {
		m.className+=m.className?' error':'error';
		mm.innerHTML = "Please enter a message.";
		var oops = true;
	}
	if (oops) {
		return false;
	} else {
		return true;
	}
}

function showSizeChart() {
	var c = document.getElementById("size-chart");
	var a = document.getElementById("size-chart-arrow");
	if(c.style.display != 'block'){
		c.style.display = 'block';
		a.style.display = 'block';
	} else {
		c.style.display = 'none';
		a.style.display = 'none';
	}
}
