$(document).ready(function() {	
	
	$("a.submit_post").click (function() {
		//check if the user is logged in
		var region_id = $(this).attr("id").substr(4);
		var topic_id = $(this).attr("href");
		$.post("http://www.in4share.org.uk/ajax/is_logged", {}, function (result) {
			if (result == 'ok') {
				//get the topic id and region id
				window.location = 'http://www.in4share.org.uk/forum/submit_post/' + region_id + '/' + topic_id;
			} else {
				$.fumodal({	
					width:300,
					height:150,
					style:true,
					content:'<p style="font-size: 12px; text-align: center;"><br /><br />You have to be logged in to submit a post.</p>',
					title:'<b>Alert</b>'
				});				
			}
		});
		return false;
	});
	
	$("a.reply_post").click (function() {
		//get the region and topic id
		var user_topic_id = $(this).attr("href");
		$.post("http://www.in4share.org.uk/ajax/get_region_and_topic", {user_topic_id: user_topic_id}, function(result) {
			result = json(result);
			$.post("http://www.in4share.org.uk/ajax/is_logged", {}, function (result_logged) {
				if (result_logged == 'ok') {
					var url_appendix = result['region_id'] + '/' + result['topic_id'] + '/' + user_topic_id;
					window.location = 'http://www.in4share.org.uk/forum/submit_post/' + url_appendix;
				} else {
					$.fumodal({	
						width:300,
						height:150,
						style:true,
						content:'<p style="font-size: 12px; text-align: center;"><br /><br />You have to be logged in to submit a post.</p>',
						title:'<b>Alert</b>'
					});				
				}
			});
		});
		return false;
	});
	
	$("a.image_show").click (function() {
		var image_src = $(this).attr("href");
		var image_tag = '<img src="' + image_src + '" alt="" />';
		$.fumodal({	
			width:540,
			height:560,
			style:true,
			content:'<table><tr><td style="text-align: center; vertical-align: middle; width: 505px; height: 500px;">' + image_tag + '</td></tr></table',
			title:'<b>Image</b>'
		});				
		
		return false;
	});	
	
});