/*======================================================================*\
|| #################################################################### ||
|| #  				  Imperial Bulletin Board v1.x                    # ||
|| # ---------------------------------------------------------------- # ||
|| # @Name: Winter Snow												  # || 
|| # @Desc: Falling winter snow java scripting.						  # ||
|| # @File: winter_snow.js											  # ||
|| # @Author: Mike Foss												  # ||
|| # ---------------------------------------------------------------- # ||
|| # NOTES:															  # ||
|| # ---------------------------------------------------------------- # ||
|| # This JS seems to have issues with the !DOCTYPE tag.			  # ||
|| # If you wish to use this script on a temporary basis during the   # ||
|| # holidays, please remove the !DOCTYPE tag while in use then		  # ||
|| # put the !DOCTYPE tag back in place once use of script is done.   # ||
|| # ---------------------------------------------------------------- # ||
|| # CREDITS:														  # ||
|| # ---------------------------------------------------------------- # ||
|| # Permission given to use the script provided that this copyright  # ||
|| # remains intact at the top and bottom of this file.				  # ||
|| # ---------------------------------------------------------------- # ||
|| #      'Copyright(c) 2007 The iBB Group All rights reserved'       # ||
|| # ---------------------------------------------------------------- # ||
|| #################################################################### ||
\*======================================================================*/

