$.fn.equalHeight = function(){
    var tallest = 0;
    $(this).children().each(function(){
          if ($(this).height() > tallest) {
        tallest = $(this).height();
      }
    });
    
    $(this).children().css('height', tallest+'px');
}

$.startHipHopHeadline = function() {
//    return;
  if ($('#site_holder').is(':visible')) {
    $('#hl #art li').css('display', 'block');
    $('#hl #art ul').equalHeight();
    if ($('#hl #art li').length > 1)
    {
      $('#hl #art:visible').jCarouselLite({
        auto: 5000,
        visible: 1,
        speed: 400,
        btnGo: ['#hl .pages .hp1', '#hl .pages .hp2', '#hl .pages .hp3', 
                '#hl .pages .hp4', '#hl .pages .hp5', '#hl .pages .hp6',
                '#hl .pages .hp7'],
        afterEnd: function(a){
          $('#hl .pages .active').removeClass('active');
          $('#hl .pages .'+$(a).attr('class')).addClass('active');
        }
      });
    }
  }
}

$.buildChartPlayer = function() {
  if (typeof(stFlvPlayer) == 'undefined' || typeof(stFlvPlayer.pchart) == 'undefined')  { return; }
  var controlh = stFlvPlayer.pchart.height - stFlvPlayer.pchart.params.flashvars.playlistsize;
  if (typeof(hh_chart_player_max_height) == 'undefined') { hh_chart_player_max_height = 0; }
  if ($('#pe').length == 0 || $('#right').length == 0) {
	if (hh_chart_player_max_height > 0) {
		stFlvPlayer.pchart.height = hh_chart_player_max_height;
		stFlvPlayer.pchart.params.flashvars.playlistsize = stFlvPlayer.pchart.height - controlh;
	}
    $('#pchart_holder').flash(stFlvPlayer.pchart);
    return;
  }
  var peh = $('#pe').outerHeight();
  var rgh = $('#right').height();
  if (rgh > peh) {
    $('#pe').height(rgh);
  } else if (peh > rgh) {
    var controlh = stFlvPlayer.pchart.height - stFlvPlayer.pchart.params.flashvars.playlistsize;
    if (peh-rgh > parseInt(stFlvPlayer.pchart.height)) {
    	stFlvPlayer.pchart.height = (peh - rgh);
    }
    
    if (stFlvPlayer.pchart.height > hh_chart_player_max_height) {
    	stFlvPlayer.pchart.height = hh_chart_player_max_height;
    }
    stFlvPlayer.pchart.params.flashvars.playlistsize = stFlvPlayer.pchart.height - controlh;
  }
  $('#pchart_holder').flash(stFlvPlayer.pchart);
}

$.siteHolderDisplay = function(){
    $('#site_holder').show();
    $.startHipHopHeadline();
    $.buildChartPlayer();
    $('#actual .row1').equalHeight();
    $('#actual .row2').equalHeight();
    return false;
}

$.removeHovers = function(){
  $('.primary ul.level_0 > li.hremove').removeClass('hremove').removeClass('hover');
}

$(document).ready(function(){
  $('.primary ul.level_0 > li').hover(function(){
        if (typeof(hhMenuTimer)!= 'undefined') {clearTimeout(hhMenuTimer);};
        $(this).removeClass('hremove');
        $('.primary ul.level_0 > li').each(function(){
           $(this).removeClass('hover');
        });
        $(this).addClass('hover');
     }, 
     function(){
         $(this).addClass('hremove');
         hhMenuTimer = setTimeout('$.removeHovers()', 3000);
  });
  if ($('#site_holder').is(':visible')) {
    $.startHipHopHeadline();
    $.buildChartPlayer();
    $('#actual .row1').equalHeight();
    $('#actual .row2').equalHeight();
  }
  $('#to .remember .close').bind('click', $.rememberHide);
  $('#signin #login_username').bind('focus', function(){
	if (!$(this).attr('rel'))
	{
	  $(this).attr('rel', $(this).val());
	  $(this).val('');
	  
	}
  });
  $('#signin #login_password').bind('focus', function(){
    if($(this).attr('type')!= 'password') {
      var pwfield = $(this).clone();
      $(pwfield).attr('type', 'password');
      $(pwfield).val('');
      $(this).replaceWith(pwfield);
      pwfield.focus();
    }
  });

  $('#search_q').bind('focus', function(){if($(this).val()=='vyhľadávanie'){$(this).val('');$(this).focus();}});
  
  $('.submit, input[type=submit]').hover(function(){$(this).addClass('submit-hover');}, function(){$(this).removeClass('submit-hover');});
  $('.link').css('cursor', 'pointer');
  $('.link, #hl #art li').bind('click', function(){window.location=$(this).find('a:first').attr('href');});
});