/* ------------------------------------------------------------------------

    Title:      Pearson HED Catalog JavaScript (behavior) file
    Filename:   rwp.js
    Method:     <link>
    Author:     Bob Prokop | bobprokop@yahoo.com
    Updated:    April 2011
    Notes:      ...		

------------------------------------------------------------------------- */
/*	what to do on load
------------------------------------------------------------------------- */
if(window.addEventListener){ // W3C DOM-standards user agents //
	window.addEventListener("load",init_page,false);
	}
else{ // Internet Explorer //
	window.attachEvent("onload",init_page);
	}

/*	initialize page
----------------------------------------------*/
function init_page(){
	if(window.addEventListener){
		treeWalker(document);
	}
}



/*	jQuery + plug-in(s)
----------------------------------------------*/
$(document).ready(function(){
						   
//	Initialize various modules
	init_verticalAccordion();
	init_tabs();
	init_toc();
	init_promos();
	init_tooltip();
	init_standardForms();
	init_NewAddress();
	init_nickName();
	init_deleteButtons();
	init_closeMsg();
	init_cancelButtons();
	init_saveButtons();
	init_editButtons();
	init_miniForm();
	init_tipMessaging();
	init_myAccountForm();
	init_repLocatorForm();
	init_resetButtons();
	init_requestExamCopy();
	init_closeModal();
	init_removeItem();
	init_GoBack();
	init_signInViaCheckoutForm();
	init_forgotInfo();
	init_CMGforgot();
	//init_checkOutWithAccount();
	//init_checkoutAsGuestForm();
	init_requestAccessForm();
	init_advancedSearchForm();
	init_pageControls();
	init_haveYouAdopted();
	init_ChangeAddress();
	init_FDOCregistrationForm();
	init_FDOCmodals();

// don't cache our simple ajax requests
$.ajaxSetup({
    cache: false
});


/*	hide these elements using jQuery; if visitor is browsing with
	JavaScript turned off they will still be able to see these
	elements which are 'hidden' via stylesheet file(s).
------------------------------------------------------------------------*/
	$('ul.cluster').hide();
	$('ul.course').hide();
	$('.edit-mode-only').hide();
	$('tr.conditional').hide();
	$('.modal').hide();



/*	Equalize column height
----------------------------------------------*/
	equalHeight($('.equal-column'));



	
/*	promotional gallery + controls
----------------------------------------------*/

//	Expand the container
	init_height = $('#promotions-gallery').css('height');
	
	$('button.expand').live('click', function(){
		
		//	Pause the carousel/slider motion when user expands content
		$('#promotions-gallery').cycle('pause');
		cur_height= $('#promotions-gallery').css('height');
		(cur_height == '800px') ? height= init_height : height= '800px';
		
		//	Swap out text-label for min-max button
		var txt = (cur_height == '800px') ? 'Show more' : 'Show less';
		$('button.expand').text(txt);
		$('button.expand').toggleClass('max min');
		
		//	Hide this control: a concessions to IE7 (bleh)
		$('#expand-controls').fadeOut(100, function(){
            
			//	This would be the actual animation transition
			$('#promotions-gallery').animate({
                'height' : height
            	},300);
			});
		
		//	Show the controls again (IE7; see above)
          $('#expand-controls').fadeIn('medium');
       });



/*	Removes the bottom border from the last child of a given parent.
	Frees development team from having to implement in template logic.
------------------------------------------------------------------------*/
	$('ul.cluster > li:last-child > span').addClass('no-border');
	$('ul.course > li:last-child > a').addClass('no-border');
	$('.product-list > li:last-child').addClass('no-border');
	$('.tabs > ul > li:last-child').addClass('no-border');
	$('.vertical-menu > li:last-child').addClass('no-border');
	$('.section-toc > li:last-child > a').addClass('no-border');
	//$('div.cover > ul > li:last-child > a').addClass('no-border');
	
	//	When generated dynamically via an Ajax call, we need bind events with 'live'
	$('.product-list > li:last-child').live('load', function(){
	$('.product-list > li:last-child').addClass('no-border');
	});


/*	prettyPhoto
	Use to open content in modal window. Content can be:
	--inline
	--external file
	--iframe
	--video (.mov, .avi, .swf, .ogg, etc.)
------------------------------------------------------------------------*/
	$("a[rel^='prettyPhoto']").prettyPhoto(); //-- use default parameters //

				   
/*	Footer: dynamically generate the 'Copyright + symbol + current year'
	Template is populated with 'Copyright + symbol' (no year) as
	a fallback for visitors w/o JavaScript enabled; if JS is enabled
	this script will print out the string and the current year.
------------------------------------------------------------------------*/
	var currentYear = (new Date).getFullYear();
	$('#current-year-footer').html('Copyright ' + '&copy; ' + (new Date).getFullYear() + ' ');


/*	Prevent widows and orphans by inserting a non-breaking space between
	the last two words in a given string/element. 'Widon't 2.1.1' was
	developed, written, and published by Shaun Inman www.shauninman.com
------------------------------------------------------------------------*/
	$('ul.discipline > li > a > span').widont();
	$('ul.cluster > li > span').widont();
	$('div#promotions-gallery > .panel > p').widont();
	$('.parent-title').widont();
	$('td.tip-small > p').widont();
	$('p.tip').widont();
	$('.normalize > li > p').widont();
	$('div#intro > p').widont();
	$('.widont').widont();
	//$('div.sidebar-narrow > p').widont();


/*	Promotion gallery controls. Based on the work of Mike Alsup and his
	wonderful 'jQuery Cycle' plug-in: http://jquery.malsup.com
------------------------------------------------------------------------*/
	$(function(){
		//	Pause button
		$('.pause').click(function(){
			$('#promotions-gallery').cycle('pause');
			$('.pause').css({display: 'none'});
			$('.play').css({display: 'block'});
			return false;
			});
		//	Play button
		$('.play').click(function(){
			$('#promotions-gallery').cycle('resume');
			$('.play').css({display: 'none'});
			$('.pause').css({display: 'block'});
			return false;
			});
		//	Hover over gallery to reveal controls (Note: disabled per LL March-2011)
		$('#gallery-container').hover(
			function() { $("#promo-controls:not('#promo-controls.sticky')").fadeIn(); },
			function() { $("#promo-controls:not('#promo-controls.sticky')").fadeOut(); }
		);
		//	Transition between panel content
	   $('#promotions-gallery').cycle({
			cleartype:  1, // enable cleartype corrections 
			delay: -4000,
			speed: 250,
			timeout: 9000,
			/*fx:'curtainX,curtainY,fade,fadeZoom,growX,growY,scrollHorz,scrollVert,slideX,slideY,turnUp,turnDown,turnLeft,turnRight,uncover,wipe,zoom,scrollLeft,scrollDown,scrollRight,scrollUp',
			10-Feb-2011: eliminate all transitions except for 'scrollRight' ('...sweeps in from left...') per Lisa Linard */
			fx:'scrollLeft', /* Note: old value was 'scrollRight', but change in scroll orientation was requested per Lisa Linard on 22-Feb-2011 */
			randomizeEffects: false,
			pause: true,
			next: '.next',
			prev: '.prev'
		});
	});

/*	Sets 'title' attribute for dynamically generated <a href> links
------------------------------------------------------------------------*/
	//	Discipline
	$('ul.discipline > li > a').each(function(){
		var discTooltip = $(this).children('span').text();
			if($('body').hasClass('discipline')){
				return false;
			}
			else{
				$(this).attr('title', 'Browse our catalog for products in ' + discTooltip);
			}
		});
	
	//	Cluster
	$('ul.cluster > li > span').each(function(){
		var clusterTooltip = $(this).text();
			$(this).attr('title', 'Click to toggle course(s) for ' + clusterTooltip);
		});
	
	//	Course
	$('ul.course > li > a').each(function(){
		var courseTooltip = $(this).children('span').text();
			$(this).attr('title', 'Browse our catalog for products in ' + courseTooltip);
		});
	
	//	Open-course
	$('ul.open-course > li > a').each(function(){
		var courseTooltip = $(this).children('span').text();
			$(this).attr('title', 'Browse our catalog for products in ' + courseTooltip);
		});
	
	//	Subhead
	$('ul.subhead > li > a').each(function(){
		var subheadTooltip = $(this).text();
			$(this).attr('title', 'Click to view ' + subheadTooltip + ' (scroll page)');
		});
	
	//	Tab sort
	$('ul.tabs > li > a').each(function(){
		var tabTooltip = $(this).text();
			$(this).attr('title', 'Show: ' + tabTooltip);
		});
	
	//	Error messages
	$('div.msg-error > p').each(function(){
		var msgErrorTooltip = $(this).text();
			$(this).attr('title', tabToolTip);
		});



/*	If visitor is on Discipline-level page, disable the
	'current-discipline' link (no point in refreshing the page).
	Check to see if the <body> tag has a class 'discipline' and then
	apply a return false(); to each discipline link.
------------------------------------------------------------------------*/
	$('ul.discipline > li > a.current-discipline').live('click', function(){
		if($('body').hasClass('discipline')){
			return false;
			}
		});


/*	Toggle various nodes of the taxonomy browse menu in the sidebar on
	the super-discipline, discipline, and course pages. For this version
	of the Pearson HED catalog, we are only toggling the clusters, which
	groups related courses underneath the discipline level of the
	catalog hierarchy structure.
------------------------------------------------------------------------*/
	$(function(){
		$('ul.discipline > li > a').live("click", function(){
				$(this).toggleClass('strong');
				$(this).next('ul.cluster').toggle(100);
			});

		$('ul.cluster > li > span').live("click", function(){
			if ($(this).is('.current-cluster')){
				$(this).toggleClass('current-highlight open');
				$(this).next('ul.course').toggle(100);
				$(this).next('ul.open-course').toggle(100);
				}
			else{
				$(this).toggleClass('strong open');
				$(this).next('ul.course').toggle(100);
				$(this).next('ul.open-course').toggle(100);
				}
			});
	});


/*	Scroll anchor links for more fluid and natural navigation for in-page
	links. Must set 'rel' attribute on link to 'anchor' for this to work.
------------------------------------------------------------------------*/
	$('a[rel=anchor]').live("click", function(){
		var full_url = this.href;
		var parts = full_url.split("#");
		var trgt = parts[1];
		var target_offset = $("#"+trgt).offset();
		var target_top = target_offset.top;
			$('html, body').animate({scrollTop:target_top}, 325);
			return false;
		});


/*	Variation on the 'big target' script; in this instance, we're making
	an entire list-item <li> with the compact product profiles clickable.
	Script checks for first <href> it finds inside the <li> (which will
	should always be the linked cover image if markup doesn't change)
	and applies that click event to the entire parent container.
------------------------------------------------------------------------*/
	/* Make entire <li> for compact product profiles clickable on discipline page */
	$('ol.big-target > li').live('click', function(){
		window.location=$(this).find('a:first').attr('href');
		});
	$('ol.big-target dd > a').live('click', function(event){
		event.stopPropagation();
		});

	//make first ajax call for content
	$('#ajax-content').load($('li.current-tab > a').attr('href'));


});/* end jQuery */





/*------------------------------------------------------------------------

	Note: The following are either functions called by event listeners
	found above or are non-jQuery function(s)
	
-------------------------------------------------------------------------*/
/*	not currently being used
$.fn.enumerate = function( start ){
  return this.each(function(i){
    $(this).append( "<strong class='mar-left-6px'>#" + ( i + start ) + "</strong>" );
  });
}*/
		
