




function defineModule(moduleName) {
	modules = moduleName.split(".");
	var parentModule = window;
	var parentModuleName = "window";
	for ( var i = 0; i < modules.length; i++) {
		var moduleName = modules[i];
		if (typeof(eval(parentModuleName+"."+moduleName))=="undefined") {
			parentModule[moduleName]={};
		}
		parentModule = parentModule[moduleName];
		parentModuleName= parentModuleName+"."+moduleName
	}
}

defineModule("LaRoueVerte.JsLibs");

LaRoueVerte.JsLibs.loadedScripts = [];
LaRoueVerte.JsLibs.log = function(msg) {if (typeof(window.console)!="undefined") window.console.log(msg); };

if (typeof(window.contextPath)!='undefined')
	LaRoueVerte.contextPath = window.contextPath;

var jQueryUrl = LaRoueVerte.contextPath + "/common/javascript/jquery-1.3.2.min.js";

LaRoueVerte.ModulesLoader = (function(jQueryUrl) {
	
	var loaders = [];
	
	var bindToScope = function(scope, fn) {
		return function() {
			return fn.apply(scope, arguments);
		}
	}
	
	var loadJavascript = function(url, scriptLoaded, scriptNotLoaded) {
		var headID = document.getElementsByTagName("head")[0];         
		var newScript = document.createElement('script');
		newScript.type = 'text/javascript';
		
	    var browserName=navigator.appName;
		
	    if (scriptLoaded) {
	        if(browserName == "Netscape") {
	        	newScript.onload = scriptLoaded;
	        } else if(browserName == "Microsoft Internet Explorer") {
		         // IE 6 & 7
		         newScript.onreadystatechange = function() {
			         if (this.readyState == 'loaded' || this.readyState == 'complete') {
			        	 newScript.onreadystatechange=null;
			        	 newScript.onload=null;
			        	 scriptLoaded();
			         }
		         }
		    }
		}		 
		
		if (scriptNotLoaded) {
			newScript.onerror = scriptNotLoaded;
		}
		newScript.src = url;
		headID.appendChild(newScript);
	};
	
	var loadOnceJQuery = function(successCallback, errorCallback) {
		if (typeof(jQuery) == "undefined") {
			return loadJavascript(jQueryUrl, successCallback, errorCallback);
		}
		successCallback();
	}
	
	var ScriptsQueueLoader = function(index, scripts, onLoad) {
		this.scriptsQueue = scripts;
		this.index = index;
		this.onLoad = onLoad;
		this.loadedScriptsCounter = 0;
	};
	
	ScriptsQueueLoader.prototype = {
		load: function() {
			this.loadedScriptsCounter = 0;
			loadOnceJQuery(bindToScope(this, this.startLoading), function() {alert("Debug loading failed");});
		},
		startLoading: function() {
			jQuery("body").bind("script:loaded", bindToScope(this, this.onScriptLoaded));
			for (var i=0;i<this.scriptsQueue.length;i++) {
				if (jQuery.inArray(this.scriptsQueue[i], LaRoueVerte.JsLibs.loadedScripts) != -1) {
					LaRoueVerte.JsLibs.log(this.scriptsQueue[i] + " already loaded");
					this.triggerScriptLoaded();
				} else {
					LaRoueVerte.JsLibs.log(this.scriptsQueue[i] + " is loading ...");
					loadJavascript(this.scriptsQueue[i], bindToScope(this, this.triggerScriptLoaded));				
				}
			}
		},
		triggerScriptLoaded: function() {
			jQuery("body").trigger("script:loaded", [this.index]);
		},
		onScriptLoaded: function(event, index) {
			if (index === this.index) {
				LaRoueVerte.JsLibs.log(this.scriptsQueue[this.loadedScriptsCounter] + " is loaded");
				LaRoueVerte.JsLibs.loadedScripts.push(this.scriptsQueue[this.loadedScriptsCounter]);
				this.loadedScriptsCounter++;
				if (this.loadedScriptsCounter == this.scriptsQueue.length) {
					LaRoueVerte.JsLibs.log("Queue has been loaded");
					this.onLoad();
				}
			}
		}
	}
	
	return {
		load: function(scripts, onLoad) {
			var newindex = loaders.length;
			loaders[newindex] = new ScriptsQueueLoader(newindex, scripts, onLoad);
			loaders[newindex].load();
		},
		loadModule: function(script, onLoad) {
			if (script instanceof Array)
				this.load(script, onLoad);
			else
				this.load([script], onLoad);
		},
		loadModules: function(scripts, onLoad) {
			this.load(scripts,onLoad);
		},
		loadCSS: function (url) {
			window.loadingScript = url;
			var headID = document.getElementsByTagName("head")[0];         
			var newScript = document.createElement('link');
			newScript.type = 'text/css';
			newScript.href = url;
			newScript.rel='stylesheet';
			headID.appendChild(newScript);
		},
		
		loadJavascript:loadJavascript
	}
	
})(jQueryUrl);

var timestamp = "?timestamp="+LaRoueVerte.timestamp; 

