// JavaScript Document
$.fn.reverse = [].reverse;

$(document).ready(function() {

	var agent = navigator.userAgent.toLowerCase(); 

	     if ($.browser.msie)         { $('body').addClass('ie ie'+$.browser.version.substr(0,1)); }
	else if (agent.match(/chrome/i)) { $('body').addClass('chrome'); }
	else if (agent.match(/safari/i)) { $('body').addClass('safari'); }

	if (agent.match(/iphone/i)) { $('body').addClass('iphone'); }

	$('#topMenu ul li').hover(function() { $(this).addClass('hover'); }, function() { $(this).removeClass('hover'); });

	$(':has(li)').each(function() {

		$(this).children('li').first().addClass('first');
		$(this).children('li').last().addClass('last');

	});

	$('.hoverImage').hover(
		function(e) { $(this).find('.default').first().css('display', 'none'); $(this).find('.hover').first().css('display', 'block'); },
		function(e) { $(this).find('.hover').first().css('display', 'none'); $(this).find('.default').first().css('display', 'block'); }
	);

	$('.clearOnFocus').focus(function() { if ($(this).val() == $(this).attr('alt')) { $(this).val(''); } });
	$('.clearOnFocus').blur(function()  { if ($(this).val() == '') { $(this).val($(this).attr('alt')); } });

	$('table tbody').each(function() { $(this).children('tr:odd').addClass('even'); $(this).children('tr:even').addClass('odd'); });

	//Validate newsletter form (basic validation!)
	$('#subForm').submit(function() {

		var returnVal = true;
		var firstOffender = false;

		$(this).find('input:text').each(function() {

			if ($(this).val() == '' || $(this).val() == $(this).attr('alt')) {
				returnVal = false;
				firstOffender = (firstOffender == false ? $(this) : firstOffender);
			}

		});

		firstOffender.focus();
		return returnVal;

	});

});

