function showSubMenu(e) {
	var pos = jQuery('#'+e.data.tag+'-nav').position();
	jQuery('#'+e.data.tag+'-sub-nav').css('left', (pos.left-38) + 'px');
	jQuery('#'+e.data.tag+'-sub-nav').css('top', (pos.top+36) + 'px');
	jQuery('#'+e.data.tag+'-sub-nav').show();
}

function hideSubMenu() {
	jQuery('#services-sub-nav').hide();
	jQuery('#blog-sub-nav').hide();
}

function isValidEmail(strEmail){
    validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;

    // search email text for regular exp matches
    if (strEmail.search(validRegExp) == -1)
        return false;
    else
        return true; 
}
/*
var currentTestimonial = 0;

function changeTestimonial(step) {
    jQuery('#testimonial-content').hide('normal');
    testimonials = new Array();
    testimonials[0] = '<p>"Integer commodo consequat dui. Integer mauris. Duis sollicitudin mollis mauris. Suspendisse tempus. Pellentesque est sem, auctor non, pellentesque et, vehicula nec, mauri."</p><cite>- John Doe, Troy, MI</cite>'
    testimonials[1] = '<p>"Lorem ipsum Sed congue purus. Curabitur vitae lacus. Sed id est. Nulla sed enim sed felis adipiscing imperdiet. Praesent dictum, mi at faucibus condimentum nec, mauri."</p><cite>- Peter Mirror, Birmingham, MI</cite>'
    if (step == 'next') {
        currentTestimonial = currentTestimonial + 1;
            if (currentTestimonial > (testimonials.length - 1))
                currentTestimonial = 0;
    }
    else {
        currentTestimonial = currentTestimonial - 1;
        if (currentTestimonial < 0)
            currentTestimonial = testimonials.length - 1;
    }
    jQuery('#testimonial-content').html(testimonials[currentTestimonial]);
    jQuery('#testimonial-content').show('normal');
    return false;
}
*/

jQuery(document).ready( function() {
   jQuery('#prevTestimonial').bind('click', function() {
        return changeTestimonial('previous');
   });
   jQuery('#nextTestimonial').bind('click', function() {
        return changeTestimonial('next');
   });

    jQuery('#services-nav').bind('mouseover', {tag: 'services'}, showSubMenu);
    jQuery('#blog-nav').bind('mouseover', {tag: 'blog'}, showSubMenu);
    //jQuery('#services-nav').bind('mouseout', hideSubMenu);
    jQuery('body').bind('click', hideSubMenu);
    jQuery('.no-sub').bind('mouseover', hideSubMenu);
    jQuery('#content').bind('mouseover', hideSubMenu);
    jQuery('#contactForm').bind('submit', function() {
        jQuery('#formErrors').hide();
        var errors = new Array();
        var errorCount = 0;
        if ( jQuery('#name').val() == '' ) {
            errors[errorCount] = 'name';
            errorCount = errorCount + 1;
        }
        if ( jQuery('#email').val() == '' || !isValidEmail(jQuery('#email').val()) ) {
            errors[errorCount] = 'email address';
            errorCount = errorCount + 1;
        }
        if ( jQuery('#phone').val() == '' ) {
            errors[errorCount] = 'phone number';
            errorCount = errorCount + 1;
        }
        if ( jQuery('#interestedIn').val() == '' ) {
            errors[errorCount] = 'interest';
            errorCount = errorCount + 1;
        }
        if ( jQuery('#message').val() == '' ) {
            errors[errorCount] = 'message';
            errorCount = errorCount + 1;
        }

        if (errorCount > 0) {

            var errorText = errors.join(', ');
            if ( errors.length == 2 )
                errorText = errorText.replace(',', ' and');
            else if ( errors.length > 2 ) {
                lastComma = errorText.lastIndexOf(',');
                lastPhrase = errorText.substr(lastComma, errorText.length);
                lastPhraseNew = lastPhrase.replace(',', ', and');
                errorText = errorText.replace(lastPhrase, lastPhraseNew);
            }

            jQuery('#formErrors').html('Please enter your ' + errorText + '.');
            jQuery('#formErrors').show('normal');

            return false;

        }
   });

});
