
var on = true;
var skipswitch = false;
var fx1 = function()
{ 
    if (!skipswitch)
    {
        var button = $('lowstock');
        if (on)
        {
            button.tween('backgroundImage', 'url(\'/html/images/almost_gone.gif\')'); 
            on = false;
        }
        else
        {
            button.tween('backgroundImage', 'url(\'/html/images/piitblight.gif\')');
            on = true;
        }
    }
}
    
function init()
{
   var toggle = $('toggle');
   // get a handle on the low stock button (the almost gone flasher)
   if (!Browser.Engine.webkit)
      toggle.set('style', 'display: block');
   
   var button = $('lowstock');
   
   // alternate the 2 images
   if (button)
   {
      fx1.periodical(1200);
   }
   
   // the effect to close the ingredients popup
   var closeIt = function()
   {
      var shade = $('shade');
      var ing = $('ingContainer');
   
      shade.fade(0);
      ing.fade(0);
   }
   
   // get the ingredient button, and the close button, and the ingredients

   var close = $('close');
   var content = $('ingredients');
   
   // mouse over highlight for the toggle button
   toggle.addEvent('mouseover', function(){
      toggle.highlight();
   });
   
   // make any click in the box close it
   content.addEvent('click', closeIt);
   close.addEvent('click', closeIt);
   
   
   // the onclick event for the toggle button
   toggle.addEvent('click', function() {
      
      var shade = $('shade');
      var ing = $('ingContainer');
      var content = $('ingredients');
      
      // if we have no ingredients yet, then get it from the server
      if (content.get('html').length < 15)
      {
         var request = new Request.HTML({evalScripts:false, evalResponse:false, update:content, method:'get', url:'/index/getingredients' });
         request.send();
      }
         
      // set the shade to the document size
      doResize();
      
      // make sure the shade and the popup are off
      shade.set('opacity', 0);
      shade.style.display = 'block';
      ing.set('opacity', 0);
      ing.style.display = 'block';
      
      // fade in the shade and the popup
      shade.fade(0.7);
      ing.fade(1);
   } );
}
 
/**
 * set the size of the shade to the document size
 */
function doResize()
{
   var body = $('header');
   var content = $('content');
   var footer = $('footer');
   var shade = $('shade');
   
   shade.style.width = body.getSize().x;
   shade.style.height = body.getSize().y + content.getSize().y + footer.getSize().y;
}
