/**
 * This file is reponsible for managing the js library of classes and functions
 *
*/
var LibraryManager = {

	/**
	 * Calculates and sets the relative path from the js library to the root
	 *
	 * @return void  
	 */
	 calculatePath: function() {
		
		// condition : is object var already set?
		if (this.path==null) {
			
			// get path from LibraryManager javascript include string
			var scriptTags = document.getElementsByTagName("script");
			for(var i=0;i<scriptTags.length;i++) {
				if(scriptTags[i].src && scriptTags[i].src.match(/LibraryManager\.js(\?.*)?$/)) {
					this.path = scriptTags[i].src.replace(/LibraryManager\.js(\?.*)?$/,'');
					break;
				}
			}
		}
	},
	
	/**
	 * Includes a js file
	 * 
	 * @param string libraryfile The path from the js library root to the file
	 *
	 * @return void  
	 */
	require: function(libraryfile) {
		this.calculatePath();
		document.write('<script type="text/javascript" src="'+ this.path + libraryfile +'"></script>');
	},
	
	/**
	 * Loads the core js libraries
	 *
	 * @return void  
	 */
	load: function() {
		this.require('prototype/prototype.js');
		this.require('scriptaculous/builder.js');
		this.require('scriptaculous/effects.js');
		this.require('scriptaculous/dragdrop.js');
		this.require('scriptaculous/controls.js');
		this.require('scriptaculous/slider.js');
		this.require('alchemilla.js');
	}
}

LibraryManager.load();
