(function() {

$(document).ready(function() {
    $('#pplace li:has(div.popup)').popup();
    $('ul.listes li:has(ul)').plus_minus();
    $('table.t_spec > tbody > tr:nth-child(even)').addClass('even');
    $('div.scrollable').scrollable({ size: 5 });
    $('div.scrollable > .items').gallery();
    $('div.g-photo').gallery();
});

$.fn.extend({
    popup: function() {
        this.find('a')
          .mouseover(function() {
              showPopup(this);
          })
          .mouseout(function() {
              hidePopup(this);
          });
    },
    plus_minus: function() {
        this.find('ins')
          .click(function() {
            pmSwitch(this);
          })
          .attr("class","plus")
          ;
    },
    gallery: function() {
      this.each(function() {
        $(this).find('img')
        .click(function() {
          showBigImg(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('gp-blue')
      .wrapInner('<div class="v"><div class="h" /></div>')
      .append('<em class="lt" /><em class="rt" /><em class="lb" /><em class="rb" />')
      ;
    $('#wrap').append($popup);
    var top = offset.top - $popup.height() - 9;
    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 showBigImg(elImg) {
  var id = elImg.id;
  var win = window.open("/photo.html?id="+id, "popup", "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();
}

function pmSwitch(caller) {
    if ($("ul",caller.parentNode).css("display") == 'none') {
      $("ul",caller.parentNode).css("display","block")
      caller.className = "minus";
    } else {
      $("ul",caller.parentNode).css("display","none")
      caller.className = "plus";
    }
}
})();


