
/*overstate*/
$(document).ready(function () {
    var ie7 = (navigator.userAgent.indexOf("MSIE") != -1 && navigator.userAgent.indexOf("7") != -1) ? true : false;

    if (ie7) {
        //$('.rsvp-submit').css("position", "relative");
        $('.rsvp-submit').css("margin-top", "-18px");
    }


    $(".menuoverstate").each(function (i) {

        preload_image = new Image();
        preload_image.src = this.src.replace(".png", "_o.png");

        $(this).hover(
            function () {
                if (this.src.indexOf("_o.png") == -1) {
                    this.src = this.src.replace(".png", "_o.png");
                }

            },

            function () {
                this.src = this.src.replace("_o.png", ".png");

            });

    });

    jQuery("#calendar th:last-child, #calendar td:last-child").css("margin-right", "0");

    jQuery(".box:nth-child(4n+4)").css("margin-right", "0");

    jQuery(".box, .fader, a img").hover(function () {
        if ($(this).hasClass("no-fade") || $(this).parent().hasClass("no-fade")) {

        }
        else {
            if ($(this).hasClass("heavy-fade"))
                jQuery(this).stop().animate({ opacity: 0.4 }, 200);
            else
                jQuery(this).stop().animate({ opacity: 0.8 }, 200);
        }
    },
        function () {
            if ($(this).hasClass("no-fade") || $(this).parent().hasClass("no-fade")) {

            }
            else {
                jQuery(this).stop().animate({ opacity: 1.0 }, 200);
            }
        });

    jQuery(".header-fade").hover(function () {
        jQuery(this).stop().animate({ opacity: 0.9 }, 200);
    }, function () {
        jQuery(this).stop().animate({ opacity: 1 }, 200);
    });

    $('.hover-bar').stop().animate({ opacity: 0 }, 200);


    $('.overstate2').hover(function () {
        $(this).parent().children('.overstate_main').stop().animate({ opacity: 0.6 }, 200);
    }, function () {
        $(this).parent().children('.overstate_main').stop().animate({ opacity: 1 }, 200);
    });

    $('.list-page-overstate').hover(function () {
        $(this).children('.main-image').stop().animate({ opacity: 0.6 }, 200);
        $(this).children('.hover-bar').stop().animate({ opacity: 1 }, 200);
    }, function () {
        $(this).children('.main-image').stop().animate({ opacity: 1 }, 200);
        $(this).children('.hover-bar').stop().animate({ opacity: 0 }, 200);

    });

    var currentID = 1;


    $('#slideshow').cycle({
        after: function (curr, next, opts) {
            $('#gallery-nav-' + currentID).removeClass("gallery-nav-onstate");

            currentID = opts.currSlide + 1;

            $('#gallery-nav-' + currentID).addClass("gallery-nav-onstate");
        }
    });


    var cCount = ($('#pagination ul').children().length) - 2;

    $('#pagination ul').css("margin-left", (600 - ((cCount * 29) + 53 + 30)) / 2);

    Cufon.replace('h1, h2, .cufon');

    $('.event-gallery-thumb').click(function () {

        var src = $(this).children('img').attr("src");

        $('.main-image-event').attr("src", src);

        return false;
    });

    $('.grey-input').focus(function () {
        if ($(this).val() == " Find a show or event...") {
            $(this).val("");
        }
    });

    $('.grey-input').blur(function () {
        if ($(this).val() == "") {
            $(this).val(" Find a show or event...");
        }
    });


    $('#header-gallery-nav a').click(function () {

        var ID = $(this).attr("id").split('-')[2];

        $('#slideshow').cycle(ID - 1);
    });

    var navHover = "";

    $('.nav-all').hover(function () {
        navHover = "all";
        expandBorder();
    }, function () {
        navHover = "";
    });

    $('.nav-theatre').hover(function () {
        navHover = "theatre";
        expandBorder();
    }, function () {
        navHover = "";
    });

    $('.nav-film').hover(function () {
        navHover = "film";
        expandBorder();
    }, function () {
        navHover = "";
    });

    $('.nav-comedy').hover(function () {
        navHover = "comedy";
        expandBorder();
    }, function () {
        navHover = "";
    });

    $('.nav-dance').hover(function () {
        navHover = "dance";
        expandBorder();
    }, function () {
        navHover = "";
    });

    $('.nav-music').hover(function () {
        navHover = "music";
        expandBorder();
    }, function () {
        navHover = "";
    });

    $('.nav-community').hover(function () {
        navHover = "community";
        expandBorder();
    }, function () {
        navHover = "";
    });

    $('.nav-youth').hover(function () {
        navHover = "youth";
        expandBorder();
    }, function () {
        navHover = "";
    });


    function expandBorder() {


        widthAll = $('.nav-all').css("border-left-width").split("p")[0];
        widthTheatre = $('.nav-theatre').css("border-left-width").split("p")[0];
        widthFilm = $('.nav-film').css("border-left-width").split("p")[0];
        widthComedy = $('.nav-comedy').css("border-left-width").split("p")[0];
        widthDance = $('.nav-dance').css("border-left-width").split("p")[0];
        widthMusic = $('.nav-music').css("border-left-width").split("p")[0];
        widthCom = $('.nav-community').css("border-left-width").split("p")[0];
        widthYou = $('.nav-youth').css("border-left-width").split("p")[0];
        if (navHover != "" || widthAll != 2 || widthTheatre != 2 || widthFilm != 2 || widthComedy != 2 || widthDance != 2 || widthMusic != 2 || widthCom != 2 || widthYou != 2) {
            setTimeout(function () {

                if (navHover == "all" && widthAll < 5) {
                    widthAll++;
                }
                else if (navHover != "all" && widthAll > 2) {
                    widthAll--;
                }

                if (navHover == "theatre" && widthTheatre < 5) {
                    widthTheatre++;
                }
                else if (navHover != "theatre" && widthTheatre > 2) {
                    widthTheatre--;
                }

                if (navHover == "film" && widthFilm < 5) {
                    widthFilm++;
                }
                else if (navHover != "film" && widthFilm > 2) {
                    widthFilm--;
                }

                if (navHover == "comedy" && widthComedy < 5) {
                    widthComedy++;
                }
                else if (navHover != "comedy" && widthComedy > 2) {
                    widthComedy--;
                }

                if (navHover == "dance" && widthDance < 5) {
                    widthDance++;
                }
                else if (navHover != "dance" && widthDance > 2) {
                    widthDance--;
                }

                if (navHover == "music" && widthMusic < 5) {
                    widthMusic++;
                }
                else if (navHover != "music" && widthMusic > 2) {
                    widthMusic--;
                }

                if (navHover == "community" && widthCom < 5) {
                    widthCom++;
                }
                else if (navHover != "community" && widthCom > 2) {
                    widthCom--;
                }

                if (navHover == "youth" && widthYou < 5) {
                    widthYou++;
                }
                else if (navHover != "youth" && widthYou > 2) {
                    widthYou--;
                }

                $('.nav-all').css("border-left-width", widthAll + "px");
                $('.nav-all').css("margin-left", ((widthAll - 2) * -1) + "px");

                $('.nav-theatre').css("border-left-width", widthTheatre + "px");
                $('.nav-theatre').css("margin-left", ((widthTheatre - 2) * -1) + "px");

                $('.nav-film').css("border-left-width", widthFilm + "px");
                $('.nav-film').css("margin-left", ((widthFilm - 2) * -1) + "px");

                $('.nav-comedy').css("border-left-width", widthComedy + "px");
                $('.nav-comedy').css("margin-left", ((widthComedy - 2) * -1) + "px");

                $('.nav-dance').css("border-left-width", widthDance + "px");
                $('.nav-dance').css("margin-left", ((widthDance - 2) * -1) + "px");

                $('.nav-music').css("border-left-width", widthMusic + "px");
                $('.nav-music').css("margin-left", ((widthMusic - 2) * -1) + "px");

                $('.nav-community').css("border-left-width", widthCom + "px");
                $('.nav-community').css("margin-left", ((widthCom - 2) * -1) + "px");

                $('.nav-youth').css("border-left-width", widthYou + "px");
                $('.nav-youth').css("margin-left", ((widthYou - 2) * -1) + "px");


                expandBorder();
            }, 25);
        }
    }


});