/*	Reusable Module: vertical accordion element
	Simply build a definition list <dl> in the markup
	and give it a class name of 'accordion-vertical';
	when user clicks on <a> nested inside each 
	definition term <dt> element, the very next
	definition data <dd> element will be displayed
	and all other sibling <dd> elements will collapse.
	
	Note:
	Wrap the entire <dl> inside a <div> container
	element if you wish to utilize the 'toggle all'
	functionality.
	
------------------------------------------------------------------------*/
	// Initialize
	function init_verticalAccordion(){
		//	monitor the situation
			var isToggled = false;
			
		//	first we hide the <dd> elements using JavaScript; visitors not using js will see the full list (accessibility) //
			$('dl.accordion-vertical > dd').hide();
	
			$('dl.accordion-vertical > dt > a').live('click', function(){
		
		//	fetch parent list
			var $dl = $(this).parents('dl:first');
		
		//	fetch parents <dt>
			var $dt = $(this).parents('dt:first');
		
		//	grab the next def data <dd>
			var $dd = $(this).parents('dt').next('dd');
		
		//	expand the <dd>
			$dd.toggle(100);
			
		//	style the toggle <dt>
			$dt.toggleClass('toggle-open');
			
			if($(this).parents('div:first').find('dl.accordion-vertical > dt.toggle-open').length){
				$(this).parents('div:first').find('a.toggle-all').html('Hide all');
				isToggled = true;
			}
			else{
				$(this).parents('div:first').find('a.toggle-all').html('Show all');
				isToggled = false;
			}
			
		//	don't follow link
			this.blur();
			return false;
		});
			
		//	toggleAll
		$('.toggle-all').live('click', function(){
			
			if(isToggled == false){
				$(this).html('Hide all');
				isToggled = true;
				$(this).parents('div').find('dl.accordion-vertical > dt').addClass('toggle-open');
				$(this).parents('div').find('dl.accordion-vertical > dd').show(100);
			}
			else{
				$(this).html('Show all');
				isToggled = false;
				$(this).parents('div').find('dl.accordion-vertical > dt').removeClass('toggle-open');
				$(this).parents('div').find('dl.accordion-vertical > dd').hide(100);
			}
			
			//	don't follow link
				this.blur();
				return false;
			});
	}
	
	
	
	// Initialize | Reusable module: tabbed content toggle
	function init_tabs(){
	//	Listen for click on tabs.
		$('ul.tabs > li > a').live('click', function(e){
													 
		//	If not current tab.
			if(!$(this).parent('li').hasClass('current-tab')) {
	
			//	Change the current indicator.
				$(this).parent('li').addClass('current-tab').siblings('li.current-tab').removeClass('current-tab');
			
			//	Load content
				$('#ajax-content').load($(this).attr('href'));
				this.blur();
				return false;
	
			}
			this.blur();
			return false;
			e.preventDefault;
			e.stopPropagation;
		});
	}
	
	
	
	// Initialize | Reusable module: vertical TOC content toggle
	function init_toc(){
	//	Listen for click on tabs.
		$('ul.section-toc > li > a').live('click', function(e){
			
		// Should this menu load new content (ajax) or scroll to anchor link?
			if(!$(this).is('[rel=ajax]')){
				return;
			}
			else{
				// If not current tab.
				if(!$(this).parent('li').hasClass('current-segment')){
					
					// Change the current indicator.
					$(this).parent('li').addClass('current-segment').siblings('li.current-segment').removeClass('current-segment');
				}
				
				//	If this link should replace the full panel of content, including the segement-toc sidebar nav
				if($(this).hasClass('ajax-replace-all')){
					
					//	Load full panel worth of content, including replacement of this sidebar
					$('#ajax-content').load($(this).attr('href'));
					this.blur();
					return false;
				}
				
				//	If this is a standard sidebar link, simply replace the panel content but leave segement-toc sidebar nav in place
				else{
					
					//	Show target, hide others.
					$('#right-column').load($(this).attr('href'))
					this.blur();
					return false;
				}
			}
			this.blur();
			return false;
			e.preventDefault;
			e.stopPropagation;
		});
		
	}



/*	Initialize | Promotional gallery
	We don't want to show the promotional control elements
	(previous | play/pause | next) if there is only a single
	promotion on the page
------------------------------------------------------------------------*/
	function init_promos(){
	//	How many special promotions are present?
		var promo_count = $('div.panel').size();
	
		//	If there is only 1 hide the gallery controls
		//	Note: is there are none, the gallery doesn't render controls by default
			if(promo_count == 1){
				$('#promo-controls').hide();
			}
			//	If more than 1, show the controls
			else{
				$('#promo-controls').show();
			}
	}



/*	Tooltips:
	
	Behavior based on script found in O'Reilly's "jQuery
	Cookbook"; source files publicly available online at:
	http://examples.oreilly.com/9780596159788/
	
-------------------------------------------------------------------------*/
	// Initialize.
	function init_tooltip(){
	
		// Does element exist?
		if(!$('.tooltip').length){
	
			// If not, exit.
			return;
		}
		
		//else{
	
		// Insert tooltip (hidden).
		$('body').append('<div id="tooltip"><div id="tooltip_inner"></div></div>');
	
		// Empty variables.
		var $tt_title, $tt_alt;
	
		var $tt = $('#tooltip');
		var $tt_i = $('#tooltip_inner');
	
		// Watch for hover.
		$('.tooltip').hover(function(){
	
			// Store title, empty it.
			if($(this).attr('title')){
				$tt_title = $(this).attr('title');
				$(this).attr('title', '');
			}
	
			// Store alt, empty it.
			if($(this).attr('alt')){
				$tt_alt = $(this).attr('alt');
				$(this).attr('alt', '');
			}
	
			// Insert text.
			$tt_i.html($tt_title);
	
			// Show tooltip.
			$tt.fadeIn('fast');
		},
		function(){
	
			// Empty text.
			$tt_i.html('');
			
			// Hide tooltip.
			$tt.hide('fast');
	
			// Fix title.
			if($tt_title){
				$(this).attr('title', $tt_title);
			}
	
			// Fix alt.
			if($tt_alt){
				$(this).attr('alt', $tt_alt);
			}
	
		// Watch for movement.
		}).mousemove(function(ev){
	
			// Event coordinates.
			var $ev_x = ev.pageX;
			var $ev_y = ev.pageY;
	
			// Tooltip coordinates.
			var $tt_x = $tt.outerWidth();
			var $tt_y = $tt.outerHeight();
	
			// Body coordinates.
			var $bd_x = $('body').outerWidth();
			var $bd_y = $('body').outerHeight();
	
			// Move tooltip.
			$tt.css({
				'top': $ev_y + $tt_y > $bd_y ? $ev_y - $tt_y : $ev_y,
				'left': $ev_x + $tt_x + 20 > $bd_x ? $ev_x - $tt_x - 10 : $ev_x + 15
			});
		});
	}



/*	Initialize standard forms
------------------------------------------------------------------------*/
	function init_standardForms(){
		
		// Does element exist?
		if(!$('form.standard-form').length){
			// If not, exit.
			return;
		}
		else{
		
		//	HIDE the tips and conditional table rows
		$('.tip-small > p').hide();
		$('tr.conditional').hide();
		
		//	jQuery UI date-picker modal function
		$('.d-date').datepicker();
	
		
		//	AUTOFOCUS is being used for browsers that support it, but for others
		//	we need to use the following 2 lines to focus on the first visible
		//	input (where type=text) and then show its accompanying 'tip' if present
		var $firstVisibleTextInput = $('form.standard-form').not('form.read-only').find('input:text:visible:first')
		
		$firstVisibleTextInput.focus().addClass('IE7').nextAll('.tip-small > p:first').fadeIn('slow');
		$firstVisibleTextInput.parents('tr').find('label').addClass('strong');

		
		
		//	INPUT: TEXT > focus
		//	CSS handles the style for the input element itself (with exception for IE7)
		//	jQuery helps us target the element's parent and style it as well
		$('form.standard-form input:text, select, textarea, .pseudoSelect').live('focus, click', function(){
			
			//	if this is contained within a read-only fieldset, stop
			if($(this).parents('fieldset').hasClass('read-only-mode')){
				return;
				}
				
			//	un-style the other instances
			$(this).parents('form').find('label').removeClass('strong');
			$(this).parents('form').find('.pseudoLabel').removeClass('strong');
			$(this).parents('form').find('input:text, select, textarea').removeClass('IE7');
			$(this).parents('form').find('a.pseudoSelect').not(this).removeClass('isActive');
			
			$('.tip-small > p').fadeOut(200);
			
			//	style this instance
			$(this).addClass('IE7').addClass('isActive'); // IE7 doesn't understand ':focus'
			$(this).parents('tr').find('label').addClass('strong');
			$(this).parents('tr').find('span.pseudoLabel').addClass('strong');
			$(this).parents('tr').find('.tip-small > p').fadeIn(200);
			});
		
		
		//	Need to set up a blur for input:text in order to hide 'tip' content
		//	INPUT:TEXT > blur{
			
			$('form.standard-form input:text, select, textarea, .pseudoSelect').live('blur', function(){
				
				// if this is contained within a read-only fieldset, stop
				if($(this).parents('fieldset').hasClass('read-only-mode')){
					return;
					}
						
				//	else...
				$('label, span, .pseudoLabel').removeClass('strong');
				$('a.pseudoSelect').removeClass('isActive');
				$('.tip-small > p').fadeOut(200);
				});
		
		

		//	INPUT: CHECKBOXES + RADIO BUTTONS > focus
		/*$('form.standard-form input:checkbox, input:radio').live('focus, click', function(){
			
			//	style this instance
			if($(this).is(':checked')){
				$(this).next('label').addClass('strong');
				 }
			else{
				$(this).next('label').removeClass('strong');
				}
			});*/
		
		
		
		//	Pseudo-labels, too ('span.label'; for pseudo-dropdowns)
		$('form.standard-form .pseudoLabel').live('focus, click', function(){
			
			//	un-style others, including actual <label>s
			$(this).parents('form').find('label').removeClass('strong');
			$(this).parents('form').find('.pseudoLabel').removeClass('strong');
			
			//	style this instance
			$(this).addClass('strong').parents('tr').find('td > a.pseudoSelect').focus();
			});
		
		
		//	FOCUSOUT: Blur all when focus is removed from inside form
		$('form.standard-form').live('focusout', function(){
			$(this).children('label, span, .pseudoLabel').removeClass('strong');
			$(this).children('a.pseudoSelect').removeClass('isActive');
			$(this).children('.tip-small > p').fadeOut(200);
			});
		}
		
		
		//	RESET: Resetting the form w/o using an actual input:reset
		$('form.standard-form :reset').live('click', function(){
			$(this).parents('form').find('input:text:visible:first').focus().addClass('IE7').nextAll('.tip-small > p:first').fadeIn('slow');
			});
		
	}
	

/*	Initialize the 'Advanced Search' form
-------------------------------------------------------------------------*/
	function init_advancedSearchForm(){
	
	//	set up commonly referenced items
	
	//	the form id
	var $advancedSearchForm = $('form#advancedSearchForm');
	
	//	what fields are associated with this form that we need to interact with?
	var $keyword = $advancedSearchForm.find('input#keyword');
	var $author = $advancedSearchForm.find('input#author');
	var $title = $advancedSearchForm.find('input#title');
	var $isbn = $advancedSearchForm.find('input#isbn');
	var $edition = $advancedSearchForm.find('input#edition');
	var $series = $advancedSearchForm.find('input#series');
	var $copyrightYear = $advancedSearchForm.find('input#copyright-year');
	var $discipline = $advancedSearchForm.find('select#discipline');
	var $subject = $advancedSearchForm.find('select#subject');
	var $submitSearch = $advancedSearchForm.find('button#submit-search');
	var $resetSearch = $advancedSearchForm.find('input#reset-search');
	
	//	hide the row that contains the subject area dropdown
	$subject.parents('tr').hide();
	
	//	DISCIPLINE dropdown: enable subject dropdown when visitor selects a valid discipline option
	$discipline.live('change', function(){
		
		//	if user chooses a valid option
			if($discipline.val() != 0){
				
				//	show the 'subject' parent table row and reset its value
				$subject.val(0).parents('tr').fadeIn(200);
			}
			
			else{
			
				//	else, if default option is chosen for discipline: reset value of 'subject' and hide its parent table row
				$subject.val(0).parents('tr').fadeOut(200);
			}
		});
	
	//	hijack the form submission
	$advancedSearchForm.submit(function(event){
		if($keyword.val() == 0 && $author.val() == 0 && $title.val() == 0 && $isbn.val() == 0 && $edition.val() == 0 && $series.val() == 0 && $copyrightYear.val() == 0 && $discipline.val() == 0 && $subject.val() == 0){
			//	remove the error message if it already exists
			$('div.message').remove();
			
			//	build a message
			$submitSearch.parent('td').prepend('<div class="message msg-error" style="width:264px;"><p class="group" title="Click to close">Please complete at least one field.</p></div>');
			
			//	display the message
			$('div.message').hide().delay(400).slideDown(200);
			
			//	prevent the form from being submitted
			event.preventDefault();
		}
		else{
			
			//	remove the error message
			$('div.message').remove();
			
			//	submit the form
			return true;
		}
	});
	
	//	hijack the form reset
	$resetSearch.click(function(event){
		
		//	remove the error message
			$('div.message').remove();
	});
	

	}



