﻿/////////////////////////////////////////////////////////////////////////
//                                                                     //
//  Creator: Jeff Killingsworth                                        //
//  Created On: 2008/03/24                                             //
//                                                                     //
//  Description: This file contains the "include" class.               //
//               This object is used as an means of referencing other  //
//               javascript files like includes.                       //
//                                                                     //
//  History:                                                           //
//                                                                     //
/////////////////////////////////////////////////////////////////////////



/*=========================================== CONSTANTS ===========================================*/



// Static variable to hold included files
include.includedFiles = new Array();



/*=========================================== PUBLIC METHODS ===========================================*/



/////////////////// include //////////////////////////////////////////
//                                                                  //
//  Description: Constructor                                        //
//                                                                  //
//  Params:                                                         //
//      path - string that contains the path of the file to include //
//                                                                  //
//  Return: self                                                    //
//                                                                  //
//////////////////////////////////////////////////////////////////////
function include( path ){
	
	// Call inner add function
	include.add( path );
}



/*=========================================== PRIVATE METHODS ===========================================*/



/////////////////// add //////////////////////////////////////////////
//                                                                  //
//  Description: This will add a file to the current document.      //
//                                                                  //
//  Params:                                                         //
//      path - path of the file to include                          //
//                                                                  //
//  Return: void                                                    //
//                                                                  //
//////////////////////////////////////////////////////////////////////
include.add = function( path ) {

	// if the file has not already been included
	if ( !include.isIncluded( path ) ) {
	
		// create a script tage and write it out
		document.write( '<script type="text/javascript" src="' + path + '"></script>' );
		
		// add the file to the include array
		include.includedFiles[ include.includedFiles.length ] = path;
	}
}


/////////////////// isIncluded ///////////////////////////////////////
//                                                                  //
//  Description: This will check to see if a file has already be    //
//               included.                                          //
//                                                                  //
//  Params:                                                         //
//      path - path of the file                                     //
//                                                                  //
//  Return:                                                         //
//      true/false                                                  //
//                                                                  //
//////////////////////////////////////////////////////////////////////
include.isIncluded = function( path ) {
	
	// loop through the array
	for( var i = 0; i < include.includedFiles.length; i++ ) {
		
		// if any one item matches then it has benn added already
		if ( include.includedFiles[ i ] == path ) {
		
			// It was found
			return true;
		}
	}
	
	// It was not found
	return false;
}