/**
 * @fileOverview The init.js file is used to load up and include new files
 * this is called on every page, only add things in here
 * if they are globally needed to the entire project.  
 * @author Joe Cianflone
 * @version	2.1
 * @copyright CC, Creative Commons Attribution-ShareAlike 3.0 Unported -- http://creativecommons.org/licenses/by-sa/3.0/
 */

/**
 * Path to the root of the images.
 */
var adSampleImageRoot = '/images/products/print/ad_samples/';

/**
 * @class Core class loads up all the JavaScript that we need on a given page.
 */
var Core = {
	/**
	 * Safari has issues with DOM additions, so we need a brute force function.
	 * @function 
	 * @private
	 * @memberOf Core
	 * @param {String} includer full path variable to the location 
	 */
	include: function(includer) {
		document.write('<script type="text/javascript" src="'+includer+'"></script>');
	},//load()...
	/**
	 * Method finds the init script, reads the path and loads up all the called files.  
	 * @function
	 * @memberOf Core
	 * @param {String} [fn] if you want to load a specific file you can call this method and add in the name of the file you want to call.  If this parameter is not included load will check init.js and see if there is a load querystring.
	 * @example Core.load('library/prototype'); - Don't include the .js extension!
	 */
	load: function(fn) {
		var scripts = document.getElementsByTagName('script');
		var i=0, len=scripts.length;
		var initScript = document.getElementById('initScript');
		var path = initScript.src.replace(/init\.js(\?.*)?$/,'');
		if (fn != null) {
			Core.include(path+fn+".js");	
		}//if...
		else {
			var s = initScript.src.indexOf('load='); 
			if (s  != -1) { 
				s +=5;  //this is the value of the string 'load=' so you bypass that when you get the substring
				var query = initScript.src.substring(s).split(',');
				if (query.length > 0) {
					for (var j=0, len2=query.length; j<len2; ++j) {
						Core.include(path+query[j]+".js");
					}//for...				
				}//if...
			}//if...
		}//else...	
	}//load()...
};//Core...
Core.load('library/prototype');
Core.load();