function OpenRadio(intBitRate,streamType) {
  window.open('http://www.play.cz/listen/listen.php?sh=beat&bitrate=' + intBitRate + '&stype=' + streamType, 'playradio', 'width=490,height=200,top='+((screen.availHeight-200)/2)+',left='+((screen.availWidth-490)/2)+',status=0,scrollbars=0,resizable=1');
}

$(function(){

  // uživatelské filtry
  $.expr[':'].external = function(obj) {
    return  $(obj).is("[href^='http']") && (obj.hostname != location.hostname);
  };

  // otevírání externích odkazů v okně
  $('a:external, a.newWindow')
  .addClass('link-external')
  .append('<span class="h1dden"> (externí odkaz)</span>')     // external link indicator - for screenreaders
  .click(function(){
    window.open(this.href);
    return false;
  });

  // Nette Ajax
  $("a.ajax").live("click", function (event) {
    event.preventDefault();
    $.get(this.href);
  });

  $("a[href='/live/']").click(function(event){
    event.preventDefault();
    window.open($(this).attr("href"),"popUp","width=420,height=360,resizable=1");
  });

  $("a.contest").live("click",function(event){
    event.preventDefault();
    var name = $(this).closest(".content").find("input[name='name']");
    var email = $(this).closest(".content").find("input[name='email']");

    if (email.val() == "" || email.val() == email.data("default"))
      return !alert("Zadej svůj e-mail!");

    $.get(this.href+"&beatpoll-name="+encodeURI(name.val())+"&beatpoll-email="+encodeURI(email.val()));
  });

  $('.chart form input:checkbox').change(function(){
    var votelimit = $(this).closest(".chart").data("vl");
    var votes = $(this).closest("form").find("input:checked").length;
    $(this).closest("form").find("input:checkbox").not(":checked").not(".disabled").each(function(){
      $(this).attr("disabled",votes >= votelimit);
    });
  });

  // FancyBox (Lightbox alternative)
  $('a.fancyBox').fancybox({
    'transitionIn'  : 'elastic',
    'transitionOut' : 'elastic',
    'titlePosition' : 'inside'
  });

  // Drop-down menu
  $('ul.sf-menu').superfish();

  // Cufon - Dynamic text replacement
  Cufon.CSS.ready(function() {
    Cufon.CSS.addClass(Cufon.DOM.root(), 'cufon-replacing');
  });

  Cufon.replace('#ar-main > h1, .main-menu li > a, .portlet .header .title, .caption h4', {
    hover: true
  });

  Cufon.CSS.ready(function() {
    Cufon.CSS.removeClass(Cufon.DOM.root(), 'cufon-replacing');
  });

  $("input[data-default]").focus(function(){
    if ($(this).val() == $(this).data("default")) {
      $(this).val("");
    }
    $(this).parent().addClass("focused");
  });

  $("input[data-default]").blur(function(){
    if ($(this).val() == "") {
      $(this).val($(this).data("default"));
    }
    $(this).parent().removeClass("focused");
  });

  // Add class to odd table rows
  if($('.wysiwyg table').length){
    $('.wysiwyg table tbody tr:odd').addClass('even');
  }

  // Link - more/less frequencies
  $('#listFrequencies').css("height","195px");
  $('#more-frequencies').toggle(function(){
    $(this).addClass('less').text('méně frekvencí');
    $("#listFrequencies").animate({
      height: $('#listFrequencies table').height()
    },1000);
  },function(){
    $(this).removeClass('less').text('více frekvencí');
    $("#listFrequencies").animate({
      height: 195
    },1000);
  });


  $(".pictures-more-toggle").toggle(function(){
    $(this).addClass("less").text("skrýt galerii");
    $(".pictures").animate({
      height: $(".pictures .inner").height()
    },1000);
  },function(){
    $(this).removeClass("less").text("zobrazit celou galerii");
    $(".pictures").animate({
      height: 195
    },1000)
  });

  // Add class 'last-child'
  if($('table').length){
    $("table th:last-child, table td:last-child").addClass('last-child');
  }

  // Click on play button -> show box with bitrate
  $("#radio .control").click(function(){
    $("#radio-popup").animate({
      "top": "+=105px"
    }, "fast");
    $(this).hide();
  });

  $("#radio-popup-close").click(function(){
    $("#radio-popup").animate({
      "top": "-=105px"
    }, "fast");
    $("#radio .control").show();
    return false;
  });

  if ($('#ar-banner').length) {
    var top = $('#ar-banner').offset().top;
    var bottom = $('#footer').offset().top;


    $(window).scroll(function (event) {
      var y = $(this).scrollTop();
      if (y >= top) {
        if ((y+600) < bottom) {
          $('#ar-banner').css('marginTop',y - top);
        }
      } else {
        $('#ar-banner').css('marginTop',0);
      }
    });
  }

  $.getJSON("https://api.twitter.com/1/statuses/user_timeline.json?callback=?",{
    screen_name: "radiobeat_cz",
    count: 3,
    include_entities: true
  },function(data){
    var $cont = $('<ul class="list-tweets">');
    $.each(data,function(item){
      var itemText = data[item].text;
      if (typeof data[item].entities.urls !== "undefined") {
        $.each(data[item].entities.urls,function(url){
          var itemUrl = data[item].entities.urls[url];
          itemText = itemText.replace(itemUrl.url,'<a href="'+itemUrl.expanded_url+'">'+itemUrl.display_url+'</a>');
        });
      }
      $cont.append($("<li>").html(itemText));
    });
    $("#twitter").prepend($cont);
  });


// 	=== END OF DOCUMENT READY ===
});