/*	Initialize 'Add New Address' button
	Used on the 'My Shipping Addresses' tab under 'My Account'
------------------------------------------------------------------------*/
	function init_NewAddress(){
		
		$('button.add-new').live('click', function(){
			$('<fieldset class="mar-top-18px no-bottom-margin edit-mode list-item shipping-address"><div class="legend group"><h2>New shipping address</h2></div><table summary="Table is being used for layout purposes of form elements." cellpadding="0" cellspacing="0"><tbody><tr><td class="text-right"><label for="country" class="required">Country</label></td><td><select id="country" name="country" class="x-large"><option value="0" selected="selected">Please select your country</option><option value="AF">Afghanistan</option><option value="Z9">Albania</option><option value="DZ">Algeria</option><option value="AS">American Samoa</option><option value="AD">Andorra</option><option value="AO">Angola</option><option value="AI">Anguilla</option><option value="AG">Antigua And Barbuda</option><option value="AR">Argentina</option><option value="AM">Armenia</option><option value="AW">Aruba</option><option value="AU">Australia</option><option value="AT">Austria</option><option value="AZ">Azerbaijan</option><option value="BS">Bahamas</option><option value="BH">Bahrain</option><option value="BD">Bangladesh</option><option value="BB">Barbados</option><option value="BY">Belarus</option><option value="BE">Belgium</option><option value="BZ">Belize</option><option value="BJ">Benin</option><option value="BM">Bermuda</option><option value="BT">Bhutan</option><option value="BO">Bolivia</option><option value="BA">Bosnia and Herzegovina</option><option value="BW">Botswana</option><option value="BV">Bouvet Island</option><option value="BR">Brazil</option><option value="X1">British Indian Ocean Territory</option><option value="BN">Brunei</option><option value="BG">Bulgaria</option><option value="BF">Burkina Faso</option><option value="MM">Burma</option><option value="BI">Burundi</option><option value="KH">Cambodia</option><option value="CM">Cameroon</option><option value="CA">Canada</option><option value="X2">Canary Islands</option><option value="CV">Cape Verde</option><option value="KY">Cayman Islands</option><option value="CF">Central African Republic</option><option value="TD">Chad</option><option value="CL">Chile</option><option value="CN">China</option><option value="CX">Christmas Island</option><option value="CC">Cocos (Keeling) Islands</option><option value="CO">Colombia</option><option value="KM">Comoros</option><option value="CG">Congo</option><option value="CK">Cook Islands</option><option value="CR">Costa Rica</option><option value="CI">Cote Divoire</option><option value="HR">Croatia</option><option value="CU">Cuba</option><option value="Y6">Curaco</option><option value="CY">Cyprus</option><option value="CZ">Czech Republic</option><option value="DK">Denmark</option><option value="DJ">Djibouti</option><option value="DM">Dominica</option><option value="DO">Dominican Republic</option><option value="Y7">East Timor</option><option value="EC">Ecuador</option><option value="EG">Egypt</option><option value="SV">El Salvador</option><option value="GQ">Equatorial Guinea</option><option value="ER">Eritrea</option><option value="EE">Estonia</option><option value="ET">Ethiopia</option><option value="Z2">FYROM</option><option value="FK">Falkland Islands (Malvinas)</option><option value="FO">Faroe Islands</option><option value="FJ">Fiji</option><option value="FI">Finland</option><option value="FR">France</option><option value="Y8">France, Metropolitan</option><option value="GF">French Guiana</option><option value="PF">French Polynesia</option><option value="X4">French Southern Territories</option><option value="GA">Gabon</option><option value="Z5">Gambia</option><option value="GE">Georgia</option><option value="DE">Germany</option><option value="GH">Ghana</option><option value="GI">Gibraltar</option><option value="GR">Greece</option><option value="GL">Greenland</option><option value="GD">Grenada</option><option value="GP">Guadeloupe</option><option value="GU">Guam</option><option value="GT">Guatemala</option><option value="GN">Guinea</option><option value="GW">Guinea-Bissau</option><option value="GY">Guyana</option><option value="HT">Haiti</option><option value="HM">Heard And Mc Donald Islands</option><option value="HN">Honduras</option><option value="HK">Hong Kong</option><option value="HU">Hungary</option><option value="Z6">Iceland</option><option value="IN">India</option><option value="ID">Indonesia</option><option value="IR">Iran</option><option value="IQ">Iraq</option><option value="IE">Ireland</option><option value="IL">Israel</option><option value="IT">Italy</option><option value="X5">Ivory Coast</option><option value="JM">Jamaica</option><option value="JP">Japan</option><option value="JO">Jordan</option><option value="KZ">Kazakhstan</option><option value="KE">Kenya</option><option value="KI">Kiribati</option><option value="KP">Korea, Democratic Peoples Republic Of</option><option value="KR">Korea, Republic Of</option><option value="KW">Kuwait</option><option value="KG">Kyrgyzstan</option><option value="LA">Lao Peoples Democratic Republic</option><option value="LV">Latvia</option><option value="LB">Lebanon</option><option value="LS">Lesotho</option><option value="LR">Liberia</option><option value="LY">Libya</option><option value="LI">Liechtenstein</option><option value="LT">Lithuania</option><option value="LU">Luxembourg</option><option value="MO">Macau</option><option value="MG">Madagascar</option><option value="X6">Maderia</option><option value="MW">Malawi</option><option value="MY">Malaysia</option><option value="MV">Maldives</option><option value="ML">Mali</option><option value="MT">Malta</option><option value="MH">Marshall Islands</option><option value="MQ">Martinique</option><option value="MR">Mauritania</option><option value="MU">Mauritius</option><option value="YT">Mayotte</option><option value="MX">Mexico</option><option value="FM">Micronesia, Federated States Of</option><option value="MD">Moldova, Republic Of</option><option value="MC">Monaco</option><option value="MN">Mongolia</option><option value="MS">Montserrat</option><option value="MA">Morocco</option><option value="MZ">Mozambique</option><option value="R3">Myanmar</option><option value="X7">N. Cyprus</option><option value="X8">N. Ireland</option><option value="NA">Namibia</option><option value="NR">Nauru</option><option value="NP">Nepal</option><option value="NL">Netherlands</option><option value="AN">Netherlands Antilles</option><option value="NC">New Caledonia</option><option value="NZ">New Zealand</option><option value="NI">Nicaragua</option><option value="NE">Niger</option><option value="NG">Nigeria</option><option value="NU">Niue</option><option value="NF">Norfolk Island</option><option value="MP">Northern Mariana Islands</option><option value="NO">Norway</option><option value="OM">Oman</option><option value="PK">Pakistan</option><option value="PW">Palau</option><option value="PA">Panama</option><option value="PG">Papua New Guinea</option><option value="PY">Paraguay</option><option value="PE">Peru</option><option value="PH">Philippines</option><option value="PN">Pitcairn</option><option value="PL">Poland</option><option value="PT">Portugal</option><option value="PR">Puerto Rico</option><option value="QA">Qatar</option><option value="RE">Reunion</option><option value="RO">Romania</option><option value="RU">Russia</option><option value="RW">Rwanda</option><option value="KN">Saint Kitts And Nevis</option><option value="LC">Saint Lucia</option><option value="VC">Saint Vincent And The Grenadines</option><option value="WS">Samoa</option><option value="SM">San Marino</option><option value="ST">Sao Tome And Principe</option><option value="SA">Saudi Arabia</option><option value="Y9">Scotland</option><option value="SN">Senegal</option><option value="X9">Serbia</option><option value="SC">Seychelles</option><option value="SL">Sierra Leone</option><option value="SG">Singapore</option><option value="SK">Slovakia (Slovak Republic)</option><option value="SI">Slovenia</option><option value="SB">Solomon Islands</option><option value="SO">Somalia</option><option value="ZA">South Africa</option><option value="GS">South Georgia And The South Sandwich Islands</option><option value="ES">Spain</option><option value="LK">Sri Lanka</option><option value="Y4">St. Lucia</option><option value="Y5">St. Maarten</option><option value="Z8">St. Pierre And Miquelon</option><option value="SD">Sudan</option><option value="SR">Suriname</option><option value="SJ">Svalbard And Jan Mayen Islands</option><option value="SZ">Swaziland</option><option value="SE">Sweden</option><option value="CH">Switzerland</option><option value="SY">Syrian Arab Republic</option><option value="TW">Taiwan</option><option value="TJ">Tajikistan</option><option value="TZ">Tanzania</option><option value="TH">Thailand</option><option value="TG">Togo</option><option value="TK">Tokelau</option><option value="TO">Tonga</option><option value="Z4">Trinidad And Tobago</option><option value="TN">Tunisia</option><option value="TR">Turkey</option><option value="TM">Turkmenistan</option><option value="TC">Turks And Caicos Islands</option><option value="TV">Tuvalu</option><option value="UG">Uganda</option><option value="UA">Ukraine</option><option value="R2">United Arab Emirates</option><option value="GB">United Kingdom</option><option value="US">United States of America</option><option value="Y1">United States Minor Outlying Islands</option><option value="UY">Uruguay</option><option value="Y2">USSR (Former)</option><option value="UZ">Uzbekistan</option><option value="VU">Vanuatu</option><option value="R1">Vatican City State (Holy See)</option><option value="VE">Venezuela</option><option value="VN">Vietnam</option><option value="VG">Virgin Islands (British)</option><option value="VI">Virgin Islands (U.S.)</option><option value="Z1">Wales</option><option value="WF">Wallis And Futuna Islands</option><option value="Y3">West Bank</option><option value="EH">Western Sahara</option><option value="YE">Yemen</option><option value="YU">Yugoslavia</option><option value="ZR">Zaire</option><option value="ZM">Zambia</option><option value="ZW">Zimbabwe</option></select></td><td class="vert-top tip"></td></tr><tr><td class="text-right"><label for="nickname-01" class="required">Address nickname</label></td><td><input type="text" class="nickname large" name="nickname-01" id="nickname-01" value="" maxlength="56" /></td><td class="ver-top tip" rowspan="7"></td></tr><tr><td class="text-right"><label for="address-01" class="required">Address 1</label></td><td><input type="text" class="large" name="address-01" id="address-01" value="" /></td></tr><tr><td class="text-right"><label for="address-02">Address 2</label></td><td><input type="text" class="large" name="address-02" id="address-02" value="" /></td></tr><tr><td class="text-right"><label for="city" class="required">City/Town</label></td><td><input type="text" class="large" name="city" id="city" value="" /></td></tr><tr><td class="text-right"><label for="state" class="required">State</label></td><td><select name="stateProvince" id="stateProvince"><option value="0" selected="selected">Please select your state</option><option value="AL">ALABAMA</option><option value="AK">ALASKA</option><option value="AS">AMERICAN SAMOA</option><option value="AZ">ARIZONA</option><option value="AR">ARKANSAS</option><option value="AA">ARMED FORCES - ALANTIC DIVISION</option><option value="AE">ARMED FORCES - EUROPEAN DIVISION</option><option value="AP">ARMED FORCES - PACIFIC DIVISION</option><option value="CA">CALIFORNIA</option><option value="CO">COLORADO</option><option value="CT">CONNECTICUT</option><option value="DE">DELAWARE</option><option value="DC">DISTRICT OF COLUMBIA</option><option value="FM">FEDERATED STATES OF MICRONESIA</option><option value="FL">FLORIDA</option><option value="GA">GEORGIA</option><option value="GU">GUAM</option><option value="HI">HAWAII</option><option value="ID">IDAHO</option><option value="IL">ILLINOIS</option><option value="IN">INDIANA</option><option value="IA">IOWA</option><option value="KS">KANSAS</option><option value="KY">KENTUCKY</option><option value="LA">LOUISIANA</option><option value="ME">MAINE</option><option value="MH">MARSHALL ISLANDS</option><option value="MD">MARYLAND</option><option value="MA">MASSACHUSETTS</option><option value="MI">MICHIGAN</option><option value="MN">MINNESOTA</option><option value="MS">MISSISSIPPI</option><option value="MO">MISSOURI</option><option value="MT">MONTANA</option><option value="NE">NEBRASKA</option><option value="NV">NEVADA</option><option value="NH">NEW HAMPSHIRE</option><option value="NJ">NEW JERSEY</option><option value="NM">NEW MEXICO</option><option value="NY">NEW YORK</option><option value="NC">NORTH CAROLINA</option><option value="ND">NORTH DAKOTA</option><option value="MP">NORTHERN MARIANA ISLANDS</option><option value="OH">OHIO</option><option value="OK">OKLAHOMA</option><option value="OR">OREGON</option><option value="PW">PALAU</option><option value="PA">PENNSYLVANIA</option><option value="PR">PUERTO RICO</option><option value="RI">RHODE ISLAND</option><option value="SC">SOUTH CAROLINA</option><option value="SD">SOUTH DAKOTA</option><option value="TN">TENNESSEE</option><option value="TX">TEXAS</option><option value="TT">TRUST TERRITORIES</option><option value="UT">UTAH</option><option value="VT">VERMONT</option><option value="VI">VIRGIN ISLANDS</option><option value="VA">VIRGINIA</option><option value="WA">WASHINGTON</option><option value="WV">WEST VIRGINIA</option><option value="WI">WISCONSIN</option><option value="WY">WYOMING</option></select></td></tr><tr><td class="text-right"><label for="zip" class="required">ZIP/Postal code</label></td><td><input type="text" class="short" name="zip" id="zip" value="" /></td></tr><tr class="save-cancel-row"><td></td><td><button class="save-info" title="Save">Save</button><button class="button cancel" title="Cancel">Cancel</button></td></tr></tbody></table></fieldset>').insertBefore('#add-button-end').slideDown(200);
			return false;
		});
	}


