﻿/*============================================================
Scale images to fit content area.
	Using max-width should be enough, but of course, there's IE. 
============================================================*/

$(document).ready(function() {

	// Max width to allow
	var max_width = 370;
	
	$('.post').find('img').each(function(){
		var width = $(this).width();
		var height = $(this).height();
		if(width > max_width) {
			var ratio = (height / width);
			var new_width = max_width;
			var new_height = (new_width * ratio);
			
			// Shrink it
			$(this).height(new_height).width(new_width);				
		}
	});
	
});
		
		
/*============================================================
Nav img rollovers and preload.
- Wrap nav in a div with id="navWrapper"
- "on" images suffixed with "_ovr.gif" ("off" images have no suffix)
============================================================*/
$(document).ready(function() {	
	// Preload all rollovers
	$("#navWrapper a img").each(function() {
		// Set the original src
		rollsrc = $(this).attr("src");
		rollON = rollsrc.replace(/.gif$/ig,"_ovr.gif");
		$("<img>").attr("src", rollON);
	});
	
	// Navigation rollovers
	$("#navWrapper a").mouseover(function(){
		imgsrc = $(this).children("img").attr("src");
		matches = imgsrc.match(/_ovr/);
		
		// don't do the rollover if state is already ON
		if (!matches) {
		imgsrcON = imgsrc.replace(/.gif$/ig,"_ovr.gif"); // strip off extension
		$(this).children("img").attr("src", imgsrcON);
		}
		
	});
	$("#navWrapper a").mouseout(function(){
		$(this).children("img").attr("src", imgsrc);
	});		

});