//function ready methods required on every page
$(document).ready(function() {

    $('.nav').bnavigation();
    $("h1").prepend("<span></span>");

    //isValidEmailAdress by http://www.reynoldsftw.com/2009/03/live-email-validation-with-jquery/
    function isValidEmailAddress(emailAddress) {
      var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
      return pattern.test(emailAddress);
    }

    // use jquery for form errors
    $('form#commentform').submit(function() {
		$('#commentsErrorWrapper .comment-form-error').remove();
		var hasError = false;
		$('.requiredField').each(function() {
            // check if field is empty
			if(jQuery.trim($(this).val()) == '') {
				var labelText = $('#commentField_'+$(this).attr('id')).text().replace('*', '');
				$('#commentsErrorWrapper').append('<p class="comment-form-error">'+labelText+' is required </p><br class="clear" />');
				hasError = true;
			}
            //check for email error
            if(jQuery.trim($(this).attr('id')) == 'email') {
              if(!isValidEmailAddress(jQuery.trim($(this).val()))) {
                $('#commentsErrorWrapper').append('<p class="comment-form-error">Email Address is not valid</p><br class="clear" />');
                hasError = true;
              }
            }
		});
		if(hasError) {
			return false;
		}
	});

    /* gallery effects */
	
	$('.gallery-js li img').hover(
		function () {
			$(this).fadeTo(400, '0.3');
            return false;
		},
		function () {
            $(this).stop(true, true).fadeTo('fast', '1.0');
			
		}
	);

    $('.bebel-glow img').hover(
        function () {
            $(this).stop().animate({opacity: 0.6}, 300);
        },
        function () {
            $(this).stop().animate({opacity: 1.0}, 200);
        }
    );




    /* uncomment for glow effect
    $('.bebel-glow img').hover(
        function () {
            $(this).stop().animate({ borderTopColor: '#444', borderLeftColor: '#444', borderRightColor: '#444', borderBottomColor: '#444' }, 500);
        },
        function () {
            $(this).stop().animate({ borderTopColor: '#b8b8b8', borderLeftColor: '#b8b8b8', borderRightColor: '#b8b8b8', borderBottomColor: '#b8b8b8' }, 100);
        }
    );*/
        

});
