/* PECMS JavaScript */

$(document).ready(function(){

  $('a.targetblank').attr('target', '_blank');

  $('a.fancybox').fancybox({
    'zoomSpeedIn': 300,
    'zoomSpeedOut': 300,
    'autoScale': false,
    'overlayShow': true,
    'overlayOpacity': 0.6,
    'overlayColor': '#000000'
  });

  $('a.ihover').children('img').css('opacity', '0.7');
  $('a.ihover').hover(function() {
    $(this).children('img').animate({ opacity: 1 }, 250);
  }, function() {
    $(this).children('img').animate({ opacity: 0.7 }, 100);
  });

});

var clicked_b4janitor = false;

function formJanitor(objFormJanitor, strDestination, objSecretId) {

  var objDestination = objFormJanitor.destination;
  objDestination.value = strDestination;

  if (clicked_b4janitor == true) {
    setTimeout("alert('Operacja już wykonana')", 100);
    return false;
  } else {

    var btns = document.getElementById('buttons');
    var inputs = btns.getElementsByTagName('input');

    for(var inpt in inputs) {
      if((inputs[inpt]).getAttribute && (inputs[inpt]).getAttribute('type') == 'submit') {
        (inputs[inpt]).disabled = "disabled";
        (inputs[inpt]).className = (inputs[inpt]).className + " disabled";
        (inputs[inpt]).blur();
      }
    }
    clicked_b4janitor = true;

    btns.className = btns.className + " loading";

    var objJanitorInput = document.getElementById(objSecretId);
    if(objJanitorInput){
      objJanitorInput.value = Math.random();
      objFormJanitor.submit();
      return true;
    } else {
      return false;
    }
  }
}

