function initShowMore() {
    $(".show-more").click(function() {
        $(".extended-list").hide();
        var elem = $(this).parents(".day")[0];
        var offset = $(elem).offset();

        var extendedList = $(elem).children(".events").children(".extended-list")[0];
        $(extendedList).show();
        $(extendedList).offset(offset);
    });
    $(".extended-list-close").click(function(event) {
        event.preventDefault();
        $(".extended-list").hide();
    })
}

$(document).ready(function() {
    // Use livequery instead of a standard click event so when
    // the content is injected the click will continue to work

    initShowMore();

    $('.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);
                });

                initShowMore();
            });

        return false;
    });

    /* DISABLE THE EVENT SUMMARY UNTIL WE GET THE MOUSE_OVER WORKING PROPERLY
     // Add a mouseover to each of the event titles in the page so
     // that pointer layer is acivated
     $( 'a.event-summary' ).livequery ( 'mouseover', function ( event )
     {

     // Get the id from the element and remove 'event_' which gives us
     // the event id to pull in the content for the hover-over

     int_event = $(this).attr ( 'id' ).substring ( 6 );

     $( this ).pointerLayer ( {
     contentURL: 		'/p/social/inc.calendar-pointer-layer.php',
     contentURLData:	'event_id=' + int_event,
     horzFlipField:	'hflip',
     position:				2,
     xOffset:				20,
     yOffset:				-5
     } );

     return false;
     });

     // Hide the pointer layer when
     $( 'a.event-summary' ).livequery ( 'mouseout', function ( event )
     {
     $.pointerLayer_close ( $( this ).attr ( 'id' ) );
     });
     */

    $('.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;
    });
});

