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

var LoginForm = {
  setToPassword: function() {
    $('openid_fields').hide();
    $('password_fields').show();
  },
  
  setToOpenID: function() {
    $('password_fields').hide();
    $('openid_fields').show();
  }
}

/*var PostForm = {
	postId: null,

	reply: Behavior.create({
		onclick:function() {
    	PostForm.cancel();
    	$('reply').toggle();
    	$('post_body').focus();
		}
	}),

	edit: Behavior.create(Remote.Link, {
		initialize: function($super, postId) {
			this.postId = postId;
			return $super();
		},
		onclick: function($super) {
			$('edit-post-' + this.postId + '_spinner').show();
			PostForm.clearPostId();
			return $super();
		}
	}),
	
	cancel: Behavior.create({
		onclick: function() { 
			PostForm.clearPostId(); 
			$('edit').hide()
			$('reply').hide()
			return false;
		}
	}),

  // sets the current post id we're editing
  editPost: function(postId) {
		this.postId = postId;
    $('post_' + postId + '-row').addClassName('editing');
		$('edit-post-' + postId + '_spinner').hide()
    if($('reply')) $('reply').hide();
		this.cancel.attach($('edit-cancel'))
		$('edit-form').observe('submit', function() { $('editbox_spinner').show() })
		setTimeout("$('edit_post_body').focus()", 250)
  },

  // checks whether we're editing this post already
  isEditing: function(postId) {
    if (PostForm.postId == postId.toString())
    {
      $('edit').show();
      $('edit_post_body').focus();
      return true;
    }
    return false;
  },

  clearPostId: function() {
    var currentId = PostForm.postId;
    if(!currentId) return;

    var row = $('post_' + currentId + '-row');
    if(row) row.removeClassName('editing');
		PostForm.postId = null;
  }
}

Event.addBehavior({
	'span.time': toTimeAgoInWords,
	'#search, #reply': function() { this.hide() },
	'#search-link:click': function() {
		$('search').toggle();
		$('search_box').focus();
		return false
	},
	
	'tr.post': function() {
		var postId = this.id.match(/^post_(\d+)-/)[1]
                var anchor = this.down(".edit a")
                if(anchor) { PostForm.edit.attach(anchor, postId) };
	},
	
	'#reply-link': function() {
		PostForm.reply.attach(this)
	},
	
	'#reply-cancel': function() {
		PostForm.cancel.attach(this)
	}
})
*/

// toegevoegd
var hideReplyForm = function() {
	jQuery('#reply').css({display:'none'});
	jQuery('#reply-link').click(function() {
		jQuery('#reply').slideToggle(500);
		jQuery('html,body').animate({scrollTop: jQuery('#reply').offset().top}, 500);
	});
}

function smoothScroll() {
	jQuery('a[href*=#]').click(function() {
	  if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
	  && location.hostname == this.hostname) {
	    var $target = jQuery(this.hash);
	    $target = $target.length && $target
	    || jQuery('[name=' + this.hash.slice(1) +']');
	    if ($target.length) {
	      var targetOffset = $target.offset().top;
	      jQuery('html,body')
	      .animate({scrollTop: targetOffset}, 1000);
	     return false;
	    }
	  }
	});
}

function initWysiwygEditor(){
  if(CKEDITOR){
  	CKEDITOR.config.language = 'nl';
  	jQuery('textarea.wysiwyg').each(function(){
  		CKEDITOR.replace(jQuery(this).attr('id'));
  	})
  }
}

jQuery(document).ready(function() {
	smoothScroll();
	hideReplyForm();
	initWysiwygEditor();
});

var add_param_to_url = function(param, value){
  var url = window.location.href;
  if(window.location.href.indexOf('?') == -1){
    url += '?';
  } else {
    url += '&';
  }
  url += param;
  if (value){
    url += '=' + value;  
  }
  return url
}


$j(function(){
  (function($){
    
    $('.search_locale_check_box').change(function(){
      var url;
      $(this).attr('disabled', 'true')
      if($(this).is(':checked')){
        url = add_param_to_url('add_search_locale', $(this).val())
      } else {
        url = add_param_to_url('remove_search_locale', $(this).val())
      }
      $.get(url, function(){
        $(this).attr('disabled', 'false')
        window.location.href = window.location.href;
      })        
    })
  })(jQuery)
  
})
