/**

 * NVS_OVERLAY

 * 

 * @author		Sebastiaan Smid <sebastiaan@netvlies.nl>

 * 

 * Optional parameters:

 * @category		jQuery Plugin

 * @package			Netvlies Overlay

 * @version			1.0

 *

 */



(function($) {

 

	$.nvsOverlay= { 

	

		/**

		 * Show the overlay with default settings or the given params

		 * Also binds window resizing to overlayResize

		 * @param 	Object		background string (cssProperty), speed int (milliseconds), transparancy decimal (between 0 and 1), callback function

		 */



		show : function (options) { 

		// default settings	

			var defaults = {

				background: 'black',

				speed: 1500,

				height: this.overlayHeight(),

				transparancy: '0.5',

				callback: false

			};	

			options = $.extend(defaults, options);

		

		//hide elements that show through the overlay in IE 6

			if($.browser.msie && $.browser.version <= 6) {

				$('embed, object, select').css({ 'visibility' : 'hidden' });

			} 

			

		//add overlay to the DOM

			$('<div></div>').attr({

							id: 'nvs_overlay' 

							})

						.css({

							position: 'absolute',

							top: 0,

							left: 0,

							height: options.height,

							width: '100%',

							zIndex: '9999',

							opacity: '0',

							background: options.background

							})

						.appendTo('body')

						.fadeTo(options.speed, options.transparancy, options.callback);

	

		// bind resize function on window resize event, this will reposition the overlay when window resizes or scrolls

			$(window).bind('resize', this.overlayResize);		

		},

		

		/**

		* Hides the overlay and unbinds window resize method

		*/

		hide :	function () { 

			if($('#nvs_overlay')){

				// first fade and remove on callback

				$('#nvs_overlay').fadeTo('slow', 0, function () { 

					$('#nvs_overlay').remove();

					$('embed, object, select').css({ 'visibility' : 'visible' });

				});

			}

			$(window).unbind('resize', this.overlayResize);

		},

		

		/**

		* Resizes the overlay bound to resize event of the window DOM element

		*/

		overlayResize : function() {

			$('#nvs_overlay').css({ width: 0, height: 0 });

			oheight = $.nvsOverlay.overlayHeight();

			$('#nvs_overlay').css({	width: '100%', height: oheight });

		},

		

		/**

		 * Calculates the height of the overlay 

		 * @returns 	INT		Height of the window or document DOM element

		*/

		overlayHeight : function () {



			if($(document).height() > $(window).height()) {

				oHeight = $(document).height()

			} else {

				oHeight = $(window).height();	

			}

			

			return oHeight;

		}

		

	}

	

})(jQuery);
