jQuery( function($) {
		// on DOM load:
		
		
		// sIFR  (Flash Image Replacement)
		sIFR.replaceElement(".storytitle", named({	sFlashSrc: templateDirectory + "/scripts/sifr/engravers_mt.swf", // templateDirectory is set in header.php
													sColor: "#E41F1C",
													sWmode: 'transparent'
												})
							);
		
		// Superfish menu code
		$("ul.sf-menu").superfish({
									animation:   {opacity:'show',height:'show'},
									disableHI: 'true'
								}); 
		
		// min-height:
		var main = $('#main');
		if (main.height() < 500) {
			main.height('500px');	
		}
		
		
		/////////// PORTFOLIO ////////////
		
		// Takes a jQuery object which is the image to show.
		function showPortfolioImage( jqueryImage ) {
			jqueryImage.css('zIndex', 2).siblings().css('zIndex', 1);
		}
		
		
		$("a.portfolio-rollover").each( function() {
			var postID = $(this).attr('post'),
				img = $('img[post=' + postID + ']'),
				fancyboxLink = $('a.fancybox[post=' + postID + ']');
				
			if (img.length) {
				$(this).data('img', img);	
			}
			
			if (fancyboxLink.length) {
				$(this).data('fancyboxLink', fancyboxLink);	
			}			
		}).mouseover( function() {
			var img = $(this).data('img');
			
			if (img) {
				showPortfolioImage(img);
			}
		}).click(function(e) {
			var fancyboxLink = $(this).data('fancyboxLink');
			
			if (fancyboxLink) {
				e.preventDefault();
				fancyboxLink.click();
			}		
		});
		
		/***** FANCY BOX *****/
	
		jQuery("a.fancybox").fancybox({
				'overlayShow': true,
				'overlayOpacity': .9,
				'centerOnScroll': true,
				/* 'changeFade': 0, */
				'titlePosition': 'inside',
				'padding': 20,
				'transitionIn': 'fade',
				'transitionOut': 'fade',
				'frameWidth': 780,
				'frameHeight': 490
			});
		
		
	});
