// JavaScript Document
/*
 * Login helper
 * http://etraction.co.nz/
 *
 * Copyright (c) 2009 Mark Haussmann
 * Dual licensed under the MIT and GPL licenses.
 *
 * Date: 2009-09-19 17:34:21 -0500 (Thu, 19 Sep 2009)
 */
$(document).ready(function () {
	(function newsletterLabel() {
		var email = document.getElementById('CLEmailAddress');
		email.onblur = function () { 
			if (this.value == '') { this.value = 'ENTER EMAIL ADDRESS HERE'; }
		}
		email.onfocus = function () {
			if (this.value == 'ENTER EMAIL ADDRESS HERE') { this.value = ''; }
		}
	}) ();
});

$(document).ready(function () {
							
	var _host = document.location.host;
	var _url = document.location.href.substring(document.location.href.indexOf(_host)+_host.length).toLowerCase();
	var _anchor;
	var _parent;
	var _anchors = $(document).find('.decorate ul a');
	
	if (_url.indexOf('?') != -1) _url = _url.substring(0,_url.indexOf('?')); // must remove query variables
	
	$(".decorate ul").find("li:first-child").addClass('first');
	$(".decorate ul").find("li:last-child").addClass('last');

	for (var i=0;i<_anchors.length;i++) {
		_anchor = _anchors[i].href.substring(document.location.href.indexOf(_host)+_host.length).toLowerCase();
		_selected = (_anchor == _url);
		_parent = $(_anchors[i]);
		
		while (_parent) {
			_parent = _parent.parent();
			
			if (_parent.hasClass('decorate')) break;
			if (!_parent.is('li')) continue;
			
			if (_parent.children('ul').size() > 0) _parent.addClass('parent');
	
			_textClass = _parent.children('a').text().replace(/[ &]/g, "").toLowerCase();
			if (!_parent.hasClass(_textClass)) _parent.addClass(_textClass);
			
			if (_selected) {
				_parent.addClass('selected');
				_parent.addClass(_textClass + '-selected');
			}
			_parent.hover(
				function () { $(this).addClass('hover')},
				function () { $(this).removeClass('hover')}
			);
		}
		
	}

});
