﻿$(document).ready(function() {
    if ($("#gallery").length > 0)
        gallery.init();
    var counter = 0;
    $("#footer").after("<div class=\"menu-shadow\">&nbsp;</div>");
    $("ul#nav").superfish({
        autoArrows: false,
        onBeforeShow: function() {
            counter = 1;
            var h = $(this).height() + 14;
            var w = $(this).width() + 8;
            var offset = $(this).parent().offset();
            if (offset == null)
                offset = 0;
            var left = offset.left - 18;
            var top = offset.top + 17;
            var zIndex = $(this).css("z-index") - 1;
            $(".menu-shadow").css({ "height": h, "width": w, "left": left, "top": top, "display": "block", "z-index": zIndex });
        },
        onHide: function() {
            /*
            we need this logic because this function is called before the onShow function
            and we can't call the onShow function because it will not have the dropshadow set before
            the menu starts to animate on
            */
            if (counter == 0) {
                $(".menu-shadow").css({ "left": -999, "top": -999, "display": "none" });
            } else {
                counter = 0;
            }
        }
    });
    $(".txtMailingListEmail").bind("focus", function(event) {
        if ($(this).val() === "Enter your email address") {
            $(this).val("");
            $(this).removeClass("mask");
        }
    });
    $(".txtMailingListEmail").bind("blur", function(event) {
        if ($(this).val() === "") {
            $(this).val("Enter your email address");
            $(this).addClass("mask");
        }
    });
});
var gallery =
{
    images: [],
    currentImage: null,
    imageCount: null,
    init: function() {
        var item = $("#photos");
        this.currentImage = 0;
        this.imageCount = $(item).find("img").length;
        var counter = 0;
        $(item).find("img:first").show();
        $(item).find("img").each(function() {
            gallery.images[counter] = $(this).attr("id");
            counter++;
        });
        $("#gallery_prev").bind("click", function(e) {
            gallery.prev();
            return false;
        });
        $("#gallery_next").bind("click", function(e) {
            gallery.next();
            return false;
        });
    },
    next: function() {
        var tempImg = this.currentImage;

        this.currentImage++;

        if (this.currentImage > (this.imageCount - 1))
            this.currentImage = 0;

        $("#" + this.images[tempImg]).fadeOut("slow", function() {
            $("#" + gallery.images[gallery.currentImage]).fadeIn("slow");
        });
    },
    prev: function() {
        var tempImg = this.currentImage;
        this.currentImage--;

        if (this.currentImage < 0)
            this.currentImage = (this.imageCount - 1);

        $("#" + this.images[tempImg]).fadeOut("slow", function() {
            $("#" + gallery.images[gallery.currentImage]).fadeIn("slow");
        });
    }
}