AH.Room = {
    init: function () {
        $('#room_list a').click(function () {
            AH.Room.popup(this);
            return false;
        });
        $('#photogallery .photos a').click(function () {
            AH.Photo.changeImage(this.href);
            this.blur();
            return false;
        });
        if ($('#hotel_photo a').length == 1) {
            $('#hotel_photo ul').remove();
        } else if ($('#hotel_photo a').length < 4) {
            $('#hotel_photo ul').attr('style', 'height: 72px');
        }

        if($('div#tp_reviews').length > 0){
            $('div#primary').append('<div id="tp_overview" class="tabpanel" style="display:none;"></div><div id="tp_howtobook" class="tabpanel" style="display:none;"></div>');
        }
        else if($('div#tp_howtobook').length > 0){
            $('div#primary').append('<div id="tp_overview" class="tabpanel" style="display:none;"></div><div id="tp_reviews" class="tabpanel" style="display:none;"></div>');
        }
        else{
            $('div#primary').append('<div id="tp_reviews" class="tabpanel" style="display:none;"></div><div id="tp_howtobook" class="tabpanel" style="display:none;"></div>');            
        }

        //Borchure page experiment
        if($('div#tp_reviews').length > 0){
            $('div#primary2').append('<div id="tp_overview" class="tabpanel" style="display:none;"></div><div id="tp_howtobook" class="tabpanel" style="display:none;"></div>');
        }
        else if($('div#tp_howtobook').length > 0){
            $('div#primary2').append('<div id="tp_overview" class="tabpanel" style="display:none;"></div><div id="tp_reviews" class="tabpanel" style="display:none;"></div>');
        }
        else{
            $('div#primary2').append('<div id="tp_reviews" class="tabpanel" style="display:none;"></div><div id="tp_howtobook" class="tabpanel" style="display:none;"></div>');            
        }
        // End experiment

        //<div class="roomloading"><img src="' + loading_image + '" /></div>
        $('a.roomname').click(function(){
            AH.RoomInfo.toggle(this);
            this.blur();
            return false;
        });


        // Brochure page room information
        $('a.roomName').click(function(){
            AH.RoomInformation.toggle(this);
            this.blur();
            return false;
        });
    },
    show: function(el, div) {
        var tp = AH.Key.getTopPos(el) + 5;
        var lt = AH.Key.getLeftPos(el) + 5;
        if (typeof div == 'string') div = $('#'+div);
        $(div).css({ left: lt, top: tp }).show();
        AH.Event.track(AH.Event.displayTracker, 'Room Details', 'Show');
    },
    popup: function (el) {
        $('.room_popup').remove();
        $('<div class="room_popup"><h3>' + roomDetailsTxt + '</h3><a id="close" href="#">Close</a><div id="container"></div></div>').appendTo('body');
        $('#close').click(function () {
            $('.room_popup').remove();
            this.blur();
            return false;
        });
        AH.Room.show(el, $('.room_popup'));
        $('#container').html('<img src="' + loading_image + '" id="loading" />');
        $('#container').load(el.href);
    }
}

AH.Photo = {
    changeImage: function (href) {
        $('#mainphoto').css('backgroundImage', 'url(' + href + ')');
    }
}




AH.RoomInfo = {
    toggle: function(link){
        //add tr for room info if doesnt exist
        if($(link).parent('td').parent('tr').next('tr').children('td').children('.roominfo').length == 0){
            $(link).parent('td').parent('tr').after('<tr class="' + $(link).parent('td').parent('tr').attr('class') + '"><td colspan="4" style="padding:0;"><div class="roominfo" style="display:none;"></div></td></tr>');
        }
        var roominfo = $(link).parent('td').parent('tr').next('tr').find('.roominfo');
        if($(roominfo).children().length == 0){
            $(roominfo).html('<div class="roomloading"><img src="' + loading_image + '" /></div>')
            $(roominfo).load(link.href);
        }
        $(roominfo).slideToggle("fast");
        
        return false;
    }

}
// Brochure page room information
AH.RoomInformation = {
    toggle: function(link){
        //add tr for room info if doesnt exist
       if($(link).parent('td').parent('tr').next('tr').children('td').children('.roominfoBrochure').length == 0){
            $(link).parent('td').parent('tr').after('<tr class="' + $(link).parent('td').parent('tr').attr('class') + '"><td colspan="6" style="padding:0;"><div class="roominfo" style="display:none;"></div></td></tr>');
        }
        var roominfo = $(link).parent('td').parent('tr').next('tr').find('.roominfoBrochure');
        if($(roominfo).children().length == 0){
            $(roominfo).html('<div class="roomloading"><img src="' + loading_image + '" /></div><div class="clear">&nbsp;</div>')
            $(roominfo).load(link.href);
        }
        $(roominfo).slideToggle("fast");

        return false;
    }

}

AH.newRoomList = {
   TruncateLongRoomList: function(){
      var rows = 0;
      $('table#prices tbody#priceTable_body tr').each(function(i){
//          console.log(i);
          if(i>7){
              $(this).hide();
          }
          rows = i+1;
      });
//      console.log("rows: " + rows);

      if(rows > 8){
//          console.log("rows inside if statement: " + rows);
        $('table#prices tbody#priceTable_body').append('<tr id="morelink"><td colspan="5"><a href="#">' + transl_moreinfo + '</a></td></tr>');
      }
      $('#morelink').click(function(){
          $('table#prices tbody#priceTable_body tr').show();
           $('table#prices tbody#priceTable_body tr#morelink').remove();
          return false;
      });
   }
}

$(function () {
	AH.Room.init();
    AH.newRoomList.TruncateLongRoomList();
});


// SCROLL INFO BOXES //

$(document).ready(function() {
    
    $('a.roomtitle').click(function () {
        var thebox = $(this).parent().next();
        thebox.slideToggle();
        thebox.html('<img src="' + loading_image + '" id="loading" />');
        thebox.load(this.href);
        return false;
    });
});


function roomInfoSlide( sl, number, text )
{
    if ($('.roomInformationContent' + number).css('display') == "none")
    {
        if($('.roomInformationContent' + number).children().size() == 0)
        {
            $('.roomInformationContent' + number).html('<img src="' + loading_image + '" id="loading" />');
            $('.roomInformationContent' + number).load(sl.href);
        }
        $('.roomInformationContent' + number).slideDown("slow");
        $(sl).html('Close x');
    }
    else
    {
        $('.roomInformationContent' + number).hide();
        if( !text )
        { $(sl).html( 'view more details >>' ); }
        else
        { $(sl).html( 'view more details' + text + '>>' ); }
    }
}

$( document ).ready( function(){    
    $( 'input.jsButton' ).show();
    $( 'input.noJsButton' ).hide();
} );

function revealRoomOcc( selectName, className )
{
    var reveal = $( 'select.' + selectName ).val();
    $( '.roomOccupancy' + className ).css( 'display', 'none' );

    var i = 1;
    while( i <= reveal )
    {
       $( '#row' + className + 'selectNumber' + i ).css( 'display', 'block' );
       i++;
    }
}
