(function() {

$(document).ready(function() {
    $('div.list li:has(div.popup)').popup();
    $('div.scrollable').scrollable({horizontal:true, size: 6});
    $('div.scrollable > .items').gallery();
    $('tr:nth-child(odd)').addClass('odd');
});


$.fn.extend({
    popup: function() {
        this.find('a,span')
          .mouseover(function() {
              showPopup(this);
          })
          .mouseout(function() {
              hidePopup(this);
          });
    },
    gallery: function() {
      this.each(function() {
        $(this).find('img')
        .click(function() {
          showBigImgNW(this);
        });
      });
    }
});

function showPopup(caller) {
    var li = $(caller.parentNode);
    var offset = li.offset();
    $popup = $('<div class="g-popup" />')
      .html(li.find('div.popup').eq(0).html())
      .css({ left: offset.left+30 })
      .addClass((caller.tagName.toLowerCase() == 'a') ? 'gp-pink' : 'gp-green')
      .wrapInner('<div />')
      .append('<ins class="v" /><ins class="h" /><em class="lt" /><em class="rt" /><em class="lb" /><em class="rb" />');
    $('#wrap').append($popup);
    var top = offset.top - $popup.height();
    var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
    if (top - scrollTop < 0) top = offset.top + li.height();
    $popup.css({ top: top });
    caller.__popup = $popup;
}

function hidePopup(caller) {
    if (caller.__popup) {
        caller.__popup.remove();
    }
}

function showBigImgNW(elImg) {
  var id = elImg.id;
  var win = window.open("/picture-nw/?id="+id,"picture","width=300,height=300,innerWidth=300, innerHeight=300,dependent=yes,screenX=10,screenY=10,resizable=no,menubar=no,toolbar=no,location=no,directories=no");
  win.focus();
}

})();

