﻿/* Menu image rollovers using jQuery v1.6.4 on 10/26/2011
All menu images require id='m-3', etc. starting with 'm-0'
_____________________________________________________________________________*/
$(document).ready(function() {
	/* user defined
	_______________________ */
	var skip		= 2, // Use '2' for 1 image between each menu item, 12, 14, 16, etc.
		path		= '/graphics_slices/Schubert_', //path incl. filename prefix
		start		= 14, // starting menu image id number
		sticky		= '-sticky', // suffix for sticky item
		over		= '-over',  // suffix for hover item
		type		= '.jpg', // .jpg, .gif, .png, etc.
	/* end user defined
	_______________________ */
		section		= $('input#section').attr('value'), // this is value of hidden field id='section'
		tab_sticky	= new Array(),
		tab_over	= new Array(),
		j;
		
	$('img[id|="m"]').each(function (i) {	
		imgid = ((i*skip) + start); if (imgid < 10){imgid="0"+imgid};
		if (section == i){
			$(this).attr({ src: path+imgid+sticky+type });
			$(this).click(function (e) { e.preventDefault(); }).css("cursor","default"); // kills link cuz you're already there
		} else {
			tab_sticky[i]	=	path+imgid+type;
			tab_over[i]		=	path+imgid+over+type;
		};
		// preloads all hidden menu images on page load
		(new Image()).src	=	path+imgid+over+type; 
		(new Image()).src	=	path+imgid+sticky+type;
	});
	function enter(event) {
		j = $(this).attr('id').replace(/m-/, "");
		if (section != j){$(this).attr("src",tab_over[j]);};
	};
	function leave(event) {
		j = $(this).attr('id').replace(/m-/, "");
		if (section != j){$(this).attr("src",tab_sticky[j]);};
	};
	$('img[id|="m"]').hover(enter, leave);
});
