﻿Cufon.replace('#header-nav ul li a', {
    hover: true
});

Cufon.replace('#body-nav ul li a', {
    hover: true
});

Cufon.replace('ul.tabs-nav li a', {
    hover: true
});

Cufon.replace('#insiders-tabs ul.insiders-tabs-nav li a', {
    hover: true
});

Cufon.replace('h1');
Cufon.replace('h2');
Cufon.replace('h3');

Cufon.replace('.archer');

Cufon.replace('.archer-hover', {
    hover: true
});

$(document).mouseout(function() {
    Cufon.refresh('#header-nav ul li a');
});

$(document).ready(function() {
    //$('.poweredBySitefinityLogo').remove();

    $('input.search-phrase').keyup(function() {
        if ($(this).val() == '')
            $('input.search-go').attr('disabled', 'disabled');
        else
            $('input.search-go').removeAttr('disabled');
    });

    $('input.search-phrase').click(function() {
        if ($(this).val() == '')
            $('input.search-go').attr('disabled', 'disabled');
        else
            $('input.search-go').removeAttr('disabled');
    });

    if ($('#carousel-container').length > 0) {
        $('#carousel-container').jCarouselDynamic({
            carouselSelector: '#carousel',
            itemSelector: '.carousel-item-outer',
            prevSelector: '#carousel-previous a',
            nextSelector: '#carousel-next a',
            autoScrollSpeed: 5000,
            circular: true,
            initialiseCallback: function() {
                Cufon.replace('.archer');
            }
        });
    }

    $('#carousel .carousel-item-inner').live('mouseover', function() {
        var caption = $(this).find('.carousel-caption');

        if (!caption.is(':visible') && !caption.is(':animated'))
            caption.slideDown('fast');
    });

    $('#carousel .carousel-item-inner').live('mouseleave', function() {
        var caption = $(this).find('.carousel-caption');

        //if (caption.is(':visible') && !caption.is(':animated'))
        if (caption.is(':visible'))
            caption.slideUp('fast');
    });

    $('#home-hero-banner .slide-show .slides, #hero-banner .slide-show .slides, #blog-hero-banner .slide-show .slides').cycle({
        containerResize: 0,
        fx: 'fade',
        timeout: 5000,
        pager: '#home-hero-banner .slide-show .pager, #hero-banner .slide-show .pager, #blog-hero-banner .slide-show .pager',
        pause: 1,
        pagerAnchorBuilder: function(idx, slide) {
            if (idx > 0)
                return '<a class="float-left"><span class="png-fix">' + (idx + 1) + '</span></a>';
            else
                return '<a class="float-left"><span class="png-fix firstSlide">' + (idx + 1) + '</span></a>';
        },
        before: function(currSlideElement, nextSlideElement, options, forwardFlag) {
            var captionElement = $(currSlideElement).parents('.slide-show').find('.caption');
            var imgElement = null;

            if (nextSlideElement.tagName.toLowerCase() == 'img')
                imgElement = $(nextSlideElement);
            else
                imgElement = $(nextSlideElement).find('img');

            captionElement.html(imgElement.attr('alt'));

            Cufon.replace('#home-hero-banner .slide-show .pager a, #hero-banner .slide-show .pager a, #blog-hero-banner .slide-show .pager a');
        }
    });

    $('#insiders-inner .slide-show .slides').cycle({
        containerResize: 0,
        fx: 'fade',
        timeout: 5000,
        pager: '#insiders-inner .slide-show .pager',
        pause: 1,
        pagerAnchorBuilder: function(idx, slide) {
            if (idx > 0)
                return '<a class="float-left"><span class="png-fix">' + (idx + 1) + '</span></a>';
            else
                return '<a class="float-left"><span class="png-fix firstSlide">' + (idx + 1) + '</span></a>';
        },
        before: function(currSlideElement, nextSlideElement, options, forwardFlag) {
            Cufon.replace('#insiders-inner .slide-show .pager a');
        }
    });

    $('#bookit-business .slide-show .slides').cycle({
        containerResize: 0,
        fx: 'fade',
        timeout: 5000,
        pager: '#bookit-business .slide-show .pager',
        pause: 1,
        pagerAnchorBuilder: function(idx, slide) {
            if (idx > 0)
                return '<a class="float-left"><span class="png-fix">' + (idx + 1) + '</span></a>';
            else
                return '<a class="float-left"><span class="png-fix firstSlide">' + (idx + 1) + '</span></a>';
        },
        before: function(currSlideElement, nextSlideElement, options, forwardFlag) {
            Cufon.replace('#bookit-business .slide-show .pager a');
        }
    });

    if ($('.tabs').length > 0) {
        $('.tabs').tabsSimple({
            selectedClass: 'active',
            disabledClass: 'in-active',
            onSelect: function() {
                Cufon.refresh('ul.tabs-nav li a');
            }
        });
    }

    if ($('#insiders-tabs').length > 0) {
        $('#insiders-tabs').tabsSimple({
            selectedClass: 'active',
            disabledClass: 'in-active',
            onSelect: function() {
                Cufon.refresh('#insiders-tabs ul.insiders-tabs-nav li a');
            }
        });
        
        $('#insiders-tabs').hover(
            function() {
                $(this).addClass('hover');
            }, function() {
                $(this).removeClass('hover');
            }
        );

        window.setInterval(function() {
            var insidersTabs = $('#insiders-tabs');
        
            if (insidersTabs && !insidersTabs.hasClass('hover')) {
                var tabCount = insidersTabs.find('ul.insiders-tabs-nav li').length;
                var tabIndex = 1;

                insidersTabs.find('ul.insiders-tabs-nav li').each(function(index) {
                    if ($(this).hasClass('active'))
                        tabIndex = index + 1;
                });

                if (tabIndex < tabCount)
                    tabIndex ++;
                else
                    tabIndex = 1;

                insidersTabs.find('ul.insiders-tabs-nav li a').each(function(index) {
                    if (index == tabIndex - 1)
                        $(this).trigger('click', [true]);
                });
            }
        }, 5000);
    }

    $('a.pretty-photo').prettyPhoto({ theme: 'light_rounded' });

    if ($('#events-carousel-container').length > 0) {
        $('#events-carousel-container').jCarouselDynamic({
            carouselSelector: '#events-carousel',
            itemSelector: '.event-day',
            scrollItemCount: 2,
            prevSelector: '#events-carousel-prev',
            nextSelector: '#events-carousel-next'
        });
    }

    $('input.hint-text').focus(function() {
        if ($(this).val() == $(this).attr('title'))
            $(this).val('');
    });

    $('input.hint-text').blur(function() {
        if ($(this).val() == '')
            $(this).val($(this).attr('title'));
    });
});

function panelUpdated() {
    Cufon.replace('h1');
    Cufon.replace('h2');
    Cufon.replace('h3');

    Cufon.replace('.archer');
}

function validateNotHint(sender, args) {
    var validator = document.getElementById(sender.id);
    var control = document.getElementById(validator.controltovalidate);

    if (args.Value == $(control).attr('title'))
        args.IsValid = false;
    else
        args.IsValid = true;
}

