/* $Id: pod.js,v 1.4 2006/11/13 02:52:23 bjaspan Exp $ */

/* this is global so pod_fix does not have to rescan the DOM on resize */
var pod_fix_list = [];

/*
  1.  Convert .pod-plain to .pod, inserting the extra markup.
      This is a little subtle because I also want to move all additional
      classes on the .pod-plain div to the .pod, so you can say (e.g.)
      <div class="pod-plain float-left"> and have the float-left end up
      applying to the generated .pod div, not the .pod-content div.
  
  2.  Find all .pod-left and .pod-right divs, remember them, and call pod_fix.
*/
function pod_start() {
    $(".pod-plain")
	.removeClass("pod-plain")
	.wrap("<div class='pod'></div>")
	.each(function() {
	    $(this).parent().addClass($(this).attr('class')); })
	.attr("class", "pod-content")
	.before('<div class="pod-ul"></div><div class="pod-ur"></div>' +
		'<div class="pod-left"></div><div class="pod-right"></div>' +
		'<div class="pod-ll"></div><div class="pod-lr"></div>')
	;
    
    $(".pod-left,.pod-right").each(function() {
	pod_fix_list[pod_fix_list.length] = $(this);
    });
    pod_fix();
}				   

/* fix the height of all .pod-left and .pod-right divs */
function pod_fix() {
    $.each(pod_fix_list, function(i) {
	var c = pod_fix_list[i];
	$(c).height(Math.max($(c).parent().height() -
			     $(c).siblings(".pod-ul").height() -
			     $(c).siblings(".pod-ur").height(),
			     0)+"px");
    });
}

/*
  1.  Call pod_start() when the DOM is ready.
  2.  Call pod_fix() when the window is resized.
*/
$(document).ready(pod_start);
$(window).resize(pod_fix);