function winter_snow ( )
{
	// START EDIT CONFIGURATION OF SCRIPT HERE \\
	this.snowcolor    = new Array ( '#AAAACC', '#DDDDFF', '#CCCCDD' ); // Set the colors for the snow. (Add as many as you like.)
	this.snowtype     = new Array ( 'Arial Black', 'Arial Narrow', 'Times', 'Comic Sans MS' );// Set the fonts for the flakes. (Add as many as you like.)
	this.snowletter   = '*'; // Set the letter that creates your snowflake (recommended: *)
	this.snowmax	  = 50; // Set the number of snowflakes (more than 30 - 60 not recommended)
	this.sinkspeed    = 0.9; // Set the speed of sinking (recommended values range from 0.3 to 2)
	this.snowmaxsize  = 45; // Set the maximal-size of your snowflaxes
	this.snowminsize  = 15; // Set the minimal-size of your snowflaxes
	this.snowingzone  = 1; // (Set the snowing-zone) (1)-all-over-snowing, (2)-left-side-snowing, (3)-center-snowing, (4)-right-side-snowing
	// END EDIT CONFIGURATION OF SCRIPT HERE \\

	// DO NOT EDIT ANYTHING BELOW THIS LINE \\
	this.snowua		  = navigator.userAgent.toLowerCase ( );
	this.opera 		  = this.snowua.match ( /opera/ );  
	this.ie5   		  = ( document.all && document.getElementById && !this.opera );
	this.ns6   		  = ( document.getElementById && !document.all );
	this.marginbottom = 0;
	this.marginright  = 0;
	this.timer 		  = 0;
	this.i_snow		  = 0;
	this.snow		  = new Array ( );
	this.x_mv		  = new Array ( );
	this.crds	 	  = new Array ( );
	this.lftrght 	  = new Array ( );
	this.snowzoneary  = new Array ( 1, 2, 3, 4 );
	var self		  = this;
	
	this.snow_init = function ( )
	{
		if ( this.ie5 || this.ns6 || this.opera )
		{
			if ( this.snow_in_array ( this.snowingzone, this.snowzoneary ) )
			{
				this.snow_flakes ( );
				window.onload = function ( )
				{
					self.snow_init_flakes ( );
				};
				window.onresize = function ( )
				{
					self.snow_dimensions ( );
				};
			}
			else
			{
				alert ( 'The "do_snow.snowingzone" setting is not correct. Please choose a correct setting and try again.' );
				console.log ( 'The "do_snow.snowingzone" setting is not correct. Please choose a correct setting and try again.' );
			}
		}
	};

	this.snow_init_flakes = function ( ) 
	{
		this.snow_dimensions ( );
		var snowsizerange = this.snowmaxsize-this.snowminsize;
		for ( i = 0; i <= this.snowmax; i++ ) 
		{
			this.crds[ i ] 				 	= 0;                      
			this.lftrght[ i ] 				= Math.random ( )*15;         
			this.x_mv[ i ] 				 	= 0.03+Math.random ( )/10;
			this.snow[ i ]					= document.getElementById ( 'snowflake_'+i );
			this.snow[ i ].style.fontFamily = this.snowtype[ this.snow_maker ( this.snowtype.length ) ];
			this.snow[ i ].size			 	= this.snow_maker ( snowsizerange )+this.snowminsize;
			this.snow[ i ].style.fontSize	= this.snow[ i ].size;
			this.snow[ i ].style.color		= this.snowcolor[ this.snow_maker( this.snowcolor.length ) ];
			this.snow[ i ].sink			 	= this.sinkspeed*this.snow[ i ].size/5;
			this.snow_zone ( );
			this.snow[ i ].posy 	  		= this.snow_maker ( 2*this.marginbottom-this.marginbottom-2*this.snow[ i ].size );
			this.snow[ i ].style.left 		= this.snow[ i ].posx;
			this.snow[ i ].style.top  		= this.snow[ i ].posy;
		}
		this.snow_move ( );
	};
	
	this.snow_move = function ( ) 
	{
		this.snow_dimensions ( );
		for ( i = 0; i <= this.snowmax; i++ ) 
		{
			this.crds[ i ] 	 	   	 += this.x_mv[ i ];
			this.snow[ i ].posy	   	 += this.snow[ i ].sink;
			this.snow[ i ].style.left = this.snow[ i ].posx+this.lftrght[ i ]*Math.sin ( this.crds[ i ] );
			this.snow[ i ].style.top  = this.snow[ i ].posy;
			if ( this.snow[ i ].posy >= this.marginbottom-2*this.snow[ i ].size || parseInt ( this.snow[ i ].style.left ) > ( this.marginright-3*this.lftrght[ i ] ) )
			{
				this.snow_zone ( );
				this.snow[ i ].posy = 0;
			}
		}
		this.timer = window.setTimeout ( 'snow.snow_move ( )', 50 );
	};

	this.snow_zone = function ( )
	{
		switch ( this.snowingzone )
		{
			case 4: // right-side-snowing
				this.snow[ i ].posx = this.snow_maker ( this.marginright/2-this.snow[ i ].size )+this.marginright/2;
			break;

			case 3: // center-snowing
				this.snow[ i ].posx = this.snow_maker ( this.marginright/2-this.snow[ i ].size )+this.marginright/4;
			break;

			case 2: // left-side-snowing
				this.snow[ i ].posx = this.snow_maker ( this.marginright/2-this.snow[ i ].size );
			break;

			case 1: // all-over-snowing
				this.snow[ i ].posx = this.snow_maker ( this.marginright-this.snow[ i ].size );
			break;
			
			default:
				return false;
			break;
		}
	};

	this.snow_in_array = function ( n, h )
	{
		if ( !h.length )
		{
			return false;
		}
		for ( var i = 0 ; i < h.length ; i++ )
		{
			if ( h[ i ] === n )
			{
				return true;
			}
		}
		return false;
	};

	this.snow_dimensions = function ( )
	{
		if ( this.ie5 || this.opera ) 
		{
			this.marginbottom = document.body.scrollHeight;
			this.marginright  = document.body.clientWidth;
		}
		else if ( this.ns6 ) 
		{
			if ( window.innerHeight && window.scrollMaxY )
			{
				this.marginbottom = window.innerHeight+window.scrollMaxY;
			}
			else if ( document.body.scrollHeight > document.body.offsetHeight )
			{
				this.marginbottom = document.body.scrollHeight;
			}
			else
			{
				this.marginbottom = document.body.offsetHeight;
			}
			this.marginright  = window.innerWidth;
		}
	};

	this.snow_maker = function ( num ) 
	{		
		var ran = Math.floor ( num*Math.random ( ) );
		return ran;
	};

	this.snow_flakes = function ( )
	{
		for ( i = 0; i <= this.snowmax; i++ ) 
		{
			var flake 			 = document.createElement ( 'span' );
			flake.id 			 = 'snowflake_'+i;
			flake.style.position = 'absolute';
			flake.style.top	 	 = '-'+this.snowmaxsize+'px';
			flake.innerHTML 	 = this.snowletter;
			document.body.appendChild ( flake );
		}
	};
};
var snow = new winter_snow ( );

/*======================================================================*\
|| #################################################################### ||
|| #      'Copyright(c) 2007 The iBB Group All rights reserved'       # ||
|| #################################################################### ||
\*======================================================================*/