//////////////////////
// Copyright 2007 (C) Our Community Pty. Ltd. All Rights Reserved.
//
// Provides image rollover and hide/show functionality 
//
// Author: Oliver Hutchison, Charles Gutjahr
//
for (var i = 0; i < document.images.length; i++) { 
   var image = document.images[i]   
   if (image.className == 'rollover') {
        applyRolloverHandlers(image)
   }
}

function applyRolloverHandlers(image) {
    var normalImage = createImage(image.src)
    var rolloverImage = createImage(image.src.replace(/(.+)(\....)/, '$1_over$2'))
    image.onmouseover = function() {
        image.src = rolloverImage.src
    }
    image.onmouseout = function() {
        image.src = normalImage.src
    }
}
function createImage(src) {
    var image =  new Image()
    image.src = src
    return image
}

/* Add a class to a string */
String.prototype.addClass = function(theClass)
{
	if (this != "")
	{
		if (!this.classExists(theClass))
		{
			return this + " " + theClass;
		}
	}
	else
	{
		return theClass;
	}
	
	return this;
}

/* Check if a class exists in a string */
String.prototype.classExists = function(theClass)
{
	var regString = "(^| )" + theClass + "\W*";
	var regExpression = new RegExp(regString);
	
	if (regExpression.test(this))
	{
		return true;
	}
	
	return false;
}


/* Remove a class from a string */
String.prototype.removeClass = function(theClass)
{
	var regString = "(^| )" + theClass + "\W*";
	var regExpression = new RegExp(regString);
	
	return this.replace(regExpression, "");
}

function hideShow(node)
{
	var heading = node;
	var div = heading.nextSibling;
	
	while (div.nodeName.toLowerCase() != "div")
	{
		div = div.nextSibling;
	}
	
	if (heading.className.classExists("hidden"))
	{
		heading.title = "Click to hide your search criteria"
		heading.className = heading.className.removeClass("hidden");
		div.className = div.className.removeClass("hidden");
	}
	else
	{
		heading.title = "Click to show your search criteria"
		heading.className = heading.className.addClass("hidden");
		div.className = div.className.addClass("hidden");
	}
	
	return true;
}