var twitapi = window.twitapi || {};

twitapi.method = (function($){
	
	function init() {
		_setupSignInFirst();
		_setupNotesHideyShowey();
	}
	
	function _setupSignInFirst() {
		_checkAuthenticateSelection();
		$('input[name="authenticate_request"]').parent()
			.change(_checkAuthenticateSelection);
			//.keyup(_checkAuthenticateSelection)
			//.click(_checkAuthenticateSelection);
	}
	
	function _checkAuthenticateSelection() {
		if($('#sign-in-first').length>0) {
			if($('input[name="authenticate_request"]:checked').val() === 'True') {
				$('#sign-in-first').css('display','inline');
				$('#call-method-btn').attr('disabled','disabled');
			} else {
				$('#sign-in-first').css('display','none');
				$('#call-method-btn').removeAttr('disabled');
			}
		}
	}
	
	function _setupNotesHideyShowey() {
		$('#notes-hide-show').click(function(ev){
			ev.stopPropagation();
			var $this = $(this);
			if($this.text()==='Show') {
				$this.text('Hide');
				$('#notes-container ul').show();
			}
			else {
				$this.text('Show');
				$('#notes-container ul').hide();
			}
			return false;
		});
	}
	
	
	return {
		init:init
	}
})(jQuery);

jQuery(document).ready(twitapi.method.init);