LaRoueVerte.DefModules={
		jqueryblockui:"/common/javascript/jquery.block-ui.js"+timestamp,
		jqueryjsonp:"/common/javascript/jquery.jsonp-1.1.0.min.js"+timestamp,
		jqueryJson:"/common/javascript/libs/jquery/json/jquery.json-2.2.min.js"+timestamp,
		jquery142:"/common/javascript/libs/jquery/jquery-1.4.2.min.js"+timestamp,
		jqueryUI:"/common/javascript/jquery-ui-1.7.2.custom.min.js"+timestamp,
		jQueryUI_CSS:"/common/style/jquery-ui-1.7.2.custom.css?timestamp="+ timestamp,
		jQueryUI_LRVGRIS_CSS:"/common/style/jquery/lrv-gris/jquery-ui-lrv-gris.css?timestamp="+ timestamp,
		jQueryUI_REDMOND_CSS:"/common/style/jquery/redmond/jquery-ui-1.7.3.custom.css?timestamp="+ timestamp,
		jqueryTooltip:"/common/javascript/libs/jquery/tooltip/js/jquery.tooltip.js"+timestamp,
		jqueryDataTables:"/common/javascript/libs/jquery/datatables/js/jquery.dataTables.min.js"+timestamp,
		jqueryDataTables_CSS:"/common/javascript/libs/jquery/datatables/css/demo_table_jui.css"+timestamp,
		jqueryDataTables_FRENCH:"/common/javascript/libs/jquery/datatables/js/french.txt"+timestamp,
		jqueryTooltip_CSS:"/common/javascript/libs/jquery/tooltip/css/jquery.tooltip.css"+timestamp,
		jqueryJsTree:"/common/javascript/libs/jquery/jstree/jquery.jstree.min.js"+timestamp,
		jqueryJsTree_DEFAULT_CSS:"/common/javascript/libs/jquery/jstree/themes/default/style.css"+timestamp,
		jqueryBGIFrame:"/common/javascript/jquery.bgiframe.min.js"+timestamp,
		jqueryValidation:"/common/javascript/libs/jquery/validation/jquery.validate.min.js"+timestamp,
		prototype161:"/common/javascript/prototype-1.6.1.js"+timestamp,
		sessionManager:"/common/javascript/ajax/sessionManager.js"+timestamp,
		paginator:"/common/javascript/modules/paginator/paginator.js"+timestamp,
		lrvEmail:"/common/javascript/email.js"+timestamp,
		lrvGMap:"/common/javascript/lrv-gmap.js"+timestamp
}

//Definition of LRV modules loadable
LaRoueVerte.Modules={
		sessionManager:[
		               LaRoueVerte.DefModules.sessionManager,
		               LaRoueVerte.DefModules.jqueryJson
		],
		paginator: LaRoueVerte.DefModules.paginator
};

LaRoueVerte.ExternEvents = {};

LaRoueVerte.ExternEvents.contextPath = '';
LaRoueVerte.contextPath = '';
LaRoueVerte.ExternEvents.baseUrl='http://www.laroueverte.com';
LaRoueVerte.ExternEvents.eventId= 2
LaRoueVerte.timestamp=100831113002;


function allScriptsLoaded() {
	if (window.loadedExternEvents) {
		loadedExternEvents();
	}
}

function loadAfterExternEvents() {
	allScriptsLoaded();
}


function loadAfterDealerLocatorJS() {
	if (''!='') {
		LaRoueVerte.ModulesLoader.loadJavascript("http://www.laroueverte.com/modules/externevents/",loadAfterExternEvents);
	} else {
		loadAfterExternEvents();
	}
}

function loadAfterSessionManager() {
	LaRoueVerte.ModulesLoader.loadJavascript("http://www.laroueverte.com/modules/externevents/externevents.js",loadAfterDealerLocatorJS);
}

function loadAfterLRVEmail() {
	LaRoueVerte.ModulesLoader.loadJavascript("http://www.laroueverte.com/common/javascript/ajax/sessionManager.js",loadAfterSessionManager);
}

function loadAfterLRVGMap() {
	LaRoueVerte.ModulesLoader.loadJavascript("http://www.laroueverte.com/common/javascript/email.js", loadAfterLRVEmail);
}

function loadAfterJSONP() {
	LaRoueVerte.ModulesLoader.loadJavascript("http://www.laroueverte.com/common/javascript/lrv-gmap.js", loadAfterLRVGMap);
}

function loadAfterPrototype() {
	LaRoueVerte.ModulesLoader.loadJavascript("http://www.laroueverte.com/common/javascript/jquery.jsonp-1.1.0.min.js", loadAfterJSONP);
}

function loadAfterGMap() {
	LaRoueVerte.ExternEvents.gmap=true;
	LaRoueVerte.ModulesLoader.loadJavascript("http://www.laroueverte.com/common/javascript/prototype-1.6.1.js", loadAfterPrototype);
}

function loadAfterGMapLoader() {
	google.load("maps", "2", {callback : loadAfterGMap});	
}

function loadAfterJquery() {
	jQuery.noConflict();

    jQuery(document).ready(function(){
           LaRoueVerte.ModulesLoader.loadJavascript("http://maps.google.com/jsapi?callback=loadAfterGMapLoader&sensor=false&key=ABQIAAAA2tqyXHP-CPLmOJwDoLxzpRRxquvxpa7fRk9KCUzllunXtr5LuRRkrSdWqR3__B1wRq1mxJtJHw-3-g");
     });
}

LaRoueVerte.ModulesLoader.loadJavascript("http://www.laroueverte.com/common/javascript/jquery-1.3.2.min.js", loadAfterJquery);


