if(typeof(pengag.core20)=="undefined")
{
	pengag.core20 = {};
	
	//This area can be used to configure global options
		
	
	// This sets the version used of PengLoader.swf and other resources not versioned by them self
	pengag.core20.versionPrefix = "v2.0/";
	pengag.core20.versionSuffix = "-2.0";
	
	/**
	 * Instantiates a PengLoader object. ClientObject must be a string representation of a global accesible 
	 * Javascript Variable to this object.
	 */
	pengag.core20.CPengLoader = function(homePath)
	{
		var my = this;
		
		this.basePath = homePath; 
		pengag.warn("Home path set in loader: " + homePath);
		
		this.loadedModules = new Array();
		var pengLoader;
		var isIE;
		var elementId;
		
		this.versionInfoObject;
		
		/**
		 * Represents the global access path to this
		 */
		this.clientObject = null;
		this.preventCaching = "always";
		
		/**
		 * Loads the PengLoader.swf form the swfUrl into the HTML with the specified ID.
		 */
		this.initPeng = function (id, width, height, version, skinUrl)
		{
			elementId = id;
			
			if(pengag.core20.checkVersion(version))
			{
				pengag.info("[peng] getting player from " + my.basePath+pengag.core20.versionPrefix+"PengLoader.swf?nocache=" + (new Date()).getTime());
				var att = { data:(my.basePath+pengag.core20.versionPrefix+"PengLoader.swf?nocache=" + (new Date()).getTime()), width:width, height:height, bgcolor:"#FFFFFF" };
		        var par = { allowScriptAccess: "always", flashvars:("clientObject=" + my.clientObject + "&preventCaching=" + my.preventCaching + "&skinUrl=" + skinUrl)};
		        var idR = id;
		        pengLoader = swfobject.createSWF(att, par, idR);
		        
				if (navigator.appName.indexOf("Microsoft") != -1)
				{
					isIE = true;
				}
				else
				{
					isIE = false;
				}
			}
			else
			{
				var element = $("#"+elementId);
				var p = $("p", element);
				var html = $(p).html();
				html = html + "<br/>Sie benötigen mindestens Flash Player " + version + ".<br/>" +
					"<a href='http://www.adobe.com/go/DE-H-GET-FLASH'>Hier klicken</a> um den Flash Player herunter zu laden.";
				$(p).html(html);
			}
					
			
		}
		
		this.createModule = function()
		{
			var cpmc = new pengag.core20.CPengModuleClient();
			my.loadedModules.push(cpmc);
			cpmc.clientObject = my.clientObject + ".loadedModules[" + (my.loadedModules.length - 1) + "]";
			cpmc.pengLoader = pengLoader;
			return cpmc;
		}
		
		this.callFunction = function(id, parameters)
		{
			var functionName = String(id);
			if(typeof(parameters) == "undefined")
			{
				return pengLoader[functionName]();
			}
			else
			{
				return pengLoader[functionName](parameters);
			}
		}
		
		this.getVersionInfoObject = function()
		{
			return my.versionInfoObject;
		}
		
		this.internalLoaderReady = function()
		{
			pengag.warn("INTERNAL LOADER READY. basePath: " + my.basePath);
			pengLoader["setBasePath"](my.basePath);
			my.loaderReady();
		}
		
		/**
		 * This function is called by PengLoader when he's ready. Can be overwritten.
		 */
		this.loaderReady = function()
		{
			
		}
		
		/**
		 * @private
		 * gets the document element with the flash content
		 */
		function getPlayer(elementName) 
		{
			if (navigator.appName.indexOf("Microsoft") != -1) 
			{
				return window[elementName];
			}
			else
			{
				return document[elementName];
			}
		}
	}
	
	/**
	 * Class for communication with PengModules
	 */
	pengag.core20.CPengModuleClient = function()
	{
		var my = this;
		/**
		 * @private
		 * ID assinged to the Module by PengLoader
		 */
		this.pengId = "";
		
		/**
		 * Represents the global access path to this
		 */
		this.clientObject = "";
		
		/**
		 * The Loader which created this Module
		 */
		this.pengLoader = null;
		
		/**
		 * @private
		 * Called by the Module when it's ready
		 */
		this.internalModuleReady = function(uid)
		{
			my.pengId = uid;
			my.moduleReady();
		}
		
		/**
		 * This function is called when PengLoader finishes loading the Module.
		 */
		this.moduleReady = function()
		{
			
		}
		
		/**
		 * Loads the Module with the specified name and version, client object must be a global path to this Object.
		 */
		this.loadModule = function(id, majorVersion, minorVersion, position)
		{
			if(typeof(position) == "undefined")
			{
				my.pengLoader.loadModule(id, my.clientObject, majorVersion, minorVersion, "center");
			}
			else
			{
				my.pengLoader.loadModule(id, my.clientObject, majorVersion, minorVersion, position);
			}
		}
		
		/**
		 * Calls a function of the Module
		 */
		this.callFunction = function(id, parameters)
		{
			var functionName = String(my.pengId + "_" + id);
			if(typeof(parameters) == "undefined")
			{
				return my.pengLoader[functionName]();
			}
			else
			{
				return my.pengLoader[functionName](parameters);
			}
		}
	}
	
	pengag.core20.checkVersion = function(targetVersion)
		{
			var target = targetVersion.split(".");
			var targetMajor = target[0];
			var targetMinor = target[1];
			var targetRelease = target[2];
			
			var present = swfobject.getFlashPlayerVersion();
			var presentMajor = present.major;
			var presentMinor = present.minor;
			var presentRelease = present.release;
			
			pengag.log("[peng] player version is " + presentMajor + "." + presentMinor + "." + presentRelease);
			pengag.log("[peng] player version needed: " + targetMajor + "." + targetMinor + "." + targetRelease);
			
			if (presentMajor < targetMajor)
			{
				pengag.error("[peng] player version is to old");
				return false;
			}
			if (presentMajor == targetMajor && presentMinor < targetMinor)
			{
				pengag.error("[peng] player version is to old");
				return false;
			}
			if (presentMajor == targetMajor && presentMinor == targetMinor && presentRelease < targetRelease)
			{
				pengag.error("[peng] player version is to old");
				return false;
			}
			else
			{
				pengag.info("[peng] player version ok");
				return true;
			}
		}
}

