/*
	Progetto:		Nuovo portale INPS, 2011
	Componente:		Script di lancio
	Versione:		C40
	Status:			Production Code (4/4)
	Data:			09/02/2012
*/

Loader = {
	components: new Array (
		'script'
	),
	
	libraries: new Array (
		'libs'
	),
	
	include: function(f,p,b) {
		document.write('<script type="text/javascript" src="' + b + p + f + '"></script>');
    },

	includeStyle: function(f,p,b) {
		document.write('<link rel="stylesheet" type="text/css" href="' + b + p + f + '" media="screen" />');
    },

	detect: function(a) {
		if (window.location.href.indexOf('?') == -1) return;
		var vars = window.location.href.split('?')[1].split('&');
		var vals = new Array();
		for (var i=0; i<vars.length; i++) {
			vals[i] = {name:vars[i].split('=')[0],value:vars[i].split('=')[1]};
		}
		for (var j=0; j<vals.length; j++) {
			if (vals[j].name==a) {return vals[j].value;}
		
		}
		return;
	},

	isLocal: function() {
		if(location.host==''||location.host=='inpsnew') return true;
    },

	start: function() {
		var l = this.libraries;
		var c = this.components;
		this.basePath = (opzioni.basePath)? opzioni.basePath : './';
		if (window.opera) {
			this.includeStyle('opera.css', '', this.basePath + 'asset/css/')
		};
 		if (opzioni.skin) {
			this.includeStyle('skin.css', '', this.basePath + 'skin/' + opzioni.skin + '/')
		};

		for (var i = 0; i < l.length; i++) this.include(l[i] + '.js', 'lib/', this.basePath + 'asset/js/');
		for (var i = 0; i < c.length; i++) this.include(c[i] + '.js', '', this.basePath + 'asset/js/');
		if(this.isLocal()) this.include('local.js', '', this.basePath + 'asset/js/');
		var f = (opzioni.includes)? opzioni.includes : '';
		if(f) {
			for (var i = 0; i < f.length; i++) this.include(f[i].file + '.js', '', (f[i].path)?f[i].path:this.basePath + 'asset/js/');
		}
		this.collapsibleHeader = this.detect('collapsibleHeader');
    }
}

Loader.start();

