/**
* This is the script that defines the contents of the header
* To modify the output of the script simply change the contents returned by the getHeaderContent() method
*/

function Estrella_Header(){
	this.imageList = null;
	this.init = init;
	this.init();

	// Insert in here declaration of images for which you want specific images
	// if you do not specify here then the default image will be applied
	this.defaultImage = "new_header_line.gif";
	
	/**
	* Method to that defines the image header to be used for display in the header
	*/
	function init(){
		this.imageList = new EstrellaImageList();
		this.imageList.add( "/biology/students/", "students.gif" );
		this.imageList.add( "/testing/", "students.gif" );
		this.imageList.add( "/tmp/", "students.gif" );
		this.imageList.add( "/facilities/", "students.gif" );
		this.imageList.add( "/templates/", "students.gif" );
		this.imageList.add( "/ctl/", "ctl_header.gif" );
		this.imageList.add( "/test/budget/", "bds.gif" );
		this.imageList.add( "/unitedway/", "united_way.gif" );
		this.imageList.add( "/money_matters/", "money_matters.gif" );
		this.imageList.add( "/information_technology/", "information_technology.gif" );
		this.imageList.add( "/information_technology/help/", "information_technology.gif" );
		this.imageList.add( "/ar/", "admissions_records.gif" );
		this.imageList.add( "/nca/resources/", "institutional_self_study.gif" );
		this.imageList.add( "/nca/resources/criterion1/", "institutional_self_study.gif" );
		this.imageList.add( "/nca/resources/criterion2/", "institutional_self_study.gif" );
		this.imageList.add( "/nca/resources/criterion3/", "institutional_self_study.gif" );
		this.imageList.add( "/nca/resources/criterion4/", "institutional_self_study.gif" );
		this.imageList.add( "/nca/resources/criterion5/", "institutional_self_study.gif" );
		this.imageList.add( "/nca/resources/girs/", "institutional_self_study.gif" );
		this.imageList.add( "/nca/resources/add_resources/", "institutional_self_study.gif" );
		this.imageList.add( "/nca/", "institutional_self_study.gif" );
		this.imageList.add( "/academics/saac/", "saac.gif" );
		this.imageList.add( "/academics/nasacenter/", "center_webheader.gif" );
		this.imageList.add( "/marketing_pr/", "marketing_pr.gif" );
		//this.imageList.add( "/prospective_students/", "students.gif" );
	}
	
	// Variable declaration
	this.path = new String( document.location );
	this.path = this.path.substring( this.path.lastIndexOf( document.domain ) + document.domain.length, this.path.length );
	this.directoryArray = null;

	// function declaration 
	this.parseDirectories = parseDirectories;
	this.parseDirectories();
	this.getPath = getPath;
	this.getImage = getImage;
	this.getDirectories = getDirectories;
	this.getDirectoryPath = getDirectoryPath;
	this.getTopDirectory = getTopDirectory;
	this.getWorkingDirectory = getWorkingDirectory;
	this.setPath = setPath;
}

//*************************************** Methods used in Estrella_Header Class ***********************************************
   function setPath( location ){
		var location = new String( location );
		this.init();
		this.directoryArray = null;
		this.path = new String( location.substring( 0, location.length ) );
		this.parseDirectories();
	}	

	function getPath(){
		return this.path;
	}
	
	function getImage(){
		if( this.imageList.containsPath( this.getDirectoryPath() ) ){
			var matchingImage = this.imageList.getMatchingImage().getImage();
			return matchingImage;
		}else{
			return this.defaultImage;
		}
	}

	function getDirectories(){
		return this.directoryArray;
	}
	
	function getTopDirectory(){
	    var dir = new String(this.directoryArray);
		if (dir.indexOf( "," ) > -1 )
		{
	    	var topdir = new String( dir.substring( 0, dir.indexOf( "," ) ) );
		}
		else
		{
	    	var topdir = new String( dir );
		}
		return topdir;
	}

	function getWorkingDirectory(){
		return this.directoryArray[ this.directoryArray.length - 1 ].toString();
	}

	function getDirectoryPath(){
		var dirPath = new String( "\/" );
		for( var x = 0; x < this.directoryArray.length; x++ ){
			dirPath = new String( dirPath + this.directoryArray[ x ] + "/" );	
		}
		return dirPath.valueOf();
	}

//************************************** end of methods used in the main class ************************************

function EstrellaImageList(){
	this.add = add;
	this.imageArray = new Array( 100 );
	this.arrayCounter = 0;
	this.matchingImage = null;
	this.containsPath = containsPath;
	this.getMatchingImage = getMatchingImage;

}

// ********************************** Methods used in EstrellaImageList  class *************************
	function add( path, image ){
		this.imageArray[ this.arrayCounter++ ] = new EstrellaImage( path, image );
	}

	function containsPath( path ){
		for( var x = 0; x < (this.arrayCounter ); x++ ){
			var estrellaImage = this.imageArray[ x ];
			var imagePath = estrellaImage.getPath();
			if( imagePath == path ){
				this.matchingImage = estrellaImage;
				return true;
			}
		}
		return false;
	}

	function getMatchingImage(){
		return this.matchingImage;
	}

// ********************************** End Methods used in EstrellaImageList  class *************************

function EstrellaImage( path, image ){
	this.image = image;
	this.path = path;
	this.getImage = getImageEstrella;
	this.getPath = getPathEstrella;
}

// ************************************* Functions to be used in Estrella Image ***************************

	function getImageEstrella(){
		return this.image;
	}

	function getPathEstrella(){
		return this.path;
	}

	function parseDirectories(){
		var tmpPath = new String( this.path.toString() );
		var dirCounter = 0;
		var tmpDirectoryArray = new Array( 10 );
		while( tmpPath.indexOf( "\/" ) > -1 ){
			tmpPath = new String( tmpPath.substring( tmpPath.indexOf( "\/" ) + 1, tmpPath.length ) );	
			var dir = new String( tmpPath.substring( 0, tmpPath.indexOf( "\/" ) ) );	
			if( dir.indexOf( "." ) > -1 || dir.valueOf() == "" ){
				break;
			}
			else{
				tmpDirectoryArray[ dirCounter++ ] = dir;
			}
		}

		this.directoryArray = new Array( dirCounter );
		for( var x = 0; x < this.directoryArray.length; x++ ){
			this.directoryArray[ x ] = tmpDirectoryArray[ x ];
		}
	}
	
// ************************************* functions for String Buffering ***************************

function StringBuffer(){
	this.string = new String();
	this.append = append;
	this.toString = toString;
	function append( newString ){
		this.string = this.string.concat( newString );
	}
	function toString(){
		return this.string;
	}
}