/// <reference path="yui-2.2.2/yahoo-dom-event/yahoo-dom-event.js" />
/// <reference path="yui-2.2.2/animation/animation.js" />
/// <reference path="yui-2.2.2/event/event.js" />

YAHOO.namespace('LBH');

YAHOO.LBH.opacityMax = 0.9; // 80% opaque
YAHOO.LBH.opacityMin = 0.0; // 100% transparent
YAHOO.LBH.opacitySpeed = 1; // opacity animation takes 1 second

YAHOO.LBH.init = function() {
  var ResrvPanel;
  ResrvPanel = YAHOO.util.Dom.get('reserv') || YAHOO.util.Dom.get('avail_page');

   var availFadeIn = function(e) {
      YAHOO.util.Event.preventDefault(e); // block the default link
      YAHOO.util.Dom.setStyle(ResrvPanel, 'opacity', YAHOO.LBH.opacityMin); // ensure the correct opacity is shown before we show the block
      YAHOO.util.Dom.setStyle(ResrvPanel, 'display', 'block'); // show the block
      var anim = new YAHOO.util.Anim(ResrvPanel, { opacity: { from: YAHOO.LBH.opacityMin, to: YAHOO.LBH.opacityMax } }, YAHOO.LBH.opacitySpeed, YAHOO.util.Easing.easeOut); // setup the animation
      var showex = function(e) {
      var xy = YAHOO.util.Dom.getXY(ResrvPanel);
          xy[0] -= 202;
          YAHOO.util.Dom.setStyle('ajaxExclusivesPanel', 'display', 'block');
      };
      anim.onComplete.subscribe(showex);
      YAHOO.util.Dom.setStyle('booklink', 'display', 'none');
      YAHOO.util.Dom.setStyle('booknowdisp', 'display', 'none');
      YAHOO.util.Dom.setStyle('booklink', 'display', 'inline');
      anim.animate(); // animate
  };
   
   var availFadeOut = function(e) {
      YAHOO.util.Event.preventDefault(e); // block the default link
      var anim = new YAHOO.util.Anim(ResrvPanel, { opacity: { from: YAHOO.LBH.opacityMax, to: YAHOO.LBH.opacityMin } }, YAHOO.LBH.opacitySpeed, YAHOO.util.Easing.easeOut); // setup the animation
      
      var hide = function(e) { YAHOO.util.Dom.setStyle(ResrvPanel, 'display', 'none'); YAHOO.util.Dom.setStyle('ajaxExclusivesPanel', 'display', 'none'); }; // setup the hide function so that it can be called using the onComplete

      anim.onComplete.subscribe(hide); // subscribe to the onComplete event
      YAHOO.util.Dom.setStyle('booklink','display','inline');
      YAHOO.util.Dom.setStyle('booknowdisp','display','inline');
      anim.animate(); // animate           
   };

   // subscribe to the onclick events for the avail search and close links
   YAHOO.util.Event.addListener('booklink', 'click', availFadeIn);   
   YAHOO.util.Event.addListener('bookclose', 'click', availFadeOut);
};

// only initialize if we have the avail div in the page
YAHOO.util.Event.onAvailable('booklink', YAHOO.LBH.init);


$(function() {
   $( "#arrive" ).datepicker({
	  showOn: "button",
	  buttonImage: "/images/calendar.png",
	  buttonImageOnly: true
   });
	   
   $( "#depart" ).datepicker({
	  showOn: "button",
	  buttonImage: "/images/calendar.png",
	  buttonImageOnly: true
   });
   
   $( "#date11" ).datepicker({
	  showOn: "button",
	  buttonImage: "/images/calendar.png",
	  buttonImageOnly: true
   });
	   
   $( "#date12" ).datepicker({
	  showOn: "button",
	  buttonImage: "/images/calendar.png",
	  buttonImageOnly: true
   });
   
   $('#booknowsubmit').click(function() {
	  $('#bn-embedded').trigger('click');
   });

});
