//hover images
window.addEvent("domready",initHover);

function initHover(){
		document.getElements("img").each(function(thisImage){	
		thisImage.intOut = 0;
		outDelay = 10;
		menu = $(thisImage.getProperty('menu'));
		if(menu){var myFx = new Fx.Tween(menu,{duration:'short'});}
		function doOver(){
			$clear(thisImage.intOut);
			thisImage.src = thisImage.getProperty('hover');
			menu = $(thisImage.getProperty('menu'));
			if(menu){
				//menu.fade('in');
				myFx.cancel();
				myFx.start('height',menu.origHeight + 'px');
				myFx.addEvent('complete',function(){this.setStyle('overflow','visible');}.bind(menu));
			}
		}
		function doOut(){
			thisImage.src = thisImage.origSrc;
			menu = $(thisImage.getProperty('menu'));
			if(menu){
				//menu.fade('out');
				myFx.cancel();
				menu.setStyle('height','0px');
			    menu.setStyle('overflow','hidden');
			}
		}
		if(thisImage.getProperty('hover') != null && thisImage.origSrc == null){
			//get associated menu and pre-hide it
			menu = $(thisImage.getProperty('menu'));
			if(menu){
				//menu.fade('hide'); 
				menu.origHeight = menu.getHeight();
				menu.setStyle('height','0px');
				menu.setStyle('visibility','visible');
			}
			
			//preload hover image
			preload_image = new Image();
			preload_image.src=thisImage.getProperty('hover'); 
			
			//Swap on mouse over
			thisImage.origSrc = thisImage.src;
			thisImage.addEvent("mouseover",doOver);
			
			//Swap back on mouse out
			thisImage.addEvent("mouseout",function(){thisImage.intOut = doOut.delay(outDelay);});
			
			//if menu associated, add events to it
			if(menu){
				menu.addEvent("mouseover",doOver)
				menu.addEvent("mouseout",function(){thisImage.intOut = doOut.delay(outDelay);});
			}
		}
	});
}

