// JavaScript Document


$(function() {

	// IMAGES WITH ROLLOVERS
	$('.rollover').each(function() {
		var src = $(this).attr('src');
		if (src) {
			var over = src.replace(/(\.){1}(.{3,4})$/, "-over.$2");
			if ($(this).hasClass('active')) $(this).attr('src', over);
			else {
				var pic = new Image();
				pic.src = over;
				$(this).hover( function() {
					$(this).attr('src', over);
				}, function() {
					$(this).stop(true, false).attr('src', src);
				});
			}
		}
	});

	// IF NOT IE, AND NOT 'class="rollover"'
	// ALL OTHER IMAGES NESTED INSIDE AN '<a>' TAG WILL FADE ON ROLLOVER
	if (navigator.appName != 'Microsoft Internet Explorer') {
		$("a img").each( function() {
			if (!$(this).hasClass('rollover') && !$(this).hasClass('ignore') ) {
				$(this).parents('a').hover( function() {
					$(this).css({ opacity: 0.5 });
				}, function() {
					$(this).stop(true, false).css({ opacity: 1.0 });
				});
			}
		});
	}


	// INPUT TEXT WITH PLACEHOLDERS
	$('.placeholder').each( function() {;
		var ph = $(this).addClass('faded').val();
		$(this).bind('focus', function() { if ($(this).val() == ph) $(this).val('').removeClass('faded'); });
		$(this).bind('blur', function() { if ($(this).val() == '') $(this).val(ph).addClass('faded'); });
	});


	// SUBMIT SEARCH FORM
	onSubmit_Search = function(form) {
		var q = $('input[name="q"]', form).val();
		if (q == '' || q == 'Enter keywords') alert('Please provide a term or phrase to search for.');
	};


	// SUBMIT NEWSLETTER
	onSubmit_Newsletter = function(form) {
       	var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
		var name = $('input[name="full_name"]', form).val();
		var cont = $('input[name="email"]', form).val();

                if (name == '' || name == 'Your name') {
                    alert('Please provide your name.');
                    return false;
                } else if (cont == '' || cont == 'Your email address') {
                    alert('Please provide your email address.');
                    return false;
                } else if ( !emailPattern.test(cont) ) {
                    alert('Please provide a valid email address');
                    return false;
                }
          return true;
	};

});

