var revide = revide || {};

revide = {
    init: function() {
		$("#tabs").tabs();
		
		$("#marquee").marquee("pointer").mouseover(function () {
		  $(this).trigger("stop");
		}).mouseout(function () {
		  $(this).trigger("start");
		});
		
		revide.lightBox.init();
        revide.hoverBox.init();
		revide.hoverBoxTeasers.init();
		
    },

    hoverBox: {
        init: function() {
            revide.hoverBox.buildhoverBox();
            $("a.hoverBoxClass").bind("mouseenter", function() {
                oImg = $(this).children("img");
                revide.hoverBox.imageHover(oImg, true);
                revide.hoverBox.show(oImg);
            }).bind("mouseleave", function() {
                oImg = $(this).children("img");
                revide.hoverBox.hide();
                revide.hoverBox.imageHover(oImg, 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, state) {
            image = oImg.attr("src");
            if (!state) {
                var strExt = image.match(".gif");
                imageSrc = image.split(strExt);
                oImg.attr("src", imageSrc[0] + '_bw' + strExt);
            } else {
                imageSrc = image.split('_bw.');
                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);
            });
        },

		/*
        buildhoverBox: function() {
            $('<div id="hoverBoxTeaser"><div id="hoverBoxTeaserTop">&nbsp;</div><div id="hoverBoxTeaserMiddle"></div><div id="hoverBoxTeaserBottom">&nbsp;</div></div>').appendTo('body');
        },

        show: function(oImg) {
            ohoverBox = $("div#hoverBoxTeaser");
            $("div#hoverBoxTeaserMiddle").html("<h2>" + oRoot.children(".heading").text() + "</h2>" + oRoot.children(".information").html());
            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, 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: '#8ec649' });
            }).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);
            });
			$("#lightBoxBottom a").bind("click", function() {
                revide.lightBox.hide();
            });
        },

        buildLightBox: function() {
            $('<div id="lightBox_overlay" class="lightBox_overlayBG"></div><div id="lightBox"><div id="lightBoxTop">&nbsp;</div><div id="lightBoxMiddle" class="green"></div><div id="lightBoxBottom" class="green"><a href="javascript:void(0)">St&#228;ng</a></div></div>').appendTo('body');
        },

        show: function(oContent) {
			ooverlay = $("div#lightBox_overlay");
            olightBox = $("div#lightBox");
            $("div#lightBoxMiddle").html("<div class='content'><div class='image'>" + oContent.children(".image").html() + "</div><div class='date'><strong>" + oContent.children(".date").text() + "</strong></div><h2>" + oContent.children(".heading").text() + "</h2>" + oContent.children(".information").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();
})