/**
 * MyStatus
 *
 * @author euantor <admin@xboxgeneration.com>
 * @version 1.0
 * @copyright euantor 2011
 * @package MyStatus
 * 
 * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
Event.observe(window, 'load', function() {
	Event.observe('mystatusUpdater', 'submit', function(event) {
		Event.stop(event);

		new Ajax.Updater('latestStatusList', 'misc.php?action=mystatus_update', {
			insertion: 'top',
			method: 'post',
			parameters: {
				statusText: $('statusText').value,
				accessMethod: 'js',
				my_post_key: $('mystatusPostKey').value
			},
			onFailure: function(request) { alert(request.responseText); },
			onComplete: function() { $('statusText').value = ''; $('mystatus_no_statuses_to_show').remove(); }
		});
	});

	$$("a[id^='mystatus_delete_']").invoke('observe', 'click', function(event) {
		Event.stop(event);
		
		var deleteElement = this;
		
		new Ajax.Request(this.readAttribute('href'), {
			'method': 'get',
			parameters: {
				accessMethod: 'js'
			},
			onSuccess: function() { deleteElement.up('tr').previous('tr').remove(); deleteElement.up('tr').remove(); },
			onFailure: function(request) { alert(request.responseText); }
		});
	});
});
