$(document).ready(function(){

  /* no-spam */
  $('form[action="/null"]').attr('action', '');


  /* ie7 pngfix */
  $('#menu li ul').css('zoom', 1);


  $('#menu').menu_horizontal({
    appendText: '',
    speed: ( $.browser.msie && parseFloat($.browser.version) < 8 ? 0 : 'fast' ),
    showAnimation: {height: 'show'},
    hideAnimation: {height: 'hide'}
  });


  /* external links */
  $('a[href^="http"]').addClass('external').attr('target', '_blank').each(function(){
    if ($(this).attr('title') != undefined)
      $(this).attr('title', $(this).attr('href'));
  });
  
  $('#rightbar h1:first').addClass('first');

  
  /* menu */
  var url = window.location.href.replace(/^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/, '$9');
  if (url != '/') {
    var cnt = 0;
    $('#menu li>a[href="'+url+'"]:first').each(function(){
      $(this).addClass('active');
      cnt++;
    });
    $('#menu-kategoriak li>a[href="'+url+'"]:first').each(function(){
      $(this).addClass('active');
      cnt++;
    });
  } /*else
    $('div#sidebar ul li>a[href="/"]:first').addClass('active');*/
  //$("div#sidebar ul li:has(ul)").not(':has(.active)').children("ul").not(":has(.active)").hide();
  $("#menu li:has(ul li a.active)").find('a:first').addClass('active');


  $('#menu-termekek li, #menu-termekek2 li').each(function(){
    var $this = $(this);
    $img = $this.find('a:first').attr('rel');
    $this.css({backgroundImage: "url('/misc/categories/"+$img+ ($img < 7 ? ".png" : ".jpg") +"')"})
    $this.find('a:first').wrapInner($('<div>'));
  });


  if ($.browser.msie && parseFloat($.browser.version) < 7) {
    $('<div/>', {
      css: {
        display: 'none',
        margin: 0,
        textAlign: 'center'
      }
    }).addClass('error'
    ).html('A Ön által használt böngésző elavult, verziója nem támogatott! (Microsoft Internet Explorer '+$.browser.version+') Kérjük frissítse: <a href="http://www.browserchoice.eu/BrowserChoice/browserchoice_hu.htm" target="_blank">támogatott böngészők</a>'
    ).prependTo($('body')).slideDown();
  } 


  if (! (document.cookie.indexOf('ISENTER=true') >= 0)) {
    $('#header-picture').slider({
      delay: 5000,
      showSpeed: 600,
      hideSpeed: 400
    });
  }

  
  (function session_keepup() {
    window.setTimeout(function(){
      if (document.cookie.indexOf('ISENTER=true') >= 0) {
        $.get('/?session_keepup', function(data) {
          session_keepup()
        });
      }
    }, 5*60*1000);
  })();


  function resizeContent() {
    var dHeight = $(window).height() - $('body').height();
    //$('body').height($(window).height());
    $('#body').css({minHeight: $('#body').height() + dHeight});
  }
  $(window).resize(function(){resizeContent()});
  resizeContent();

});
