$(function(){
                //form validation
                $('form.validate').find('.submit').click(function(){
                                //trim whitespace at start and end of strings
                                $('form.validate').find('input[type=text], textarea').each(function(){
                                                function trim(str) {
                                                                return str.replace(/^\s+|\s+$/g,"");
                                                }
                                                $(this).val(trim($(this).val()));
                                });
 
                                //check for empty fields
                                var e = 0;
                                $('form.validate').find('.req').each(function(){
                                                var val = $(this).val();
                                                if (val === "") {
                                                                e += 1;
                                                                $(this).parent().prev().css('color','red'); //might need to edit traversel to label corresponding to this input, based on structure of html on form
                                                                Cufon.replace('h4', { fontFamily: 'Gotham' }); //only needed if label is cufon'd
                                                } else {
                                                                $(this).parent().prev().css('color','gray'); //might need to edit traversel to label corresponding to this input, based on structure of html on form
                                                                Cufon.replace('h4', { fontFamily: 'Gotham' }); //only needed if label is cufon'd
                                                }
                                });
 
                                //check email syntax
                                var email = $('form.validate').find('.email').val();
                                function isEmail(str){
                                                if (str == '') return false;
                                                var re = /^[^\s()<>@,;:\/]+@\w[\w\.-]+\.[a-z]{2,}$/i
                                                return re.test(str);
                                }
                                if ( !isEmail(email) ) {
                                                $('.email').parent().prev().css('color','red'); //might need to edit traversel to label corresponding to this input, based on structure of html on form
                                                Cufon.replace('h4', { fontFamily: 'Gotham' }); //only needed if label is cufon'd
                                } else {
                                                $('.email').parent().prev().css('color','gray'); //might need to edit traversel to label corresponding to this input, based on structure of html on form
                                                Cufon.replace('h4', { fontFamily: 'Gotham' }); //only needed if label is cufon'd
                                }
 
                                //check url syntax
                                var url = $('form.validate').find('.url').val();
                                function isURL(str) {
                                                var re = /(http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
                                                return re.test(str);
                                }
                                if (url) {
                                                if ( !isURL(url) ) {
                                                                $('.url').parent().prev().css('color','red'); //might need to edit traversel to label corresponding to this input, based on structure of html on form
                                                                Cufon.replace('h4', { fontFamily: 'Gotham' }); //only needed if label is cufon'd
                                                } else {
                                                                $('.url').parent().prev().css('color','gray'); //might need to edit traversel to label corresponding to this input, based on structure of html on form
                                                                Cufon.replace('h4', { fontFamily: 'Gotham' }); //only needed if label is cufon'd
                                                }
                                }
                               
                                //if email syntax is invalid, or if any required fields are empty
                                if (!url) {
                                                if ( !isEmail(email) || e>0 ) {
                                                                $('#required').show();
                                                                return false;
                                                }
                                } else {
                                                if ( !isURL(url) || !isEmail(email) || e>0 ) {
                                                                $('#required').show();
                                                                return false;
                                                }
                                }
                });
               
                //hide all but first hero
                $('#hero').find('.heros').find('a:not(:eq(0))').hide();
 
                //hero dots
                $('#hero').find('.nav').find('a').click(function(){
                                var i = $(this).index();
                                $('#hero').find('.heros').find('a:not(:eq(' + i + '))').fadeOut(1000);
                                $('#hero').find('.heros').find('a:eq(' + i + ')').fadeIn(1000);
                                $(this).addClass('active').siblings().removeClass();
                                return false;
                });
               
                //set interval for auto rotation
                var timer = window.setInterval(slideShow, 6000);
 
                //pause interval on hero hover
                $('#hero').hover(function(){
                                timer = window.clearInterval(timer);
                }, function(){
                                timer = window.setInterval(slideShow, 6000);
                });
 
                function slideShow(){
                                var max = $('#hero').find('.heros').find('a').length,
                                                vis = $('#hero').find('.heros').find('a:visible'),
                                                dot = $('#hero').find('.nav').find('a.active')
                                vis.fadeOut(1000);
                                dot.removeClass('active');
                                //if reached end, fade in first hero
                                if (vis.next().length === 0){
                                                $('#hero').find('.heros').find('a:eq(0)').fadeIn(1000);
                                                $('#hero').find('.nav').find('a:eq(0)').addClass('active');
                                //otherwise fade in next hero
                                } else {
                                                vis.next().fadeIn(1000);
                                                dot.next().addClass('active');
                                }
                }
});

