var adfusionmonitor = $.Class.create({

	ad: null,

	background: null,

	slide1: null,
	right: null,
	logo: null,

	initialize: function( node ) {

		this.ad = node;

		this.background = this.ad.children('.background');
		this.slide1 = this.ad.children('.slide1');
		this.right = this.slide1.children('.right');
		this.logo = this.slide1.children('.logo');

	},

	start: function ( ads, index ) {

		var mthis = this;
		var next = 0;

		if ( ads.length > 1 ) {

			next = Math.floor(Math.random()*ads.length);

			while (index === next) {

				next = Math.floor(Math.random()*ads.length);

			}

		}

		mthis.background.hide();
		mthis.logo.hide();
		mthis.right.hide();
		mthis.right.css('top','-165px');
		mthis.right.css('width','442px');
		mthis.right.css('opacity','0');
		mthis.right.children('img.big').hide();
		mthis.right.children('img.big').css('top','-165px');
		mthis.right.children('img.small').hide();

		mthis.animate(ads,next);

	},

	animate: function ( ads, next ) {

		var mthis = this;

		mthis.background.fadeIn(1000,function(){});

		mthis.ad.fadeIn(1000,function(){

			mthis.background.children('img').animate({top:'-737px'},3000,function(){});

			mthis.right.show();

			mthis.right.animate({top:0,opacity:1},1500,function(){

				mthis.right.children('img.big').fadeIn(1500,function(){

					mthis.right.children('img.big').animate({top:0},1500,function(){

						mthis.right.children('img.big').fadeOut(1500,function(){});

						mthis.right.children('img.small').fadeIn(4000,function(){});

						mthis.background.children('img').animate({top:0},3000,function(){});

						mthis.right.animate({width:'340px'},2500,function(){

							mthis.logo.fadeIn(3000,function(){

								setTimeout(function(){

									mthis.logo.fadeOut(2000,function(){});
									mthis.right.fadeOut(2000,function(){});
									mthis.background.fadeOut(2000,function(){});

									mthis.ad.fadeOut(2000,function(){

										ads[next].start(ads,next);

									});

								},5000);


							});

						});

					});

				});

			});

		});

	}

});
