jQuery(document).ready(function ()
{
    /* ##### CUFON ##### */
    Cufon.replace('a.cfMainNav', { hover: true, textShadow: '0px 0px #ccc' });
    Cufon.replace('a.cfQuickLinks', { hover: true });
    Cufon.replace('div.sub', { hover: true });
    Cufon.replace('h1.rotatorFooter', { hover: true });
    Cufon.replace('ul.menu', { hover: true });
    Cufon.replace('div.fourCol h2', { hover: true });
    Cufon.replace('div.twoCol h2', { hover: true });
    Cufon.replace('div#pageTitle h1', { hover: true });
    Cufon.replace('div#interiorContent h2', { hover: true });
    Cufon.replace('div#interiorContent h3', { hover: true });

    /* ##### DROPDOWN NAVIGATION ##### */

    function megaHoverOver()
    {
        jQuery(this).find(".sub").stop().fadeTo('fast', 1).show();

        //Calculate width of all ul's
        (function (jQuery)
        {
            jQuery.fn.calcSubWidth = function ()
            {
                rowWidth = 0;
                //Calculate row
                jQuery(this).find("ul").each(function ()
                {
                    rowWidth += jQuery(this).width();
                });
            };
        })(jQuery);

        jQuery(this).calcSubWidth();
        if (jQuery(this).find(".last").length > 0)
        {
            var left = (jQuery(this).find(".sub").position().left - rowWidth) + jQuery(this).width() - 40;
            jQuery(this).find(".sub").css({ 'left': left });
        }
        jQuery(this).find(".sub").css({ 'width': rowWidth });

    }

    function megaHoverOut()
    {
        var left = jQuery(this).position().left;
        jQuery(this).find(".sub").stop().fadeTo('fast', 0, function ()
        {
            jQuery(this).css({ 'left': left });
            jQuery(this).hide();

        });

    }

    var config = {
        sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)    
        interval: 0, // number = milliseconds for onMouseOver polling interval    
        over: megaHoverOver, // function = onMouseOver callback (REQUIRED)    
        timeout: 200, // number = milliseconds delay before onMouseOut    
        out: megaHoverOut // function = onMouseOut callback (REQUIRED)    
    };

    jQuery("ul.mainNav li .sub").css({ 'opacity': '0' });
    jQuery("ul.mainNav li").hoverIntent(config);


    /* ##### HOME PAGE ROTATOR ##### */
    jQuery('#slider').cycle({
        fx: 'fade',
        speed: 'fast',
        timeout: 6000,
        pager: '#rotatorNav'

    });
    jQuery('#rotatorNav a').click(function ()
    {
        jQuery('#slider').cycle('pause');
    });

    /* ##### RESULTS TABS ##### */
    jQuery('#slideshow .slides').cycle({
        fx: 'fade',
        speed: 'fast',
        timeout: 6000,
        pager: '#tabNav',
        prev: '#prev1',
        next: '#next1'
    });

    jQuery('#tabNav a').click(function ()
    {
        jQuery('#slideshow .slides').cycle('pause');
    });

    /* ##### SOCIAl TABS ##### */

    //Default Action
    jQuery(".tab_content").hide(); //Hide all content
    jQuery("ul.menu li:first").addClass("active").show(); //Activate first tab
    jQuery(".tab_content:first").show(); //Show first tab content

    //On Click Event
    jQuery("ul.menu li").click(function ()
    {
        jQuery("ul.menu li").removeClass("active"); //Remove any "active" class
        jQuery(this).addClass("active"); //Add "active" class to selected tab
        jQuery(".tab_content").hide(); //Hide all tab content
        var activeTab = jQuery(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
        jQuery(activeTab).fadeIn(); //Fade in the active content
        return false;
    });

    /* END */
});
