var revide = revide || {};

revide = {
    init: function() {
		$("#tabs").tabs();
		
		$("#marquee").marquee("pointer").mouseover(function () {
		  $(this).trigger("stop");
		}).mouseout(function () {
		  $(this).trigger("start");
		});
		
        revide.hoverBox.init();
	revide.hoverBoxTeasers.init();
	revide.lightBox.init();
    },

    hoverBox: {
        init: function() {
            revide.hoverBox.buildhoverBox();
	    $(".hoverBoxClass img.image").hide();
            $("a.hoverBoxClass").bind("mouseenter", function() {
		oImgBw = $(this).children("img.image");
		oImg = $(this).children("img.image_bw");
                revide.hoverBox.imageHover(oImg, oImgBw, true);
                revide.hoverBox.show(oImgBw);
            }).bind("mouseleave", function() {
                oImgBw = $(this).children("img.image");
		oImg = $(this).children("img.image_bw");
                revide.hoverBox.hide();
                revide.hoverBox.imageHover(oImg, oImgBw, false);
            });


            $("a.hoverBoxClassNoToolTip").bind("mouseenter", function() {
		oImgBw = $(this).children("img.image");
		oImg = $(this).children("img.image_bw");
                revide.hoverBox.imageHover(oImg, oImgBw, true);
            }).bind("mouseleave", function() {
                oImgBw = $(this).children("img.image");
		oImg = $(this).children("img.image_bw");
                revide.hoverBox.imageHover(oImg, oImgBw, false);
            });



        },

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

        show: function(oImg) {
            ohoverBox = $("div#hoverBox");
            $("div#hoverBoxMiddle").html("<strong>" + oImg.attr("id") + "</strong> - " + oImg.attr("alt"));
            offset = oImg.offset();
            width = oImg.width();
            hoverBoxHeight = ohoverBox.height();
            ohoverBox.css({ left: ((offset.left + (width / 2)) - 131), top: (offset.top - (hoverBoxHeight - 15)) });
            ohoverBox.show();
        },

        hide: function() {
            ohoverBox.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]);
            }
        }
    },

	hoverBoxTeasers: {
        init: function() {
            //revide.hoverBoxTeasers.buildhoverBox();
            $("a.hoverBoxTeaserClass").bind("mouseenter", function() {
                oImg = $(this).children("img");
				oRoot = $(this);
                revide.hoverBoxTeasers.imageHover(oImg, true);
                //revide.hoverBoxTeasers.show(oImg, oRoot);
            }).bind("mouseleave", function() {
                oImg = $(this).children("img");
                //revide.hoverBoxTeasers.hide();
                revide.hoverBoxTeasers.imageHover(oImg, false);
            });
        },

    imageHover: function(oImg, state) {
            image = oImg.attr("src");
            if (!state) {
                var strExt = image.match(".gif");
                imageSrc = image.split(strExt);
                oImg.attr("src", imageSrc[0] + '_hover' + strExt);
            } else {
                imageSrc = image.split('_hover.');
                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();
       $("a.contactLink").bind("click", function() {
	   $(".contactItem").hide();
       $("#id_" + $(this).attr("id")).show();
	   return false;
    })
	   
	$(".referenceListItem a").bind("mouseenter", function() {
		$(this).children("img.image").show();
		$(this).children("img.image_bw").hide();
	}).bind("mouseleave", function() {
		$(this).children("img.image").hide();
		$(this).children("img.image_bw").show();
	});
	   
    $(".referenceListItem a").bind("click", function() {
		$(this).children("img.image").show();
		$(this).children("img.image_bw").hide();													 
		$(".referenceItem").hide();
		$(".referenceListItem a").removeClass("selected");
		$(".referenceItem").removeClass("selected");
		$("#id_" + $(this).attr("id")).show();
		$(this).addClass("selected");
		return false;
    })
})