/*	Initialize 'nickname' value match
	Used ONLY on the 'My Shipping Addresses' tab under 'My Account'
------------------------------------------------------------------------*/
	function init_nickName(){
	
		$('form#form-my-account input.nickname').live('change', function(){
			
			//	define simple variables
			var $thisValue = $(this).val();
			var $thisH2 = $(this).parents('fieldset').find('div.legend > h2');
			
			//	if the nickname field is empty, supply this default label for the fieldset
			if($(this).val().length == 0){
				$thisH2.html('New Shipping Address <span>(Edit nickname field to change this label)</span>');
			}
			
			//	else, match the fieldset's legend to the value in the nickname field
			else{
				$thisH2.html($thisValue);
			}
			
		});
	}
	


/*	Initialize EXAM COPY bookbag buttons
	(Open bookbag contents in modal window/layer)
-------------------------------------------------------------------------*/
	function init_requestExamCopy(){
	
	//	event is nearly always triggered by visitor clicking the 'Request
	//	exam copy' button (product page); or link (course/series/etc. page).
	
	$('.request-exam-copy').live('click', function(e){
	
	//	Open the confirm dialog using jQuery UI
		$('#exam-copy-modal').dialog({
			modal: true,
			resizable: false,
			width: '540',
			height: '200',
			title: 'This product has been added to your exam copy bookbag',
			show: 'fade',
			hide: 'fade',
			closeOnEscape: true,
			close: function () {
				$(this).dialog('destroy');
				//$('fieldset.awaiting-deletion').removeClass('awaiting-deletion');
			}
		})
		
		return false;
		e.preventDefault;
		e.stopPropagation;
		});
	}



/*	Initialize FORGOT INFO link
	When visitor has forgotten their Pearson account information
-------------------------------------------------------------------------*/
	function init_forgotInfo(){
		
	$('.sign-in-helper').live('click', function(e){
	
	//	Open the helper dialog
		$('#forgot-password-modal').dialog({
			modal: true,
			resizable: false,
			width: '400',
			height: '380',
			title: '',
			show: 'fade',
			hide: 'fade',
			closeOnEscape: true,
			close: function () {
				$(this).dialog('destroy');
				//$('fieldset.awaiting-deletion').removeClass('awaiting-deletion');
			}
		})
		
		return false;
		e.preventDefault;
		e.stopPropagation;
		});
	}



/*	Initialize CMG FORGOT link
	We need to use the existing 'forgot info' markup/code from
	Pearson CMG for domain security and other reasons. Yuck.
-------------------------------------------------------------------------*/
	function init_CMGforgot(){
	
	$('.cmg-forgot').live('click', function(){
		window.open('http://register.pearsoncmg.com/forgotlogin/fl_enter_data.jsp', null, 'height=400,width=600,status=no,toolbar=no,menubar=no,location=no');
		return false;
		});
	}
		
		
		
/*	Initialize DELETE buttons
	Used on the My Shipping Addresses tab under My Account
-------------------------------------------------------------------------*/
	function init_deleteButtons(){
	
	// DELETE buttons
	$('.delete').live('click', function(e){
		
		//	what fieldset are we taking action on?
		var thisAddress =  $(this).parents('fieldset');//.index();
		thisAddress.addClass('awaiting-deletion');
		//alert($('fieldset.awaiting-deletion').length);

		//	Open the confirm dialog using jQuery UI
		$('#confirm-action-modal').dialog({
			modal: true,
			resizable: false,
			width: '400',
			title: '',
			show: 'fade',
			hide: 'fade',
			closeOnEscape: true,
			close: function () {
				$(this).dialog('destroy');
				$('fieldset.awaiting-deletion').removeClass('awaiting-deletion');
			}
		})
		
		//	OK via confirmation dialog
		$('.confirm-ok').live('click', function(e){
			$('fieldset.awaiting-deletion').slideUp(200).delay(150, function(){
				$('fieldset.awaiting-deletion').remove();
				});
			$(this).parents('div.confirm-modal').dialog('close');
			return false;
			e.preventDefault;
			e.stopPropagation;
			});
		
		//	CANCEL via confirmation dialog
		$('.confirm-cancel').live('click', function(e){
			$('fieldset.awaiting-deletion').removeClass('awaiting-deletion');
			$(this).parents('div.confirm-modal').dialog('close');
			return false;
			e.preventDefault;
			e.stopPropagation;
			});
	
		return false;
		e.preventDefault;
		e.stopPropagation;
		});
	}
	


/*	Initialize CHANGE (address book modal)
	(Open registered visitor's address book in modal window/layer)
-------------------------------------------------------------------------*/
	function init_ChangeAddress(){
	
	//	Generally a button w/class of 'change-info'
	$('.change-info').live('click', function(e){
	
	//	Open the confirm dialog using jQuery UI
		$('#address-book-modal').dialog({
			modal: true,
			resizable: false,
			width: '470',
			height: '420',
			title: 'Select a shipping address',
			show: 'fade',
			hide: 'fade',
			closeOnEscape: true,
			close: function () {
				$(this).dialog('destroy');
			}
		})
		
		return false;
		e.preventDefault;
		e.stopPropagation;
		});
	}
	
	
	
/*	Initialize the jQueryUI modal close buttons
	Modals used for taxonomy browse, deletion of shipping addresses,
	and adding products to exam copy bookbag
-------------------------------------------------------------------------*/
	function init_closeModal(){
		
	//	CLOSE MODAL buttons
	$('.close-modal').live('click', function(e){
		
		$(this).parents('div.modal').dialog('close');
		return false;
		e.preventDefault;
		e.stopPropagation;
		});
	}

/*	Initialize CANCEL buttons
	Used on the My Account screens
-------------------------------------------------------------------------*/
	function init_cancelButtons(){
	
	// CANCEL buttons
	$('.cancel').live('click', function(){
		
		var $thisForm = $(this).parents('form')
		var $thisField = $(this).parents('fieldset')
		var $thisLegend = $(this).parents('fieldset').find('div.legend')
		var $thisTable = $(this).parents('fieldset').find('table');
		
	   	$thisForm.find('fieldset').fadeTo(300, 1.0);
		$thisForm.find('button').not(this).removeAttr('disabled','disabled').removeClass('disabled');
		$thisField.removeClass('edit-mode').addClass('read-only-mode');
		$thisField.find(':input[type=checkbox]').hide();
		$thisField.find(':input[type=checkbox]:not(:checked)').parents('li').hide();
		$thisField.find(':input[type=radio]').hide();
		$thisField.find(':input[type=radio]:not(:checked)').parents('li').hide();
		$thisField.find(':input').not(':reset').attr('readonly', 'readonly').addClass('read-only');
		$thisForm.find('ul.plain-stack label').addClass('strong');
		
		$('#i-am-other-input').addClass('mar-left-6px');
		$('.edit-mode-only').hide();
		
		$thisField.find('select').each(function(){
			var selectText = $('option:selected', this).text();
			var selectVal = $(this).val();
				$(this).before("<span class='cloned-value'>" + selectText + "</span>");
				$(this).hide();
			});
		
		$thisLegend.append("<button class='edit-info' title='Edit'>Edit</button>");
			if($thisField.hasClass('shipping-address')){
				$thisLegend.append("<button class='delete' title='Delete this record'>Delete</button>");
		}
		
		$thisTable.find('tr.save-cancel-row').remove();
		
		});
	}


/*	Initialize SAVE buttons
	Used on My Account screens
-------------------------------------------------------------------------*/
	function init_saveButtons(){
	
	// SAVE buttons
	$('.save-info').live('click', function(event){
		
		var $thisForm = $(this).parents('form');
		var $thisField = $(this).parents('fieldset');
		var $thisLegend = $(this).parents('fieldset').find('div.legend');
		var $thisH2 = $(this).parents('fieldset').find('div.legend > h2');
		var $thisTable = $(this).parents('fieldset').find('table');
		
		$thisForm.find('fieldset').fadeTo(300, 1.0);
		$thisForm.find('button').not(this).removeAttr('disabled','disabled').removeClass('disabled');
		$thisField.removeClass('edit-mode').addClass('read-only-mode');
		$thisField.find(':input[type=checkbox]').hide();
		$thisField.find(':input[type=checkbox]:not(:checked)').parents('li').hide();
		$thisField.find(':input[type=radio]').hide();
		$thisField.find(':input[type=radio]:not(:checked)').parents('li').hide();
		$thisField.find(':input').attr('readonly', 'readonly').addClass('read-only');
		$thisForm.find('ul.plain-stack label').addClass('strong');
		$thisTable.append("<tr><td colspan='3' class='text-center no-border strong'><p class='msg color-match'>Your information has been updated.</p></td></tr>");
		$thisTable.find('tr:last').delay(2000).fadeOut('slow');
		
		$('#i-am-other-input').removeClass('mar-left-6px');
		$('.edit-mode-only').hide();

		$thisField.find('select').each(function(){
			var selectText = $('option:selected', this).text();
			var selectVal = $(this).val();
				$(this).before("<span class='cloned-value'>" + selectText + "</span>");
				$(this).hide();
			});
		
		$thisLegend.append("<button class='edit-info' title='Edit'>Edit</button>");
			if($thisField.hasClass('shipping-address')){
				$thisLegend.append("<button class='delete' title='Delete this record'>Delete</button>");
		}
		
		$thisTable.find('tr.save-cancel-row').remove();

		});
	}


/*	Initialize EDIT buttons
	Used on My Account screens
-------------------------------------------------------------------------*/
	function init_editButtons(){
	
	// EDIT buttons
	$('.edit-info').live('click', function(event){
		
		var $thisForm = $(this).parents('form')
		var $thisField = $(this).parents('fieldset')
		var $thisLegend = $(this).parent('div.legend')
		var $thisTable = $(this).parents('fieldset').find('table');
		
		$thisForm.find('input, select').not(this).removeAttr('disabled','disabled').removeClass('disabled');
		$thisForm.find('fieldset').not($(this).parents('fieldset')).fadeTo(300, 0.2);
		$thisForm.find('button').addClass('disabled').not(this).attr('disabled','disabled');
		$thisField.removeClass('read-only-mode').addClass('edit-mode');
		$thisField.find('label').removeClass('strong');
		$thisField.find(':input[type=checkbox]').parents('li').show();
		$thisField.find(':input[type=radio]').parents('li').show();
		$thisField.find(':input').removeAttr('readonly').removeClass('read-only').show();
		$thisField.find('ul.plain-stack label').removeClass('strong');
		$thisField.find('.cloned-value').remove();
		$thisField.find('input:first').focus();
		$thisTable.append("<tr class='save-cancel-row'><td></td><td><button class='save-info' title='Save'>Save</button><button class='button cancel' title='Cancel'>Cancel</button></td></tr>");
		
		$('#i-am-other-input').addClass('mar-left-6px');
		$('.edit-mode-only').show();
		
		$thisLegend.find('button.delete').remove();
		
		$(this).remove();
		
		});
	}



/*	Initialize REMOVE ITEM buttons
	Used in the 'exam copy bookbag' process/screens
-------------------------------------------------------------------------*/
	function init_removeItem(){
		
	//	REMOVE ITEM | removing items from screen and DOM
	$('.remove-item').live('click', function(e){
		
		//	what elements will we reference often?
		var $thisForm = $(this).parents('form');
		var $thisField = $(this).parents('fieldset');
		var $thisLegend = $(this).parents('fieldset').find('div.legend');
		var $thisH2 = $(this).parents('fieldset').find('div.legend > h2');
		var $thisTable = $(this).parents('table');
		
		//	inside a TABLE CELL (target parent(s): <tbody>)
		if($(this).hasClass('in-tbody')){
			
			//	how many <tbody> elements are there? each product in
			//	bookbag will have its own <tbody>; if there is only
			//	1 item and now visitor is removing it, build a message
			//	and then display it for them (1 table; multi tbodies)
			
			//	only 1 product left?
			if($thisTable.find('tbody').size() == 1){
				$thisTable.before('<p class="msg color-match strong text-center">There are currently no items in your bookbag.</p>').fadeTo(1000, 1.0);
				$thisField.removeClass('edit-mode').addClass('read-write');
				$('.check-out').fadeOut(200, function(){
					$(this).remove();
					$('div.button-row').append('<p class="color-match text-center">There are currently no items in your bookbag.</p>').fadeTo(1000, 1.0);
					$('#save-and-continue').text('Continue browsing');
					});
				}
				
			//	find <tbody> parent and remove it from DOM
			$(this).parents('tbody').fadeOut(100, function(){
      			$(this).remove();
    			});
			
			//	find previous <tbody> and remove the dividing rule element from DOM
			$(this).parents('tbody').prev('tbody').find('tr.divider').fadeOut(100, function(){
      			$(this).remove();
    			});
			
			//	don't do the usual
			//e.preventDefault();
			//return false;
		}
		
		//	inside a LIST-ITEM (target parent: <li>)
		/*else{
		$(this).parent('li').slideUp(200, function(){ 
			$(this).parent('li').remove();
			});
		}*/
		
		//	inside a LIST-ITEM (target parent: <li>)
		if($(this).parent('li')){
			
			if($(this).parents('ol').find('li').size() == 1){
				$(this).parents('div').find('.go-back').before('<p class="color-match float-left">There are currently no items in your bookbag.</p>').fadeTo(1000, 1.0);
				$('div.button-row:last').remove();
				$('.check-out').fadeOut(300, function(){
					$(this).remove();
					});
				}
				
			$(this).parent('li').slideUp(200, function(){ 
				$(this).remove();
				});
				
		}
		
		//	don't do the usual
		e.preventDefault();
		return false;
		
		});
	}
	

