if (typeof Photozou == 'undefined') {
  Photozou = {};
}

Photozou.Window = {};
Photozou.Window.cache = [];

Photozou.Window.open = function(id, content, style, className) {

  if (Photozou.Window.ready(id)) {
    Photozou.Window.restore(id);
    return;
  }

  var div = document.createElement('div');
  div.id = id;
  if (className) {
    div.className = className;
  }

  style = (function(d, s) { for (var p in s) d[p] = s[p]; return d; })({
    position: 'absolute',
    top: '0px',
    left: '0px',
    width: 'auto',
    height: 'auto',
    padding: '5px',
    zIndex: '100',
    backgroundColor: '#fff',
    border: 'solid 2px #7bbbf8',
    color: '#333',
    MozBorderRadius: '8px',
    WebkitBorderRadius: '8px',
    borderRadius: '8px'
  }, style || {});

  for (var prop in style) {
    div.style[prop] = style[prop];
  }

  if (typeof content == 'string') {
    div.innerHTML = content;
  } else {
    div.appendChild(content);
  }

  document.body.appendChild(div);

  Photozou.Window.cache.push(id);
};

Photozou.Window.close = function(id) {
  if (Photozou.Window.ready(id)) {
    $(id).hide();
  }
};

Photozou.Window.ready = function(id) {
  var w = Photozou.Window;
  for (var key in w.cache) {
    if (id == w.cache[key]) {
      return true;
    }
  }
  return false;
};

Photozou.Window.restore = function(id) {
  if (Photozou.Window.ready(id)) {
    $(id).show();
  }
}


