// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
function ausgraben(id)
{
  Effect.SlideDown('kommentar_text_'+id);
  $('ausgraben_text_'+id).style.display = 'none';
  $('begraben_text_'+id).style.display = 'inline';
  $('deaktiv_daumen_'+id).style.display = 'none';
  $('aktiv_daumen_'+id).style.display = 'inline';
}

function begraben(id)
{
  Effect.SlideUp('kommentar_text_'+id);
  $('ausgraben_text_'+id).style.display = 'inline';
  $('begraben_text_'+id).style.display = 'none';
  $('deaktiv_daumen_'+id).style.display = 'inline';
  $('aktiv_daumen_'+id).style.display = 'none';
}
function addFirefoxSearchEngine(src_url, gif_url, name)
{
  if ((typeof window.sidebar == "object") && (typeof window.sidebar.addSearchEngine == "function")) { 
      window.sidebar.addSearchEngine(
          src_url,
          gif_url, name, 'Music'
      );
  } else {
    alert("Entschuldigung, aber du benötigst den Browser 'Firefox' um dieses Such-Plugin nutzen zu können.");
  } 
}

function youtube_video_show(container_id,url)
{
  container = document.getElementById( container_id );

  container.style.backgroundColor = 'black';
  container.style.width = '425px';
  container.style.height = '345px';
  container.innerHTML = '<object width="425" height="350"><param name="movie" value="'+url+'&autoplay=1"></param><param name="wmode" value="transparent"></param><embed src="'+url+'&autoplay=1" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object>';
}



// BEAST
var TopicForm = {
  editNewTitle: function(txtField) {
    $('new_topic').innerHTML = (txtField.value.length > 5) ? txtField.value : 'New Topic';
  }
}

var LoginForm = {
  checkLogin: function(txt) {
    if(txt.value.match(/^https?:\/\//)) {
      $('password_fields').hide();
    } else {
      $('password_fields').show();
    }
  }
}

var EditForm = {
  // show the form
  init: function(postId) {
    $('edit-post-' + postId + '_spinner').show();
    this.clearReplyId();
  },

  // sets the current post id we're editing
  setReplyId: function(postId) {
    $('edit').setAttribute('post_id', postId.toString());
    //$('posts-' + postId + '-row').addClassName('editing');
    if($('reply')) $('reply').hide();
  },
  
  // clears the current post id
  clearReplyId: function() {
    var currentId = this.currentReplyId()
    if(!currentId || currentId == '') return;

    var row = $('posts-' + currentId + '-row');
    if(row) row.removeClassName('editing');
    $('edit').setAttribute('post_id', '');
  },
  
  // gets the current post id we're editing
  currentReplyId: function() {
    return $('edit').getAttribute('post_id');
  },
  
  // checks whether we're editing this post already
  isEditing: function(postId) {
    if (this.currentReplyId() == postId.toString())
    {
      $('edit').show();
      $('edit_post_body').focus();
      return true;
    }
    return false;
  },

  // close reply, clear current reply id
  cancel: function() {
    this.clearReplyId();
    $('edit').hide()
  }
}

var ReplyForm = {
  // yes, i use setTimeout for a reason
  init: function() {
    EditForm.cancel();
    $('reply').toggle();
    $('reply_post_body').focus();
    // for Safari which is sometime weird
//    setTimeout('$(\"post_body\").focus();',50);
  },

  setValue: function(value) {
    $('reply_post_body').value = value;
  }
}

Event.addBehavior({
  '#search,#monitor_submit': function() { this.hide(); }
})
// /BEAST