/*	Initialize GO-BACK buttons
	Useful for 'continue browsing' etc.
-------------------------------------------------------------------------*/
	function init_GoBack(){
		
	// GO BACK (1 screen of window history)
	$('.go-back').live('click', function(){
		
		history.go(-1);

		});

	//	GO BACK 2 (2 screens of window history)
	$('.go-back-2').live('click', function(){
										   
		history.go(-2);
		});
	
	//	GO BACK 3 (3 screens of window history)
	$('.go-back-3').live('click', function(){
		
		history.go(-3);
		});
	}



/*	Initialize RESET  buttons
	Used on various forms throughout the site
	Most often rendered as:
		<button class='reset-form'>(desired text)</button>
-------------------------------------------------------------------------*/
	function init_resetButtons(){
	
	//	RESET buttons | 'fake' versions using <button>
	$('.reset-form').live('click submit', function(event){
		
		//	hold off on the default function
		event.preventDefault();
		
		//	ok, reset the form
		$(this).parents('form')[ 0 ].reset();
		
		//	if nested inside a list, hide all but the first list-item
		$(this).parents('ul').find('li').not('li:first').slideUp(200);
		
		//	if this is the Rep Locator form, reload original content into sidebar
		if($(this).parents('form').attr('id', 'repLocatorForm')){
			$('#ajax-content').fadeOut(200).load('ajax/find-your-rep-default-sidebar.txt').hide().delay(200).fadeIn(200);
			//	if 'save info' msg is present, remove it
				$('#save-replocator-info-link').remove();
			
			//	per LL 30-March: set 'Country' to option 01 ('Please select your country')
			$('#country').val(0);
			}
		
		});
	}

	
/*	Initialize the HTML5 'placeholder' mimickry
	Used on the Sign-in (Log-in) Landing page mini-forms
-------------------------------------------------------------------------*/
	function init_miniForm(){
	
	//	elements we need to interact with
	$miniForm = $('form.mini-form');
	
	//	set default values
	$miniForm.find('input.author-mini').val("Enter the author's last name");
	$miniForm.find('input.author-keyword').val("Enter title keyword");
	
	//	on focus
	$('.mini-form > input').focus(function(){
		
		//	stupid IE //
		$(this).addClass('IE7');
		
		//	remove default value
		if($(this).val()==$(this).attr('title')){
			$(this).val('');
			}
		});
	
	//	on blur
	$('.mini-form > input').blur(function(){
		
			// stupid IE //
			$(this).removeClass('IE7');
		
		//	mimic the HTML5 'placeholder' property
		if($(this).val()==''){
			$(this).val($(this).attr('title'));
			}
		});
	
	//	hijack the form submission
	$miniForm.submit(function(event){
		
		//	what do we need to look at?
		$miniAuthor = $(this).find('input.author-mini');
		$miniKeyword = $(this).find('input.keyword-mini');
		
		//	if user has left default text inside text inputs
		if($miniAuthor.val() == "Enter the author's last name" && $miniKeyword.val() == "Enter title keyword"){
	
			
			//	remove the error message if it already exists
			$('div.message').remove();
			
			//	build a message
			$(this).parent('div').prepend('<div class="message msg-error"><p class="group" title="Click to close">Please complete at least one field.</p></div>');
			
			//	display the message
			$('div.message').hide().delay(400).slideDown(200);
			
			//	prevent the form from being submitted
			event.preventDefault();
		}
		else{
			
			//	remove the error message
			$('div.message').remove();
			
			//	submit the form
			return true;
		}
	});
	}
	
	
/*	Initialize the 'TIP' messaging
	Used on the My Account screens
-------------------------------------------------------------------------*/
	function init_tipMessaging(){
	
	// SPECIFIC to the 'My Account' form / Personal Information fieldset
	if($('#form-my-account')){
		
		// if the first tab ('My Personal and Institution Info') is the current tab
		if($('.tabs > li:first-child').hasClass('current-tab')){
			
			// build a message
			$('#form-my-account fieldset:first-child').prepend("<div class='message'><p><strong class='uppercase'>Tip</strong> You'll have the best experience on our site if your account information is complete. Use the edit buttons below to update your information.</p></div>");
			
			// display the message
			$('#form-my-account fieldset:first-child div.message').hide().delay(400).slideDown(200);
			}					  
		}
	}
	
/*	Initialize the deletion/hiding of messaging from site-to-visitor
-------------------------------------------------------------------------*/
	function init_closeMsg(){

	//	how to close an error message
	//	if inside a <table> (bleh!)
	$('tr.msg-row > td > div.msg-error > p').live('click', function(){
		$(this).parents('tr.msg-row').fadeOut(100).delay(100, function(){
			$(this).parents('tr.msg-row').remove();
		});
	});
	
	//	else (everywhere else (yeah!)
	$('div.message > p, div.msg-error > p').live('click', function(){
		$(this).fadeOut(100).delay(100, function(){
			$(this).parent('div').remove();
			});
		});
	
	//	jquery.validity style error messages
	$('div.validity-modal-msg').live('click', function(){
		$(this).fadeOut(200).delay(100, function(){
			$(this).remove();
			});
		});
	}
	



/*	Initialize the 'Have You Adopted?' radio button behavior
-------------------------------------------------------------------------*/
	function init_haveYouAdopted(){
		
	//	toggle the display of 'Adopted this book?' sub-information
	
	//	Case: YES (has adopted)
	$('.tab-it-no').find('input').live('click', function(){
		if(this.checked){
			$(this).parents('span').addClass('tab-it-active');
			$(this).closest('tr').next('tr.conditional').fadeIn(200);
			$(this).closest('tr').next('tr.conditional').find('input:first').focus();
			}
		});
	
	//	Case: NO (has not adopted)
	$('.tab-it-yes').find('input').live('click', function(){
		if(this.checked){
			$(this).parents('tr').find('span.tab-it-active').removeClass('tab-it-active');
			$(this).closest('tr').next('tr.conditional').find('ul :input').removeAttr('checked').val('');
			$(this).closest('tr').next('tr.conditional').fadeOut('200', function(){
				$(this).hide();
				});
			}
		});
	}

	
/*	Initialize the My Account form extras
-------------------------------------------------------------------------*/
	function init_myAccountForm(){
	
	// initialize (replace) dropdowns with text span based on option selected //
	$('fieldset.read-only-mode select').each(function(){
		var selectText = $('option:selected', this).text();
		var selectVal = $(this).val();
			$(this).before("<span class='cloned-value strong'>" + selectText + "</span>");
			$(this).hide();
		});

	// Show Institutions (link, appears in .edit-mode-only)
	$('#show-institutions').live('click', function(){
		alert('Developers: This should populate the Institution dropdown with the list of institutions associated with the ZIP/Postal code provided by the user.');
		$(this).parents('tr').next('tr').find('select').focus();
		return false;
		});

	// do other stuff //
		$('fieldset.read-only-mode :input:text:visible').not(':submit, :button').attr('readonly', 'readonly').addClass('read-only');
		$('fieldset.read-only-mode :input[type=checkbox]').hide();
		$('fieldset.read-only-mode: input[type=checkbox]:not(:checked)').parents('li').hide();
		$('fieldset.read-only-mode :input[type=radio]').hide();
		$('fieldset.read-only-mode :input[type=radio]:not(:checked)').parents('li').hide();
		$('fieldset.read-only-mode label').removeClass('req');
	
	//	disable all form fields except for initial button controls
		$('fieldset.read-only-mode :input').not('button.edit-info').attr('readonly', 'readonly').addClass('read-only');
	}



/*	Initialize the Check-out-as-guest form
	Visitor either does not have an account (yet) or has not signed in
--------------------------------------------------------------------------*/
	function init_checkoutAsGuestForm(){
		
	//	does the form exist?
	if($('form#checkout-as-guest').length == 0){
		//	no form? stop.
		return;
	}

	//	the form id
	var $checkoutAsGuestForm = $('form#checkout-as-guest');
	
	//	what fields are associated with this form?
	var $country = $checkoutAsGuestForm.find('select#country');
	var $customerType = $checkoutAsGuestForm.find('select#customer-type');
	var $zip = $checkoutAsGuestForm.find('input#zip');
	
	//	what other elements do we need to interact with or manipulate?
	var $fieldSet = $checkoutAsGuestForm.find('fieldset');
	var $buttonRow = $('div.button-row');
	
	
	//	set initial state of all fieldsets (but not the first) to
	//	read-only mode and establish their initial opacity state
	$fieldSet.not(':first').addClass('read-only').hide();
	$buttonRow.hide();

	//	set autofocus to country dropdown
	$country.focus();
	
	
	//	COUNTRY dropdown (note: this is an onblur AND onchange event since no 'GO' button is supplied to conduct submit)
	$('#country, #customer-type').live('change blur', function(){

		//	if the error message is not preset:
		//	build the message and display it
		
		//	1. fail: if both country and customer type have not been selected (default option chosen)
		if($country.val() == 0 && $customerType.val() == 0){
			
			//	if the error message already exists just modify its contents
			if($('#continue-msg').length != 0){
				$('#continue-msg').html('<p class="two-line">Please select your <strong>country</strong> and <strong>customer type</strong> to continue.</p>');
			}
			
			//	if the error message is not present, build it
			else{
				//$('#continue-msg').parents('tr.msg-row').remove();
				$(this).parents('table').find('tr:first').before('<tr class="msg-row"><td></td><td><div class="msg-error" id="continue-msg"><p class="two-line">Please select your <strong>country</strong> and <strong>customer type</strong> to continue.</p></div></td></tr>');
				$(this).parents('table').find('tr.msg-row').hide().delay(200).fadeIn(200);
				$fieldSet.not(':first').addClass('read-only').slideUp(400);
				$buttonRow.fadeOut(200);
			}
		}
		
		//	2. fail: if only country value has default option selected
		if($country.val() == 0 && $customerType.val() != 0){
			
			//	if the error message already exists just modify its contents
			if($('#continue-msg').length != 0){
				$('#continue-msg').html('<p>Please select your <strong>country</strong> to continue.</p>');
			}
			
			//	if the error message is not present, build it
			else{
				//$('#continue-msg').parents('tr.msg-row').remove();
				$(this).parents('table').find('tr:first').before('<tr class="msg-row"><td></td><td><div class="msg-error" id="continue-msg"><p>Please select your <strong>country</strong> to continue.</p></div></td></tr>');
				$(this).parents('table').find('tr.msg-row').hide().delay(200).fadeIn(200);
				//$('#continue-msg').text('Please select your country to continue.');
				$fieldSet.not(':first').addClass('read-only').slideUp(400);
				$buttonRow.fadeOut(200);
			}
		}
		
		//	3. fail: if only customer type value has default option selected
		if($country.val() != 0 && $customerType.val() == 0){
			
			//	if the error message already exists just modify its contents
			if($('#continue-msg').length != 0){
				$('#continue-msg').html('<p>Please select your <strong>customer type</strong> to continue.</p>');
			}
			
			//	if the error message is not present, build it
			else{
				//$('#continue-msg').parents('tr.msg-row').remove();
				$(this).parents('table').find('tr:first').before('<tr class="msg-row"><td></td><td><div class="msg-error" id="continue-msg"><p>Please select your <strong>customer type</strong> to continue.</p></div></td></tr>');
				$(this).parents('table').find('tr.msg-row').hide().delay(200).fadeIn(200);
				
				//$('#continue-msg').text('Please select your customer type to continue.');
				$fieldSet.not(':first').addClass('read-only').slideUp(400);
				$buttonRow.fadeOut(200);
			}
		}
		
		//	4. success: visitor has chosen an option for each
		if($country.val() != 0 && $customerType.val() != 0){
			//	hide and remove message
			$('#continue-msg').parents('tr.msg-row').remove();
			$fieldSet.not(':first').removeClass('read-only').slideDown(400);
			$buttonRow.fadeIn(200);
			$zip.focus();
			}
		});
		
	
	//	SHOW button (for schools and institutions)
		$('#show').live('click submit', function(event){
			event.preventDefault();
			return false;
		});
	}



