/*
4.14.2008

- image rollover code

- When rolling over a link, do the following:

	- look for the link id. 
		example: "id=walpole_library"
		
	- search for a related img id by adding "_img" to the end of the id
		example: "id=walpole_library_img"
	
	- if the image source file name contains "_off.jpg", change it to "_on.jpg"

- When rolling over an link, do the following:
	
	- same as rolling over a link (except you already have the image id), plus:
	
		- look for the link id and change the text to a highlighted state


*/


//----------------------
/*
	Show thumbnail "on" state
	
	input: link id
	-> build img id: "[link id]" + "_img"
	-> attempt to find img	
	-> if img source has "_off.jpg" turn it to "_on.jpg"
*/
//----------------------
function thumbnail_rollover_on(lnk_id){

	if (lnk_id==undefined){
		return;					// do nothing
	}
	
	var img_id = lnk_id + '_img';									// build the image id
	var imgsrc = $("#" + img_id).attr("src");
	if (imgsrc.match(/_off.jpg$/)){										// if the image in the "off" state?
		var imgsrcON = imgsrc.replace(/_off.jpg$/gi,"_on.jpg");		// yes, turn it on
		$("#" + img_id).attr("src", imgsrcON);
	}
}

//----------------------
/*
	Show thumbnail "off" state
	
	input: link id
	-> build img id: "[link id]" + "_img"
	-> attempt to find img	
	-> if img source has "_on.jpg" turn it to "_off.jpg"
*/
//----------------------
function thumbnail_rollover_off(lnk_id){

	if (lnk_id==undefined){
		return;					// do nothing
	}
	
	var img_id = lnk_id + '_img';						
	var imgsrc = $("#" + img_id).attr("src");

	if (imgsrc.match(/_on.jpg$/)){										// if the image in the "off" state?
		var imgsrcOFF = imgsrc.replace(/_on.jpg$/gi,"_off.jpg");		// yes, turn it on
		$("#" + img_id).attr("src", imgsrcOFF);
	}
}



/*

	Functions for when page is loaded
*/
$(document).ready(function() { 

	
	//----------------------
	//	Preload thumbnail images
	//----------------------	
	$("#thumbnail_previews a img").each(function() {
		var rollsrc = $(this).attr("src");
		var rollON = rollsrc.replace(/_off.jpg$/gi,"_on.jpg");
		$("<img>").attr("src", rollON);
	});
	
	
	
	//----------------------
	//	detect IMAGE ROLLOVERS
	//----------------------

	// When rolling over an image, turn the image 'on' and style the related link
	//
	$("#thumbnail_previews a").mouseover(function(){					// check for mouseover on <a ...>
		var img_id = $(this).children("img").attr("id");
		var lnk_id = img_id.replace(/_img$/,'')

		$("#" + lnk_id).addClass("ps_list_rollover");
		
		thumbnail_rollover_on(lnk_id);
	});

	// When leaving an image (mouseout), turn the image 'off' and style the related link
	//
	$("#thumbnail_previews a").mouseout(function(){					// check for mouseover on <a ...>
		var img_id = $(this).children("img").attr("id");
		var lnk_id = img_id.replace(/_img$/,'')
		$("#" + lnk_id).removeClass("ps_list_rollover");
		thumbnail_rollover_off(lnk_id);
	
	});
	
	

	//----------------------
	//	detect LINK ROLLOVERS
	//----------------------
		

	// When rolling over a link, turn the image 'on' 
	//
	$("#anchor_list_col a").mouseover(function(){					// check for mouseover on <a ...>

		var lnk_id = $(this).attr("id");						// look at id of the link
		if (lnk_id == undefined){
			//alert('nope');
		}else{
			thumbnail_rollover_on(lnk_id);
		}

	});

	// When leaving a link (mouseout), turn the image 'off'
	//
	$("#anchor_list_col a").mouseout(function(){					// check for mouseout on <a ...>
	
		var lnk_id = $(this).attr("id");						// look at id of the link
		if (lnk_id == undefined){
			//alert('nope');
		}else{
			thumbnail_rollover_off(lnk_id);
		}

	});

});
