jQuery(document).ready(function(){

	var magicBox = function(){
	
		jQuery('.magic-box').each(function(){
			var curElem = this;
			var content = jQuery(curElem).html();
			jQuery(curElem).html('');
			jQuery(curElem).append('<div class="magic-box-wrapper"/>');
			jQuery('.magic-box-wrapper',curElem).append('<div class="magic-box-tl"/>');
			jQuery('.magic-box-wrapper',curElem).append('<div class="magic-box-tc"/>');
			jQuery('.magic-box-wrapper',curElem).append('<div class="magic-box-tr"/>');
			jQuery('.magic-box-wrapper',curElem).append('<div class="magic-box-ml"/>');
			jQuery('.magic-box-wrapper',curElem).append('<div class="magic-box-mc"/>');
			jQuery('.magic-box-wrapper',curElem).append('<div class="magic-box-mr"/>');
			jQuery('.magic-box-wrapper',curElem).append('<div class="magic-box-bl"/>');
			jQuery('.magic-box-wrapper',curElem).append('<div class="magic-box-bc"/>');
			jQuery('.magic-box-wrapper',curElem).append('<div class="magic-box-br"/>');
			jQuery('.magic-box-wrapper',curElem).append('<div class="clearer"/>');
		
			jQuery('.magic-box-mc',curElem).html(content);
		
			var w = jQuery(curElem).outerWidth()-32;
			var h = jQuery(curElem).outerHeight();

		
		
			jQuery('.magic-box-tc,.magic-box-bc',curElem).css({
				width:w+'px'
			});
		
			jQuery('.magic-box-ml,.magic-box-mr',curElem).css({
				height:h+'px'
			});
		
			jQuery('.magic-box-mc',curElem).css({
				width:w+'px'/*,
				height:h+'px'*/,
				height:'auto'
			});
		
		});
		
	
	}

	magicBox();

});

function updateMagicBoxHeight(){

	jQuery('.magic-box').each(function(){

		var that = this;
		var h = 0;
		jQuery('.magic-box-mc',that).children().each(
			function(){
				h = Math.max(h,jQuery(this).outerHeight(true));
			}
		);
		/*
		jQuery('.magic-box-mc,.magic-box-ml,.magic-box-mr',that).css({
			height:h+'px'
		});
		*/
		
		jQuery('.magic-box-ml,.magic-box-mr',that).css({
			height:h+'px'
		});

	});
	
}

var prevOnload = (typeof(window.onload)=='function') ? window.onload : function(){};

window.onload = function(){
	prevOnload();
	updateMagicBoxHeight();
}


jQuery(document).load(function(){
	updateMagicBoxHeight();
});