/*	Initialize the Request Access form
--------------------------------------------------------------------------*/
	function init_requestAccessForm(){
	
	//	Does the form exist?
	if($('form#request-access-form').length == 0){
		
		//	No form? stop.
		return;
	}

	//	The form id
	var $requestAccessForm = $('form#request-access-form');
	
	//	Inputs, selects, textareas, radio buttons, checkboxes
	var $country = $requestAccessForm.find('select#country');
	var $customerType = $requestAccessForm.find('select#customer-type');
	var $zip = $requestAccessForm.find('input:text#zip');
	var	$institution = $requestAccessForm.find('select#institution');
	var	$department = $requestAccessForm.find('select#department');
	var	$discipline = $requestAccessForm.find('select#discipline');
	var $email = $requestAccessForm.find('input#email');
	var	$consideringAdoption = $requestAccessForm.find('input:radio#considering-adoption');
	var	$adopted = $requestAccessForm.find('input:radio#adopted');
	var	$needSupplements = $requestAccessForm.find('input:checkbox#need-supplements');
	
	//	Fieldsets, table elements, structural containers, etc.
	var $fieldSet = $requestAccessForm.find('fieldset');
	var $rowCustomerType = $requestAccessForm.find('#row-customer-type');
	var	$zipPostalLabel = $requestAccessForm.find('label#zipPostalLabel');
	
	//	Buttons, input:submit, input:reset, etc.
	var $countryGo = $requestAccessForm.find('button#country-go');
	var $zipGo = $requestAccessForm.find('button#show');
	
	$requestAccessForm.validity(function(){
		
		//	which fields are required and/or what kind of pattern must the input follow?
		$("#country, #customer-type, #firstname, #lastname")
			.require()

		$("#institution").assert(
			$("#institution").val() && $("#institution").val() != 0,
        	"Institution is required."
    	);
		
		$("#department").assert(
        	$("#department").val() && $("#department").val() != 0,
        	"Department is required."
    	);
		
		$("#discipline-drop").assert(
			$("#discipline-drop").val() && $("#discipline-drop").val() != 0,
        	"Discipline is required."
    	);
		
		$("#role").assert(
        	$("#role").val() != 0, 
        	"Role is required."
    	);
		
		$("#email, #confirm-email")
			.require()
			.match("email")
			.equal("E-mail and Re-type email must match.");
		
		$("#chair-email")
			.match("email", "Department chair email must be formatted as an email.")
			
		$('#author-title-edition')
			.require("Author, title, and edition are required.");
			
	});
	
	//	1. Set initial state of all fieldsets (but not the first) to read-only mode and establish their initial opacity state
	//	2. Disable the 'Customer Type' dropdown
	//	3. Hide table row that contains the 'Customer Type' dropdown
	//	4. Hide table row that contains the 'Discipline' dropdown
	//	5. Remove error styles from any fields that might still have them assigned
	//	6. Set autofocus to country dropdown
	$fieldSet.not(':first').addClass('read-only').hide();
	$customerType.attr('disabled', 'disabled');
	$rowCustomerType.hide();
	$('#row-discipline').remove();
	$country.focus();
	
	//	we need to check the value onchange; if other elements of form are currently exposed but shouldn't be based on new choice, we have to remove them from display
	$country.live('change', function(){
		
		//	Remove any error messages
		$('div.validity-modal-msg').remove();
		$('div#customerTypeGo-msg').remove();
		$('div#validity-summary').remove();
		
		//	Remove error class
		$('.validity-error').removeClass('validity-error');
			
		//	Hide all fieldsets (except this one)
		$fieldSet.not(':first').addClass('read-only').fadeOut(200);
		
		//	Set 'Customer Type' value to default and hide its parent table row
		$customerType.val(0);
		$rowCustomerType.hide();
		
	});
			
			
	//	COUNTRY GO button (button:click/submit)
	$countryGo.live('click', function(e){
		
		//	If other fieldsets are currently being displayed, hide them
		$fieldSet.not(':first').addClass('read-only').fadeOut(200);
		
		//	Hide any visible error messages
		$('div.validity-modal-msg').remove();
		$('div#customerTypeGo-msg').remove();
		$('div#validity-summary').remove();
		
		//	If visitor has not chosen a country (default value == 0)
		if($country.val() == 0){
			
			//	Prevent default behavior
			e.preventDefault();
			
			//	Style with error class
			$country.addClass('validity-error');
			
			//	Disable 'Customer Type' dropdown, set its value to default state, and display the table row that contains it
			$customerType.val(0).attr('disabled', 'disabled');
			$rowCustomerType.fadeOut(100);
			
			//	Remove any error messages
			$('div.validity-modal-msg').remove();
			
			//	Hide any exposed fieldsets
			$fieldSet.not(':first').addClass('read-only').hide();
			
			//	Build message
			var offset = $(this).offset();
			var left = offset.left;
			var top = offset.top;
			var width = $(this).width();
			var height= $(this).height();
			var parent = $(this).parents('body');
			
			/* testing
			alert("height = " + height + "px");
			alert("width = " + width + "px");
			alert("left = " + left + "px");
			alert("top = " + top + "px");
			*/
			
			// Design a style object based off of the input's location.
				var errorStyle={
					left:parseInt(left + width + 10) + "px",
					top:parseInt(top, 10) + "px"
                    };
			
			// Create one and position it next to the input.
                $("<div/>")
                    .addClass('validity-modal-msg')
                    .css(errorStyle)
                    .text('Please select your country to continue.')
					.attr('id','countryGo-msg')
                    .appendTo(parent)
					.hide()
					.delay(200)
					.fadeIn(200);
		}
		
		//	If visitor chooses 'US'
		else if($country.val() == 'US'){
			
			//	Remove error class
			$country.removeClass('validity-error');
			
			//	set label text based on option selected
			$zipPostalLabel.text('ZIP code');
			
			//	Enable 'Customer Type' dropdown, set its value to default state, and display the table row that contains it
			$customerType.removeAttr('disabled').val(0);
			$rowCustomerType.fadeIn(200);
			
			//	Inject the 'Discipline' row markup
			$('#row-Department').after('<tr id="row-discipline"><td class="text-right"><label for="discipline-drop" class="required">Discipline</label></td><td><select id="discipline-drop" name="discipline-drop" class="x-large disabled" disabled="disabled"></select></td><td class="tip"></td></tr>');
			
			//	Load appropriate content into the relevant 'May we contact you?' section
			$('#ajax-content').load('ajax/may-we-contact-nonEMA.txt');
			
			//	Set focus to Customer Type
			$customerType.focus();
		}
		
		//	If visitor chooses 'CA'
		else if($country.val() == 'CA'){
			
			//	Remove error class
			$country.removeClass('validity-error');
			
			//	set label text based on option selected
			$zipPostalLabel.text('Postal code');
			
			//	Enable 'Customer Type' dropdown, set its value to default state, and display the table row that contains it
			$customerType.removeAttr('disabled').val(0);
			$rowCustomerType.fadeIn(200);
			$('#row-discipline').remove();
			
			//	Load appropriate content into the relevant 'May we contact you?' section
			$('#ajax-content').load('ajax/may-we-contact-nonEMA.txt');
			
			//	Set focus to Customer Type
			$customerType.focus();
		}
		
		//	If visitor chooses any other country besides 'US' or 'CA'
		else{
			
			//	Remove error class
			$country.removeClass('validity-error');
			
			//	set label text based on option selected
			$zipPostalLabel.text('Postal code');
			
			//	Remove any error messages
			$('div#countryGo-msg').hide().delay(200).remove();
			
			//	Enable 'Customer Type' dropdown, set its value to default state, and display the table row that contains it
			$customerType.removeAttr('disabled').val(0);
			
			//	We don't display 'Customer Type' for anything other than US or Canada; 'Discipline is for US only
			$rowCustomerType.hide();
			$('#row-discipline').remove();
			
			//	Remove any error messages
			$('div#customerTypeGo-msg').hide().delay(200).remove();
			
			//	Load appropriate content into the relevant 'May we contact you?' section
			$('#ajax-content').load('ajax/may-we-contact-ema.txt');
			
			//	Show all fieldsets
			$fieldSet.not(':first').removeClass('read-only').fadeIn(200);
			
			//	Set focus to Customer Type
			$customerType.focus();
		}
		//	Prevent default behavior
		e.preventDefault();
		
	});
	
	
	//	CUSTOMER TYPE (select: onchange)
	$customerType.live('change', function(){
		
		//	Remove any error messages
		$('div.validity-modal-msg').remove();
		$('div#customerTypeGo-msg').remove();
		$('div#validity-summary').remove();
		
		//	Remove error class
		$('.validity-error').removeClass('validity-error');
		
		//	If visitor has not chosen a country (default value == 0)
		if($customerType.val() == 0){
			
			//	Style with error class
			$(this).addClass('validity-error');
			
			//	Hide any exposed fieldsets
			$fieldSet.not(':first').addClass('read-only').hide();
			
			//	Build message
			var offset = $(this).offset();
			var left = offset.left;
			var top = offset.top;
			var width = $(this).width();
			var height= $(this).height();
			var parent = $(this).parents('body');
			
			// Design a style object based off of the input's location.
				var errorStyle={
					left:parseInt(left + width + 12) + "px",
					top:parseInt(top, 10) + "px"
                    };
			
			// Create one and position it next to the input.
                $("<div/>")
                    .addClass('validity-modal-msg')
                    .css(errorStyle)
                    .text('Please select your customer type to continue.')
					.attr('id','customerTypeGo-msg')
                    .appendTo(parent)
					.hide()
					.delay(200)
					.fadeIn(200);
		}
		else{
			
			//	Remove error styling
			$(this).removeClass('validity-error');
			
			//	Remove any error messages
			$('div#customerTypeGo-msg').hide().delay(200).remove();
			
			//	Show all fieldsets
			$fieldSet.not(':first').removeClass('read-only').fadeIn(200);
		}
	});
	
	//	ZIP/Postal input
	//	1.	Strip dashes and white space from the ZIP/Postal code field (on blur)
	//	2.	Remove error class
	$zip.live('blur', function(){
		var cleanZip = $(this).val().replace(/[- ]+/g, "");
		$(this).val(cleanZip);
		$(this).removeClass('validity-error');
	});
		
	//	SHOW (the 'Go' button associated with 'Postal code')
	$zipGo.live('click submit', function(event){
		
		//	No submit form
		event.preventDefault();
		
		//	If ZIP/Postal field is empty
		if($zip.val() == 0){
			
			//	Style ZIP/Postal with error class
			$zip.addClass('validity-error');
			
			//	Prototype-only
			event.preventDefault();
			
			//	1.	Remove options from 'Institution, Department, and Discipline' dropdowns
			//	2.	Disable same + add 'disabled' class
			$institution.children().remove().end().addClass('disabled').attr('disabled', 'disabled');
			$department.children().remove().end().addClass('disabled').attr('disabled', 'disabled');
			$('#discipline-drop').children().remove().end().addClass('disabled').attr('disabled', 'disabled');
			
			//	Build message
			var offset = $(this).offset();
			var left = offset.left;
			var top = offset.top;
			var width = $(this).width();
			var height= $(this).height();
			var parent = $(this).parents('body');
			
			// Design a style object based off of the input's location.
				var errorStyle={
					left:parseInt(left + width + 12) + "px",
					top:parseInt(top, 10) + "px"
                    };
			
			// Create one and position it next to the input.
                $("<div/>")
                    .addClass('validity-modal-msg')
                    .css(errorStyle)
                    .text('Please enter your ZIP/Postal code to continue.')
					.attr('id','zipPostalGo-msg')
                    .appendTo(parent)
					.hide()
					.delay(200)
					.fadeIn(200);
			
			//	Remove the 'row-other-institution'
			$('#row-other-institution').remove();
		}
		
		//	If ZIP/Postal field is populated (affects the population of the 'Institution' dropdown
		else{
			
			//	Don't submit anything
			event.preventDefault();
			
			//	Remove error class styling from ZIP/Postal input
			$zip.removeClass('validity-error');
			
			//	1.	Remove all options from 'Institution' dropdown (if previously populated)
			//	2.	Enable the 'Institution' dropdown
			//	3.	Remove class of 'disabled' from 'Institution' dropdown
			//	4.	Populate the the 'Institution' dropdown
			//	5.	Set focus to the 'Institution' dropdown
			$institution.removeAttr('disabled').removeClass('disabled').children().remove().end().focus();
			$('<option/>').attr('value', '0').text('Please choose an institution').attr('selected', 'selected').appendTo($("#institution"));
			$('<option/>').attr('value', 'test-01').text('Institution #01').appendTo($("#institution"));
			$('<option/>').attr('value', 'test-02').text('Institution #02').appendTo($("#institution"));
			$('<option/>').attr('value', 'test-03').text('Institution #03').appendTo($("#institution"));
			$('<option/>').attr('value', 'test-04').text('Institution #04').appendTo($("#institution"));
			$('<option/>').attr('value', 'test-05').text('Institution #05').appendTo($("#institution"));
			$('<option/>').attr('value', 'test-06').text('Institution #06').appendTo($("#institution"));
			$('<option/>').attr('value', 'other').text('Other').appendTo($("#institution"));
			
			//	Remove any error messages
			$('div#zipPostalGo-msg').hide().delay(200).remove();
		}
	});
	
	//	INSTITUTION (select: onchange / affects the population of the 'Department' dropdown)
	//	1.	Remove all options from 'Department' dropdown (if previously populated)
	//	2.	Enable the 'Department' dropdown
	//	3.	Remove class of 'disabled' from 'Department' dropdown
	//	4.	Populate the the 'Department' dropdown
	//	5.	Set focus to the 'Department' dropdown
	$('#institution').live('change', function(){
		
		//	If visitor has not chosen an institution (default value == 0)
		if($('#institution').val() != 0){
			$department.removeAttr('disabled').removeClass('disabled').children().remove().end().focus();
			$department.removeAttr('disabled').removeClass('disabled');
			$('<option/>').attr('value', '0').text('Please choose a department').attr('selected', 'selected').appendTo($("#department"));
			$('<option/>').attr('value', 'test-01').text('Department #01').appendTo($("#department"));
			$('<option/>').attr('value', 'test-02').text('Department #02').appendTo($("#department"));
			$('<option/>').attr('value', 'test-03').text('Department #03').appendTo($("#department"));
			$('<option/>').attr('value', 'test-04').text('Department #04').appendTo($("#department"));
			$('<option/>').attr('value', 'test-05').text('Department #05').appendTo($("#department"));
			$('<option/>').attr('value', 'test-06').text('Department #06').appendTo($("#department"));
			$('<option/>').attr('value', 'other').text('Other').appendTo($("#department"));
		}
		
		//	If visitor chooses 'other'
		if($('#institution').val() == 'other'){
			
			//	Remove the 'row-other-institution' if already exists
			$('#row-other-institution').remove();
			
			//	Inject 'row-other-institution' markup into the DOM
			$('#row-Institution').after('<tr id="row-other-institution"><td class="text-right"></td><td colspan="2" class="pad-bot-18px"><div class="mar-top-6px mar-bot-18px mar-left-18px width-300"><p class="default width-300 mar-bot-6px">Please enter your <strong>institution</strong> (other) information using the fields below:</p><label for="institution-other">Institution name</label><input type="text" class="mar-bot-3px mar-top-3px block other" name="institution-other" id="institution-other" /><label for="institution-other-address-01">Address 01</label><input type="text" class="mar-bot-3px mar-top-3px block other" name="institution-other-address-01" id="institution-other-address-01" /><label for="institution-other-address-02">Address 02</label><input type="text" class="mar-bot-3px mar-top-3px block other" name="institution-other-address-02" id="institution-other-address-02" /><label for="institution-other-city">City/Town</label><input type="text" class="mar-bot-3px mar-top-3px block other" name="institution-other-city" id="institution-other-city" /><label for="institution-other-stateProvince">State/Province</label><select name="institution-other-stateProvince" id="institution-other-stateProvince" class="mar-top-3px block other"><option value="0" selected="selected">Please select institution state/province</option><option value="AL">ALABAMA</option><option value="AK">ALASKA</option><option value="AS">AMERICAN SAMOA</option><option value="AZ">ARIZONA</option><option value="AR">ARKANSAS</option><option value="AA">ARMED FORCES - ALANTIC DIVISION</option><option value="AE">ARMED FORCES - EUROPEAN DIVISION</option><option value="AP">ARMED FORCES - PACIFIC DIVISION</option><option value="CA">CALIFORNIA</option><option value="CO">COLORADO</option><option value="CT">CONNECTICUT</option><option value="DE">DELAWARE</option><option value="DC">DISTRICT OF COLUMBIA</option><option value="FM">FEDERATED STATES OF MICRONESIA</option><option value="FL">FLORIDA</option><option value="GA">GEORGIA</option><option value="GU">GUAM</option><option value="HI">HAWAII</option><option value="ID">IDAHO</option><option value="IL">ILLINOIS</option><option value="IN">INDIANA</option><option value="IA">IOWA</option><option value="KS">KANSAS</option><option value="KY">KENTUCKY</option><option value="LA">LOUISIANA</option><option value="ME">MAINE</option><option value="MH">MARSHALL ISLANDS</option><option value="MD">MARYLAND</option><option value="MA">MASSACHUSETTS</option><option value="MI">MICHIGAN</option><option value="MN">MINNESOTA</option><option value="MS">MISSISSIPPI</option><option value="MO">MISSOURI</option><option value="MT">MONTANA</option><option value="NE">NEBRASKA</option><option value="NV">NEVADA</option><option value="NH">NEW HAMPSHIRE</option><option value="NJ">NEW JERSEY</option><option value="NM">NEW MEXICO</option><option value="NY">NEW YORK</option><option value="NC">NORTH CAROLINA</option><option value="ND">NORTH DAKOTA</option><option value="MP">NORTHERN MARIANA ISLANDS</option><option value="OH">OHIO</option><option value="OK">OKLAHOMA</option><option value="OR">OREGON</option><option value="PW">PALAU</option><option value="PA">PENNSYLVANIA</option><option value="PR">PUERTO RICO</option><option value="RI">RHODE ISLAND</option><option value="SC">SOUTH CAROLINA</option><option value="SD">SOUTH DAKOTA</option><option value="TN">TENNESSEE</option><option value="TX">TEXAS</option><option value="TT">TRUST TERRITORIES</option><option value="UT">UTAH</option><option value="VT">VERMONT</option><option value="VI">VIRGIN ISLANDS</option><option value="VA">VIRGINIA</option><option value="WA">WASHINGTON</option><option value="WV">WEST VIRGINIA</option><option value="WI">WISCONSIN</option><option value="WY">WYOMING</option></select></div></td></tr>');
			$('#institution-other').focus();
		}
		
		//	If visitor chooses anything other than 'other'
		if($('#institution').val() != 'other'){
			
			//	Remove the 'row-other-institution'
			$('#row-other-institution').remove();
		}
	});
	
	
	//	DEPARTMENT (select: onchange / affects the population of the 'Discipline' dropdown, which is US-only)
	//	1.	Remove all options from 'Discipline' dropdown (if previously populated)
	//	2.	Enable the 'Discipline' dropdown
	//	3.	Remove class of 'disabled' from 'Discipline' dropdown
	//	4.	Populate the the 'Discipline' dropdown
	//	5.	Set focus to the 'Discipline' dropdown
	$('#department').live('change', function(){
		
		//	If visitor has not chosen an institution (default value == 0)
		if($('#department').val() != 0){
			$('#discipline-drop').removeAttr('disabled').removeClass('disabled').children().remove().end().focus();
			$('<option/>').attr('value', '0').text('Please choose a discipline').attr('selected', 'selected').appendTo($("#discipline-drop"));
			$('<option/>').attr('value', 'test-01').text('Discipline #01').appendTo($("#discipline-drop"));
			$('<option/>').attr('value', 'test-02').text('Discipline #02').appendTo($("#discipline-drop"));
			$('<option/>').attr('value', 'test-03').text('Discipline #03').appendTo($("#discipline-drop"));
			$('<option/>').attr('value', 'test-04').text('Discipline #04').appendTo($("#discipline-drop"));
			$('<option/>').attr('value', 'test-05').text('Discipline #05').appendTo($("#discipline-drop"));
			$('<option/>').attr('value', 'test-06').text('Discipline #06').appendTo($("#discipline-drop"));
			$('<option/>').attr('value', 'other').text('Other').appendTo($("#discipline-drop"));
		}
	});

	
	
	//	I-AM-OTHER (input)
	//	Check the box associated with this input field if the value is not empty (on blur from input field)
	$('input#i-am-other-input').live('blur', function(){
		
		//	If this is NOT empty
		if($(this).val() != 0){
			$(this).parent('li').find('input:checkbox').attr('checked', 'checked');
		}
		
		//	If this IS empty
		else{
			$(this).parent('li').find('input:checkbox').removeAttr('checked');
		}
	});
	
	//	ADOPTION STATUS
	//	This is a set of (2) radio buttons inside the 'Your textbook information fieldset'
	//	If a user checks the 'I have adopted' radio, display the conditional <li> ('I need supplements')
	//	If a user checks the 'I am considering' radio, uncheck the conditional checkbox and hide the parent <li>
	
	//	hide any conditional list-item containing parent elements
	$('li.conditional').hide();
	
	//	disabled the 'need supplements' checkbox so its value isn't accidentally transmitted during form submission
	$needSupplements.attr('disabled', 'disabled');
	
	//	if visitor chooses the 'I am considering this book' radio
	$consideringAdoption.live('click', function(){
		if($(this).is(':checked')){
			$needSupplements.removeAttr('checked');
			$needSupplements.parent('li.conditional').fadeOut(200);
		}
	});
	
	//	if visitor chooses the 'I have adopted this book' radio
	$adopted.live('click', function(){
		if($(this).is(':checked')){
			$needSupplements.removeAttr('disabled');
			$needSupplements.parent('li.conditional').fadeIn(200);
		}
	});
	

	//	--------	universal functions for this form	--------	//
	
	//	if user resizes browser window, toss the absolutely positioned error messages
	//	rather than re-position
	$(window).resize(function(){
		$('.validity-modal-msg, #validity-summary').fadeOut(200).remove();
	});
	
	//	scroll to first error field on click of summary
	$('div#validity-summary').live('click', function(){
		
		//	Locate the position of the first invalid field and scroll to it
		var summaryOffset = $('.validity-error:first').offset(),
			destination = summaryOffset.top;
			$('html, body').animate({scrollTop:destination}, 650);
	});

	}

