function init() {
	document.body.className += " loading js";
}

$(function() {
	
	Setup.init();
	Block.init($('div#blog-description'));
	Posts.init();
	Cufon.replace('h2, h3', { fontFamily: 'Helvetica Neue', hover: true });
	Cufon.replace('div#blog-description', { fontFamily: 'Helvetica Neue Light' });
});

/* Setup
------------------------- */
var Setup = {	
	Body: null,
	init: function() {
		var cc = this;
		cc.Body = $(document.body);
		cc.Body.addClass('jsReady');
		cc.Body.removeClass('loading');
		// utility classes
		$("ul li:first-child").addClass("first");
		$("ul li:last-child").addClass("last");
	}
};

/* Posts
------------------------- */
var Posts = {
	Items: null,
	init: function() {
		var cc = this;
		cc.Items = $('#content div.post');
		cc.render();
		
	},
	render: function() {
		var cc = this;
		
		cc.Items.each(function() {
			
			var media = $(this).find('div.media');
			var images = $(this).find('img').parent();
			var videos = $(this).find('object').parent();
			
			images.appendTo(media);
			videos.appendTo(media);
			$(this).addClass('post-media');
	
				// 		
				// if(images.length>0) {
				// 	$(images).wrapAll(media);
				// // 				$(this).addClass('post-media');
				// }
			
			// 
			// 			if(images.length>0) {
			// 				$(images).wrapAll('<div class="media" />');
			// 				var media = $(this).find('div.media');
			// 				$(this).css('minHeight',media.height());
			// 				$(this).addClass('post-media');
			// 			}
			// 			
			// 			var videos = $(this).find('object').parent();
			// 			var height = 0;
			// 			if(videos.length>0) {
			// 				$(videos).wrapAll('<div class="media" />');
			// 				var media = $(this).find('div.media');
			// 				$(this).addClass('post-media');
			// 			}
			
		});
	}
}

/* Block
------------------------- */
var Block = {
	Items: null,
	init: function(items) {
		var cc = this;
		if(items) {
			cc.Items = items;
		}
		else {
			cc.Items = $('.block');
		}
		if(cc.Items.length>0) {
			cc.render();
		}
	},
	render: function() {
		var cc = this;
		cc.Items.each(function() {
			if($(this).find('a').length>0) {
				var target = $(this).find('a');
				var words = target.text().split(' ');
			}
			else {
				var target = $(this);
				var words = target.text().split(' ');
			}
			var text = '';
			$.each(words, function(key, value) {
				text+='<strong>'+value+'</strong>';
			});
			$(this).addClass('cF');
			$(target).html(text);
		});
		Cufon.replace('h1 strong, h2 strong');
	}
}

