$(function() {
  $('.playground_debugbar_span').click(function() {
    $('.playground_debugbar_panel').slideUp();
    if($(this).next().css('display') != 'block') {
      $(this).next().slideDown();
    }
  });
  
  $('.playground_debugbar_toogle').click(function() {
    $container = $('#playground_debugbar');
    if($container.position().left > 0) {
      $('.playground_debugbar_panel').slideUp();
      $('.playground_debugbar_toogle > img').attr('src', PG.url('../debugbar/web/img/arrow.png'));
      var d = new Date(); d.setTime(d.getTime() + (365*24*60*60*1000));
      // set cookie
      document.cookie = 'pgdebug_hide=yes; expires='+d.toGMTString()+'; path=/';
      
      var leftPos = parseInt($container.outerWidth()-$('.playground_debugbar_toogle').outerWidth());
      
      return $container.animate({ left: "-" + leftPos + "px" }, "normal", "swing");     
    } else {
      $('#playground_debugbar_sections').show();
    
      $('.playground_debugbar_toogle > img').attr('src', PG.url('../debugbar/web/img/arrow_180.png'));
      var d = new Date(); d.setTime(d.getTime() + (-1*24*60*60*1000));
      document.cookie = 'pgdebug_hide=yes; expires='+d.toGMTString()+'; path=/';
      return $container.animate({left: "5px"}, "normal", "swing");
    }
  });
  
  $('.playground_debugbar_togglevar').click(function() {
    var $vc = $(this).next('.playground_devbar_variables');
    if($vc.is(':visible')) {
      $vc.slideUp();
      $(this).find('img').attr('src', PG.url('../debugbar/web/img/toggle_small.png'));
    } else {
      $vc.slideDown();
      $(this).find('img').attr('src', PG.url('../debugbar/web/img/toggle_small_collapse.png'));
    }
  });
});

