jQuery(document).ready(function(){
	//drop cap, do it!
	swap_letter();
	//If the User resizes the window, adjust the #container height
	//jQuery(window).bind("resize", moveLayout);
});

function moveLayout() {
	var win = jQuery(document).width();
	var site = jQuery("#container").width();
	if(win>site+200){
		var shift = (site-900)/2;
		s = "-=" + shift + "px"; 
		jQuery("#container").animate({
    	'marginLeft' : s
		});
	}
};
	
function swap_letter() {
  jQuery('.dropcap').each(function(index) {
	var paragraph = this;
	var node = paragraph;
	while (node.childNodes.length) {
	   node = node.firstChild;
	 }
	 var text = node.nodeValue;
	 var first_letter = text.substr(0,1);
	 switch (first_letter) {
		case "a":
		case "A": 
			var theNum = 2;
			break;
		case "b": 
		case "B":
			var theNum = 2; 
			break;
		case "c": 
		case "C":
			var theNum = 4; 
			break;
		case "d": 
		case "D":
			var theNum = 5; 
			break;
		case "e": 
		case "E":
			var theNum = 5; 
			break;
		case "g": 
		case "G":
			var theNum = 3;
			break;
		case "i": 
		case "I":
			var theNum = 4;
			break;
		case "p": 
		case "P":
			var theNum = 2; 
			break;
		case "w": 
		case "W":
			var theNum = 3; 
			break;
		default: 
			var theNum = 1;
	}
	 var match = /[a-zA-Z]/.test(first_letter);
	 if ( match ) {
	   node.nodeValue = text.slice(1);
	   jQuery('<img />')
	    .attr('src','http://jhische.com/dailydropcap/' + first_letter.toUpperCase() + '-'+theNum+'-cap.png')
	    .attr('alt',first_letter)
	    .addClass('jhische-dropcap')
	    .prependTo( paragraph );
	   first_letter = "";
	 }
  });
}
