// JavaScript Document

$(document).ready(function() {
	// set max char count
	var maxChar = 27;
	
	// classname holder
	var listStr = '';
	
	// parse headlines
	$headlines = $('.post h2 a');
	if ($headlines.length > 0)
	{
		$headlines.each(function (idx) {
			var words = $(this).html().split(' ');
			var charCount = 0;
			var myParent = $(this).parent();
	
			// split headline into array
			var i, lines = [''];
			var j = 0;
			
			for (i = 0; i < words.length; i++)
			{
				charCount += words[i].length;
				if (charCount > maxChar)
				{
					j++;
					charCount = 0;
					lines[j] = '';
				}
				lines[j] += words[i] + ' ';
			}
	
			myParent.html('<a rel="bookmark" href="' + $(this).attr('href') + '" class="title splitted hvr_' + idx + '">' + lines[0] + '</a><br />');
	
			for (i = 1; i < lines.length; i++)
			{
				myParent.append('<a rel="bookmark" href="' + $(this).attr('href') + '" class="title splitted hvr_' + idx + '">' + lines[i] + '</a><br />');
			}
		});
	}
	else
	{
		$('.post h2').each(function (idx) {
			var words = $(this).html().split(' ');
			var charCount = 0;
			var curItem = $(this);
	
			// split headline into array
			var i, lines = [''];
			var j = 0;
			
			for (i = 0; i < words.length; i++)
			{
				charCount += words[i].length;
				if (charCount > maxChar)
				{
					j++;
					charCount = 0;
					lines[j] = '';
				}
				lines[j] += words[i] + ' ';
			}
	
			curItem.html('<span class="title splitted hvr_' + idx + '">' + lines[0] + '</span><br />');
	
			for (i = 1; i < lines.length; i++)
			{
				curItem.append('<span class="title splitted hvr_' + idx + '">' + lines[i] + '</span><br />');
			}
		});
	}
	
	$('.splitted').hover(
		function () {
			var classList = $(this).attr('class').split(/\s+/);
			listStr = '';
			for (var i = 0; i < classList.length; i++)
			{
				listStr += '.' + classList[i];
			}
			$(listStr).addClass('hovering');
		}, 
		function () {
			$(listStr).removeClass('hovering');
		}
	);
});
