/**
 * Init/onLoad function.
 *
 * Dodaje obsługę kliknięć na nagłówki H1 (użyte w boksach jako
 * tytuły/nagłówki) - możliwość zwinięcia/rozwinięcia danego modułu oraz
 * zamykanie niektórych reklam.
 */
$(function () {
   /* Ukrywanie/pokazywanie modułów. */
/*   $($(this).find('h1'&&'h5').parentNode).find('span.state').click(function (e) {
      var state   = $(this.parentNode).find('span.state').get(0);
      var content = $(this.parentNode).find('div.content').get(0);

      if ( state.innerHTML == '-' ) {
         $(content).slideUp('fast', function() { state.innerHTML = '+'; });
      } else if ( state.innerHTML == '+' ) {
         $(content).slideDown('fast', function() { state.innerHTML = '-'; });
      } else if ( state.innerHTML == 'x' ) {
         this.parentNode.innerHTML = '';
      }

   })
*/

  $($(this).find('h1.ad').parentNode).find('span.state').click(function (e) {
      var state   = $(this.parentNode).find('span.state').get(0);
      var content = $(this.parentNode).find('div.content').get(0);

      if ( state.innerHTML == '-' ) {
         $(content).slideUp('fast', function() { state.innerHTML = '+'; });
      } else if ( state.innerHTML == '+' ) {
         $(content).slideDown('fast', function() { state.innerHTML = '-'; });
      } else if ( state.innerHTML == 'x' ) {
         this.parentNode.innerHTML = '';
      }
   })

   /* Podświetlanie wiadomości (panel_news). */
   /*$('div#panel_news').find('div.item').mouseover(function (e) {
      $(this).css('background', '#fefad5 url("gfx/panel/news/item_top.hover.gif") top center no-repeat');
      $($(this).find('div.footer').get(0)).css('background', 'url("gfx/panel/news/item_bottom.hover.gif") top center no-repeat');
   }).mouseout(function (e) {
      $(this).css('background', '');
      $($(this).find('div.footer').get(0)).css('background', 'url("gfx/panel/news/item_bottom.gif") top center no-repeat');
   })*/

   /* Zwijanie wiadomości wg. miesiąca */
   var i = 0;
   $('div#panel_left > div.box > div.content > div.news').each(function (i) {
     if ( i > 0 ) {
      $(this).find('div').hide();
     }
      /*if ( i > 0 ) {
         $(this).find('a').slideUp('fast');
      } else {
         $(this).find('h4').slideUp('fast');
      }*/

      var x = this;
      $(this).find('h4').click(function (e) {
         $('div#panel_left > div.box > div.content > div.news').each(function (i) {
            if ( this != x ) {
               /*$(this).find('a').slideUp('slow');
               $(this).find('h4').slideDown('slow');*/
             //$(this).find('div').slideUp('slow');
             $(this).find('div').hide();
            } else {
               /*$(this).find('a').slideDown('slow');
               $(this).find('h4').slideUp('slow');*/
             $(this).find('div').show();
            }
         })
      })

      i++;
   })
})
