/**
 * copyright (c) 2005 - lx barjon <lx@iassa.com>
 * class jsIncluder
 * version : 1.0 (07-11-2005)
 * licence : GNU GPL
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 **************************************************************************
 *
 * @author lx barjon <lx@iassa.com>
 * @access public
 * @version 1.0
 */

var jsIncluder = Class.create();
jsIncluder.prototype = {

	initialize: function( jsToInclude, options ) {
		Object.extend( this.options = {
			pathToScripts: 'Lib/jscript/'
		}, options || {} );
		if ( !jsToInclude || jsToInclude.length < 1 ) return;
		this.jsToInclude = jsToInclude;
		var jscripts = document.getElementsByTagName( 'script' );
		this.includedJS = [];
		var lastJS;
		for ( var cpt = 0; cpt < jscripts.length; cpt++ ) {
			if ( jscripts[cpt].src ) {
				var startPos = jscripts[cpt].src.indexOf(this.options.pathToScripts);
				this.includedJS.push( jscripts[cpt].src.substring(startPos, jscripts[cpt].src.length) );
				lastJS = jscripts[cpt];
			}

		}
		this.addJS();
	},

	addJS: function() {
		var head = document.getElementsByTagName( 'head' )[0];
		var currentScript = '';
		for ( var cpt = 0; cpt < this.jsToInclude.length; cpt++ ) {
			if ( !inArray(this.jsToInclude[cpt], this.includedJS) ) {
				currentScript = document.createElement( 'script' );
				currentScript.type = 'text/javascript';
				currentScript.src = this.jsToInclude[cpt];
				head.appendChild( currentScript );
			}
		}
	}

}
