if (typeof EnergyApps == "undefined"){EnergyApps = {App: {}};}
/**
 * @class EnergyApps.App
 * The central application singleton
 * @singleton
 * @namespace EnergyApps
 * @extends Publicis.Observable
 * @author Alexis Dorn
 *   
 */

EnergyApps.App = function (){
	return {
		/**
		 * this method is called on dom ready
		 */
		start: function (){
			//Starting Webfeature Manager
			EnergyApps.App.WebFeature = new EnergyApps.Webfeature.Manager();

			//Starting Concert Manager
			EnergyApps.App.Concert= new EnergyApps.Concert.Manager();
			
			//Starting EnergyApps.App.TabJumper
			EnergyApps.App.TabJumper.start();
			
			//Starting EnergyApps.Video.Manager
			EnergyApps.App.Video= new EnergyApps.Video.Manager();
			
			//Starting EnergyApps.Gallery.Manager
			if (EnergyApps.Gallery){
			EnergyApps.App.Gallery= new EnergyApps.Gallery.Manager();
			} 
		}
	}
}()

Publicis.onDomReady(EnergyApps.App.start.bindAsEventListener(EnergyApps.App));

/**
 * @class EnergyApps.App.WebFeature
 * Instance of EnergyApps.Webfeature.Manager
 * @singleton
 * @namespace EnergyApps.App
 * @author Alexis Dorn
 */

/**
 * @class EnergyApps.App.Concert
 * Instance of EnergyApps.Concert.Manager
 * @singleton
 * @namespace EnergyApps.App
 * @author Alexis Dorn
 */

/**
 * @class EnergyApps.App.DownloadArea
 * Instance of EnergyApps.DownloadArea.Panel
 * @singleton
 * @namespace EnergyApps.App
 * @author Alexis Dorn
 */

/**
 * @class EnergyApps.App.TabJumper
 * Listener for requested urls with hash patterns like #content=Description to activate given tabs or accordions
 * @singleton
 * @namespace EnergyApps.App
 * @author Alexis Dorn
 */

/**
 * @class EnergyApps.App.Video
 * Instance of EnergyApps.Video
 * @singleton
 * @namespace EnergyApps.App
 * @author Sebastian Sauer
 */

/**
 * @class EnergyApps.App.Gallery
 * Instance of EnergyApps.Gallery
 * @singleton
 * @namespace EnergyApps.App
 * @author Jonas Bach
 */

EnergyApps.App.TabJumper = function (){
	return {
		/**
		 * Starts the listener
		 */
		start: function(){
			var hashdata = window.location.hash.split("#content="), 
				i, 
				sprys,
				headline;
			sprys = Publicis.ThirdParty.Spry.SpryMgr.getAll();	
			if (hashdata.length == 2){
				headline = hashdata[1];
				if (sprys.length > 0) {
					for (i = 0; i < sprys.length; i++) {
						sprys[i].avtivatePanelByContent(decodeURIComponent(headline));
					}
				}else{
					window.location.hash = decodeURIComponent(window.location.hash);
				}
			}
			if (sprys.length > 0) {
				for (i = 0; i < sprys.length; i++) {
					sprys[i].addListener("tabclick", this.onSpryTabClick, this);
				}
			}
		},
		/**
		 * callback for tabclick event
		 * @private
		 */
		onSpryTabClick: function (panel, node, value){
			window.location.hash = "#content=" + encodeURIComponent(value);
		}
	}
}();

