var ApplicationProxy = new Class
({
	Extends: Proxy,
	app:null,
	
	initialize: function( app )
	{
		this.parent( ApplicationProxy.NAME, app );
	},

	/**
	 * @return sy.Application
	 */
	getApplication: function()
	{
		return this.data;
	}
	
});
ApplicationProxy.NAME = "ApplicationProxy";




var GridProxy = new Class
({
	Extends: Proxy,
	totalImages:0,
	loadListClosure:null,
	images:null,

	initialize: function( imageBaseNames )
	{
		this.parent( GridProxy.NAME, imageBaseNames );
		this.totalImages = imageBaseNames.length;
		this.loadListClosure = this.loadCompleteListener.bind(this);
	},
	
	onRegister: function()
	{
		var imageBaseNames = this.data;
		var urls = [];
		for( var i=0; i<this.totalImages; i++ )
		{
			var img = imageBaseNames[i];
			urls.push( 'images/grid/' + img + ".jpg" );
		}

		this.images = Asset.images( urls, { onComplete:this.loadListClosure }  );
	},
	loadCompleteListener: function()
	{
		this.sendNotification( NotificationList.GRID_IMAGES_LOADED, this.images );
	}
});
GridProxy.NAME = "GridProxy";


var BgProxy = new Class
({
	Extends: Proxy,

	currentLoadedImageA:null,
	lastLoadedUrl:null,
	
	initialize: function()
	{
		this.parent( BgProxy.NAME );
	},

	load: function( url )
	{
		if( url == this.lastLoadedUrl ) {
			return;
		}
		this.currentLoadedImageA = new Asset.images( url, { onComplete: this.loadCompleteListener.bind(this) } );
		this.lastLoadedUrl = url;
	},
	
	loadCompleteListener: function()
	{
		this.sendNotification( NotificationList.BACKGROUND_LOADED, this.currentLoadedImageA[0] );
	}

});
BgProxy.NAME = "BgProxy";


var NavigationProxy = new Class
({
	Extends: Proxy,
	activeMenPt:null,
	initialize: function()
	{
		this.parent( NavigationProxy.NAME );
	},
	setActiveMenPt: function( nicename )
	{
		this.activeMenPt = nicename;
	},
	getActiveMenPt: function()
	{
		return this.activeMenPt;
	}
});
NavigationProxy.NAME = "NavigationProxy";



var CasestudyProxy = new Class
({
	Extends: Proxy,
	url:null,
	vos:null,
	forDeeplink:false,
	
	initialize: function( url, forDeeplink )
	{
		this.parent( CasestudyProxy.NAME );
		this.forDeeplink = forDeeplink;
		this.url = url;
		this.vos = {};
	},
	/**
	 *
	 * @param nicename
	 */
	getVoByNicename: function( nicename )
	{
		if( this.vos[nicename] ) {
			return this.vos[nicename];
		}
	},
	/**
	 *
	 * @param {String} tileId
	 * @return CasestudyProxy 
	 */
	getVoByTileTriggerName: function( tileId )
	{
		/**
		 * @type CaseStuduyVo
		 */
		var vo;
		for( var i in this.vos )
		{
			vo = this.vos[i];
			if( vo.triggerId == tileId ) {
				return vo;
			}
		}
		return null;
	},
	onRegister: function()
	{
		this.load( this.url );
	},
	load: function( url )
	{
		new Request.JSON( { url:url, onComplete:this.loadCompleteListener.bind(this) }  ).get();
	},
	loadCompleteListener: function( res )
	{
		/**
		 * @type CaseStuduyVo
		 */
		var vo;
	
		for( var i=0; i < res.casestudy.length; i++ )
		{
			var item = res.casestudy[i];
			vo = new CaseStuduyVo();
			vo.navTitle = item.navTitle;
			vo.title = item.title;
			vo.gridTitle = item.gridTitle.replace( "#", "<br />");
			vo.nicename = item.nicename;
			vo.textP1 = item.text.p1;
			vo.textP2 = item.text.p2;
			vo.textP3 = item.text.p3;
			vo.videoURL = item.media.video ? item.media.video.embedurl : null;
			vo.gallery = item.media.gallery.image; // Arrray of single field objects [n].basename
			vo.triggerId = item.tileTrigger;

			if( vo.gallery instanceof Array && vo.gallery.length ){
				item.media.gallery.image.each( function( img ) {
					img.url = "images/casestudies/" + vo.nicename + "/" + img.basename + ".jpg";
				});
			}

			this.vos[vo.nicename] = vo;
		}
		this.__notify( res );
	},
	__notify: function( res )
	{
		this.sendNotification( this.forDeeplink ? NotificationList.APPLICATION_INIT_READY_DEEPLINK_DATA_LOADED : NotificationList.INITIAL_DATA_LOADED );
	}
});
CasestudyProxy.NAME = "CasestudyProxy";


/*
var CaseStudyDeeplinkStartProxy = new Class
({
	Extends: CasestudyProxy,
	
	initialize: function( url )
	{
		this.parent( url, CaseStudyDeeplinkStartProxy.NAME );
	},
	__notify: function( res )
	{
		this.sendNotification( NotificationList.APPLICATION_INIT_READY_DEEPLINK_DATA_LOADED );
	}
});
CaseStudyDeeplinkStartProxy.NAME = "CaseStudyDeeplinkStartProxy";
*/




var CaseStuduyVo = new Class
({
	title:null,
	navTitle:null,
	gridTitle:null,
	nicename:null,
	textP1:null,
	textP2:null,
	textP3:null,
	videoURL:null,
	gallery:null,
	triggerId:null
});
