// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

var Site = {
  resize: function() {
    this.y = window.getSize().y;
    $('logo').setStyle('margin-top', this.y < 600 ? 28 : '');
    $('menu').setStyle('margin-top', this.y < 600 ? 0 : '');
  }
};

window.addEvent('resize', Site.resize);
window.addEvent('domready', function() {

  Site.resize();

  var flash = $('notice_flash')
  var roar = new Roar({ position: 'lowerLeft', duration: 6000 });
  if (flash) {
    flash.hide();
    roar.alert(flash.innerHTML);
//    flash.set('tween', { duration: 550, transition: 'sine:in' });
//    flash.set('slide', { duration: 1000, transition: 'sine:in' });
//
//    flash.tween.delay(1800, flash, ['margin-bottom', 0]);
//    flash.slide.delay(2360, flash, 'out');
  }

//  $$('h3 + p').both().addClass('blob');

//  var session = document.getElement('p.session a');
//  if (session && session.get('href') == '/login') {
//    session.addEvent('click', function(e) {
//      e.stop();
//      var password = prompt('Lösenord?');
//      if (password && password != '') {
//        new Request({
//          url: '/sessions', 
//          data: { 
//            'password': password,
//            'authenticity_token': AUTH_TOKEN
//          },
//          onSuccess: function(){
//            location.reload();
//          }
//        }).send();
//      }
//
//      });
//  }

  var badge = $('badge');
  if (badge) {
    var img = badge.getPrevious();
    var area = badge.getElement('area');
//    area.addEvent('mouseenter', function(e){
//      img.fade(1);
//    });
//    area.addEvent('mouseleave', function(e){
//      img.fade('.6');
//    });
    area.addEvent('click', function(e){
      e.stop();

//      Element.implement({
//        toggle: function(){
//          var op = this.getStyle('opacity').toInt();
//          if (op == 0) {
//            
//          }
//        }
//      });

      var box = $('overlay');
      if (box) {
//        box.fade('0').then(function(e){ this.dispose(); });
//        box.toggle();
        box.dispose();
        img.fade('1');
      } else {
        var box = new Element('div', { 'id': 'overlay'
//          ,'styles': {
//            'width': window.getSize().x,
//            'height': window.getSize().y
//          }
        }).fade(['0', '.94']);
        box.inject(document.body);
        img.fade.delay(500, img, '.4');
      }

    });
  }

  var properties = new Tips($$('div.material ul li'), {
  	showDelay: 200,
  	hideDelay: 100,
  	fixed: true,
        offset: {'x': -70, 'y': -90}
  });
  //properties.addEvent('hide', function(tip, el){
  //  tip.fade('out');
  //});
  //properties.addEvent('show', function(tip, el){
    //tip.setStyle('top', tip.getStyle('top').toInt()-tip.getStyle('height').toInt());
  //});

});
