function hideBulletinBox(){
  bulletin_box.hide();
  if(show_bulletin_box) show_bulletin_box.show();
}

function showBulletinBox(event){
    bulletin_box.show();
    show_bulletin_box.hide();
    event.stop();
}

//Do zmiany. Pogadać z grafikami
function bulletinBoxShouldHide(event){
  var current_element = event.findElement();
  if(!bulletin_box_structure.include(current_element)) hideBulletinBox();
}

function addBulletinBoxHandlers(){
  if(show_bulletin_box) show_bulletin_box.observe('click',showBulletinBox);
  hide_bulletin_boxes.invoke('observe','click',hideBulletinBox);
  Event.observe(window,'click',bulletinBoxShouldHide);
}

function hideBulletinBoxLayer(){
  bulletin_box.hide();
}

function setBulletinBoxGlobalVariable(){
  bulletin_box = $('bulletin_box');
  bulletin_box_content = $('bulletin_box_content');
  bulletin_box_structure = [bulletin_box_content,bulletin_box_content.descendants()].flatten();
  show_bulletin_box = $('show_bulletin_box');
  hide_bulletin_boxes = $$('.hide_bulletin_box');
}

function prepareBulletinBox(){
  if(!$('bulletin_box')) return false;
  setBulletinBoxGlobalVariable()
  hideBulletinBoxLayer();
  addBulletinBoxHandlers()
}

document.observe('dom:loaded',prepareBulletinBox);