//The purpose of the following script is to circumvent a bug in the Flex Compiler depending on the Browser History integration
if(typeof(BrowserHistory)=="undefined")
{
	BrowserHistoryUtils = {addEvent: function(elm, evType, fn, useCapture){return true;}}
	BrowserHistory = (function() {
		function getHistoryFrame(){return null;}
	    function getAnchorElement(){return null;}
	    function getFormElement(){return null;}
	    function getRememberElement(){return null;}
	    function getPlayer(id){return undefined;}
	    function getPlayers(){return {};}
		function getIframeHash(){}
	    function getHash(){return '';}
	    function setHash(hash){}
	    function createState(baseUrl, newUrl, flexAppUrl){}
	    function addHistoryEntry(baseUrl, newUrl, flexAppUrl){}
	    function _storeStates(){}
	    function handleBackButton(){}
	    function handleForwardButton(){}
	    function handleArbitraryUrl(){}
	    function checkForUrlChange(){}
	    function addAnchor(flexAppUrl){}
		return {
	        historyHash: null,
	        backStack: function(){return null;},
	        forwardStack: function(){return null;},
	        getPlayer: null,
	        initialize: function(src){},
	        setURL: function(url){},
	        getURL: function(){return '';},
	        getTitle: function(){return '';},
	        setTitle: function(title){},
	        setDefaultURL: function(def){},
	        setBrowserURL: function(flexAppUrl, objectId){},
	        browserURLChange: function(flexAppUrl){},
	        getUserAgent: function(){return '';},
	        getPlatform: function(){return '';}
	    }
	})();
	function setURL(url){}
	function backButton(){}
	function forwardButton(){}
	function goForwardOrBackInHistory(step){}
}
