SM.blog = {
	init: function(){
		var self=this;
		// element references
		self.featuredPhoto = $('div#featuredImage');
		self.postThumbs = $('div.postThumb');
		self.featuredMetaData = $('div.featuredMetaData');
		self.catDropdown = $("select#cat");
		
		
		// variables
		self.postThumbHover = 0;
		self.featuredShowTimer = 0;
		self.thumbShowTimer = 0;
		
		// setup
		// self.alignFeaturedPhoto(); // commented out for now, not necessary now that photos are being loaded via WP and not imported from MT
		self.applyFancybox();
		
		// event handlers
		
		// load new page on category select from dropdown
		self.catDropdown.change(function(){
			if ( self.catDropdown.find('option:selected').index() > 0 ) {
				window.location.href = "/?cat="+self.catDropdown.find('option:selected').val();
			}
	    });
	    
		self.featuredPhoto.hover(
		function(){
			self.featuredShowTimer = setTimeout(function(){
				self.overlayShowLg();
			}, 300);
		},
		function(){
			clearTimeout(self.featuredShowTimer);
			self.overlayHideLg();
		});
		
		self.postThumbs.hover(
		function(){
			self.postThumbHover = $(this);
			self.thumbShowTimer = setTimeout(function(){
				self.overlayShowSm();
			},300);
		},
		function(){
			clearTimeout(self.thumbShowTimer);
			self.postThumbHover = $(this);
			self.overlayHideSm();
		});
		

	},
	
	alignFeaturedPhoto: function(){
		var featuredPhoto = $('div#featuredImage div.image img');
		var imgMargin = ( featuredPhoto.height() - featuredPhoto.parents('div.image').height() ) * -0.5;
		featuredPhoto.css('margin-top', imgMargin);
	},
	
	overlayShowLg: function(){	    
		$('#featuredImage .overlay').stop(true, true).animate({backgroundPosition: '0 0'}, 200);
		$('#featuredImage .overlay .details').stop(true, true).delay(200).fadeIn(200);
	},
	
	overlayHideLg: function(){
		$('#featuredImage .overlay .details').stop(true, true).fadeOut(200);
		$('#featuredImage .overlay').stop(true, true).delay(150).animate({backgroundPosition: '-481px 0'},200);
	},
	
	overlayShowSm: function(){
		var self = this;
		
		self.postThumbHover.children('.overlay').stop(true, true).animate({backgroundPosition: '0 0'}, 150);
		self.postThumbHover.find('.details').stop(true, true).delay(150).fadeIn(150);
	},
	
	overlayHideSm: function(){
		var self = this;
		
		self.postThumbHover.find('.details').stop(true, true).fadeOut(150);
		self.postThumbHover.children('.overlay').stop(true, true).delay(150).animate({backgroundPosition: '-178px 0'}, 150);
	},
	
	applyFancybox: function(){
		var self = this;
		var fancyboxTriggers = $('a[href$=".bmp"],a[href$=".gif"],a[href$=".jpg"],a[href$=".jpeg"],a[href$=".png"],a[href$=".BMP"],a[href$=".GIF"],a[href$=".JPG"],a[href$=".JPEG"],a[href$=".PNG"]');
		fancyboxTriggers.attr('rel', 'fancybox');
		fancyboxTriggers.fancybox({
			'titleShow' : false,
			'autoScale' : true,
			'centerOnScroll' : true,
			'showCloseButton' : true
		});
	}
	
	
}

