
/*
the myApp class which is the center of our library
it contains important variables that are used in other methods
and the method to load on domready
@author:ben
*/

function myApp(){
	//all the buttons from the application
	this.buttons = new Array();

	/*
	//we increment an array of code to execute once the dom is fully loaded
	@author:ben
	*/
	this.onDOMready = function(codePassed) {
		//register code in the domready array
		myGlobals.DOMcodeToFire.push(codePassed);
		//if it is the first time we come there we can go to the browserDOMready
		if(myGlobals.DOMfctset===false)	this.browserDOMready();
	}//endfct


	/*
	function to help us detect which browser we are on and use a specific method to load the code on domready
	@author:ben
	*/
	this.browserDOMready = function(){
		//we have been to that function so we flag it
		myGlobals.DOMfctset=true;

		//to know if the DOM is loaded on internet explorer
		//this is conditional compilation on internet explorer
		//we flag our entrance into that crazy conditional compilation thing
		myGlobals.flagIE=false;
		/*@cc_on @*/
		/*@if (@_win32)
			myGlobals.flagIE=true;
			var proto = "src='javascript:void(0)'";
			if (location.protocol == "https:") proto = "src=//0";
			document.write("<scr"+"ipt id=__ie_onload defer " + proto + "><\/scr"+"ipt>");
			var script = document.getElementById("__ie_onload");
			script.onreadystatechange = function() {
			    if (this.readyState == "complete") {
			        myGlobals.DOMready();
			    }
			};
		/*@end @*/

		//if we didn't flagIE that means we need for the winning browser
		if(!myGlobals.flagIE){
			//to know when the DOM is loaded on mozilla and opera 9
			if (document.addEventListener) {
				document.addEventListener("DOMContentLoaded", myGlobals.DOMready, null);
			}else{
				//identify safari
				if (/WebKit/i.test(navigator.userAgent)) {
					var _timer = setInterval(function() {
						if (/loaded|complete/.test(document.readyState)) {
							clearInterval(_timer);
							myGlobals.DOMready();
						}//endif
					}, 10);
				}else{
					//if it is another browser we load it in the window on load
	   				window.onload = myGlobals.DOMready;
				}//endif
			}//endif
		}//endif
	}//endfct
}//endclass


//the object that we are gonna use to manage all kind of javascript
var myLib = new myApp();




/*
the myGlobals object
it contains important variables that are used in other methods
@author:ben
*/
var myGlobals = {

	lang : 'en',
	subsection : '',
	DOMfctset : false,//fct to tell that we already set the dom function
	DOMcodeToFire : [],//array of function containing js code to fire on DOM loaded

	//fire all the code which should be run on DOMready
	DOMready : function() {
		//execute all the functions added onDOMready
		for (i = 0;i < myGlobals.DOMcodeToFire.length;i++)	myGlobals.DOMcodeToFire[i]();
	}//endfct

};//endobject