/*	Initialize the Sign-In form (accessed via Check out process)
--------------------------------------------------------------------------*/
	function init_signInViaCheckoutForm(){
	
	//	the form id
	var $signInViaCheckoutForm = $('form#signInViaCheckoutForm');
	
	//	what fields are associated with this form?
	var $username = $signInViaCheckoutForm.find('input#username');
	var $password = $signInViaCheckoutForm.find('input#password');
	
	//	what other elements (buttons, etc.) do we need to interact with?
	//var $signInButton = $signInViaCheckoutForm.find('input:submit#sign-in');
	
	/*
	//	Apply the validity plug-in engine
	$.validity.setup({ 
		outputMode:"modal",
	
		// The css class on the output
		cssClass:"error",
	
		// The this property is set to true, validity will scroll the browser viewport
		// so that the first error is visible when validation fails:
		scrollTo:false,
	
		// If this setting is true, modal errors will disappear when they are clicked on:
		modalErrorsClickable:true	
	});
	*/
	
	$signInViaCheckoutForm.validity(function(){
		
		//	which fields are required and/or what kind of pattern must the input follow?
		$("#username, #password")
			.require()
			
		// SIGN-IN button
		/*$signInButton.live('click', function(){
											 
			//	username cannot be empty or null
			if($username.val() == 0){
				
				//	remove any existing messages
				$(this).parents('ul').find('.msg-error').remove();
				
				//	build message
				$username.parent('li').find('label').before('<div class="msg-error short-width"><p>Please enter your username</p></div>');
				
				//	display message
				$username.parent('li').find('.msg-error').hide().delay(400).slideDown(200);
				
				//	do not submit
				return false;
			}
			
			//	password cannot be empty or null
			if($password.val() == 0){
				
				//	remove any existing messages
				$(this).parents('ul').find('.msg-error').remove();
				
				//	build message
				$password.parent('li').find('label').before('<div class="msg-error short-width"><p>Please enter your password</p></div>');
				
				//	display message
				$password.parent('li').find('.msg-error').hide().delay(400).slideDown(200);
				
				//	do not submit
				return false;
				
			}
			
			//	else all is fine
			else{
				
				//	remove any existing messages
				$(this).parents('ul').find('.msg-error').remove();
				
				//	submit
				return true;
			}*/
			
		});
		
		//	--------	universal functions for this form	--------	//
		
		//	if user resizes browser window, toss the absolutely positioned error messages
		//	rather than re-position
		$(window).resize(function(){
			$('.validity-modal-msg, #validity-summary').fadeOut(200).remove();
		});
	}


	
/*	Initialize the FDOC Registration form
--------------------------------------------------------------------------*/
	function init_FDOCregistrationForm(){
	
	//	Does the form exist?
	if($('form#fdoc-registration').length == 0){
		
		//	No form? stop.
		return;
	}

	//	The form id
	var $fdocRegistration = $('form#fdoc-registration');
	
	$fdocRegistration.validity(function(){
		
		//	which fields are required and/or what kind of pattern must the input follow?
		$("#firstname, #lastname, #institution, #department, #zip, #course, #enrollment")
			.require()

		$("#email")
			.require()
			.match("email", "Please provide a valid email address.");
	
		//	Visitor must choose an option from the (3) "Course Materials" (Ordered a Technology Package) radio button set
		//	In this case, I gave all the radio buttons in the set a shared class name;
		//	We check to see if any of the radio buttons with that class is checked;
		//	If not, we display the error message
		if($(".ordered-pkg:checked").length == 0){
			var $courseMaterialsLabel = $('#course-materials-label');
			
			//	Build message
			var offset = $courseMaterialsLabel.offset();
			var left = offset.left;
			var top = offset.top;
			var width = $courseMaterialsLabel.width();
			var height= $courseMaterialsLabel.height();
			var parent = $courseMaterialsLabel.parents('body');
			
			// Design a style object based off of the input's location.
				var errorStyle={
					left:parseInt(left + width + 240) + "px",
					top:parseInt(top - 9, 10) + "px"
                    };
			
			// Create one and position it next to the input.
                $("<div/>")
                    .addClass('validity-modal-msg')
                    .css(errorStyle)
                    .text('Please tell us if you ordered a technology package to continue.')
					.attr('id','techPkg-msg')
                    .appendTo(parent)
					.hide()
					.delay(200)
					.fadeIn(200);
		}
		else{
			
			//	Remove any error messages
			$('div#techPkg-msg').hide().delay(200).remove();
		}
	});
	}



