/** add_page_load_event.js allows us to run one or multiple functions on page load
The advantage of this funtion is it won't override any previously set onload functions,
and also that it will trigger at the point of HTML being ready, rather than waiting for every image to load */

/** Code to run on page load, including image rollovers and anything else fancy */
function page_setup()
{
	// make sure the popup detail div is hidden (only applies on the roster page)
	$('.popup_detail').hide()
	
	$('#mainmenu').hrmenu();
	
	// holds the html for the ladies info
	var ladyPopups = [];
//	var left   = 0;
//	var top    = 0;
//	var width  = 0;
//	var height = 0;
	var lady_id = 1;
	
	// capture everythign with a specific class
	$('.roster_popup').each
	(
		function()
		{
	     	$(this).hover (
	            function() // rollover function
				{
					// set the lady id
					lady_id = $(this).attr('id');
					//alert(lady_id);
					
					// set the position of the div
					var left 	= $(this).offset().left;  
					var top		= $(this).offset().top;  
					var width 	= $(this).width();
					var height 	= $(this).height();
					if (left + $('.popup_detail').width() > 1200)
					{
						left = (left + width) - $('.popup_detail').width();
					}
					$(".popup_detail").css(
						{'position': 'absolute',
						 'left': (left) + 'px', 
						 'top': (top + height + 20) + 'px'
						});
//					alert(left);
					//alert( $(this).attr('id') );
					if( ladyPopups[lady_id] !== undefined )
					{
						// there is already the html for this lady in the pre-cached array
//						//alert('test is undefined');
						$(".popup_detail").html(ladyPopups[lady_id]);
	                    $(".popup_detail").fadeIn('fast'); 
					}
					else
					{
						// get the lady info via an ajax request
//						//alert('test is defined');
						$.ajax(
						{
							// POST request
							type: "POST",
							// make request synchronous so you cant do other stuff while waiting
							async: false,
							// use our combobox url
							// show the lady details using the 'cleos_ladies_list_lady' template
							url: 'execfunc.php?q=8m4vIyM7lrXEzqY6qQUMz7G3P09_xF5Eb4_KwEN1x6szL3SwbH2TC1pAuYjDfA',
							// tack on the new date as POST data
							data: 'lady_id=' + lady_id,
							success: function( msg )
							{
								// store the html of the lady in the array
								ladyPopups[lady_id] = msg;
								$(".popup_detail").html(msg);
	                    		$(".popup_detail").fadeIn('fast'); 
							}						
						})
					}
				},
				function()  // rollout function
				{
					// fade out the lady div
					$(".popup_detail").fadeOut('fast');
				}
			)
		}
	);

// add an on-mouseover event to that class

// write function that is the mouseover event
	
}

$(document).ready( page_setup );
