﻿/**
*	AbstractSiteScreen
*/
var AbstractSiteScreen = AbstractScreen.extend(
	{
		/**
		*   init
		*
		*   Constructs the screen
		*
		*	@param	t - type string
		*	@param	m - manager instance
		*	@param	h - view holder instance 
		*/
		init: function(t, m, h)
		{
			//alert( t + " initiating..." );
			
			this._super( t, m, h );
			
			// define internal instance
			var obj = this;
			
			// listen to any applicable model events
			$( this.manager.getCore() ).bind( 'onAssignedAdsReceived', function( evt, data ) { obj.updateComponents( evt, data ); } );
		},
		
		/**
		*   setup
		*
		*   Sets up the view instance
		*
		*	@param	o - forum owner id
		*/
		setup: function()
		{
			//alert( this.getType() + " setting up" );
			
			// call super last once all setup is complete
			// this will init the screen & build all the views
			this._super();
		},
		
		/**
		*   build
		*
		*   Builds the view
		*/
		build: function()
		{
			//alert( this.getType() + " building" );
			
			// load all abstract page elements
			this._super();
		},
		
		/**
		*   buildComponents
		*
		*   Builds the screen components
		*/
		buildComponents: function()
		{
			//alert( this.type + " building components" );
			
			// @@ ad placement : 1
			var pData1 = new PlacementData();
				pData1.setPlacementId( 1 );
				pData1.setWidth( 468 );
				pData1.setHeight( 60 );
				pData1.setDirectory( "468x60" );
			this.ad1 = new Advert( this.getManager(), "div#comp_ad_1" );
			this.ad1.setup( pData1 );
			this.manager.getControl( "AdvertsControl" ).getAssignedAds( pData1.getPlacementId() );
			
			// @@ ad placement : 2
			var pData2 = new PlacementData();
				pData2.setPlacementId( 2 );
				pData2.setWidth( 120 );
				pData2.setHeight( 600 );
				pData2.setDirectory( "120x600" );
			this.ad2 = new Advert( this.getManager(), "div#comp_ad_2" );
			this.ad2.setup( pData2 );
			this.manager.getControl( "AdvertsControl" ).getAssignedAds( pData2.getPlacementId() );/**/
			
			// build abstract components
			this._super();
		},
		
		/**
		*   updateComponents
		*
		*   Updates the screen components
		*
		*	@param	evt - event
		*	@param	data - data object
		*/
		updateComponents: function(evt, data)
		{
			//alert( "updating components : " + evt.type + " : " + data );
			
			this.ad1.update( evt.type, data );
			this.ad2.update( evt.type, data );
			
			// update abstract components
			this._super(evt, data);
		}
	}
);