try {
	document.execCommand('BackgroundImageCache', false, true);
} catch(e) {}
	
var Pager = Class.create( {
  initialize: function( page_count ) {
    this._active = null;
    this._page_count = page_count;
  },
	next: function() {
		this.setActive( ( this._active + 1 ) % this._page_count, 'next' );
	},
	setActive: function( page, origin ) {
		this._active = page;
    document.fire( "pager:changed", { active: page, origin: origin } );
	}
});


var Pages = Class.create( {
  _pages: null,
  _count: 0,
  
  initialize: function( container ) {
    this._pages = container.childElements();
    i = 0;
    this._pages.each( function( p ) {
			p.absolutize();
      if( !i++ ) {
        this._active = p;
      } else {
        p.hide();
      }
    }.bind( this ) );

    this._count = i;
  },
  
  getCount: function() {
    return this._count;
  },
  
  show: function( page_nr ) {
    page = this._pages[page_nr - 1];
		active = this._active;
		active.style.zIndex = 100;
		page.style.zIndex = 90;
		page.show();
    new Effect.Fade( active, { duration: 2, afterFinish: function() {
     		this._active = page;
			}.bind(this)
		});
  }
});

var onload_actions = {
	'page2': function()
	{
		//prepare pages
	 	if( images && images.length > 1 ) {
			ul = new Element( 'ul', { id: 'moodlist' } );

			images.each( function( img ) {
				if( img ) {
					ul.appendChild( new Element( 'li', { 'class': 'mooditem' } ).update( img ) );					
				}

			} );

			$('mood_image').update( ul );
			var pages = new Pages( ul );
			var pager = new Pager( pages.getCount() );
			
			
			var pe = new  PeriodicalExecuter( function( pe ) {
				pager.next();
			}, 6 );

			document.observe("pager:changed", function(event) {
    		pages.show( event.memo.active + 1 );
  		} ); 


		}
		
	}
};

document.observe( 'dom:loaded', function() {
	body_id = document.body.id;
	onload_actions['page2']();
} );