﻿var months = {
 '01': 'styczeń',
 '02': 'luty',
 '03': 'marzec',
 '04': 'kwiecień',
 '05': 'maj',
 '06': 'czerwiec',
 '07': 'lipiec',
 '08': 'sierpień',
 '09': 'wrzesień',
 '10': 'październik',
 '11': 'listopad',
 '12': 'grudzień'
}
jQuery.fn.italic = function(text) {
 return this.each(function() {
  var html = $(this).text();
  var reg = new RegExp(text, 'gi');
  html = html.replace(reg,'<em>'+text+'</em>');
  $(this).html(html);
 });
}
$(function() {
 $("#breadcrumb a,#breadcrumb span").italic('direct');
 $("#content .newsList li p.name a").italic('direct');
 $("#content .news p.name a, #content .message p.name a").italic('direct');
 $("#content .newsTable h3 a").italic('direct');
 $("#content .sitemap a").italic('direct');
 $("#content .header h2").italic('direct');
 $("#content #guide ol.guide div.head p strong").italic('direct');
});
jQuery.fn.createTabs = function(target) {
 return this.each(function() {
  var tabs = $(this).find("div.tab");
  $(target).empty();
  $(target).find('div.pressTab').hide();
  var note = null;
  $(tabs).hide().each(function() {
   var title = $(this).attr('title');
   if(title == "note") {
    note = this;
  }
   if($(this).text().indexOf('pressTrigger') >= 0) {
    var pt = $('div.pressTab:first');
    if(pt != null) {
     $(this).html($(pt).html());
     $(pt).remove();
  }
  }
  if(title != "note") {
    $(target).append('<li><span><a>'+(title.length > 0 ? title : 'zakładka')+'</a></span></li>');
  }
   $(this).removeAttr("title");
  });
  $(target).find('a').italic('direct');
  $(target).find('a').italic('banking');
  var headline = $('#content div.header h2:first').text()
  $(target).find('a').click(function() {
   if(pageTracker != null) {
    pageTracker._trackPageview('/'+headline+'/'+$(this).text());
   }
   $(tabs).hide().eq($(target).find('a').index(this)).show();
   $(target).find('li.active').removeClass('active');
   $(this).parents('li').eq(0).addClass('active');
   return false;
  });
  var eq = 0;
  var hash = window.location.hash;
  if(hash.length > 2) {
   if($('#'+hash.substring(2)).length > 0) {
    eq = $('#'+hash.substring(2)).prevAll('.tab').length;
  }
 }
  $(target).find('a').eq(eq).click();
  if(note != null) {
  $(target).find('li.active').removeClass('active');
  $(tabs).hide();
  $(note).show();
 }
 });
}
jQuery.fn.pagesFor = function(elem,atPage,parent,pager) {
 return this.each(function() {
  elem = $(this).children(elem);
  if(elem.length <= atPage) return false;
  var pages = Math.ceil(elem.length / atPage);
  var off = 0;
  for(var i=0;i<pages;i++) {
   $(this).append('<div class="page"></div>');
   var page = $(this).find("div.page:last");
   for(var j=0;j<atPage;j++) {
    if(off == elem.length) break;
    $(elem).eq(off).appendTo(page);
    off++;
   }
   $(this).parents(parent).eq(0).find(pager).eq(0).find("li.next").before('<li><a>'+(i+1)+'</a></li>');
  }
  pages = $(this).find("div.page");
  $(pages).not($(pages).eq(0)).hide();
  $(pager).find("a").eq(1).parent().addClass("active");
  $(pager).find("li.prev a").unbind();
  $(pager).find("li.next a").unbind();
  $(pager).find("a").click(function() {
   if($(this).parent().attr("class").indexOf("prev") >= 0) {
    var li = $(pager).find("li.active").prev();
    if($(li).attr("class").indexOf("prev") < 0) {
     $(li).find("a").click();
    }
   } else if($(this).parent().attr("class").indexOf("next") >= 0) {
    var li = $(pager).find("li.active").next();
    if($(li).attr("class").indexOf("next") < 0) {
     $(li).find("a").click();
    }
   } else if($(this).parent().attr("class").indexOf("active") < 0) {
    var pg = parseInt($(this).text()-1);
    $(pages).hide();
    $(pages).eq(pg).show();
    $(pager).find("li.active").removeClass("active");
    $(this).parent().addClass("active");
    if($(this).parents("div.results").length == 0) {
     window.location.hash = "#"+$(this).text();
    }
   }
   return false;
  });
  $(pager).show();
  if(window.location.hash.length > 1) {
   var page = parseInt(window.location.hash.substring(1));
   $(pager).find("a").eq(page).click();
  }
 });
}
jQuery.fn.archiveWork = function() {
 return this.each(function() {
  var arch = $(this).find('ul').eq(0);
  if(arch != null) {
   var initLi = $(arch).find("li.active");
   var mouseOut = false;
   var max = 0;
   var maxLi = initLi;
   $(arch).find("ul").each(function() {
    if($(this).height() > max) {
     max = $(this).height();
     maxLi = $(this).parent();
    }
   });
   $(arch).find("div").not(maxLi).hide();
   $(maxLi).show();
   $(arch).css("height",$(arch).height()+"px");
   $(arch).find("div").hide();
   $(initLi).find("div").show();
   $(arch).find("p").click(function() {
    var li = $(this).parent();
    if($(li).attr("class").indexOf("active") >= 0) return false;
     $(arch).find("li.active div").slideUp(300,function() {
     $(this).parent().removeClass("active");
    });
    $(li).addClass("active").find("div").slideDown(305,function() {
     if(mouseOut) {
      $(initLi).find("p").click();
      mouseOut = false;
     }
    });;
   });
   $(arch).hover(function() {}, function() {
    if($(initLi).length > 0) {
     $(initLi).find("p").click();
    } else {
     $(arch).find('li.active div').eq(0).slideUp(300,function() {
      $(this).parent().removeClass('active');
   });
  }
    mouseOut = true;
   });
  }
 });
}
$(function() {
 var initPad = 0;
 setTimeout(function() {
  $("#navMain li.active").each(function() {
   var ul = $("#navSub ul").eq($("#navMain li").index(this));
   var mOff = $("#navMain").offset();
   mOff = mOff['left'];
   if((ul != null) && (ul.length > 0)) {
    var off = $(this).offset();
    off = off['left']-mOff;
    var li = $(ul).find('li').eq(0);
    if(li.length > 0) {
      initPad = parseInt($(li).css('padding-left'));
      $(li).css('padding-left',initPad+off);
    }
   }
  });
  $("#navSub").show();
 },100);
 $("#navMain li").hover(function() {
  $("#navSub ul").hide();
  $("#navRoll li.highlight").find('img').each(function() {
  $(this).attr('src',$(this).attr('src').replace(/_on./i,'_off.'));
 });
  $("#navRoll li.highlight").removeClass("highlight");
  $("#navRoll li.highlightLeaf").find('img').each(function() {
  $(this).attr('src',$(this).attr('src').replace(/_on./i,'_off.'));
 });
  $("#navRoll li.highlightLeaf").removeClass("highlightLeaf");
  $("#navRoll li.active").find('img').each(function() {
  $(this).attr('src',$(this).attr('src').replace(/_on./i,'_off.'));
 });
  $("#navRoll li.active").addClass("selected").removeClass("active");
  if($(this).attr("class").indexOf("leaf") >= 0) {
   $(this).addClass("highlightLeaf");
   var img = $(this).find('img').eq(0);
   $(img).attr('src',$(img).attr('src').replace(/_off./i,'_on.'));
  } else {
   $(this).addClass("highlight");
   var img = $(this).find('img').eq(0);
   $(img).attr('src',$(img).attr('src').replace(/_off./i,'_on.'));
   var index = $("#navMain li").index(this);
   var ul = $("#navSub ul").eq(index);
   var li = $(ul).find('li').eq(0);
   if(li.length > 0) {
    if(initPad == 0) {
      initPad = parseInt($(li).css('padding-left'));
   }
    if(parseInt($(li).css('padding-left')) == initPad) {
     var mOff = $("#navMain").offset();
     mOff = mOff['left'];
     var off = $("#navMain li").eq(index).offset();
     off = off['left']-mOff;
      initPad = parseInt($(li).css('padding-left'));
      $(li).css('padding-left',initPad + off);
  }
  }
  $(ul).show();
  }
 }, function() {});
 $("#navSub li").hover(function() {
  $("#navSub li.highlight").find('img').each(function() {
  $(this).attr('src',$(this).attr('src').replace(/_on./i,'_off.'));
 });
  $("#navSub li.highlight").removeClass("highlight");
  $("#navSub li.active").find('img').each(function() {
  $(this).attr('src',$(this).attr('src').replace(/_on./i,'_off.'));
 });
  $("#navSub li.active").addClass("selected").removeClass("active");
  var img = $(this).find('img').eq(0);
 $(img).attr('src',$(img).attr('src').replace(/_off./i,'_on.'));
  $(this).addClass("highlight");
 }, function() {});
 $("#navMain li").click(function() {
  if($(this).attr("class").indexOf("leaf") < 0) return false;
 });
 $("#navRoll").hover(function() {}, function() {
  $("#navSub ul").hide();
  $("#navSub li.selected").parent().show();
  $("#navRoll li.highlight").find('img').each(function() {
  $(this).attr('src',$(this).attr('src').replace(/_on./i,'_off.'));
 });
  $("#navRoll li.highlight").removeClass("highlight");
  $("#navRoll li.highlightLeaf").find('img').each(function() {
  $(this).attr('src',$(this).attr('src').replace(/_on./i,'_off.'));
 });
  $("#navRoll li.highlightLeaf").removeClass("highlightLeaf");
  $("#navRoll li.selected").find('img').each(function() {
  $(this).attr('src',$(this).attr('src').replace(/_off./i,'_on.'));
 });
  $("#navRoll li.selected").addClass("active").removeClass("selected");
 });
});
$(function() {
 $("div.table ol li div.question").click(function() {
  if($(this).parent().attr("class").indexOf("active") < 0) {
   $(this).parent().addClass("active");
   $(this).parent().find("div.answer").slideDown(300);
  } else {
   $(this).parent().find("div.answer").slideUp(300,function() {
    $(this).parent().removeClass("active");
   });
 }
  return false;
 });
});
$(function() {
 var x = 0;
 $("div.table").each(function() {
  var links = $(this).find("div.shortLinks");
  var i = 0;
  $(this).find("h3").each(function() {
   if(i%2==0) $(this).addClass('odd');
   else $(this).addClass('even');
   var txt = $(this).find("span").eq(0).text();
   var tx = txt;
   var pos = txt.indexOf(' ');
   if(pos >= 0) tx = txt.substring(0,pos);
   $(this).find("a.toTop").attr("name",x+'_'+i+'_'+tx);
   $(links).find('ul').append('<li><a href="#'+(x+'_'+i+'_'+tx)+'">'+txt+'</a></li>');
   i += 1;
  });
  x += 1;
 });
});
jQuery.fn.styleWraps = function() {
 return this.each(function() {
  $(this).selectbox();
 });
}
jQuery.fn.checkWraps = function() {
 return this.each(function() {
  var cl = $(this).attr("class");
  cl = cl.substring(cl.indexOf("sbWrap")+7);
  cl = cl.substring(0,cl.indexOf("Wrap"));
  $(this).find("input.txt").addClass(cl);
  $(this).find("select").addClass(cl).styleWraps();
 });
}
$(function() {
 $('#content').createTabs($('#content div.header ul').eq(0));
 $("div.sbWrap").checkWraps();
});
jQuery.fn.checkDate = function(dateCont,dateElem) {
 return this.each(function() {
  $(this).each(function() {
   var archive = $('#content div.archive').eq(0);
   var date = $(this).find(dateCont).eq(0).find(dateElem).eq(0).text();
   if(date.indexOf('(') == 0) date = date.substring(1);
   var year = date.substring(0,4);
   var month = date.substring(5,7);
   $(archive).find('li p').each(function() {
    if($(this).text() == year) {
     $(this).parent().addClass('active');
     $(archive).archiveWork();
     return false;
    }
   });
   $(archive).find('li.active li a').each(function() {
    if($(this).text().toLowerCase() == months[month]) {
     $(this).parent().addClass('active');
     $(archive).archiveWork();
     return false;
    }
   });
  });
 });
}
$(function() {
 if(window.location.pathname.indexOf('_') >= 0) {
  $('#content div.leftCol div.news').checkDate('p.name','span');
  $('#content div.leftCol div.message').checkDate('p.name','span');
 } else {
  $('#content div.rightCol .archive').archiveWork();
 }
});
jQuery.fn.doRedirect = function(id) {
 return this.each(function() {
  var cont = this;
  var opt = {
  beforeSubmit: function(d,f,o) {
   var ind = null;
  $('#'+id+'_container').find('li').each(function() {
   if(($(this).attr('class') != null) && ($(this).attr('class').toLowerCase().indexOf('active') >= 0)) {
    ind = this;
    return false;
  }
  });
  if(ind != null) {
   ind = $('#'+id+'_container').find('li').index(ind);
   ind = $('#'+id).find('option').eq(ind).attr('value');
  window.open(ind);
  }
   return false;
  }
 };
  $(cont).find('select').change(function() {
   $(cont).find('form').eq(0).ajaxSubmit(opt);
  });
  $(cont).find("form").eq(0).ajaxForm(opt);
 });
}
$(function() {
 $('#crossBox').doRedirect('crossGo');
 $('#quickLinks').doRedirect('redirect');
});
function toStrict(str) {
 var mapHash = {'ą': 'a', 'ć': 'c', 'ę': 'e', 'ł': 'l', 'ń': 'n', 'ś': 's', 'ł': 'l', 'ń': 'n', 'ó': 'o', 'ś': 's', 'ź': 'z', 'ż': 'z', ' ': '_', '-': '_'};
 $.each(mapHash, function(ogonek, bezogonek) {
  str = str.replace(new RegExp(ogonek, 'g'), bezogonek);
 });
 return str;
}
jQuery.fn.linksToImages = function(path) {
 return this.each(function() {
  $(this).find('li a').each(function() {
   var txt = $(this).text();
   if($(this).parents('li').eq(0).attr('class').indexOf('active') >= 0) {
    $(this).html('<img src="'+path+toStrict(txt.toLowerCase())+'_on.gif'+'" alt="'+txt+'" />');
  } else {
   $(this).html('<img src="'+path+toStrict(txt.toLowerCase())+'_off.gif'+'" alt="'+txt+'" />');
  }
  });
 });
}
jQuery.fn.linkToImage = function(path) {
 $(this).find('a').each(function() {
  var txt = $(this).text();
  $(this).html('<img src="'+path+toStrict(txt.toLowerCase())+'.gif'+'" alt="'+txt+'" />');
 });
}
$(function() {
 $("#navMajor").linksToImages('/menu/');
 $("#navMain").linksToImages('/menu/');
 $("#navSub").linksToImages('/menu/');
 $("#navRoll #extraLinks span").linkToImage('/menu/');
});
$(function() {
 $("#quickLinks form").eq(1).ajaxForm({
  beforeSubmit: function(d,f,o) {
   if($("#search").val().length > 0) {
    window.location.href = $(f).attr("action")+"#"+$("#search").val();
  }
   return false;
  }
 });
});
$(function() {
 $("#content a").each(function() {
  if($(this).attr("title") == "fake") {
   if($(this).attr('target').length > 0) {
    if($(this).attr('href').indexOf('pomoc') >= 0) {
     $(this).attr('href',$(this).attr('href')+'#faq_'+$(this).attr('target'));
   } else if($(this).attr('href').indexOf('dokumenty') >= 0) {
    $(this).attr('href',$(this).attr('href')+'#doc_'+$(this).attr('target'));
   }
   $(this).removeAttr('target');
  } else {
     var url = $(this).attr("href");
     $(this).attr("title",$(this).text());
     var usc = url.indexOf('_');
     var dot = url.lastIndexOf('.');
     url = url.substring(0,usc)+url.substring(dot)+'#_id_'+url.substring(usc+1,dot);
     $(this).attr("href",url);
    $(this).click(function() {
      var path = window.location.pathname;
      var href = $(this).attr("href");
    var pos = href.indexOf('#');
    var id = '';
    if(pos > 0) {
     id = href.substring(pos);
     href = href.substring(0,pos);
    }
    if(href == path) {
     var eq = $('#'+id.substring(2)).prevAll('.tab').length;
     $('#content div.header ul').eq(0).find('a').eq(eq).click();
     scroll(0,0);
     return false;
    }
    });
  }
  }
 });
 $("div.article table,div.message table").each(function() {
    var x = 1;
    $(this).find('tr').each(function() {
     if(x % 2 == 0) {
      $(this).addClass('even');
   } else {
    $(this).addClass('odd');
   }
   x += 1;
  });
 });
 $("div.article tr,div.message tr").hover(function() {
  $(this).addClass("active");
 }, function() {
  $(this).removeClass("active");
 });
});
$(function() {
  if($("#content div.table").length > 0) {
   var hash = window.location.hash;
   if(hash.length > 0) {
    var pos = hash.indexOf('faq_');
    if(pos > 0) {
      hash = hash.substring(1);
      var q = $("#content div."+hash+"_q");
      if(q.length > 0) {
        q = q.eq(0);
        var tab = $(q).parents("div.tab").eq(0).prevAll(".tab").length;
        $("#content div.header ul li a").eq(tab).click();
        $(q).click();
        var off = $(q).parent().offset();
        scroll(0,off['top']);
      }
    }
    pos = hash.indexOf('doc_');
    if(pos > 0) {
     hash = hash.substring(1);
      var f = $("#content li."+hash+"_f");
   if(f.length > 0) {
    f = f.eq(0);
    var tab = $(f).parents('div.tab').eq(0).prevAll('.tab').length;
    $("#content div.header ul li a").eq(tab).click();
   }
  }
   }
  }
});
$(function() {
  var hash = window.location.hash;
  if(hash.length > 1) {
    if(hash.indexOf('id_') >= 0) {
      if($(hash).length > 0) {
        if($(hash).attr("class").indexOf("tab") >= 0) {
          var eq = $(hash).prevAll("div.tab").length;
          $("#content div.header ul li a").eq(eq).click();
          scroll(0,0);
        }
      }
    }
  }
});
$(function() {
 $('#content div.error #searchForm').ajaxForm({
  beforeSubmit: function(d,f,o) {
   var val = $('#searchTerm').eq(0).val();
   if(val.length > 0) {
    window.location = $(f).attr('action')+'#'+val;
   }
   return false;
  }
 });
});
$(function() {
 $("div.news ul").pagesFor('li',3,'div.leftCol','div.pager');
 $("div.pressList ul").pagesFor('li',3,'div.leftCol','div.pager');
 $("div.gadgets ul").pagesFor('li',4,'div.leftCol','div.pager');
 $("#content div.pager").each(function() {
  var cont = $(this).parents(".leftCol").eq(0);
  var w1 = $(cont).width();
  var w2 = $(cont).parent().width();
  $(this).css('margin-left',Math.floor(w2-w1)+'px');
 });
});
$(function() {
 $('#content #guide').each(function() {
  var ol = $(this).find('ol').eq(0);
  var sh = $(this).find('ul.shorts').eq(0);
  if($(ol).find('li').length < 1) return false;
  $(ol).find('li').find('div.head').click(function() {
   if($(ol).attr('class').indexOf('working') >= 0) return false;
   var li = $(this).parents('li').eq(0);
   $(ol).find('li.selected').find('div.text').slideUp(300,function() {
    $(ol).find('li.selected').removeClass('selected');
   });
   if($(li).attr('class').indexOf('selected') < 0) {
    $(ol).addClass('working');
    $(li).addClass('working').find('div.text').slideDown(300,function() {
     $(li).addClass('selected');
     $(li).removeClass('working');
     $(ol).removeClass('working');
    });
   }
   return false;
  });
  $(sh).find('a').click(function() {
   var href = $(this).attr('href');
   if(href.length > 1) {
    var hd = $(ol).find(href).find('div.head').eq(0);
    if(hd == null) return false;
    if($(href).attr('class').indexOf('selected') < 0) $(hd).click();
    return true;
   } else return false;
  });
 });
 var dok = $('div#navBottom ul li:last').prev();
 var act = $('div#navMajor li').index($('div#navMajor li.active').eq(0));
 if(act >= 0) $(dok).find('a').eq(0).attr('href',$(dok).find('a').eq(0).attr('href')+'?tab'+act);
 if($('div.header h2').eq(0).text() == 'Dokumenty') {
  var x = window.location.href;
  x = x.substring(x.indexOf('?tab')+4);
  if(parseInt(x) >= 0) {
   $('div.header ul a').eq(parseInt(x)).click();
 }
 }
 $('div#content ul.cycleBoxes li').each(function() {
  var r = $(this).find('div.r');
  $(r).each(function() {
   if($(this).hasClass('fl')) {
    if(!FlashDetect.versionAtLeast(9)) {
    if($(this).find('img').length < 1) {
   $(this).remove();
  }
   }
  }
 });
 r = $(this).find('div.r');
  if(r.length < 1) return true;
  var e = $(r).eq(Math.floor(Math.random()*r.length));
  $(r).not($(e)).remove();
  $(e).show();
 });
 $('div#content div.rightCol').each(function() {
  var r = $(this).find('div.r');
  $(r).each(function() {
   if($(this).hasClass('fl')) {
    if(!FlashDetect.versionAtLeast(9)) {
    if($(this).find('img').length < 1) {
   $(this).remove();
  }
   }
  }
 });
 r = $(this).find('div.r');
  if(r.length < 1) return true;
  var e = $(r).eq(Math.floor(Math.random()*r.length));
  $(r).not($(e)).remove();
  $(e).show();
 });
});
$(function() {
    $('div#dwzFlash').each(function() {
        var div = $(this).find('div.dwzFlash');
        if(div.length > 0) {
            var eq = Math.floor(Math.random()*div.length);
            $(div).eq(eq).show().siblings('div.dwzFlash').remove();
        }
    });
    $('div#dwz div.dwzListYT ul').each(function() {
      var i = 0;
      $(this).find('li').each(function() {
        if(i%2 == 0) $(this).before('<li class="clear"></li>');
        i++;
   });
   $(this).append('<li class="clear"></li>');
  });
});