<!--

	var day = new Array(7);
	day[0]  = 'Sunday';
	day[1]  = 'Monday';
	day[2]  = 'Tuesday';
	day[3]  = 'Wednesday';
	day[4]  = 'Thursday';
	day[5]  = 'Friday';
	day[6]  = 'Saturday';

	var short_day = new Array(7);
	short_day[0]  = 'Sun';
	short_day[1]  = 'Mon';
	short_day[2]  = 'Tue';
	short_day[3]  = 'Wed';
	short_day[4]  = 'Thu';
	short_day[5]  = 'Fri';
	short_day[6]  = 'Sat';
	
	var month = new Array(12);
	month[0]  = 'January';
	month[1]  = 'February';
	month[2]  = 'March';
	month[3]  = 'April';
	month[4]  = 'May';
	month[5]  = 'June';
	month[6]  = 'July';
	month[7]  = 'August';
	month[8]  = 'September';
	month[9]  = 'October';
	month[10] = 'November';
	month[11] = 'December';
	
	var short_month = new Array(12);
	short_month[0]  = 'Jan';
	short_month[1]  = 'Feb';
	short_month[2]  = 'Mar';
	short_month[3]  = 'Apr';
	short_month[4]  = 'May';
	short_month[5]  = 'Jun';
	short_month[6]  = 'Jul';
	short_month[7]  = 'Aug';
	short_month[8]  = 'Sep';
	short_month[9]  = 'Oct';
	short_month[10] = 'Nov';
	short_month[11] = 'Dec';
	
