$(document).ready(function() {

    // Home page carousel
    if($('#hmFeaturesCntnr').length > 0)
    {
            var rand = Math.floor(Math.random() * 5);

        $('#hmFeaturesCntnr').before('<div id="nav">').cycle(
        {
            fx:     'scrollHorz',
            prev:   '#prev',
            next:   '#next',
            timeout: 0 ,
            cleartype:  1,
            pager:  '#nav',
            startingSlide: rand,
            cssBefore: {display: 'block'},
            cleartypeNoBg: true,
            pagerAnchorBuilder: function(idx, slide)
            {
                switch (idx) {
                    case 0:
                        return '<a id="apex_lnk" href="#" onclick="$(\'#hmFeaturesCntnr\').cycle(\'pause\');">Apex Environmental</a>';
                        break;
                    case 1:
                        return '<a id="prodigy_lnk" href="#" onclick="$(\'#hmFeaturesCntnr\').cycle(\'pause\');">Prodigy Preschool</a>';
                        break;
                    case 2:
                        return '<a id="rusk_lnk" href="#" onclick="$(\'#hmFeaturesCntnr\').cycle(\'pause\');">Rusk Heating &amp; Cooling</a>';
                        break;
                    case 3:
                        return '<a id="frank_lnk" href="#" onclick="$(\'#hmFeaturesCntnr\').cycle(\'pause\');">Frank\'s Glass</a>';
                        break;
                    case 4:
                        return '<a id="fassler_lnk" href="#" onclick="$(\'#hmFeaturesCntnr\').cycle(\'pause\');">Fassler Florist</a>';
                        break;
                }
            }
        });
    }

    // --------------------------------------------------

    $('#hmFeaturesBg #nav a').click(function(){
        $.akModalCloseAndRemove();
    })

    // --------------------------------------------------

    // Scroll pane is only active on Twitter page
    if($('.scroll-pane').length > 0)
    {
        $('.scroll-pane').jScrollPane({scrollbarWidth: 20, dragMaxHeight: 22});
    }

    $(".bundle a").click(function(e){
        var p = $(this).parent();

        if($(p).hasClass("on"))
        {
            return;
        }
        else
        {
            e.preventDefault();
        }
    })

    $(".bundle").hover(function(){
            $(this).addClass("on");
        },
        function(){
            $(this).removeClass("on");
        }
    );

    $("#openfeatures").click(function(){$("#features").show();});
    $("#features").click(function(e){e.preventDefault(); $("#features").hide();});
});


/**
 * This function removes the intro video from the dom
 */
function skipIntro()
{
    $('#intro-cntnr').fadeOut('normal');
}