var numDebugWrites = 1;
function debugWrite( toWrite ) {
	$("#jsDebug").html( $("#jsDebug").html() + "<p>" + numDebugWrites + ": " + toWrite + "</p>" );
	numDebugWrites++;
}

var blueBoxVertSizeCompensation = 50; // in pixels

function sizeContent() {
	// Begin inelegant code.
	var heightOfTopBlock = 69; // pixels
	var heightOfBottomBlock = 5; // pixels
	
	$("[class*=blueBox]").each( function() {
		// The blue boxes are hidden to prevent the sizing code from blinking unsized boxes.
		$(this).css( "display", "block" );

		// Extract the content's height
		var contentHeight = $(this).find("[class=content]").height();
		// The width the background-repeats need to fill to
		var fillWidth = $(this).width() - 5 - 9;	// Total Width - Width(leftShadow) - Width(rightBorder)

		// Place and size the rest of the box's elements accordingly
		var middleHeight = contentHeight - heightOfTopBlock - heightOfBottomBlock + blueBoxVertSizeCompensation;
		// Set the height of the div and the div's childen
		$(this).find("[class=midBlock]:first").height( middleHeight )
		$(this).find("[class=midBlock]:first div").height( middleHeight )
		$(this).find("[class*=shrinkWidthSet]").width( fillWidth )
		

	});
}

// Function that runs when the DOM is prepared
function domReady() {
//    $('#workshopAccordion').accordion({
//	      header: "h2"
//	    	  });

    sizeContent();
}

$(document).ready( domReady );



// Workshop page
function loadWorkshop( eventID, levelNum, divToReplace, isWaitlisted ) {
	// Check current page location
	// If page has 'workshopContent.php' embedded stay here
	// If page has no workshopContent navigate to workshop.php
	
	// When an event isWaitlisted it cannot be signed up for, therefore simply navigate to the voice workshop page
	
	// If the body with the specified id doesn't exist, navigate the page.
	if( $("body[id=workshops]").length == 0 ) {
		//window.location = "./workshops.php" + "?eventID=" + eventID + "#level" + levelNum;
		window.location = "./workshops.php" + "#level" + levelNum;
	}
		
	if( false == isWaitlisted )
		myRef = window.open( "./registration.php?eventID=" + eventID, "workshopReg",
			'left=20,top=20,width=800,height=700,scrollbars=yes');
	
	
	/*$(document).css( {cursor: "wait" } );
	// Open div with correct workshop that was clicked.
	$.post( "./pagelets/registration.php", { eventID: eventID }, function( returnPHP ) {
		
		$("#" + divToReplace ).html( returnPHP );
		
		// when the new HTML is injected the content size will change
		$("#" + divToReplace ).show( "normal", sizeContent )
	});*/
	
}
