var adrfusion = $.Class.create({

	ad: null,

	slide1: null,
	animation1: null,
	animation2: null,
	animation3: null,
	animation4: null,

	slide2: null,
	rfusion: null,
	zoom: null,

	slide3: null,
	button: null,
	logo: null,

	initialize: function( node ) {

		this.ad = node;

		this.slide1 = this.ad.children('.slide1');
		this.animation1 = this.slide1.children('.animation1');
		this.animation2 = this.slide1.children('.animation2');
		this.animation3 = this.slide1.children('.animation3');
		this.animation4 = this.slide1.children('.animation4');

		this.slide2 = this.ad.children('.slide2');
		this.rfusion = this.slide2.children('.rfusion');
		this.zoom = this.slide2.children('.zoom');

		this.slide3 = this.ad.children('.slide3');
		this.button = this.slide3.children('.button');
		this.logo = this.slide3.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.slide1.hide();
		mthis.animation1.children('img').hide();
		mthis.animation2.children('img').hide();
		mthis.animation3.children('img').hide();
		mthis.animation4.children('img').hide();
		mthis.animation1.children('img').css('top', '155px');
		mthis.animation2.children('img').css('top', '-155px');
		mthis.animation3.children('img').css('top', '155px');
		mthis.animation4.children('img').css('top', '-155px');

		mthis.slide2.hide();
		mthis.rfusion.children('img').hide();
		mthis.zoom.children('img').hide();
		mthis.zoom.children('img').css('top','0');

		mthis.slide3.hide();
		mthis.button.children('img').hide();
		mthis.logo.children('img').hide();

		mthis.animate(ads,next);

	},

	animate: function ( ads, next ) {

		var mthis = this;

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

			mthis.slide1.fadeIn(2000, function () {

				mthis.animation1.children('img').show();
				mthis.animation2.children('img').show();
				mthis.animation3.children('img').show();
				mthis.animation4.children('img').show();

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

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

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

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

								mthis.animation1.children('img').fadeOut(1500, function () {});
								mthis.animation2.children('img').fadeOut(1500, function () {});
								mthis.animation3.children('img').fadeOut(1500, function () {});
								mthis.animation4.children('img').fadeOut(1500, function () {});

								mthis.slide1.fadeOut(1500, function () {

									mthis.rfusion.children('img').fadeIn(2000, function () {});

									mthis.slide2.fadeIn(1500, function () {

										mthis.zoom.children('img').fadeIn(2000, function () {

											mthis.zoom.children('img').animate({top:-378},5000, function () {

												mthis.rfusion.children('img').fadeOut(2000, function () {});
												mthis.zoom.children('img').fadeOut(2000, function () {});
												mthis.slide2.fadeOut(2000, function () {

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

														mthis.button.children('img').fadeIn(2000, function () {

															mthis.logo.children('img').fadeIn(2000, function () {

																setTimeout(function(){

																	mthis.logo.children('img').fadeOut(2000, function () {});
																	mthis.button.children('img').fadeOut(2000, function () {});
																	mthis.slide3.fadeOut(3000, function () {

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

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

																		});

																	});


																},3000);

															});

														});

													});

												});

											});

										});

									});

								});

							});

						});

					});
				});

			});

		});


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

			mthis.slide1.fadeIn(5000, function () {

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

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

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

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

								mthis.slide1.fadeOut(5000, function () {



									mthis.slide2.fadeIn(2000, function () {});

									//mthis.rfusion.fadeIn(2000, function () {});

										mthis.zoom.fadeIn(4500, function () {

											mthis.zoom.children('img').animate({top:-378},5000, function () {

												mthis.slide2.fadeOut(1000, function () {

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

														mthis.button.fadeIn(2000, function () {

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

																setTimeout(function(){

																	mthis.logo.fadeOut(2000, function () {});
																	mthis.button.fadeOut(2000, function () {});
																	//mthis.slide3.fadeOut(2000, function () {});

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

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

																	});

																},3000);

															});

														});

													});

												});

											});

										});



								});

							});

						});

					});

				});

			});

		});
		*/

	}

});
