var gazeta_pl = {};

var g_insp = {
  init: function() {
    var _ = this;
    $('#insp_box .c0').prepend('<div id="insp_selector"></div>');
    var o_sel = $('#insp_selector');

    for (var section in jsonTagi) {
      var first = true;
      for (var elem in jsonTagi[section]) {
        var el = jsonTagi[section][elem];
        if (first) {
          var htm = '<strong>'+el+'</strong><ul><li>'+(section == 'wnetrze' ? 'Dowolne' : 'Dowolny')+'</li>';
          first = false;
        } else
          htm += '<li>'+el+'</li>';
      }
      htm += '</ul>';
      o_sel.append(htm);
    }

    $('#insp_selector li').click(function() {
      if ($(this).hasClass('sel')) return;
      $(this).parent().find('.sel').removeClass('sel');
      $(this).removeClass('hover');
      $(this).addClass('sel');

      var res = [];
      $('#insp_selector .sel').each(function() {
        res.push(_.fix_value($(this).html()));
      });
      document.location.href = document.location.href.replace(/(\/[0-9]+,[0-9]+).*$/, '$1') + ',,' + res.join('_') + '.html';
    });

    $('#insp_selector li').hover(
      function() { 
        if ($(this).hasClass('sel')) return;
        $(this).addClass('hover');
      },
      function() { 
        if ($(this).hasClass('sel')) return;
        $(this).removeClass('hover');
      }
    );

    var args = document.location.href.split(',').pop().replace(/\.html.*$/, '');

    if (args.match(/_/)) {
      args = args.split(/_/);
      while (args.length < 3) args.push('1');
    } else {
      args = ['1', '1', '1'];
    }

    for (var i = 0; i < args.length; i++) {
      $('#insp_selector ul').eq(i).find('li').each(function() {
        if (_.fix_value($(this).html()) == args[i]) {
          $(this).addClass('sel');
        }
      });
    }
  },

  fix_value: function(str) {
    str = str.toLowerCase();
    str = str.replace(/ /, '');
    str = str.replace(/dowoln[ey]/, '1');
    str = str.replace(/[±¡]/, 'a');
    str = str.replace(/[æÆ]/, 'c');
    str = str.replace(/[êÊ]/, 'e');
    str = str.replace(/[³£]/, 'l');
    str = str.replace(/[ñÑ]/, 'n');
    str = str.replace(/[óÓ]/, 'o');
    str = str.replace(/[¶¦]/, 's');
    str = str.replace(/[¼¬]/, 'z');
    str = str.replace(/[¿¯]/, 'z');
    return str;
  }
};

