
	$(document).ready(function()
	{	
		// Use livequery instead of a standard click event so when
		// the content is injected the click will continue to work
		$( '.calendarAction' ).livequery ( 'click', function ( event )
		{
			// Get the id from the element and removed calendar-
			// from it as this defines the action
			str_action = $(this).attr ( 'id' ).substring ( 9 );
			
			//Get the URL to go to (stripping off the query string)
			var str_full_url = $(this).attr('href');

			//Get the query string parameters			
			var int_group_id;
			var str_action;
			var int_event_id;
						
			var arr_params = new Array();
			var arr_href = str_full_url.split('?');
			var str_query = arr_href[1];
			
			var keyValues = str_query.split('&');
			
			for (var i in keyValues) 
			{
				var key = keyValues[i].split('=');
				
				if (key[0] == "cgi")
				{
					int_group_id = key[1];
				}
				else if (key[0] == "calendarAction")
				{
					str_action = key[1];
				}				
				else if (key[0] == "event_id")
				{
					int_event_id = key[1];
				}				
			}
			
			$.get('/p/social/inc.calendar.php', { 'calendarAction': str_action, 'event_id': int_event_id, 'cgi' : int_group_id },					  					  
			function ( str_data )
			{
				$( '#calendarContainer' ).html ( str_data );

				$( '.fullheight' ).each ( function ( i )
				{
					// Calculate how much padding the element has
					var str_elPadTop				= $(this).css ( 'padding-top' );
					var str_elPadBot				= $(this).css ( 'padding-bottom' );
					str_elPadTop						= str_elPadTop.substring ( 0, str_elPadTop.length - 2 );
					str_elPadBot						= str_elPadBot.substring ( 0, str_elPadBot.length - 2 );
					// Calculate how much border the element has
					var str_elBorderTop			= $(this).css ( 'border-top-width' );
					var str_elBorderBot			= $(this).css ( 'border-bottom-width' );
					str_elBorderTop					= str_elBorderTop.substring ( 0, str_elBorderTop.length - 2 );
					str_elBorderBot					= str_elBorderBot.substring ( 0, str_elBorderBot.length - 2 );
					// The padding and border must be deducted from
					// the element height to calculate how tall it should be
					var int_elPadding				= parseInt ( str_elPadTop ) + parseInt ( str_elPadBot )
					var int_elBorder				= parseInt ( str_elBorderTop ) + parseInt ( str_elBorderBot )
					var int_containerHeight	= $(this).parent().height() - int_elPadding - int_elBorder;
					// Set the new height of teh container
					$(this).css ( 'height', int_containerHeight );
				});

			});				

			return false;
		});
		
		/* HelpLayer not working great, so disabled for now
		$( 'a.event-summary' ).livequery ( 'mouseover', function ( event )
		{	
			// Get the id from the element and removed calendar-
			// from it as this defines the action
			int_event = $(this).attr ( 'id' ).substring ( 6 );

			$.get("/p/social/inc.calendar-event-summary.php", { 'event_id': int_event },
			function ( str_data )
			{
				$( '#calendarEventHover div.helplayer_content' ).html ( str_data );
				showHelpLayer ( 'calendarEventHover' );
			});
		});
		
		
		$( 'a.event-summary' ).livequery ( 'mouseout', function ( event )
		{
			hideHelpLayer ( );
		});
		
		
		$( '.unsubLightBox' ).livequery ( 'click', function ( event )
		{
			// Get the query string from the link we've clicked
			// so we can pass the data to the lightbox content URL
			var str_url = $( this ).attr ( 'href' );
			var	int_qs	= str_url.indexOf ( '?' ) + 1;	
			var str_qs	= str_url.substr ( int_qs );
						
			$( this ).htmlLightBox ( { contentURL: '/p/social/inc.calendar-confirm-unsub.php', contentURLData: str_qs, closeElementId: 'htmlLightboxClose' }); 
			return false;
		}); 
		$( '.subLightBox' ).livequery ( 'click', function ( event )
		{
			// Get the query string from the link we've clicked
			// so we can pass the data to the lightbox content URL
			var str_url = $( this ).attr ( 'href' );
			var	int_qs	= str_url.indexOf ( '?' ) + 1;	
			var str_qs	= str_url.substr ( int_qs );
			
			$( this ).htmlLightBox ( { contentURL: '/p/social/inc.calendar-confirm-sub.php', contentURLData: str_qs, closeElementId: 'htmlLightboxClose' });
			// Reload the page so all the plus/minus subscription icon is correct
			return false;
		}); 
		
		
		$( '.deleteLightBox' ).livequery ( 'click', function ( event )
		{
			// Get the query string from the link we've clicked
			// so we can pass the data to the lightbox content URL
			var str_url = $( this ).attr ( 'href' );
			var	int_qs	= str_url.indexOf ( '?' );	
			var str_qs	= str_url.substr ( int_qs );
						
			$( this ).htmlLightBox ( { contentURL: '/p/social/inc.calendar-confirm-delete.php' + str_qs, closeElementId: 'htmlLightboxClose' }); 
			return false;
		});
		*/
	});
