//////////////////////////////////////////////////////////////////////////////
//
//	File	: 	image_rollover.js
//
//	Author	: 	Micheal O Abidakun - mabidakun@carltononline.com
//
//	Created	: 	March 2000
//
//	Last mod:	13/04/2000
//
//	Comment	:	This javascript include enables image rollovers to benefit from the 
//				object oriented pardigm!!!
//
//////////////////////////////////////////////////////////////////////////////

// ---- create a global array to hold the image objects
	var array_image_objects = new Array( 1 );

	/**
		This methods checks for the existence of the images array object
		which is a property of the document.
		If it is not present, this browser probably does not support
		image rollover (i.e. it can't handle images!)
	*/	
	function canHandleImages(){
    	return (document.images); 
	}
	
	/**
		Returns an image object from with our array.
		The image is keyed on it's name in the document, and an integer
		identifier (1-3), for each of it states
	*/
	function getImageObj( name, id ){
//		alert( "getImageObj( " + name + ", " + id + " )" );
		return this.array_image_objects[name+"," + id];
	}

	function imageOn( szImageName, iState ){
//		alert( "imageOn( " + szImageName + ", " + iState + " )" );
    	if( !canHandleImages() )
        	return;
		
		img = this.getImageObj(szImageName, iState );

        if( img != null ){
			if( document [szImageName]){
            	document [szImageName].src = img.src;
			}
        }
	}

	/*
		Returns the state id of the named image.
		The methoid returns the value of the id when it finds that id is the one that
		is currently set in the document.		
	*/
	function getImageID( image_name ){
		var result = -1;

		if( image_name == null ){
			return result;
		}

		for( var i=0; i < 100; i++){
			var image_path= this.array_image_objects[image_name+","+(i+1)].src;
			
			if( !this.array_image_objects[image_name+","+(i+1)] ){
				break;
			}
				
			if( document[image_name].src == image_path ){
				return (i+1);
			}
		}
		return result;
	}
	
	/*
		image_name : the name of the image as it is specified in the HTML
		Any additional paramaters passed will be counted (in order) as the alternate states
		of the image
		
	*/	
	function add( image_name ){
//		alert( "add( " + image_name + "); arguments.length=" +arguments.length );
	
// ---- if the image_name (i.e. the name given in the <img> tag) is the only parameter,
// ----  or even less than that was passed, we simply ignore that image.
		if( arguments.length < 2 )
			return;
			
					
// ---- create the image objects (an array of them)
		for( var i=1; i< arguments.length; i++){
	// ---- build an associative table of the paths for a particular image.		
	// ---- add the object to the array, key on the name 
			this.array_image_objects[image_name+"," + i]	= new Image();
			this.array_image_objects[image_name+"," + i].src= arguments[i];
		}
	}

	
	function getImagePath(){
		return this.PATH;
	}

	/**
		This is a constrcutor.
		It creates a "CImageRollover_Manager" object to handle preload and modyfing
		images.
		
		To instantiate :-
		
		imageRolloverImageObj = new CImageRollover_Manager( "/img/" );
	*/
	function CImageRollover_Manager( szInitialImagePath ){
//		alert("CImageRollover_Manager( " + szInitialImagePath + " ) called" );
	
// ---- initiliase the properties
		this.PATH = ( szInitialImagePath == null ? "" : szInitialImagePath );

		//make the global variable an instance variable fo this object
		this.array_image_objects = array_image_objects;
		
// ---- assign the methods
		this.imageOn 			= imageOn;
		this.canHandleImages	= canHandleImages;
		this.getImageObj 		= getImageObj;
		this.getImagePath		= getImagePath;
		this.add				= add;
		this.getImageID			= getImageID;
	}


// ---- create the image manager object	
// ---- this is the handle to be used reference the image manager
// ---- in subsequent javascript includes.
	var imageManager = new CImageRollover_Manager( "/img/" );