/*	Initialize the Find Your Rep (repLocator) form
--------------------------------------------------------------------------*/
	function init_repLocatorForm(){
	
	//	the form id
	var $repLocatorForm = $('form#repLocatorForm');
	
	//	inputs, selects, radios, checkboxes, etc.
	var $country = $repLocatorForm.find('select#country');
	var $zipPostal = $repLocatorForm.find('input#zipPostal');
	var $stateProvince = $repLocatorForm.find('select#stateProvince');
	var	$institution = $repLocatorForm.find('select#institution');
	var $department = $repLocatorForm.find('select#department');
	var	$city = $repLocatorForm.find('input#city');
	
	//	labels
	var	$labelzipPostal = $repLocatorForm.find('label#label-zipPostal');
	var $labelstateProvince = $repLocatorForm.find('label#label-stateProvince');
	
	//	buttons
	var $go = $repLocatorForm.find('button#go');
	var $startOver = $repLocatorForm.find('button#start-over');
	var $show = $repLocatorForm.find('button#show');
	var	$goState = $repLocatorForm.find('button#go-state');
	//var $skip = $repLocatorForm.find('a.skip-step');
	
	
	
	//	identify the next list-item for reveal
	var $nextLI = $(this).parent('li').next('li');
	
		//	SET UP: on first step/view of 'Find your rep' form, hide all but Step 1
		$repLocatorForm.find('li').not('li:first').hide();
		$repLocatorForm.find('input#city').attr('disabled', 'disabled').hide();
	
		// GO button (for country)
		$go.live('click', function(e){
			
			//	hide next list-item each time a choice is made
			$(this).parent('li').nextAll('li').fadeOut(200);
			
			//	reset any chosen values
			$zipPostal.val("");
			$stateProvince.val(0);
			$city.val("");
			$institution.val(0);
			$department.val(0);
				
			//	UNITED STATES of AMERICA chosen
			if($country.val() == 'US'){
				
				//	set label text
				$labelzipPostal.text('Enter your ZIP code:');
				$labelstateProvince.text('Select your state:').attr('for', 'stateProvince');
				
				//	enable stateProvice, disable and hide city
				$city.attr('disabled', 'disabled').hide();
				$stateProvince.removeAttr('disabled').show();
				
				//	expose next list-item
				$(this).parent('li').next('li').fadeIn(200);
				
				//	hide and remove message
				$(this).parents('ul').find('.msg-error').fadeOut(200).delay(400).remove();
				
				//	set focus to zip field
				$zipPostal.focus();
				
				//	hide the sidebar content
				$('#ajax-content').fadeOut(200);
			}
			
			//	CANADA chosen
			else if($country.val() == 'CA'){
				
				//	set label text
				$labelzipPostal.text('Enter your postal code:');
				$labelstateProvince.text('Select your province:').attr('for', 'stateProvince');
				
				//	enable stateProvice, disabled and hide city
				$city.attr('disabled', 'disabled').hide();
				$stateProvince.removeAttr('disabled').show();
				
				//	expose next list-item
				$(this).parent('li').next('li').fadeIn(200);
				
				//	hide and remove message
				$(this).parents('ul').find('.msg-error').fadeOut(200).delay(400).remove();
				
				//	set focus to zip field
				$zipPostal.focus();
				
				//	hide the sidebar content
				$('#ajax-content').fadeOut(200);
			}
			
			//	DEFAULT VALUE (no choice: 'Please select...') chosen
			else if($country.val() == 0){
				
				//	remove any existing messages
				$(this).parents('ul').find('.msg-error').remove();
				
				//	if any of the other list-items are showing, hide them
				$(this).parent('li').nextAll('li').fadeOut(200);
				
				//	build message
				$(this).parent('li').find('label').before('<div class="msg-error"><p>Please select your country</p></div>');
				
				//	display message
				$(this).parent('li').find('.msg-error').hide().delay(400).slideDown(200);
				
				//	show default sidebar content
				$('#ajax-content').load('ajax/find-your-rep-default-sidebar.txt').show();
			}
			
			//	ANY OTHER COUNTRY (any option but US, CA, or default)
			else{
				
				//	set label text
				$labelzipPostal.text('Enter your postal code:');
				$labelstateProvince.text('Enter your city/town:').attr('for', 'city');
				
				//	disable and hide stateProvice, enable and show city
				$stateProvince.attr('disabled', 'disabled').hide();
				$city.removeAttr('disabled').show();
				
				//	expose next list-item
				$(this).parent('li').next('li').fadeIn(200);
				
				//	hide and remove message
				$(this).parents('ul').find('.msg-error').fadeOut(200).delay(400).remove();
				
				//	set focus to zip field
				$zipPostal.focus();
				
				//	hide the sidebar content
				$('#ajax-content').fadeOut(200);
			}
		return false;
		e.preventDefault();
		});
		
		
		
		//	GO button (associated with zip/postal code field)
		$show.live('click', function(){
			
			//	if SHOW is clicked, but field is empty
			if($zipPostal.val() == 0 && $stateProvince.val() == 0 && $city.val() == 0){
				
				//	remove any existing messages
				$(this).parents('ul').find('.msg-error').remove();
				
				//	if any of the other list-items are showing, hide them
				$(this).parents('li').nextAll('li').slideUp(200);
				
					//	build message
					//	if 'US'
					if($country.val() == 'US'){
						$(this).parent('div').before('<div class="msg-error"><p>Please enter your ZIP code</p></div>');
					}
					//	if any other country chosen
					else{
						$(this).parent('div').before('<div class="msg-error"><p>Please enter your postal code</p></div>');
					}
				
				//	display message
				$(this).parents('li').find('.msg-error').hide().delay(400).slideDown(200);
			}
			
			//	TESTING purposes ONLY: if user has entered the string 'office' and clicked the associated 'Go' button, render the international office listing in ajax results container
			else if($zipPostal.val() == "office"){
				$('#ajax-content').fadeOut(200).load('ajax/find-your-rep-office-results.txt').hide().delay(200).fadeIn(200);
			}
					
			else{
				//	expose next list-item
				$(this).parents('li').next('li').slideDown(200);
				
				//	hide and remove message
				$(this).parents('ul').find('.msg-error').fadeOut(200).delay(400).remove();
			}
		return false;
		});
		
		
		//	GO button (associated with state/province/city element)
		$goState.live('click', function(){
			
			//	if SHOW is clicked, but field is empty
			if($zipPostal.val() == 0 && $stateProvince.val() == 0 && $city.val() == 0){
				
				//	remove any existing messages
				$(this).parents('ul').find('.msg-error').remove();
				
				//	if any of the other list-items are showing, hide them
				$(this).parents('li').nextAll('li').slideUp(200);
				
					//	build message
					//	if 'US'
					if($country.val() == 'US'){
						$(this).parent('div').prev('div').before('<div class="msg-error"><p>Please select your state</p></div>');
					}
					else if($country.val() == 'CA'){
						$(this).parent('div').prev('div').before('<div class="msg-error"><p>Please select your province</p></div>');
					}
					//	if any other country chosen
					else{
						$(this).parent('div').prev('div').before('<div class="msg-error"><p>Please enter your city/town</p></div>');
					}
				
				//	display message
				$(this).parents('li').find('.msg-error').hide().delay(400).slideDown(200);
			}
			else{
				//	expose next list-item
				$(this).parents('li').next('li').slideDown(200);
				
				//	hide and remove message
				$(this).parents('ul').find('.msg-error').fadeOut(200).delay(400).remove();
			}
		return false;
		});
		
		//	INSTITUTION dropdown (note: this is an onblur AND onchange event since no 'GO' button is supplied to conduct submit)
		$institution.live('blur change', function(){
			
			//	if user chooses default where value == 0
			if($institution.val() == 0){
				
				//	remove any existing messages
				$(this).parents('ul').find('.msg-error').remove();
				
				//	if any of the other list-items are showing, hide them
				$(this).parent('li').nextAll('li').slideUp(200);
				
				//	build message
				$(this).parent('li').find('label').before('<div class="msg-error"><p>Please select your institution</p></div>');
				
				//	display message
				$(this).parent('li').find('.msg-error').hide().delay(400).slideDown(200);
			}
			else{
				//	expose next list-item
				$(this).parent('li').next('li').slideDown(200);
				
				//	hide and remove message
				$(this).parent('li').find('.msg-error').fadeOut(200).delay(400).remove();
				
				//	set focus to department dropdown
				$department.focus();
			}
		return false;
		});
		
		
		//	DEPARTMENT dropdown (note: this is an onblur AND onchange event since no 'GO' button is supplied to conduct submit)
		$department.live('change', function(){
			
			//	if user chooses default where value == 0
			if($department.val() == 0){
				
				//	remove any existing messages
				$(this).parents('ul').find('.msg-error').remove();
				
				//	if any of the other list-items are showing, hide them
				$(this).parent('li').nextAll('li').slideUp(200);
				
				//	build message
				$(this).parent('li').find('label').before('<div class="msg-error"><p>Please select your department</p></div>');
				
				//	display message
				$(this).parent('li').find('.msg-error').hide().delay(400).slideDown(200);
			}
			else{
				//	expose next list-item
				$(this).parent('li').next('li').slideDown(200);
				
				//	hide and remove message
				$(this).parent('li').find('.msg-error').fadeOut(200).delay(400).remove();
				
				//	load results in sidebar with simple ajax call
				$('#ajax-content').fadeOut(200).load('ajax/find-your-rep-results.txt').hide().delay(200).fadeIn(200);
			}
		return false;
		});
		
	}



/*	Initialize FDOC "Learn more" modal windows
-------------------------------------------------------------------------*/
	function init_FDOCmodals(){
		
		//	Handout
		$('.fdoc-modal-handout-link').live('click', function(){
		
			//	Open the FDOC (handout) dialog using jQuery UI
			$('#fdoc-handout-modal').dialog({
				modal: true,
				resizable: false,
				width: '470',
				height: '300',
				title: 'First Day of Class: Handout',
				show: 'fade',
				hide: 'fade',
				closeOnEscape: true,
				close: function () {
					$(this).dialog('destroy');
				}
			})
			
		return false;
		e.preventDefault;
		e.stopPropagation;
		});
		
		//	Presentation
		$('.fdoc-modal-presentation-link').live('click', function(){
		
			//	Open the FDOC (handout) dialog using jQuery UI
			$('#fdoc-presentation-modal').dialog({
				modal: true,
				resizable: false,
				width: '540',
				height: '560',
				title: 'First Day of Class: Presentation',
				show: 'fade',
				hide: 'fade',
				closeOnEscape: true,
				close: function () {
					$(this).dialog('destroy');
				}
			})
			
		return false;
		e.preventDefault;
		e.stopPropagation;
		});
		
		//	Email
		$('.fdoc-modal-email-link').live('click', function(){
		
			//	Open the FDOC (handout) dialog using jQuery UI
			$('#fdoc-email-modal').dialog({
				modal: true,
				resizable: false,
				width: '470',
				height: '380',
				title: 'First Day of Class: Email',
				show: 'fade',
				hide: 'fade',
				closeOnEscape: true,
				close: function () {
					$(this).dialog('destroy');
				}
			})
			
		return false;
		e.preventDefault;
		e.stopPropagation;
		});
	}
	
/* Initialize page control functions
-------------------------------------------------------------------------*/
	function init_pageControls(){
		
		//	open the default print dialog 
		$('.print').live('click', function(){
			window.print();
		});
	}

/*	Equal height columns (used for multi-col taxonomy browse elements
	and more (courtesy of Rob Glazerbrook)
-------------------------------------------------------------------------*/
	function equalHeight(group){
		var tallest = 0;
		group.each(function(){
			var thisHeight = $(this).height();
			if(thisHeight > tallest){
				tallest = thisHeight;
			}
		});
		group.height(tallest);
	}



/*	Make Moz happy = clean up whitespace(facilitates DOM crawling)
-------------------------------------------------------------------------*/
	function treeWalker(node){
		//this function breaks the WYSIWYG text, so skip it when we get to the div containing it
		if(node.id == "ajax-content")
		{ return; }

		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)
				}
			}
		}

