// JavaScript Document

jQuery(function($) {

	$('.lightbox').lightBox();

	$('.opennewwindow').attr('target', '_blank');

	//CLEAR ON FOCUS
	$('.clearOnFocus').focus(function() { if ($(this).val() == $(this).siblings('#' + $(this).attr('id') + '-default').val()) { $(this).val(''); } $(this).addClass('hasfocus'); $(this).addClass('hascontent'); });
	$('.clearOnFocus').blur(function()  { if ($(this).val() == '') { $(this).val($(this).siblings('#' + $(this).attr('id') + '-default').val()); $(this).removeClass('hascontent'); } $(this).removeClass('hasfocus'); });
	$('.clearOnFocus').each(function() { if ($(this).val() != $(this).siblings('#' + $(this).attr('id') + '-default').val()) { $(this).addClass('hascontent'); } });
	//END CLEAR ON FOCUS

	//Validate newsletter form (basic validation!)
	if ($('.newsletter_form').length > 0) {

		$('.newsletter_form').submit(function() {

			var returnVal = true;
			var firstOffender = false;

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

				if (firstOffender == false) {

					if ($(this).val() == '' || $(this).val() == $(this).siblings('#' + $(this).attr('id') + '-default').val()) {
						returnVal = false;
						firstOffender = $(this);
					} else if ($(this).hasClass('email-input')) {
						if ($(this).val().indexOf('@') < 0 || $(this).val().lastIndexOf('.') < $(this).val().indexOf('@')) {
							returnVal = false;
							firstOffender = $(this);
						}
					}

				}

			});

			firstOffender.focus();
			return returnVal;

		});

	}
	//End Validate newsletter form

});
