$(document).ready(function() {
  //var _a = $("#lower-nav li a.active").attr("href");
  $("#scroll-boxes .sc-box").hide();
  //$("#scroll-boxes "+_a).addClass("active").show();

  $("#lower-nav li a").click(function() {
    var _b = $(this).attr("href");
    var carousel_container = $('#scroll-boxes ' + _b);

    if(!$(this).hasClass("active")) {
      $("#lower-nav li a.active").removeClass("active");
      $("#lower-nav li.active").removeClass("active");
      $(this).addClass("active");
      $(this).parent().addClass('active');
      $("#scroll-boxes .active").removeClass("active").hide();
      //$("#scroll-boxes .sc-box").hide(); 

      $(carousel_container).addClass("active").fadeIn();

      if (!$(carousel_container).hasClass('initialized')) {
        $(carousel_container).addClass('initialized');

        if (_b == '#meetings') {
          $('#scroll-boxes ' + _b + ' .footer-carousel .carousel-wrapper').jCarouselLite({btnNext: ".next", btnPrev: ".prev", visible: 3});
        }
        else {
          $('#scroll-boxes ' + _b + ' .footer-carousel .carousel-wrapper').jCarouselLite({btnNext: ".next", btnPrev: ".prev", visible: 3});
        }

        $('#scroll-boxes ' + _b + ' .footer-carousel .scroll-pane').jScrollPane({showArrows: true});
      }
    }
    return false;
  });

  $('#lower-nav li:first a').trigger('click');

  $('.scroll-pane').jScrollPane({showArrows: true});
  
  $("#lower-nav li a.lower_faq").click( function() {
          window.open(this.href
, this.target || "_self");
          return false;
      });
  
  // Room description switch
  $(".room-description").not(".room-description:first").hide();
  $(".room-description:first").addClass("selected");

  $("ul.ins-nav li a").click(function() {
    if(!$(this).hasClass("selected")) {
      $("ul.ins-nav li a").removeClass("selected");
      $(this).addClass("selected");
      var $ajax_url = $(this).attr('href');

      $('.ins-cnt-right .scroll-pane').fadeOut('normal', function() {
        $.post($ajax_url, function(data) {
          $('.ins-cnt-right .scroll-pane').html(data);
          $('.ins-cnt-right .scroll-pane').fadeIn('normal', function() {
            $('.ins-cnt-right .scroll-pane').jScrollPane({showArrows: true});           
          });
        });
      });
    }
    return false;
  });

  $('.scroll-pane').jScrollPane({showArrows: true});

  $('.inside-content-header h1').click(function() {
    if ($('#inside-holder').hasClass('active')) {
      $('#inside-holder').removeClass('active').animate({'height': '40px'}, 1000);
      $(this).parent().css("background-position","top");
	  $('#featureholder').delay(1000).fadeIn('slow');
	  $('#feat').delay(1000).fadeIn('slow');
    }
    else {
      $('#inside-holder').addClass('active').animate({'height': '250px'}, 1000);
      $(this).parent().css("background-position","50% -44px ");
	  $('#featureholder').hide();
    }
  });


$('div.closebutton').click(function() {
  $('#feat').hide();
});


});

$(window).load(function() {
  // Open a subpage if specified 
  var request_url = window.location.href;
  var params = request_url.split('?');

  if ($(params).size() > 1) {
    var params_parts = params[1].split('=');

    if (params_parts[0] = 'show') {
      $('ul.ins-nav li a[href=/' + params_parts[1] + ']').trigger('click');
    }
  }
});

