var revide = revide || {};

revide = {
    init: function() {
        revide.tooltipArrowTopRight.init();
        revide.hoverBox.init();
        revide.hoverBoxArrowRight.init();
        revide.hoverBoxSmall.init();
        revide.lightBox.init();
    },
  
    tooltipArrowTopRight: {
        init: function() {
          revide.tooltipArrowTopRight.buildTooltip();
          $("a.tooltipClassArrowTopRight").bind("mouseenter", function() {
              oImg = $(this).children("img.image");
              revide.tooltipArrowTopRight.show(oImg);
          }).bind("mouseleave", function() {
              revide.tooltipArrowTopRight.hide();
          });
        },

        buildTooltip: function() {
            $('<div id="tooltipArrowTopRight"><div class="top">&nbsp;</div><div class="middle"></div><div class="bottom">&nbsp;</div></div>').appendTo('body');
        },

        show: function(oImg) {
            otooltip = $("div#tooltipArrowTopRight");
            $("#tooltipArrowTopRight .middle").html("<div class='content'><strong>" + oImg.attr("id") + "</strong> </div>&nbsp;-&nbsp;" + oImg.attr("alt"));
            offset = oImg.offset();
            width = oImg.width();
            tooltipHeight = otooltip.height();
            otooltip.css({ left: ((offset.left + (width / 2)) - 225), top: (offset.top + (tooltipHeight - 38)) });
            otooltip.show();
        },

        hide: function() {
            otooltip.hide();
        }
    },  

    hoverBox: {
        init: function() {
            revide.hoverBox.buildhoverBox();
            $("a.hoverBoxClass").bind("mouseenter", function() {
                oContent = $(this);
                revide.hoverBox.show(oContent);
            }).bind("mouseleave", function() {
                revide.hoverBox.hide();
            });
        },

        buildhoverBox: function() {
            $('<div id="hoverBox"><div id="hoverBoxTop">&nbsp;</div><div id="hoverBoxMiddle"></div><div id="hoverBoxBottom">&nbsp;</div></div>').appendTo('body');
        },

        show: function(oContent) {
            ohoverBox = $("div#hoverBox");
            $("div#hoverBoxMiddle").html("<div class='content'>" + oContent.children(".content").html() + "</div>");
            offset = oContent.offset();
            width = oContent.width();
            hoverBoxHeight = ohoverBox.height();
            ohoverBox.css({ left: ((offset.left + (width / 2)) - 200), top: (offset.top - (hoverBoxHeight)) });
            ohoverBox.show();
        },

        hide: function() {
            ohoverBox.hide();
        }
    },
  
    hoverBoxArrowRight: {
        init: function() {
            revide.hoverBoxArrowRight.buildhoverBoxArrowRight();
            $("a.hoverBoxClassArrowRight").bind("mouseenter", function() {
                oContent = $(this);
                revide.hoverBoxArrowRight.show(oContent);
            }).bind("mouseleave", function() {
                revide.hoverBoxArrowRight.hide();
            });
        },

        buildhoverBoxArrowRight: function() {
            $('<div id="hoverBoxArrowRight"><div id="hoverBoxTop">&nbsp;</div><div id="hoverBoxMiddleArrowRight"></div><div id="hoverBoxBottomArrowRight">&nbsp;</div></div>').appendTo('body');
        },

        show: function(oContent) {
            ohoverBox = $("div#hoverBoxArrowRight");
            $("div#hoverBoxMiddleArrowRight").html("<div class='content'>" + oContent.children(".content").html() + "</div>");
            offset = oContent.offset();
            width = oContent.width();
            hoverBoxHeight = ohoverBox.height();
            ohoverBox.css({ left: ((offset.left - (width / 2)) - 128), top: (offset.top - (hoverBoxHeight)) });
            ohoverBox.show();
        },

        hide: function() {
            ohoverBox.hide();
        }
    },
  
    hoverBoxSmall: {
        init: function() {
            revide.hoverBoxSmall.buildhoverBoxSmall();
            $(".hoverBoxSmallClass img.image").hide();
            $("a.hoverBoxSmallClass").bind("mouseenter", function() {
                oImgBw = $(this).children("img.image");
                oImg = $(this).children("img.image_bw");
                revide.hoverBoxSmall.imageHover(oImg, oImgBw, true);
                //revide.hoverBoxSmall.show(oImgBw);
            }).bind("mouseleave", function() {
                oImgBw = $(this).children("img.image");
                oImg = $(this).children("img.image_bw");
                //revide.hoverBoxSmall.hide();
                revide.hoverBoxSmall.imageHover(oImg, oImgBw, false);
            });
        },

        buildhoverBoxSmall: function() {
            $('<div id="hoverBoxSmall"><div id="hoverBoxSmallTop">&nbsp;</div><div id="hoverBoxSmallMiddle"></div><div id="hoverBoxSmallBottom">&nbsp;</div></div>').appendTo('body');
        },

        show: function(oImg) {
            ohoverBoxSmall = $("div#hoverBoxSmall");
            $("div#hoverBoxSmallMiddle").html("<strong>" + oImg.attr("id") + "</strong> - " + oImg.attr("alt"));
            offset = oImg.offset();
            width = oImg.width();
            hoverBoxSmallHeight = ohoverBoxSmall.height();
            ohoverBoxSmall.css({ left: ((offset.left + (width / 2)) - 155), top: (offset.top - (hoverBoxSmallHeight)) });
            ohoverBoxSmall.show();
        },

        hide: function() {
            ohoverBoxSmall.hide();
        },

        imageHover: function(oImg, oImgBw, state) {

            image = oImg.attr("src");
            if (!state) {
                oImgBw.hide();
                oImg.show();
                var strExt = image.match(".gif");
                imageSrc = image.split(strExt);
                //oImg.attr("src", imageSrc[0] + '' + strExt);
            } else {
                oImgBw.show();
                oImg.hide();
                imageSrc = image.split('.');
                // oImg.attr("src", imageSrc[0] + '.' + imageSrc[1]);
            }
        }
    },
    

    lightBox: {
        init: function() {
            revide.lightBox.buildLightBox();
            $("div.lightBoxClass").bind("mouseover", function() {
                $(this).children(".summary").css({ color: '#3784C5' });
            }).bind("mouseleave", function() {
                $(this).children(".summary").css({ color: '#000000' });
            });
            $("div.lightBoxClass").bind("mouseover", function() {
                $(this).css({ cursor: 'pointer' });
            });

            $("div.lightBoxClass").bind("click", function() {
                oContent = $(this);
                revide.lightBox.show(oContent);
            });

            $("#lightBoxTop a.close").bind("click", function() {
                revide.lightBox.hide();
            });

            $("#lightBoxBottom a.homepage").bind("click", function() {
                revide.lightBox.hide();
            });
        },

        buildLightBox: function() {
            $('<div id="lightBox_overlay" class="lightBox_overlayBG"></div><div id="lightBox"><div id="lightBoxTop"><a href="javascript:void(0)" class="close">Close</a></div><div id="lightBoxMiddle"></div><div id="lightBoxBottom"></div></div>').appendTo('body');
        },

        show: function(oContent) {
            ooverlay = $("div#lightBox_overlay");
            olightBox = $("div#lightBox");
            $("div#lightBoxMiddle").html("<div class='content'><h2>Directions</h2>" + oContent.children(".directions").html() + "</div>");
            offset = oContent.offset();
            width = oContent.width();
            lightBoxHeight = olightBox.height();
            ooverlay.show();
            olightBox.show();
        },

        hide: function() {
            olightBox.hide();
            ooverlay.hide();
        }
    }

}

// Start it!
$(document).ready(function() {
  revide.init();
})
