/* need jquery and cooquery */

bg = new Array(11);
bg[0]  = 'Dark-Blue.jpg';
bg[1]  = 'black_background_3.jpg';
bg[2]  = 'black-background.jpg';
bg[3]  = 'Black-Background [DesktopNexus.com].jpeg';
bg[4]  = 'Black Background Leather - 2560x1600 by Freeman.jpg';
bg[5]  = 'Black Background Metal Hole very small - 2560x1600 by Freeman.jpg';
bg[6]  = 'Leopard Edition Apple Dark Background (1).jpg';
bg[7]  = '7245ad0605b84683b7ea29ed8f201d90.jpg';
bg[8] = 'Mac Apple DEsktop Intel Core 2 Duo.jpg';
bg[9] = 'Black Background wood 3 - 2560x1600 by Freeman.jpg';
bg[10] = 'Classique-Black [DesktopNexus.com].jpg';

/*
body
{
background: #3f7f9c url(images/background/bg_multicolor_abstract.png) center top repeat-x;
}
*/

function randombg() {
    var EJB_bgImage = $.readCookie('EJB_bgImage');
    //[testing]// 
    EJB_bgImage = null;
    /*
    if( EJB_bgImage )
    alert( "Hey! This cookie exists, and its value is : \n" + EJB_bgImage );
    else
    alert( 'This cookie \'does not exist\'!' );
    */

    //alert(EJB_bgImage);
    if (EJB_bgImage == null) {
        var index = Math.floor(Math.random() * bg.length);
        //[testing]	index = 49;
        var bg_Image = bg[index];
        //alert(bg_Image);
        //alert(bg_Image.search("bg_"));
        //if (typeof (bg_Image) == 'undefined') bg_Image = "bg_Clouds.jpg";
        if (bg_Image.search(".jpg") == -1) bg_Image = "black-background.jpg";
        
        bg_Image = "black_background_3.jpg";
        
        /*
        tmp = '<style type="text/css" media="screen">'
        + '  body{ background: #000000 url(images/background/' + bg_Image + ') center top no-repeat; }'
        + '</style>';
        */
        tmp = '<img src="images/background/' + bg_Image + '\" alt=\"\" id=\"bg\" />';
        //alert(tmp);
        var cookie = $.setCookie('EJB_bgImage', bg_Image, {      // set cookie
            // duration: 1,                                             // 1 day
            // duration: 0.1666666666666667,                            // 6 hrs
            // duration: 0.2,                                           // 5 hrs
            duration : 0.041666666666666666666666666666667,             // in day unit = 1 hr  
            // duration : 0.020833333333333333333333333333333,          // in day unit = 0.5 hr
            path: '',
            domain: '',
            secure: false
        });
        /*
        if (cookie)
        alert('Cookie created!');
        else
        alert('Oops, an error occurred!');
        */
        //alert(index);
    }
    else {
        /*
        tmp = '<style type="text/css" media="screen">'
        + '  body{ background: #000000 url(images/background/' + EJB_bgImage + ') center top no-repeat; }'
        + '</style>';
        */
        tmp = '<img src="images/background/' + EJB_bgImage + '\" alt=\"\" id=\"bg\" />';
    }
    document.write(tmp);
    //alert(tmp);

}

randombg();

