/**********************************************************/
//  for Westwood > Schedules and Routes
/**********************************************************/

/********************************************************************************
 *
 *	imageFlip.js
 *	
 *	usage : 
 *		Change OFF_SUFFIX and ON_SUFFIX to match image names.
 *		
 *		For each image which is to be flipped, document.onload should call
 *			flip.myFlipName = new Flip( myImageName, myImageSource )
 *		To turn image on, call 
 *			flip.myFlipName.on()
 *		To turn image off, call
 *			flip.myFlipName.off()
 *
 ********************************************************************************/

var IMAGE_OFF_SUFFIX = "_off.gif"
var IMAGE_ON_SUFFIX = "_on.gif"

var flip = new Array();
function Flip( imgName, imgSrc )
{
	this.docImg = getDocImg(imgName);
	this.imgOff = new Image( this.docImg.width, this.docImg.height )
	this.imgOffsrc = this.imgOff.src = this.docImg.src;
	
	this.imgOn = new Image ( this.docImg.width, this.docImg.height )
	if ( imgSrc )
		this.imgOnsrc = this.imgOn.src = imgSrc
	else 
		this.imgOnsrc = this.imgOn.src = this.docImg.src.replace( IMAGE_OFF_SUFFIX, IMAGE_ON_SUFFIX )
}

Flip.prototype.on = function(){	
	this.docImg.src = this.imgOn.src;
	//if ( this.status )
	//	window.status = this.status;
	return true;
}

Flip.prototype.off = function(){
	this.docImg.src = this.imgOff.src
	//window.status = "";
	return true;
}

//  function getDocImg( name )
//  - searches recursively through document.layers for the named image
//  - returns the named element in document.image
function getDocImg(name, d){
	d = ( d == null ) ? document : d; //set d to be the document if empty
	var img = d.images[name];
	if (img) return img; //found it
	
	if ( ! document.layers ) return null; //in ie, we die here
	
	for ( var i=0; i < d.layers.length; i++ ) 
		if ( d.layers[i].id ){
			img = getDocImg( name, d.layers[i].document )  //recursive call
				if (img) return img; //found it
		}
	return null; //did not find it
}

// function getAllImages( d )
//  - searches through document for images
//  - recurses through layers
function getAllImages( d ){
	d = ( d == null ) ? document : d; //set d to be the document if empty
	for ( var i = 0; i < d.images.length; i++ ){
		var src = d.images[i].src
		if ( d.images[i].name ){
			if ( src.indexOf( IMAGE_OFF_SUFFIX ) != -1 ){
				flip[ d.images[i].name ] = new Flip( d.images[i].name )
			}
		}
	}
	if ( !document.layers ) return;
	for ( var i=0; i < d.layers.length; i++ ) 
		getAllImages( d.layers[i].document )  //recursive call
}

//  function mouseover(name)
//	- turn on flip[name] if it exists
function mouseover(name){
	if (flip[name])
		flip[name].on()
}

//  function mouseover(name)
//	- turn off flip[name] if it exists
function mouseout(name){
	if (flip[name])
		flip[name].off()
}


		var routes = new Array();
		routes["west1"] = new Flip( "mapImg", '/image/businesses/westwood/route_west1.gif' );
		routes["west2a"] = new Flip( "mapImg", '/image/businesses/westwood/route_west2a.gif' );
		routes["west2b"] = new Flip( "mapImg", '/image/businesses/westwood/route_west2b.gif' );		
		routes["east"] = new Flip( "mapImg", '/image/businesses/westwood/route_east.gif' );
		function routeOver( name ){
			for( var i in routes ){
				if( i == name ){
					mouseover( i );
					routes[i].on();
					status = routes[i].imgOnsrc
				}
				else{
					mouseout( i );
				}
			}			
		}


