/*=============================================================================

			 	 TITLE:		NetMediaOne - Hyperlink "Preview" Box
		  MODIFIED:		2007.10.24
		 AUTHOR(S): 	Graham Wheeler - NetMediaOne - www.netmediaone.com
		  REQUIRES:		NetMediaOne Core 1.2

=============================================================================*/

NMO.LinkPreviewBox = new function LinkPreviewBox() {
	
	return {

		init: function() {
			$("#layoutWrapper").prepend('<div id="linkPreviewBox" style="display: none;"><img src="" alt="" class="PicCenter"><h3></h3><span></span></div><div id="linkPreviewBoxShadow"></div>');
			this.container = $("#linkPreviewBox");
			this.shadow = $("#linkPreviewBoxShadow");
			this.shadow.fadeTo( 10, 0.25 );
			this.image = $("#linkPreviewBox img");
			this.title = $("#linkPreviewBox h3");
			this.caption = $("#linkPreviewBox span");
			this.image.attr( "src", NMO.rootPath + "resources/images/preview_loading.gif" );
			var pb = this;
			$(".PreviewLink").hover(
				function() {
					pb.show(this);
				},
				function() {
					pb.hide();
				}
			).mousemove(
				function() {
					pb.update();
				}
			);
		},
		
		show: function(aTag) {
			var $aTag = $(aTag);
			var pb = this;
			var img = new Image();
			img.onload = function(e) {
				pb.image.attr( "src", img.src );
			};
			img.src = NMO.rootPath + "resources/images/" + $aTag.attr("primage");
			this.title.html( $aTag.attr("title") );
			this.caption.html( $aTag.attr("prcaption") );
			this.container.css("display", "block");
			this.shadow.css("display", "block");
			this.shadow.fadeTo( 10, 0.25 );
			this.shadow.height( this.container.height() + 20 );
			this.update();
		},
		
		hide: function() {
			this.container.css("display", "none");
			this.shadow.css("display", "none");
			this.image.attr( "src", NMO.rootPath + "resources/images/preview_loading.gif" );
		},
	
		update: function() {			
			var tpY = NMO.documentMouseY - this.container.height() - 35;
			if( (NMO.getPageScroll()[1] - tpY) > 5 )	{ 
				tpY = NMO.getPageScroll()[1] + 35;
			}
			this.container.css({ left: (NMO.documentMouseX - this.container.width() - 80) + "px", top: tpY + "px" });
			this.shadow.css({ left: (NMO.documentMouseX - this.container.width() - 75) + "px", top: (tpY+5) + "px" });
		}
		
	};

};

jQuery( function() { NMO.LinkPreviewBox.init(); });
