/**
 * @author tony.obyrne
 */
/*
 *	In the private section, Scottrade would like the two columns to line up perfectly.
 *	Currently, there is a left and right div, left floated to give two columns - .taxLeftCol and .taxRightCol
 *
 *	Step 1
 *		Find the heights of both columns and set the height of the shorter column to the height of the larger column
 *	Step 2
 *		Expand the height of the last .taxGuideModule in the smaller column such that the bottom of that module lines
 *		up with the bottom of the last .taxGuideModule in the larger column
 *
 *   To get the amount of space to add...
 *   Step 3
 *   	get the offset of the last .taxGuideModule in the shorter column - this gives the top left corner.
 *
 *   Step 4
 *   	get the height of the last .taxGuideModule in the shorter column and add it to the offset - this gives us the bottom.
 *
 *   Step 5
 *   	subtract the bottom of the last .taxGuideModule (found in step 2) from the bottom of the column (after the column has been expanded)
 *
 *	 Step 6
 *   Should I pad the last paragraph of the .taxGuideModule, or distribute the padding?
 *   	distributing the padding would make things look inconsistent across all the modules
 *   	distributing only the last would be an easy jQuery selector (:last)
 *   	last paragraph/element it is.
 *
 *   All this should be done before the user realizes what's going on.
 */
//	I'm in the development stage - this is to turn debug output on/off
var bBuildMode = false ;
//	This lets me use the above switch to turn debugging output on or off and use "debug('theoutput')"
var debug = function( output ){ if(bBuildMode){console.log(output)}} ;


$(window).bind('load',function() {
	//	trying to properly namespace stuff that I'll be needing across functions for this.
	var taxVariables = {} ;

	makeSameColumnHeights( taxVariables ) ;			//	Step 1
	stretchAppropriateTaxModule( taxVariables ) ;	//	Step 2

	attachTurboTaxPopup();
})


/*
$(document).ready( function(){
	//	trying to properly namespace stuff that I'll be needing across functions for this.
	var taxVariables = {} ;

	makeSameColumnHeights( taxVariables ) ;			//	Step 1
	stretchAppropriateTaxModule( taxVariables ) ;	//	Step 2
});
*/

function makeSameColumnHeights( taxVariables ){
	//	Get the heights of both columns
	taxVariables.leftHeight = $(".taxLeftCol").height( ) || 0 ;
	taxVariables.rightHeight = $(".taxRightCol").height( ) || 0 ;

	//	If the heights are equal, we don't need to do anything.
	if( taxVariables.leftHeight == taxVariables.rightHeight ) return ;

	//	Set the height of the smaller column
	taxVariables.smallerColumn = taxVariables.leftHeight < taxVariables.rightHeight ? $(".taxLeftCol") : $(".taxRightCol") ;
	taxVariables.largerColumn =  taxVariables.leftHeight > taxVariables.rightHeight ? $(".taxLeftCol") : $(".taxRightCol") ;	//	Just in case I need it later

	taxVariables.smallerHeight = taxVariables.leftHeight < taxVariables.rightHeight ? taxVariables.leftHeight : taxVariables.rightHeight ;
	taxVariables.largerHeight =  taxVariables.leftHeight > taxVariables.rightHeight ? taxVariables.leftHeight : taxVariables.rightHeight ;

	//	This gets the last taxGuideModule in the smaller column
	taxVariables.lastInSmallCol = $(".taxGuideModule:last", taxVariables.smallerColumn) ;

	//	Set the height of the smaller column to that of the larger column - jQuery appends 'px' by default, so I don't need to worry about units
	$(taxVariables.smallerColumn).height( taxVariables.largerHeight ) ;
}

function stretchAppropriateTaxModule( taxVariables ){
	if( !taxVariables.smallerColumn ) return;

	//	I need to get the smaller column's offset and use that in all this math
	taxVariables.topReference = taxVariables.smallerColumn.offset().top ;

	//	The last taxmodule in the shorter column has already been identified and "bookmarked" in taxVariables.lastInSmallCol
	taxVariables.lastModuleVerticalOffset = taxVariables.lastInSmallCol.offset().top - taxVariables.topReference ;

	taxVariables.lastModuleHeight = taxVariables.lastInSmallCol.height( ) ;

	//	Step 4
	taxVariables.lastModuleBottomOffset = taxVariables.lastModuleVerticalOffset + taxVariables.lastModuleHeight ;

	//	Step 5
	taxVariables.spaceToFill = taxVariables.largerHeight - taxVariables.lastModuleBottomOffset ;

	//	Step 6
	taxVariables.lastModuleContent = $(".helpSmallModuleContent", taxVariables.lastInSmallCol) ;
	taxVariables.lastModuleContentHeight = taxVariables.lastModuleContent.height( ) ;

	//	Append a div with the spaceToFill as the height to the moduleContent
	var newDiv = "<div style='height:" + taxVariables.spaceToFill + "px'></div>" ;
	taxVariables.lastModuleContent.append( newDiv ) ;
}

function attachTurboTaxPopup( ){
	return;
	//	How is the popup being managed?
	//	I already had this jQuery code to show/hide a div on the page, but after consulting
	//	with design & project management, discovered it's a regular window popup.  I left the existing
	//	code there and added a switch, just in case the decision is made to use the page div method.

	var disclaimerMethod = "newWindowPopup" ;

	switch( disclaimerMethod ){
	case "newWindowPopup":
		$(".ttPopupLink").click( function(e){
			//window.open( "../../knowledgecenter/taxguide/taxguide.asp" ) ;
			popUp( "../../knowledgecenter/taxguide/turboTaxDisclosure.asp", e ) ;
		}) ;
		break ;
	case "pageInternalDiv":
		//	Make the disclaimer hideable by clicking anywhere on the page.
		$("#turboTaxDisclaimer").click( function(){
			$("#turboTaxDisclaimer").hide( ) ;
		});

		$(".ttPopupLink").click( function(e){
			//	simple positioning for the popup.
			var topPos = (e.pageY - 280) + 'px' ;
			var leftPos = (e.pageX - 200) + 'px' ;

			$("#turboTaxDisclaimer").css({position: 'absolute', top: topPos, left: leftPos });

			$("#turboTaxDisclaimer").toggle( ) ;
		});
		break ;
	}
}

function popUp( URL, e ){
	var topPos = (e.pageY - 800) + 'px' ;
	var leftPos = (e.pageX - 200) + 'px' ;

	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '', 'addressbar=0,directories=0,toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=405,height=280,screenX=" + leftPos + ",screenY=" + topPos + "');");
}
// End -->

