var BearCafe = {};

BearCafe.gmap = function() {
  if (GBrowserIsCompatible()) {
    var point = new GLatLng(42.0404, -74.152712);
    var gmap = new GMap2($('map'));
    gmap.setCenter(point, 13);
    var marker = new GMarker(point);
    gmap.addOverlay(marker);
    var map = $('gmimap0');
    var area = $E('area', map);
    if (area) area.href = 'http://maps.google.com/maps?li=d&hl=en&f=d&iwstate1=dir:to&daddr=295+Tinker+St,+Woodstock,+NY+12498+(Bear+Cafe)&geocode=13937011380338881012,42.040446,-74.153209&iwloc=1&dq=the+bear+cafe+295+tinker+street+woodstock,+ny&cid=42040446,-74153209,13296175209112652198';
  }
}

// Assimilated from window.cnet.js by Aaron Newton http://clientside.cnet.com
                
BearCafe.popup = new Class({
  initialize: function(rel, props) {
    this.props = Object.extend({
      width: 519,
      height: 640,
      x: 'auto',
      y: 'auto',
      toolbar: 0,
      location: 0,
      directories: 0,
      status: 0,
      scrollbars: 'yes',
      resizeable: 1,
      name: 'popup'
    }, props || {}); 
    
    anchors = $ES('a[rel="' + rel + '"]');    
    anchors.each(function(a) {
       a.onclick = function(h) { this.open(h); return false; }.pass(a.href, this);       
    }, this);   
    
    return this;
  }, 
  
  open: function(url) {
    url = url || this.url; 
    
    this.window = window.open(url,
      this.props.name,
      'toolbar='+this.props.toolbar+
      ',location='+this.props.location+
      ',directories='+this.props.directories+
      ',status='+this.props.status+
      ',scrollbars='+this.props.scrollbars+
      ',resizable='+this.props.resizeable+
      ',width='+this.props.width+
      ',height='+this.props.height+
      ',top='+this.props.y+
      ',left='+this.props.x
    );
    
    this.window.focus();
    
    return this.window;
  }, 
  
  close: function() { 
    this.window.close(); 
    } 
});


BearCafe.slideshow = function() {
  var slideshow = $E('div.slideshow');
  
  var div = new Element('div');
  div.addClass('shadow').injectInside(slideshow);

  var classes = ['a', 'b', 'c', 'd'];
  var klass = classes[$random(0, 3)];

  $ES('li', slideshow).each(function(li, i) {
    k = klass;
    while (klass == k) { klass = classes[$random(0, 3)]; }

    li.addClass(klass);

    a = $E('a', li);
    var fx = function(el) { el.effect('top', { duration: 750, transition: Fx.Transitions.elasticOut }).start(60, -8); }.delay(i * 100, this, a);
  });
}


BearCafe.image = function() {
  var classes = ['a', 'b', 'c', 'd'];
  var klass = classes[$random(0, 3)];

  var pn = $('cont-pri');

  $ES('img', pn).each(function(img) {
    k = klass;
    while (klass == k) { klass = classes[$random(0, 3)]; }

    img.addClass(klass);
  });
}


BearCafe.specials = new Class({
  initialize: function(hide) {
    var pn = $('cont-pri');
  
    $ES('h2', pn).each(function(h2, i) {
      special = h2.getNext();

      if (!special.hasClass('specials')) return;

      var a = new Element('a').injectInside(h2);

      if (hide) {
        a.appendText('Show Specials');
        special.setStyles({ height: 0, marginBottom: 45, opacity: 0 });
      }
      else { 
        a.appendText('Hide Specials').addClass('toggle');
      }
      
      a.addEvent('click', function(a, el) { this.toggle(a, el); }.pass([a, special], this));
    }, this);
  },

  toggle: function(a, el) {
    h = el.scrollHeight;

    if (el.getStyle('height').toInt() > 0) { // collapse
      a.setText('Show Specials').removeClass('toggle');
      fx = { height: [h, 0], marginBottom: [10, 45], opacity: [1, 0] };
    }
    else {
      a.setText('Hide Specials').addClass('toggle');
      fx = { height: [0, h], marginBottom: [45, 10], opacity: [0, 1] };
    }

    el.effects({ duration: 750, transition: Fx.Transitions.quadInOut }).custom(fx);
  }
});