/* ------------------------------------------------------------------------

    Title:      Pearson At-a-Glance JavaScript (behavior) file
    Filename:   main.js
    Method:     <link>
    Author:     Bob Prokop | bobprokop@yahoo.com
    Updated:    April 2010
    Notes:      ...		

------------------------------------------------------------------------- */
/*------ what to do onload of document ------*/
	// W3C DOM-standards user agents //
	if(window.addEventListener){
		window.addEventListener("load",init_page,false);
	}
	// Internet Explorer //
	else{
		window.attachEvent("onload",init_page);
	}
/*-------------------------------------------*/
function init_page(){
	/*--- make Moz happy and clean-up whitespace ---*/
	if(window.addEventListener){
		treeWalker(document);
	}
}
//-------------------------------------------------------------------------------------------------------
// jQuery + plug-in stuff
//-------------------------------------------------------------------------------------------------------
$(document).ready(function(){
	
/* prevent widows and orphans by inserting a non-breaking space between the last two words in a given
element or element type */
$('p').widont();
//$('p').not('.arrow').widont();
$('.ditl > ul > li').widont();

/* footer: get + print current year */
var currentYear = (new Date).getFullYear();
$('#current-year-footer').text((new Date).getFullYear());

/* footer (print): get full date */
var currentTime = new Date()
var month = currentTime.getMonth() + 1
var day = currentTime.getDate()
var year = currentTime.getFullYear()
$('#current-full-date').text(month + '/' + day + '/' + year);

/* Equalize column height */
$('.col').equalHeights();

});

$(window).load(function(){ 

	// For each instance of p.caption
	$('.caption').each(function(){
		$(this)
			// Add the following CSS properties and values
			.css({
				'width' : $(this).children('img').width() + 'px'
			})
	// End $(this)
	});

});

//-------------------------------------------------------------------------------------------------------
// The following scripts are called from the init_page function (and some of these call other functions) 
//-------------------------------------------------------------------------------------------------------
/* equal height columns (used for multi-col taxonomy browse elements), courtesy of Rob Glazerbrook */
(function($){
	$.fn.equalHeights = function(minHeight, maxHeight){
		tallest = (minHeight) ? minHeight : 0;
		this.each(function(){
			if($(this).height() > tallest){
				tallest = $(this).height();
			}
		});
		if((maxHeight) && tallest > maxHeight) tallest = maxHeight;
		return this.each(function(){
			if ($(this).height() < tallest){
			$(this).height(tallest).css('overflow','auto');
			}
		});
	}
})(jQuery);

/* make Moz happy and clean up any whitespace */
function treeWalker(node){
	var notWhitespace = /\S/
	for(var x = 0; x < node.childNodes.length; x++){
		var childNode = node.childNodes[x];
			if((childNode.nodeType == 3)&&(!notWhitespace.test(childNode.nodeValue))){
      			node.removeChild(node.childNodes[x])
     			 x--
    		}
    		if(childNode.nodeType == 1){
      			treeWalker(childNode)
    		}
  		}
}
