window.addEvent( "domready", function() { new MA_Home(); }  );

(function() {
	MA_Home = new Class
	({
		f:null,
		loadCount:2,
		
		initialize: function()
		{
			if( !Browser.Features.Touch ) {
				this.f = new FitImage( "images/home/home_1.jpg", {startupDelay:1200, injectElement:"bgImageHolder"} );
				this.f.addEvent( "inject", this.loadNext.bind(this) );
				document.id("homeInfoblock").set("tween", {duration:2000} );
				this.fadeUp.delay( 5200, this );
			}else{
				 MA_Touch.orienter.addEvent( "orientationchange" , this.orientationChangeListener.bind(this) );
			}
			new MA_Home_Cop();
		},
		orientationChangeListener: function( orientation )
		{
			this.f = new FitImage( "images/home/home_2.jpg", { yManual: orientation == "landscape" ? 992 : 1400, xManual:orientation == "landscape" ? 1500 : 2116, yShiftManual:orientation == "landscape" ? -360 : -140, xShiftManual:orientation == "landscape" ? -200 : -500, injectMobileElement:document.id("wrapper") } );
			this.fadeUp.delay( 2200, this );
			new MA_Footer_Touch( window.getSize().y - 100 );
		},
		loadNext: function()
		{
			this.f.removeEvents( "inject" );
			if( !Browser.ie ) {
				this.f = new FitImage( "images/home/home_" + this.loadCount + ".jpg", {injectElement:"bgImageHolder", injectPosition:"bottom", startupDelay:1000 });
				this.loadCount++;
				if( this.loadCount == 3 ) {
					return;
				}
				this.f.addEvent( "inject", this.loadNext.bind(this) );
			}else{
				this.tridentDel.delay( 200, this );
			}

		},
		fadeUp: function()
		{
			document.id("homeInfoblock").tween( "opacity", 1 );
		},
		tridentDel: function()
		{
			this.f = new FitImage( REMOTE_BASE + "images/home/home_" + this.loadCount + ".jpg", {injectElement:"bgImageHolder", injectPosition:"bottom", triggerAlt:true });
			this.loadCount++;
			if( this.loadCount == 3 ) {
				return;
			}
			this.f.addEvent( "inject", this.loadNext.bind(this) );
		}
	});

	MA_Home_Cop = new Class
	({
		initialize: function()
		{
			["Cop2", "Cop3", "Cop4"].each( function( id ) {
				var el = document.id( id );
				el.addEvent( "click", this.clickListener.bind(this) );
			}.bind(this));
		},
		clickListener: function( e )
		{
			e.stop();
			var t = document.id(e.target);
			if(  t.get("tag") != "a" ) {
				t = t.getParent("a");
			}
			var id = t.get("id");
			id = "home" + id;

			$$(".homeCop").each( function(el) {
				el.setStyle("display", "none");
			});

			document.id( id ).setStyle( "display", "block" );
		}
	});
	
})();

