/*

	This scripts formats single posts which are displayed in asides across the site

*/


jQuery(document).ready(function($){
	
	var single = $('#single-post');
//-- Get elements
	var head = single.find('h2:first').detach();
	var img = single.find('img:first').attr('class','').detach();	
	var sText = single.find('.post-body').text().substr(0,100);
	sText = sText.substr(0,sText.lastIndexOf(' ')) + '...';
//-- Get url
	var url = head.find('a').attr('href');
//-- Create anchor and wrap it around the img	
	if(img.length == 1)
	{
		var oAnchor = $('<a></a>')
							.attr({
								href: url,
								title: head.text()	
							})
							.css({
								display: 'block'	
							})
							.html(img.attr({'width':'','height':''}));
							
		single.html(oAnchor);
	} else {
		single.html('');	
	}
//-- Attach heading
	head.appendTo(single);
//-- Attach introduction	
	$('<div></div>')
		.attr({
			'class': 'post-body'	
		})
		.text(sText)
		.appendTo(single);
//-- Attach link		
	var oP = $('<p></p>')
				.attr({
					'class':'hasFloat'	
				})
				.appendTo(single);
				
	$('<a></a>')
		.attr({
			href: url,
			title: 'Read More',
			'class': 'btn'	
		})
		.text('Read More')
		.appendTo(oP);
						
});










