var PAuthor = "Henry Schmieder | henry@thoughtomatic.co.uk";
function d()
{
	if( window["console"] && console.log ) {
		console.log.apply( console, arguments );
	}
}
window.addEvent( "domready", init );
if( !sy ) {
	var sy = {};
}
function init() {
	new sy.Application();
}

function PSingleton() {};
PSingleton.create = function()
{
	if (!$chk( this.$INSTANCE ) ) {
		var p = this.prototype;
		this.$INSTANCE = new this();
		if( $defined( p.initialize ) ) {
			p.initialize = function()
			{
				throw new Error("This class is a Singleton and can not be instantiated directly");
			}
		}
		if( $defined( p.initializeSingleton ) ) {
			if( arguments.length > 0 ) {
				this.$INSTANCE.initializeSingleton.apply( this.$INSTANCE, arguments );
			}else{
				this.$INSTANCE.initializeSingleton();
			}
		}else{
			if( arguments.length > 0 ) {
				throw new Error("You try to create singleton instance with arguments. There has to be initializeSingleton to take them");
			}
		}
	}
	return this.$INSTANCE ? this.$INSTANCE : null;
};
PSingleton.getInstance = PSingleton.create;
PSingleton.adapt = function( clazz )
{
	clazz.getInstance = PSingleton.getInstance;
	clazz.create = PSingleton.create;
};


sy.Application = new Class
({
	isReady: false,
	gridCanvas:null,
	bgImage:null,
	navigation:null,
	contentPane:null,
	contentWhy:null,
	contentContact:null,
	contentBlog: null,
	
	initialize:function()
	{
		//return;
		this.gridCanvas = new ui.GridCanvas();
		this.bgImage = new ui.BackgroundImage();
		this.navigation = new ui.Navigation();
		this.contentPane = new ui.ContentPane();
		this.contentCasestudies = new ui.ContentCasestudies();
		this.contentContact = new ui.ContentContact();
		this.contentWhy = new ui.ContentWhy();
		this.contentBlog = new ui.ContentBlog();

		var facade = ApplicationFacade.getInstance();
		facade.startup( this );

	}
});


/**
 * @extends Facade
 * @augments Facade
 */
var ApplicationFacade = new Class
({
	Extends: new Class( new Facade() ),
	
	initializeSingleton: function()
	{
		
	},
	
	startup: function( app )
	{
		this.sendNotification( NotificationList.STARTUP, app );
	},
	
	initializeController: function()
	{
		this.parent();
		this.registerCommand( NotificationList.STARTUP, StartupCommand );
		this.registerCommand( NotificationList.URLSTATE_CHANGED, URLChangedCommand );
		this.registerCommand( NotificationList.URLSTATE_INITIAL_CHANGED_NO_FRAGMENT, URLChangedInitialCommand );
		this.registerCommand( NotificationList.BROWSER_RESIZE, BrowserResizeCommand );
		this.registerCommand( NotificationList.GRID_READY, ApplicationInitReadyCommand );
		this.registerCommand( NotificationList.GRID_HOVER_ITEM, GridItemHoverCommand );
		this.registerCommand( NotificationList.URLSTATE_INITIAL_CHANGED_WITH_FRAGMENT, ApplicationInitReadyCommand );
		this.registerCommand( NotificationList.BACKGROUND_LOADED, BackgroundLoadedCommand );
		this.registerCommand( NotificationList.APPLICATION_INIT_READY_DEEPLINK_DATA_LOADED, ApplicationInitReadyCommand );
		this.registerCommand( NotificationList.INITIAL_DATA_LOADED, InitiaGridActionCommand );
		this.registerCommand( NotificationList.PANE_CLOSE, PaneCloseCommand );
		this.registerCommand( NotificationList.PANE_CLOSE_EXT, PaneCloseExtCommand );
		this.registerCommand( NotificationList.PANE_HIDE_COMPLETE, PaneHideCompleteCommand );
		this.registerCommand( NotificationList.TRANSITION_START, TransitionStartCommand );
		this.registerCommand( NotificationList.TRANSITION_END, TransitionEndCommand );

		//document.id("backgroundImage").erase("src");
		
	}
});
PSingleton.adapt( ApplicationFacade );









