$(document).ready(function() {
	$('button, a.button, input[type=submit], input[type=button], input[type=reset]').bind('mouseover mouseout mousedown mouseup blur', function(event) {
		switch (event.type) {
			case 'mouseover':
				$(this).addClass('button-mouseover');
				break;
			case 'mouseout':
				$(this).removeClass('button-mouseover');
				break;
			case 'mousedown':
				$(this).addClass('button-mousedown');
				break;
			case 'mouseup':
				$(this).removeClass('button-mousedown');
				break;
			case 'blur':
				$(this).removeClass('button-mousedown');
				break;
		}

	}); 	
	var active_color = '#000'; // Colour of user provided text
	var inactive_color = '#999'; // Colour of default text
	$("#header-search-text-box").css("color", inactive_color);
	$("#newsletter-email-text-box").css("color", inactive_color);
	var default_values = new Array();
	$("input.text-box").focus(function() {
		if (!default_values[this.id]) {
			default_values[this.id] = this.value;
		}
		if (this.value == default_values[this.id]) {
			this.value = '';
			this.style.color = active_color;
		}
		$(this).blur(function() {
			if (this.value == '') {
				this.style.color = inactive_color;
				this.value = default_values[this.id];
			}
		});
	});
});	

function urldecode( str ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Philip Peterson
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: AJ
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // %          note: info on what encoding functions to use from: http://xkr.us/articles/javascript/encode-compare/
    // *     example 1: urldecode('Kevin+van+Zonneveld%21');
    // *     returns 1: 'Kevin van Zonneveld!'
    // *     example 2: urldecode('http%3A%2F%2Fkevin.vanzonneveld.net%2F');
    // *     returns 2: 'http://kevin.vanzonneveld.net/'
    // *     example 3: urldecode('http%3A%2F%2Fwww.google.nl%2Fsearch%3Fq%3Dphp.js%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dcom.ubuntu%3Aen-US%3Aunofficial%26client%3Dfirefox-a');
    // *     returns 3: 'http://www.google.nl/search?q=php.js&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:unofficial&client=firefox-a'
   
    var histogram = {}, histogram_r = {}, code = 0, str_tmp = [];
    var ret = str.toString();
   
    var replacer = function(search, replace, str) {
        var tmp_arr = [];
        tmp_arr = str.split(search);
        return tmp_arr.join(replace);
    };
   
    // The histogram is identical to the one in urlencode.
    histogram['!']   = '%21';
    histogram['%20'] = '+';
   
    for (replace in histogram) {
        search = histogram[replace]; // Switch order when decoding
        ret = replacer(search, replace, ret) // Custom replace. No regexing   
    }
   
    // End with decodeURIComponent, which most resembles PHP's encoding functions
    ret = decodeURIComponent(ret);
 
    return ret;
}
