// ***************************************************
// Mouse-over effects scripting for ccunderground
// Author: Andi Friedman
// Creation Date: 07-04-2005
// Last Modified: 09-04-2005 (Andi Friedman)

// Copyright: AMPT 2005
// ***************************************************

// -----------------------------------------------------------------------------------------------------------------------------------
// Function: SImgRoll
// 
// Performs an image rollover.  If the first argument is true, the image source is set to the "mouse-over" image.
// If the first argument is false, the image source is set to the "mouse-out" image.  To use the function, create two images,
// one for the normal state, and one for the roll over state.  Name the second image the same as the first but with an extension
// to the original name e.g. use an underscore ("_") at the end (before the extension).
// 
// Parameters:
//		over - boolean indicating mouse status (i.e. true = mouse-over, false = mouse-out)
//		obj - image object
//		selector - string specifying the addition to the path to select the mouse-over image
//
// Return value: none
//
// Example:
// Calling SImgRoll(true, this, "_") from the onMouseOver event for an image with source "temp.gif" will set the image source to
// temp_.gif.
// -----------------------------------------------------------------------------------------------------------------------------------

function SImgRoll(over, obj, selector)
{
	// Retrieve the image object's source
	iSrc = obj.src;
	
	// Retrieve the image object's extension (e.g. "gif", "jpg", "jpeg", etc)
	iExt = iSrc.substr( iSrc.indexOf('.') );
	
	// Retrieve the image path and name (no extension)
	iPath = iSrc.substring( 0, iSrc.indexOf('.') );

	// Append the selector to the source if this is a mouse-over and remove the selector if this is a mouse-out
	if ( over )
	{
		iPath += selector;
	}
	else
	{
		iPath = iPath.substring( 0, iPath.length - selector.length );
	}
	
	// Append the extension to the path
	iPath += iExt;
	
	// Set the object's source to the new path
	obj.src = iPath;
}

// -----------------------------------------------------------------------------------------------------------------------------------

// -----------------------------------------------------------------------------------------------------------------------------------
// Function: SImgRollId
//
// Performs an image rollover using an image's id as a reference
// -----------------------------------------------------------------------------------------------------------------------------------

function SImgRollId(over, imgid, selector)
{
	obj = document.getElementById( imgid );
	SImgRoll(over, obj, selector);
}

// -----------------------------------------------------------------------------------------------------------------------------------

// -----------------------------------------------------------------------------------------------------------------------------------
// Function: MImgRoll
// 
// Performs an image rollover for multiple images.  If the first argument is true, the image sources are set to the "mouse-over" images.
// If the first argument is false, the image sources are set to the "mouse-out" images.  To use the function, create two images (for
// each image object), one for the normal state, and one for the roll over state.  Name the second image the same as the first but with a
// selector (e.g. "_") at the end (before the extension).  In addition, give all the image objects in the html page the same id but append a
// number to each, i.e. if there are 5 images which must change when any are rolled over, give each an id img1, img2, img3, ...
// Add this function call to each of the image object's onMouseOver events.
// 
// Parameters:
//		over - boolean indicating mouse status (i.e. true = mouse-over, false = mouse-out)
//		groupid - id for the image group (the common part of the image objects ids')
//		icount - number of images in image group.
//		selector - string specifying the addition to the path to select the mouse-over image
//
// Return value: none
//
// Example:
// Calling MImgRoll(true, 'mygroup', 3, "_") from the onMouseOver event will perform the rollover for each image object in the group 
// (images with ids mygroup1, mygroup2, mygroup3).
// -----------------------------------------------------------------------------------------------------------------------------------

function MImgRoll(over, groupid, icount, selector)
{
	debug = false;	// set this variable to true to display errors.
	
	// Iterate through the images in the group
	for ( i = 1; i <= icount; i++ )
	{
		// Get a reference to the image object given the image id
		obj = document.getElementById( groupid + i );
		
		// Only perform the rollover for a valid object
		if ( obj )
		{
			// Perform the rollover
			SImgRoll( over, obj, selector );
		}
		else if ( debug )
		{
			alert( "No image with id " + groupid + i + " exists.  Ensure images have been named correctly." )
		}
	}
}

// -----------------------------------------------------------------------------------------------------------------------------------




