$(document).ready(function (){
    
    // jquery.cycle SLIDESHOW
    $('#slideshow') 
        .cycle({ 
            fx: 'fade',
            speed:  300,
            timeout: 4000,
            prev: '#prev_slide',
            next: '#next_slide, #call_to_action_link'
    });
    
    // initially pause slideshow
    $('#slideshow').cycle('pause');
    
    // slideshow arrows fadeIn/fadeOut when mouse enters or leaves element
    $('.primary_content_container').hover(
        function(){ 
            $('#prev_slide, #next_slide').fadeIn('fast');
        },
        function(){
            $('#prev_slide, #next_slide').fadeOut('fast');
        }
    );
    
    // unbind clicks on arrows and slide pager to pause slideshow
    var unbindSlideNavClicks = function() {
        $('#prev_slide, #next_slide').unbind('click.arrow', pauseSlideShow );
    };
    
    // pause slideshow when user makes explicit navigation
    var pauseSlideShow = function() {
        $('#slideshow').cycle('pause');
        
        unbindSlideNavClicks();
    };
    
    // bind clicks on arrows and slide pager to pause slideshow
    var bindSlideNavClicks = function() {
        $('#prev_slide, #next_slide').bind('click.arrow', pauseSlideShow );
    };
    
    bindSlideNavClicks();
    
    
    // CUSTOM EVENT CALLBACK FUNCTIONS
    // from 'email_form.js'
    
    // extra messaging in callout
    var homeCalloutMsg = $('.email_alert_submit').parents('.email_form')
                            .siblings('h2').children('span');
    
    // remove extra messaging in callout once submitted
    var removeHomeCalloutMsg = function() {
        if (homeCalloutMsg) {
            homeCalloutMsg.remove();
        }
    };
    
    // email successfully submitted
    $(window).bind('successEmail', function() {
        removeHomeCalloutMsg();
    });
    
    // email submitted and is already on list
    $(window).bind('alreadyOnListEmail', function() {
        removeHomeCalloutMsg();
    });
    
    // DEPENDENCY: bound to function in dialog_cta.js
    $('#cta_top, #cta_bottom').bind('click', openDialog);
});

$(window).load(function() {
    // after window load, resume slideshow
    $('#slideshow').cycle('resume');
});
