// Requires jQuery and jQuery form plugin
// Wrapper written by skills

var Events = {

	init: function(loadfunc, hookfunc, container, loadContainer) {

		if (!$('#'+container).is('*') || !$('#'+loadContainer).is('*'))
			return;

		$('#'+container).hide();

		$.ajax({
			type:		'get',
			url:		'/assets/includes/events.php',
			dataType:	'html',
			complete:	function(){
					$('#'+loadContainer).hide('fast');
					$('#'+container).show('slow');
				},
			success:	function(html){
					$('#'+container).html(html);
					hookfunc(hookfunc, loadfunc, container, loadContainer);
				},
			error:		function(r,t,e){
					$('#'+container).html('An error occurred retrieving events content');
				}
		});
	},

	loadContent: function(loadfunc, hookfunc, url, postdata, container, loadContainer) {

		$('#'+container).hide('fast');
		$('#'+loadContainer).show('slow');

		$.ajax({
			type:		'post',
			url:		url,
			data:		postdata,
			dataType:	'html',
			complete:	function(){
					$('#'+loadContainer).hide('fast');
					$('#'+container).show('slow');
				},
			success:	function(html){
					$('#'+container).html(html);
					hookfunc(hookfunc, loadfunc, container, loadContainer);
				},
			error:	function(r,t,e){
					$('#'+container).html('An error occurred retrieving events content');
				}
		});

	}, 
	
	hook: function(hookfunc, loadfunc, container, loadContainer) {
		$('#'+container)
			.find('a')
			.each(function(){
				var href = $(this).attr('href');
				if (href.indexOf('forums/') == -1) {
					$(this).click(function(){ 
						loadfunc(loadfunc, hookfunc, href, {}, container, loadContainer);
						return false;
					});
				}
			});

		$('#'+container)
			.find('form')
			.each(function(){
				$(this).ajaxForm({
					dataType:		'html',
					beforeSubmit:	function() {
							$('#'+container).hide('fast');
							$('#'+loadContainer).show('slow');
						},
					success:		function(html) {
							$('#'+container).html(html);
							$('#'+loadContainer).hide('fast');
							$('#'+container).show('slow');
							hookfunc(hookfunc, loadfunc, container, loadContainer);
						}
				});
			});
	}

};