var g_switchbox = {
  init: function() {
    $('.switchBox').each(function() {
      $(this).find('.tabs li:first').addClass('active');
      $(this).find('.tabs a').click(function() {
        var subtarget = $(this).parent().parent().attr('id').split(/_/).shift();
        var a_tab = $(this).parent().parent().find('.active').eq(0);
        var a_target = '#' + subtarget + '_' + a_tab.find('a').eq(0).attr('href').replace(/#/, '');
        var c_target = '#' + subtarget + '_' + $(this).attr('href').replace(/#/, '');

        $(a_target).hide();
        $(a_tab).removeClass('active');

        $(c_target).show();
        $(this).parent().addClass('active');
      });
    });
  }
};

$(document).ready(function() {
  $('#k12 .index .head,.ZJwrp1 h1,.galeriesBox h4,.MZBChead,.ZBCspecH h3,.zajSzukaj h1,.wideoIndex h2').each(function() {
    if ($(this).find('a').length == 0) {
      $(this).wrapInner('<span>');     
    } else {
      $(this).find('a').wrapInner('<span>');
    }
  });

  $('.wideoIndex .clr').next('li').addClass('first');

  $('.MZBCwrp_5 .MZBClead a').hover(
    function() { $(this).parent().parent().addClass('hover'); },
    function() { $(this).parent().parent().removeClass('hover'); }
  );

  $('.MZBCwrp_4 .MZBimgC').each(function() {
    $(this).find('img').eq(0).show();
  });

  $('.MZBCwrp_4 .MZBimgC').hover(
    function() { $(this).find('img').eq(0).hide(); $(this).find('img').eq(1).show(); },
    function() { $(this).find('img').eq(0).show(); $(this).find('img').eq(1).hide(); }
  );

  // embed flash
  (function() {
    if (gazeta_pl.flash_holders) {
      var l = gazeta_pl.flash_holders.length;
      if (l > 0) {
        var params = { wmode: 'opaque', allowScriptAccess: 'always' };
        for (var i = 0; i < l; i++) {
          var fl = gazeta_pl.flash_holders[i];
          params.flashvars = fl.vars;
          swfobject.embedSWF(fl.url, fl.id, fl.width, fl.height, '9.0.0', '/info/expressInstall.swf', {}, params);
        }
      }
    }
  }());

  $('.SONwrp').prepend('<div class="SONtitle"><span>Sonda¿</span></div>');
  $('.SONwrp .sondaBut').attr('src', '/i/obrazki/czterykaty/vote-btn.png');
  $('.SONwrp .sondaBut').hover(
    function() { $(this).attr('src', '/i/obrazki/czterykaty/vote-btn-active.png'); },
    function() { $(this).attr('src', '/i/obrazki/czterykaty/vote-btn.png'); }
  );
  $('.SONwrp form').css({ display: 'block' });
  $('.SONwrp .sondaBut').show();

  var wi = $('.wideoIndex .index_str');
  if (wi.length > 0) {
    if (wi.find('.prev a').length == 0) wi.find('.prev').append('<span>&laquo; poprzednia</span>');
    if (wi.find('.next a').length == 0) wi.find('.next').append('<span>nastêpna &raquo;</span>');
  }

  if ($('#insp_box').length > 0) g_insp.init();
  if ($('.switchBox').length > 0) g_switchbox.init();

  $('.MZBCwrp_4').each(function() {
    var t1 = $(this).find('.MZBCw');
    t1.insertAfter($(this).parent());
    t1.addClass('MZBCw_outer');
  });

  fixIEpng();

  $('#navH li').hover(
    function() { $(this).addClass('hover'); },
    function() { $(this).removeClass('hover'); }
  );
   ie6();
});

function ie6(){
 if ( navigator.userAgent.indexOf('MSIE 6.0') > 0 && navigator.userAgent.indexOf('MSIE 7.0') < 0 && navigator.userAgent.indexOf('MSIE 8.0') < 0 ){
	var doc=document.body;
	doc.style.paddingTop="50px";
	var desc = document.createElement('div');
	desc.setAttribute("id","IE6_warning");
	desc.style.background="#faf0a7";
	desc.style.margin="0";
	desc.style.fontFamily="Arial, sans-serif";
	desc.style.fontSize="14px";
	desc.style.height="50px";
	desc.style.width="100%";
	desc.style.zIndex="99999";
	desc.innerHTML='<div id="IE6_con" style="width: 940px; text-align: left; margin: 0 auto; position: relative; height: 30px; padding: 10px 0;"><strong style="font-weight: bold;">Internet Explorer 6 nie zapewnia ju&#380; odpowiedniego poziomu bezpiecze&#324;stwa. </strong><p>Cz&#281;&#347;&#263; stron b&#281;dzie si&#281; &#378;le wy&#347;wietla&#263;.</p><a id="IE6_btn" href="http://gazeta.hit.gemius.pl/hitredir/id=AkfqlqrNGyYy8Wqp2ABDV2ZUfSqNecbhJ9CvGwgvXf7.k7/url=ie8.gazeta.pl/internet_explorer_8/0,0.html" target="_blank" style="position: absolute; right: 100px; bottom:10px; display: block; border: 1px solid #ccc; padding: 6px 10px; background: #fffbdf; color: #114488; text-decoration: none; font-weight: bold;">Pobierz Internet Explorer 8</a></div><img src="http://gazeta.hit.gemius.pl/redot.gif?id=AkHgkqsrPw2YwOMuYdGfwbR5HSGK7gexhoUlkx6YLh3.H7" height="1" width="1" alt="" />';
	var d = document.getElementById('fb-root');
	doc.insertBefore(desc, d);
	}
}

