jQuery(document).ready(function(){
    
    jQuery('.special_offer').click(function(){
        window.location = '/newsletterSignup.php';
    })
    
    jQuery('#news_drop').click(function(){
        var link = jQuery(this).children('a').attr('href');
        window.location = link;
    })
    
    
    
    
    
           
    jQuery.ajaxSetup({
        cache: false
    });
    
    //declare booking method variable
     bookingMethod = '';    

    //load rooms and add change behaviour uisi
    jQuery.get('/applications/hotelRooms.php',function(data) {
       jQuery('#roomList').html('<p>'+data+'</p>'); 
    });
    
    jQuery('#roomSelectList').live('change',function(){
        var roomNumber = jQuery(this).val();
        jQuery('#bookingDetails').slideUp(1200,function(){
            jQuery(this).html('');
        });
        
        jQuery('#roomDates').load('/applications/roomDates.php?roomID='+roomNumber);
    });
    
    jQuery('.bookingLink').live('click',function(){
        var roomDate = jQuery(this).siblings('.roomDate').val();
        var roomID = jQuery(this).siblings('.roomID').val();
        bookingMethod = 'viaList';     
        
        jQuery.get ('/applications/roomDetails.php?roomDate='+roomDate+'&roomID='+roomID, function(data){
            jQuery('#bookingDetails').html(data);
            jQuery('#bookingDetails').slideDown();
        })
        
    })

    /**
    * 
    * Need to improve 
    * date selection
    * 
    */
    jQuery('#addCart').live('click',function(){
        
        var roomID = jQuery('#chosenRoomID').val();
        var dateID = jQuery('#dateID').val();
            
        jQuery.get('/processCart.php?action=add&chosenRoomID='+roomID+'&dateID='+dateID, function(){
            jQuery.get('/includes/miniCart.php',function(data){
                jQuery('#miniCart').html(data);
                jQuery('#roomDates').load('/applications/roomDates.php?roomID='+roomID);
                jQuery('#bookingDetails').slideUp(function(){
                    if (jQuery('#bookingFromCalendarWarning').length == 0 && bookingMethod == 'viaCalendar') {
                        jQuery('#roomDates h2').after('<p id = "bookingFromCalendarWarning">Please note you may only choose other dates from this room.</p>');
                    } else if (jQuery('#bookingFromCalendarWarning') > 0) {
                        jQuery('#bookingFromCalendarWarning').remove();
                    }
                });
            });
        });
            
    })
    
    jQuery('.pickDateLink').live('click',function(){
        
        bookingMethod = 'viaCalendar';     
        
        var roomDate = jQuery(this).siblings('.roomDate').val();
        var roomID = jQuery(this).siblings('.roomID').val();
        
        jQuery('#chosenRoomID').val(roomID);
        
        jQuery.get ('/applications/roomDetails.php?roomDate='+roomDate+'&roomID='+roomID, function(data){
            jQuery('#bookingDetails').html(data);
            jQuery('#bookingDetails').slideDown();
        })
        
    })
    

    
})
