$(document).ready(function(){
	
	$('marquee').marquee('pointer');

        $('#locations_handle').click(function(e) {
            e.preventDefault();
            $('#locations').toggle();
            $('#locations_handle').focus();
            
        });

        var hideLocations = false;
        $('#locations_handle').blur(function() {
            hideLocations = true;
        });

        $(document).mouseup(function() {
            if(hideLocations) { setTimeout('$("#locations").hide()', 100); hideLocations = false; }
        });

        var intCalendarCount = 1;
        var intCurCal = 1;
        $('#bookings .none').each(function() {
            var div = $(this);

            div.attr('calnr', intCalendarCount);

            if(intCalendarCount == 1) {
                div.find('.prevmonth').parent().html('&nbsp;');
            }
            if(intCalendarCount == 12) {
                div.find('.nextmonth').parent().html('&nbsp;');
            }
            div.hide();
            if(intCurCal == intCalendarCount && div.find('td.selected').html()) {
                div.show();
            }
            else {
                intCurCal++;
            }


            div.find('.prevmonth').attr('calnr', intCalendarCount);
            div.find('.nextmonth').attr('calnr', intCalendarCount);
            div.attr('id', 'cal_' + intCalendarCount);
            intCalendarCount++;

        });

        if(intCurCal > 12) {
            $('#cal_1').show();
        }

        $('#bookings a.prevmonth').click(function(e) {
            e.preventDefault();
            var month = parseInt($(this).attr('calnr'));
            var change = parseInt($(this).attr('calnr')) - 1;
            $('#cal_' + month).hide();
            $('#cal_' + change).show();

        });

        $('#bookings a.nextmonth').click(function(e) {
            e.preventDefault();
            var month = parseInt($(this).attr('calnr'));
            var change = parseInt($(this).attr('calnr')) + 1;
            $('#cal_' + month).hide();
            $('#cal_' + change).show();

            
        });


});
