var snowflakes = new Array();

function snow() {
    body = document.getElementsByTagName( 'body' )[ 0 ];
    for ( i = 0; i < 20; i = i + 1 ) {
        x = Math.round( Math.random() * (document.clientWidth ? document.clientWidth : document.body.clientWidth ) - 80 ) + 40;
        y = Math.round( Math.random() * (document.clientHeight ? document.clientHeight : document.body.clientHeight ) - 80 ) + 40;
        child = document.createElement( 'div' );
        image = document.createElement( 'img' );
        image.setAttribute( 'src', '/conf/styles/ru/snow/snowflake.gif' );
        child.appendChild( image );
        child.id = 'snowflake' + i;
        child.style.position = 'absolute';
        child.style.top = y;
        child.style.left = x;
        child.style.zIndex = 9999;
        body.appendChild( child );
        snowflakes[ i ] = [ x, y, 0 ];
    }
    setInterval( 'updateSnowflakes();', 100 );
}

function updateSnowflakes() {
    for ( i = 0; i < snowflakes.length; i = i + 1 ) {
        snowflake = snowflakes[ i ];
        snowflake[ 1 ] = snowflake[ 1 ] + Math.round( Math.random() * 5 );
        snowflake[ 2 ] = snowflake[ 2 ] + 0.3;
        if ( snowflake[ 1 ] > ( (document.clientHeight ? document.clientHeight : document.body.clientHeight ) - 20 ) ) {
            snowflake[ 0 ] = Math.round( Math.random() * (document.clientWidth ? document.clientWidth : document.body.clientWidth ) - 40 ) + 20;
            snowflake[ 1 ] = 0;
            snowflake[ 2 ] = 0;
        }
        e = document.getElementById( 'snowflake' + i );
        e.style.top = snowflake[ 1 ];
        e.style.left = snowflake[ 0 ] + Math.cos( snowflake[ 2 ] ) * ( i + 2 );
    }
}

