/// <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('aman');

YAHOO.aman.opacityMax = 0.8; // 80% opaque
YAHOO.aman.opacityMin = 0.0; // 100% transparent
YAHOO.aman.opacitySpeed = 1; // opacity animation takes 1 second

YAHOO.aman.init = function() {
  var availPanel;
  availPanel = YAHOO.util.Dom.get('avail') || YAHOO.util.Dom.get('avail_page');

   var availFadeIn = function(e) {
      YAHOO.util.Event.preventDefault(e); // block the default link
      YAHOO.util.Dom.setStyle(availPanel, 'opacity', YAHOO.aman.opacityMin); // ensure the correct opacity is shown before we show the block
      YAHOO.util.Dom.setStyle(availPanel, 'display', 'block'); // show the block
      var anim = new YAHOO.util.Anim(availPanel, { opacity: { from: YAHOO.aman.opacityMin, to: YAHOO.aman.opacityMax } }, YAHOO.aman.opacitySpeed, YAHOO.util.Easing.easeOut); // setup the animation
      var showex = function(e) {
      var xy = YAHOO.util.Dom.getXY(availPanel);
          xy[0] -= 202;
          //            xy[0] += "px";
          //            xy[1] += "px";
          YAHOO.util.Dom.setStyle('ajaxExclusivesPanel', 'display', 'block');
//          YAHOO.util.Dom.setXY('ajaxExclusivesPanel', xy);
//          var tmpHeight = (parseInt(YAHOO.util.Dom.getStyle(availPanel, 'height')) - 15) + "px";
//          YAHOO.util.Dom.setStyle('ajaxExclusivesPanel', 'height', tmpHeight);
      };
      anim.onComplete.subscribe(showex);
      YAHOO.util.Dom.setStyle('availlink', 'display', 'none');
      YAHOO.util.Dom.setStyle('booknowdisp', 'display', 'none');
      YAHOO.util.Dom.setStyle('availlink', 'display', 'inline');
      anim.animate(); // animate
  };
   
   var availFadeOut = function(e) {
      YAHOO.util.Event.preventDefault(e); // block the default link
      var anim = new YAHOO.util.Anim(availPanel, { opacity: { from: YAHOO.aman.opacityMax, to: YAHOO.aman.opacityMin } }, YAHOO.aman.opacitySpeed, YAHOO.util.Easing.easeOut); // setup the animation
      // var hide = function(e) { YAHOO.util.Dom.setStyle(availPanel, 'display', 'none'); }; // setup the hide function so that it can be called using the onComplete
      var hide = function(e) { YAHOO.util.Dom.setStyle(availPanel, '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('availlink','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('availlink', 'click', availFadeIn);
   YAHOO.util.Event.addListener('availlink2', 'click', availFadeIn);
   YAHOO.util.Event.addListener('availoff', 'click', availFadeOut);
};

// only initialize if we have the avail div in the page
YAHOO.util.Event.onAvailable('availlink', YAHOO.aman.init);

//==================================================
// Nucleus aman search object
//==================================================

YAHOO.namespace('amansearch');

YAHOO.amansearch.opacityMax = 0.9; // 90% opaque
YAHOO.amansearch.opacityMin = 0.0; // 100% transparent
YAHOO.amansearch.opacitySpeed = 1; // opacity animation takes 1 second

YAHOO.amansearch.init = function() {

  var showSearchBox;
  showSearchBox = YAHOO.util.Dom.get('search_panel');

   var searchFadeIn = function(e) {
      YAHOO.util.Event.preventDefault(e); // block the default link
      YAHOO.util.Dom.setStyle(showSearchBox, 'opacity', YAHOO.amansearch.opacityMin); // ensure the correct opacity is shown before we show the block
      YAHOO.util.Dom.setStyle(showSearchBox, 'display', 'block'); // show the block
      var anim = new YAHOO.util.Anim(showSearchBox, { opacity: { from: YAHOO.amansearch.opacityMin, to: YAHOO.amansearch.opacityMax } }, YAHOO.amansearch.opacitySpeed, YAHOO.util.Easing.easeOut); // setup the animation
      YAHOO.util.Dom.setStyle('searchlink', 'display', 'none');
      anim.animate(); // animate
   };
   
   var searchFadeOut = function(e) {
      YAHOO.util.Event.preventDefault(e); // block the default link
      var anim = new YAHOO.util.Anim(showSearchBox, { opacity: { from: YAHOO.amansearch.opacityMax, to: YAHOO.amansearch.opacityMin } }, YAHOO.amansearch.opacitySpeed, YAHOO.util.Easing.easeOut); // setup the animation
      var hide = function(e) { YAHOO.util.Dom.setStyle(showSearchBox, '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('searchlink', 'display', 'inline');
      anim.animate(); // animate
   };

   YAHOO.util.Event.addListener('searchlink', 'click', searchFadeIn);
   YAHOO.util.Event.addListener('searchoff', 'click', searchFadeOut);

};

YAHOO.util.Event.onAvailable('searchlink', YAHOO.amansearch.init); // only initialize if we have search div in the page
