//Whitespace Javascript
var whitespace = {
	'gat': null,
	'parse': function() {
		var login_form, login_button, header, para, text;
		
		//login form clicks
		login_form = $("login_form");
		
		if (login_form !== null) {
			login_button = login_form.getElement("input[type='submit']");
			
			if (login_button !== null) {
				whitespace.gat.register(login_button, WSGat.Types.event, {
					'category': 'Members-login',
					'action': 'Login'
				});
			}
		}
		
		//search results
		header = $$("h1.genericheading");
		
		if (header.length > 0) {
			header = header[0];
			para = header.getNext("p");
			text = para.textContent || para.innerText;
			
			if (para !== null && text.match(/searched\s+the\s+website\s+for/i)) {
				text = para.getChildren("strong")
				
				if (text.length > 0) {
					try {
						text = (text[0].textContent || text[0].innerText);
						whitespace.gat.track_event("Search", text);
					} catch (e) { }
				}
			}
		}
	}
};

window.addEvent('domready', function() {
	whitespace.gat = new WSGat.Create({
		'async': false
	});
	
	whitespace.parse();
});
