function cookies_action() {
    this.current = 0;
    this.cookname = 'unknown';

    this.set_name = function( cname ) {
        this.cookname = cname;
    }

    this.get_current = function() {
        if ( !this.current ) {
            this.current = this.get( this.cookname );

            if ( !this.current ) {
                this.current = 0;
            }
        }
        return parseInt( this.current );
    }

    this.set = function( name, value, days ) {
        var date = new Date();
        date.setTime( date.getTime() + days * 86400000 );
        document.cookie =
            name + '=' + value + '; ' +
            'expires=' + date.toGMTString() + '; ' +
            'path=/';
    }

    this.get = function( name ) {
        var re = new RegExp( '\\s*' + name + '=' );
        var cookies = document.cookie.split(';');
        for( var i = 0; i < cookies.length; i++ ){
            var c = cookies[i];
            if ( re.test( c ) )
                return c.replace( re, '' );
        }
        return '';
    }

    this.set_next = function( count ) {
        if ( count < ( this.get_current() + 1 ) ) {
            this.current = 0;
        }
        else {
            this.current++;
        }
        this.set( this.cookname, this.current, 10 );
    }
}


function get_informer( infpl ) {                                                                                                                         
    if ( ! infpl.length ) {
        return false;
    }
    var num = Math.floor( Math.random() * infpl.length );
    return infpl[ num ];
}


function tbl_create( infarray ) {
    var tbl = document.createElement('table');
    var tblBody = document.createElement('tbody');
    var row = document.createElement('tr');
    row.align = 'center';

    for ( var i = 0; i < infarray.length && i < 4; i++ ) {
        row.appendChild( cell_create( get_informer( infarray[i] ) ) );
    }

    tblBody.appendChild( row );
    tbl.appendChild( tblBody );
    tbl.border = 0;
    tbl.cellSpacing = 0;
    tbl.cellPadding = 1;
    tbl.style.backgroundColor = "#F7FAEF";

    return tbl;
}

function cell_create( el ) {
    var cell = document.createElement('td');

    cell.appendChild( href_create( el ) );
    cell.align = 'center';
    cell.width = '25%';

    return cell;
}

function href_create( el ) {
    var href = document.createElement('a');
    href.href = el.url;
    href.title = el.text;

    var br = document.createElement('br');

    var img = document.createElement('img');
    img.src = el.img;
    img.alt = el.text;
    img.width = 100;
    img.height = 67;

    var text = document.createTextNode( el.text );

    href.appendChild( img );
    href.appendChild( br );
    href.appendChild( text );

    text = null; img = null; br = null;

    return href;
}




rotatorList.push( AutonewsInformersArray );
rotatorList.push( RealtyInformersArray );
rotatorList.push( LfInformersArray );

var rotatorcookact = new cookies_action();
rotatorcookact.set_name( 'rotator' );
rotatorcookact.set_next( rotatorList.length - 1 );
var cookieVal = rotatorcookact.get_current();

var idiv = document.getElementById( 'informersdivcenter' );
idiv.appendChild( tbl_create( rotatorList[ cookieVal ] ) );

cookieVal = null; rotatorcookact = null;