$(document).ready(function(){
	// Site wide element styles
	$('textarea').autogrow({
		minHeight: 100
	});
	
	$('.as-link').live('mouseover', function() {
		$(this).css({'cursor':'pointer'});
	});
	
	$('.as-link').live('mouseout', function() {
		$(this).css({'cursor':'auto'});
	});
	
	/*
	$('.as-link').hover(
		function() {
			$(this).css({'cursor':'pointer'}); //'background-color': '#D3D9E2'
		},
		function() {
			$(this).css({'cursor':'auto'});
		}
	);
	*/
	/*
	$('input[type="submit"],input[type="button"]').hover(
		
		function() {
			$(this).css({'border-color': '#DBDBDB', 'color': '#DBDBDB', 'cursor': 'pointer'}); //'background-color': '#D3D9E2'
		},
		function() {
			$(this).css({'background-color': '#A8ADB5', 'border-color': '#000000', 'color': '#000000'});
		}
	);
	*/
	
	// Textarea styling code
	$('.style-post').hover(
		function() {
			$(this).css({'cursor':'pointer'}); //'background-color': '#D3D9E2'
		},
		function() {
			$(this).css({'cursor':'auto'});
		}
	);
	
	// Textarea styling code
	$('.smiley-select').hover(
		function() {
			$(this).css({'cursor':'pointer'}); //'background-color': '#D3D9E2'
		},
		function() {
			$(this).css({'cursor':'auto'});
		}
	);
	
	// Bold text
	$('.style-bold').click(function() {
		var input_textarea = $(this).closest('div').find('textarea.style-input');
		var sel_text       = input_textarea.getSelection().text;
		
		if ((sel_text == '') || (sel_text == undefined)) {
			alert('Please select the text within your post that you would like to make bold and then hit this button again.');
			return false;
		}
		
		input_textarea.replaceSelection('[b]'+sel_text+'[/b]');
		return true;
	});
	
	// Italic text
	$('.style-italic').click(function() {
		var input_textarea = $(this).closest('div').find('textarea.style-input');
		var sel_text       = input_textarea.getSelection().text;
		
		if ((sel_text == '') || (sel_text == undefined)) {
			alert('Please select the text within your post that you would like to make italic and then hit this button again.');
			return false;
		}
		
		input_textarea.replaceSelection('[i]'+sel_text+'[/i]');
		return true;
	});
	
	// Plane Mad Photo
	$('.style-pmpic').click(function() {
		$(this).closest('div').find('div.pmpic').slideDown('slow');
		$(this).parent().find('[name="pmpic"]').focus();
	});
	
	// Plane Mad Rejected Photo
	$('.style-rejpic').click(function() {
		$(this).closest('div').find('div.rejpic').slideDown('slow');
		$(this).parent().find('[name="rejectpic"]').focus();
	});
	
	// Other hosted Photo
	$('.style-hostpic').click(function() {
		$(this).closest('div').find('div.hostpic').slideDown('slow');
		$(this).parent().find('[name="urlpic"]').focus();
	});
	
	// Video
	$('.style-vid').click(function() {
		$(this).closest('div').find('div.vid').slideDown('slow');
		$(this).parent().find('[name="video"]').focus();
	});
	
	// Descriptive Link
	$('.style-link').click(function() {
		$(this).closest('div').find('div.link').slideDown('slow');
		$(this).parent().find('[name="link-url"]').focus();
	});
	
	// Smileys
	$('.style-smiley').click(function() {
		$(this).closest('div').find('div.smiley').slideDown('slow');
	});
	
	$('.smiley-select').click(function() {
		
		var code = '';
		
		switch ($(this).attr('alt')) {
			case 'happy':
				code = ':)';
			break;
			
			case 'sad':
				code = ':(';
			break;
			
			case 'off topic':
				code = ':-ot';
			break;
			
			case 'sorry':
				code = ':-sorry';
			break;
			
			case 'ban':
				code = ':-ban';
			break;
			
			case 'censored':
				code = ':-censored';
			break;
			
			case 'big grin':
				code = ':D';
			break;
			
			case 'cry':
				code = ':\'(';
			break;
			
			case 'shocked':
				code = ':o';
			break;
			
			case 'confused':
				code = ':S';
			break;
			
			case 'angry':
				code = ':@';
			break;
			
			case 'tongue out':
				code = ':P';
			break;
			
			case 'rolling eyes':
				code = '8-)';
			break;
			
			case 'laughing':
				code = ':L';
			break;
		}
		
		$(this).parent().parent().find('textarea.style-input').insertAtCaretPos(code);
	});
	
	$('.shortcut-submit').click(function(){
		
		var textarea_value = '';
		//$(this).parent().find('.shortcut-input').focus();
		
		switch ($(this).attr('name')) {
			// Plane Mad photo gallery pic
			case 'sbt-pmpic':
				var photo_id = $(this).parent().find('[name="pmpic"]').val();
				
				if (photo_id == '') {
					alert('Please enter a photo ID. The ID can be found above the photograph in our photo gallery.');
					return false;
				}
				
				textarea_value = '[photo='+photo_id+']';
			break;
			
			// Plane Mad rejected pic
			case 'sbt-rejectpic':
				var photo_id = $(this).parent().find('[name="rejectpic"]').val();
				
				if (photo_id == '') {
					alert('Please enter a photo ID. The ID can be found in the rejection e-mail you received.');
					return false;
				}
				
				textarea_value = '[reject='+photo_id+']\n';
			break;
			
			// Externally hosted image
			case 'sbt-urlpic':
				var pic_url = $(this).parent().find('[name="urlpic"]').val();
				
				if (pic_url == '') {
					alert('Please enter the URL of the photo you would like to embed into the post.');
					return false;
				}
				
				textarea_value = '[img]http://'+pic_url+'[/img]\n';
			break;
			
			// Video
			case 'sbt-video':
				var vid_url = $(this).parent().find('[name="video"]').val();
				
				if (vid_url == '') {
					alert('Please enter the URL of the video you would like to embed into the post.');
					return false;
				}
				
				textarea_value = 'http://'+vid_url+'\n';
			break;
			
			// Descriptive Link
			case 'sbt-link':
				var link_url  = $(this).parent().find('[name="link-url"]').val();
				var link_desc = $(this).parent().find('[name="link-desc"]').val();
				
				if (vid_url == '') {
					alert('Please enter the URL and description for the link you would like to include in your post.');
					return false;
				}
				
				textarea_value = '[link=http://'+link_url+']'+link_desc+'[/link]\n';
			break;
		}
		
		$(this).parent().parent().find('textarea.style-input').insertAtCaretPos(textarea_value);
		cancel_shortcut($(this));
		return true;
	});

	
	// All cancels
	$('.shortcut-cancel').click(function() {
		cancel_shortcut($(this));
	});
	
	// To cancel all shortcuts
	function cancel_shortcut(input_obj) {
		input_obj.parent().find('.shortcut-input').val('');
		input_obj.closest('div').slideUp('slow');
	}
	
	// Show the preview
	$('.preview-button').click(function() {
		
		$(this).after('<div id="preview-wait">'+wait_img+'</div>');		
		var input_text = $(this).closest('form').find('.style-input').val();
		
		if (input_text == '') {
			alert('Please enter a message before clicking preview.');
			return false;
		}
		
		var msg_el     = $(this).closest('div').find('.post-preview');
		$(msg_el).find('.preview-text').html(wait_img_code);
				
        submit_ajax('msg='+escape(input_text), $(msg_el).find('.preview-text'), 'http://www.plane-mad.com/preview-post.php')
	});
	
	$('.preview-close').click(function() {
		$.unblockUI();
	});
	
	$('.preview-submit').click(function() {
		$.unblockUI();
		$(this).closest('form').submit();
	});
	
	// Radio / Checkbox button highlighting
	$('input:checked').each(function() {
		var tag_id = $(this).attr('id');
		$(this).parent().find('label[for="'+tag_id+'"]').addClass('bold');
	});
	
	$('input:radio').click(function() {
		highlight_selected($(this));
	});
	
	$('input:checkbox').click(function() {
		highlight_selected($(this));
	});
});

	function ajax_success(obj, msg) {
		// forum full message fetching
		$('#preview-wait').remove();
		
		if ($(obj).hasClass('prev-msg')) {
			show_full_msg(obj, msg);
		} else if ($(obj).hasClass('forum-posts-link')) {
			//alert('no post links');
			show_all_msgs(obj, msg);
		} else if ($(obj).hasClass('preview-text')) {
			$(obj).html(msg.full_post);
			
			$.blockUI({ message: $(obj).closest('div.post-preview'),
					css: { 
	            		'border': '3px solid #8B91AB',
	            		'height': '80%',
	            		'overflow': 'auto',
	            		'top': '10%',
	            		'width': '674px'
	            		}  });
	            
		}
	}
	
	function get_just_num(text_string) {
		return text_string.replace(/[^0-9]+/g, "");
	}
	
	function highlight_selected(obj) {
		var name   = obj.attr('name');
		var obj_id = obj.attr('id');
		
		// For each input with the same name unbold any existing selections
		$(obj).parent().find(':input[name="'+name+'"]').each(function() {
			if (!$(this).is(':checked')) {
				var el_id = $(this).attr('id');
				$(this).parent().find('label[for="'+el_id+'"]').removeClass('bold');
			}
		});
		
		// Add bold to selected label
		$(obj).parent().find('label[for="'+obj_id+'"]').addClass('bold');
	}
	
	function close_login() {
		$.unblockUI();
	}
	
	function reset_form(submitted_form) {
		$(submitted_form).find('input[type="text"],textarea').each(function() {
			var attr_name = $(this).attr('name');
			
			if (($(submitted_form).find('[name="'+attr_name+'-keep"]').length == 0) || (!$(submitted_form).find('[name="'+attr_name+'-keep"]').is(':checked'))) {
				$(this).val('');
			}
		});
	
	/*
	$(submitted_form).find('input[type="text"]').val('');
	$(submitted_form).find('textarea').val('');
	*/
	}
/*
function show_login() {
	$.blockUI({ message: $('#login-form'),
				css: { 
            		border: '3px solid #8B91AB'
            		}  }); 
}
*/

	function selected_text() {
	
		var user_selection;
		
		if (window.getSelection){
			user_selection = window.getSelection();
		} else if (document.selection) {
			user_selection = document.selection.createRange().text;
		}
		
		return user_selection;
	}
	
	function show_search() {
		$.blockUI({ message: $('#site-search-form'),
					css: { border: '1px solid #8395ad',
							'-moz-border-radius': '3px',
							'-webkit-border-radius': '3px'
						 }
				}); 
		$('.pop-close').attr('title','Close this window').click($.unblockUI);
	}

	function submit_ajax(submit_data, obj, action) {
		if (action == '') {
			action = location.href;
		}
		
		 $.ajax({
			  type: "POST",
			  url: action,
			  dataType: "json",
			  data : submit_data,
			  success: function(msg){
			  	ajax_success(obj, msg);
			   },
	           error: function(request, textStatus, errorThrown){
	           		alert(request+' '+textStatus+' '+errorThrown);
				}
			});
	}
	
	
-->
