(function() {

	var jQ = typeof jQuery == 'function';
	
	var colors 	= { 'white': '#FFFFFF', 'black': '#000000', 'none': null };
	var cover;
	var covers	= {};
	
	function toggleCover(  ) 					
	{
		toggle();
	}
	
	function init( props )						
	{
		var id = $( '.cover' ).length
		props.color =  ( ( colors[ settings.color ] != null ) ? colors[ settings.color ] : settings.color );
		props.covertarget = 	( ( settings.covertarget != null ) ? settings.covertarget : this );
		props.z = 	( ( settings.covertarget == null ) ? parseInt( this.css( 'z-index' ) ) - 1 : 0 );
		if( !cover )
		{
			$( props.covertarget ).append( $( 		'<div id=\"cover' + id + '\" ' 
									+	'class=\"cover\" '
									+	'style=\"position:absolute; left:0px; top:0px; width:' + pageDim( 0 ) + 'px;height:' +  pageDim( 1 ) + 'px; visibility: hidden; z-index:' + props.z + '; '
									+   'filter:alpha(opacity=0); -ms-filter: \"progid:DXImageTransform.Microsoft.Alpha(opacity=0)\"; filter: progid:DXImageTransform.Microsoft.Alpha(opacity=0); opacity: 0; -moz-opacity:0\"'
									+	'>'
									+	'</div>' ) );
		}
		props.cover = props.covertarget.find( '#cover' + id  );
		
		
		return props;
	};
	
	function toggle(  )						
	{
		var a = 0;
		
		if( cover.css( 'visibility' ) == 'hidden' ) { cover.css( { visibility: 'visible' } ); a = 0.6; };

		cover.delay( 700 ).animate(
		{
			opacity: a
		},
		{
			duration: 	500,
			complete: 	function()
			{
				if( a < 0.1 ) cover.css	( 'visibility', 'hidden' );
			}
		});
	};
		

	function pageDim( dim )						
	{
		return ( ( dim == 0 ) 
				  ? ( ( !jQuery.support.leadingWhitespace ) ? document.body.clientWidth : window.innerWidth ) 
				  : ( ( !jQuery.support.leadingWhitespace ) ? document.body.clientHeight : window.innerHeight ) );
	}

	//$( window ).resize( function ()											
	//{   
	//	setDimensions();   
	//});   
		
	function setDimensions(  )						
	{
		cover.css(
		{
			width:	 pageDim( 0 )	,
			height:	 pageDim( 1 )	
		} );
	}




	if (jQ)												
	{	
		jQuery.fn.ikCover = function( options ) 
		{	
  			settings = jQuery.extend(
			{
				name:				"cover",
				classname:		null,
				scale:		 		[ 1, 1 ],
				size:		 			null,
     			color: 				"black",						// 		black, hex
				opacity:				0.6,
     			global:		 		true
  			}, 
			options);
			var props = settings;
			
			init.call( this, props );
			props.parent = this.attr( 'id' )
			covers[ this.attr( 'id' ) ] = props;
			
			return covers[ this.attr( 'id' ) ];
		};
		
		jQuery.fn.toggle = function(  ) 
		{
			cover = covers[  this.attr( 'id' ) ].cover
			cover.css( 'z-index', covers[  this.attr( 'id' ) ].z )
			toggle(  );
		}

	}

})();

