
	/*----------------------------------------------------------------------

		Stirling Group
		http://www.stirling-group.com/

		Developed by Designition Ltd - www.designition.co.uk

		Copyright 2009

	----------------------------------------------------------------------*/

	var Sg =  {

		init : function() {

			Sg.forum_reply();
			Sg.tweaks();

		},	//	init : function()


		forum_reply : function() {
			if ($('.thread_reply').get(0)) {
				$('.thread_reply button').removeAttr("disabled");

				$('.thread_reply').submit(function() {
					if ($('.choothar').get(0)) $('.choothar').remove();

					val_response = $('.thread_reply textarea').val();

					if (!val_response) {
						$('.thread_reply textarea').css({ borderColor: '#fbc2c4' });

						$('<span class="choothar">Your comment can\'t be empty!</span>').insertAfter('.thread_reply button').effect('pulsate', { times : 2 });

						return false;
					} else {
						$('.thread_reply textarea').css({ borderColor: '#99a8c1' });

						$('<img src="/img/icons/ajax_indicator.gif" class="ajax_activity" alt="Please wait&hellip;" />').insertAfter('.thread_reply button');
						$('.thread_reply button').attr("disabled", "disabled");

						$.ajax({
							type : 'POST',
							url  : '/incs/actions/post_forum_reply.php',
							data : 'response=' + val_response + '&ajax=true',
							success : function(response) {
								reply = $(response).find('reply');

								switch (reply.attr('status')) {
									case 'win' :
										r_content      = reply.find('content').text().replace(/([^>]?)\n/g, '$1' + "<br />" + '\n');
										r_datetime     = reply.find('datetime').text();
										r_datewords    = reply.find('datewords').text();
										r_user_id      = reply.find('user_id').text();
										r_user_name    = reply.find('user_name').text();
										r_user_company = reply.find('user_company').text();
										r_user_query   = reply.find('user_query').text();
										r_reply_id     = reply.find('reply_id').text();

										new_reply  = '<li id="reply_' + r_reply_id + '"> \
											<h4>Posted by ' + r_user_name + ' (' + r_user_company + ') - \
											<span class="date">' + r_datewords + '<span> - ' + r_datetime + ' <abbr title="Greenwich Mean Time">GMT</abbr></span></span></h4> \
											<div class="content_block"><p>' + r_content + '</p></div> \
											</li>';

										$(new_reply).appendTo('.replies_list').effect('highlight');
										$('form.thread_reply').remove();
									break;

									case 'not_logged_in' :
										$('.ajax_activity').fadeOut();
										$('.thread_reply button').removeAttr("disabled");

										$('<span class="choothar">You are not logged in!</span>').insertAfter('#response_form button');
									break;

									default :
										$('.ajax_activity').fadeOut();
										$('.thread_reply button').removeAttr("disabled");

										$('<span class="choothar">An error occured! Please try again&hellip;</span>').insertAfter('#response_form button');
									break;
								}
							},

							dataType : 'xml'
						});
					}

					return false;
				});
			}
		},


		tweaks : function () {

			$('body').addClass('js');

			if ($('.lead_image').get(0)) {
				$('<div class="lead_image_corners"></div>').appendTo('.lead_image');
			}

			//	Subscribe form labels
			$('input.clicfield')
				.focus(function() { $(this).addClass('focus');    })
				.blur(function()  { $(this).removeClass('focus'); });

			$('tbody tr:odd').addClass('alt');

			//	FireBug, yeah? - Load it up, load it up real good!
			if ($.isFunction(window.loadFirebugConsole)) window.loadFirebugConsole();

		}	//	tweaks : function ()

	}; //	//	var Sg = Sg || {}

	//	That's the anthem - get your damn hands up!
	$(function() { Sg.init(); });

