// JavaScript Document
$(document).ready(function () {
    var slide = false;
    bannerAdjust();

    $(window).resize(function () {
        bannerAdjust();
    });

    function bannerAdjust() {
        var W = $(window).width();
        if (W <= 1279) {
            W = (1280 - W);
            if (W <= 145) {
                $('.PageLayout').css('margin-left', '-' + W + 'px');
            }
            else {
                $('.PageLayout').css('margin-left', '-145px');
            }
        }
        else {
            $('.PageLayout').css('margin', 'auto');
        }
    }

    // https for tickets page if we are not localhost otherwise make sure we are not https
    if (window.location.toString().indexOf('://localhost') == -1) {
        if (window.location.toString().indexOf('/tickets.html') != -1) {
            if (window.location.toString().indexOf('http://') == 0) {
                window.location = window.location.toString().replace('http://', 'https://');
            }
        }
        else if (window.location.toString().indexOf('https://') == 0) {
            window.location = window.location.toString().replace('https://', 'http://');
        }
    }

    $('#ContentCycle').cycle({
        fx: 'scrollVert',
        speed: 'normal',
        timeout: 0,
        after: function () {
            var visible = $('#ContentCycle > div:visible');

            if (!window.ticketsPlease) {
                visible.css('height', 'auto');
                $(visible).parent().animate({ height: $(visible).outerHeight() + 'px' });
            }
        },
        pager: '.tabMenu',
        pagerAnchorBuilder: function (idx, slide) {
            var length = $(this).parent().children().length;
            var anchor = '<a href="#" hideFocus="true" class="tabs' + (idx == 0 ? ' tabsOn' : '') + '" id="T' + idx + '" style="' + (idx + 1 == length ? 'border-right:none; ' : '') + ($(slide).attr('name') == 'hidden' ? ' display: none' : '') + '">' + $(slide).attr('name') + '</a>';

            return anchor;
        }
    });

    $('.tabMenu a').live('click', function () {
        $('.tabMenu a').toggleClass('tabsOn', false);
        $(this).toggleClass('tabsOn', true);
    });

    var showsMediaClick = function () {
        $(".ShowsMedia a").fancybox({
            'transitionIn': 'elastic',
            'transitionOut': 'elastic',
            'speedIn': 600,
            'speedOut': 200,
            'overlayShow': true
        });
    }
    showsMediaClick();

    var testimonials = function () {
        $('#testimonials').cycle({
            fx: 'scrollHorz',
            speed: 'fast',
            timeout: 0,
            next: '#testimonialsNext',
            prev: '#testimonialsPrev',
            after: function () {
                var visible = $('#testimonials > div:visible');
                var index = $('#testimonials > div').index(visible) + 1;
                $('#testimonialsPage').text(index);
                $(visible).parent().animate({ height: $(visible).outerHeight() + 'px' });
            }

        });
        $('#testimonialsPage').text('1');
        $('#testimonialsPages').text($('#testimonials > div').length);
    }
    testimonials();

    var share = function () {
        $('.shareLink').each(function (i, e) {
            $(e).attr('href', $(e).attr('href').replace(/\{0\}/g, encodeURIComponent('http://' + window.location.host + '/')));
        });

        $('.shareLink1').each(function (i, e) {
            $(e).attr('href', $(e).attr('href').replace(/\{0\}/g, encodeURIComponent(window.location.toString())));
        });
    }
    share();
    $('a.showInfo').live('click', function (e) {
        e.preventDefault();
        var anchor = this;
        $('div[name="hidden"]').load($(this).attr('href') + ' .Content > div', function () {

            $('.tabs:last').show().text($(anchor).attr('title'))
            $('.tabs:last').trigger('click')

            testimonials();

            showsMediaClick();

            share();

            if (!!$.scrollTo) {
                $.scrollTo('.tabMenu')
            }
        });
    });

    textShadow();

    $.ajaxSetup({
        // Disable caching of AJAX responses
        cache: false
    });

    $("#extLink").fancybox({
        'width': 1000,
        'height': 700,
        'autoScale': false,
        'transitionIn': 'elastic',
        'transitionOut': 'elastic',
        'speedIn': 600,
        'speedOut': 200,
        'type': 'iframe'
    });

    $(".CSoon").fancybox({
        'transitionIn': 'elastic',
        'transitionOut': 'elastic',
        'speedIn': 600,
        'speedOut': 200
    });

    $('#shareNav').click(function (e) {
        e.preventDefault();
        if (slide == false) {
            $('#shareNav').attr("class", "navON");
            slide = true;
        }
        else {
            $('#shareNav').attr("class", "nav");
            slide = false;
        }

        $('#shareIcons').fadeToggle("slow", "linear");
    });
});

function textShadow() {
    if ($.browser.msie) {
        var visibles = $('.ShowTitleClone').remove();
        $('.ShowTitle:visible').each(function (i, e) {
            var clone = $(e).clone();
            clone.toggleClass('ShowTitleClone', true);
            var top = $(e).position().top;
            var left = $(e).position().left;
            clone.css('top', (top + 2) + 'px').css('left', (left + 2) + 'px').css('color', '#000000')
            clone.fadeTo(0.0, 0.80);
            $('span', clone).fadeTo(0.0, 0.80).css('color', '#000000');
            $(e).before(clone);
        });

        $('.ShowTitle:visible').each(function (i, e) {
            var clone = $(e).clone();
            clone.toggleClass('ShowTitleClone', true);
            var top = $(e).position().top;
            var left = $(e).position().left;
            clone.css('top', (top - 1) + 'px').css('left', (left + 1) + 'px').css('color', '#000000')
            clone.fadeTo(0.0, 0.46);
            $('span', clone).fadeTo(0.0, 0.46).css('color', '#000000');
            $(e).before(clone);
        });
    }
}


// essential so all browsers fire the ready event on reload
$(window).unload(function () { });
