$(document).ready(function() {

	// Disable caching
	$.ajaxSetup({
		cache: false
	});

	var error = "0";
	$('#error').fadeIn('slow');
	$('#success').fadeIn('slow');
	$('textarea.expanding').autogrow();
	
	$('textarea[name=new_comment]').focus();
	
	function requireLogin() {
		$('#basicModalContent').modal(); // jQuery object; this demo
		$.modal(document.getElementById('basicModalContent')); // DOM
	}
	
	// Templates
	$("#css-default").click(function() {
		unset_theme_thumbs();
		$("link.custom").attr("href",'/themes/default/theme.css');
		$('img[name=default-thumb]').addClass('select_thumb');
		$('#theme_name').val('default');
	});
	
	$("#css-twitter").click(function() {
		unset_theme_thumbs();
		$("link.custom").attr("href",'/themes/twitter/theme.css');
		$('img[name=twitter-thumb]').addClass('select_thumb');
		$('#theme_name').val('twitter');
		
	});
	
	$("#css-dunkindonuts").click(function() {
		unset_theme_thumbs();
		$("link.custom").attr("href",'/themes/dunkindonuts/theme.css');
		$('img[name=dunkindonuts-thumb]').addClass('select_thumb');
		$('#theme_name').val('dunkindonuts');
		
	});
	
	$("#css-flowers").click(function() {
		unset_theme_thumbs();
		$("link.custom").attr("href",'/themes/flowers/theme.css');
		$('img[name=flowers-thumb]').addClass('select_thumb');
		$('#theme_name').val('flowers');
		
	});
	
	$("a[id^=share_link]").click(function() {
		var c_id = $(this).attr('name');
		$("div[name=share_box_" + c_id + "]").toggle('slow');	
	});
	
	$("a[id=show_whatis]").click(function() {
		$("div[id=hidden_whatis]").toggle('slow');
		
		if ($('a[id=show_whatis]').html() == 'learn more') {
			$('a[id=show_whatis]').html('minimize');
		} else {
			$('a[id=show_whatis]').html('learn more');
		}

	});
	
	
	// Retweet Link
	$("a[id^=retweet_link]").click(function() {
		var c_id = $(this).attr('name');
		var c_text = $(this).attr('value');
		$("input[name=tweet_c_id]").val(c_id);
		$("textarea[name=tweet_text]").text(c_text);
		$('#tweet_story').modal(); // jQuery object; this demo
		$.modal(document.getElementById('tweet_story')); // DOM	
	});
	
	// Email Link
	$("a[id^=email_link]").click(function() {
		var c_id = $(this).attr('name');
		var c_text = $(this).attr('value');
		$("input[name=send_c_id]").val(c_id);
		$("textarea[name=send_text]").text(c_text);
		$('#send_story').modal(); // jQuery object; this demo
		$.modal(document.getElementById('send_story')); // DOM	
	});
	
	// Follow me 
	$("#follow-me").click(function() {
		$.get('/actions/users.php', {
			user_id:	$('div[name=profile_id]').text(),
			q: 'follow_me'
		}, 
		function (response) { 
			if (response == 'nologin') {
				requireLogin();
				
				return false;
			}
		
			/*followers = parseInt($('#follow_number').text())+1;*/
			if (response == 'success') {
				$("#follow-me").fadeOut('slow', function() { $("#unfollow-me").fadeIn('slow'); });
				/*$('#follow_number').text(followers);*/
			} else {
				$('#profile_nav').text('unable to follow me!');
			}
		});
	});
	
	// Unfollow me
	$("#unfollow-me").click(function() {
		$.get('/actions/users.php', {
			user_id:	$('div[name=profile_id]').text(),
			q: 'unfollow_me'
		}, 
		function (response) { 
			if (response == 'nologin') {
				requireLogin();
				
				return false;
			}
		
			/*followers = parseInt($('#follow_number').text())-1;*/
			if (response == 'success') {
				$("#unfollow-me").fadeOut('slow', function() { $("#follow-me").fadeIn('slow'); });
				/*$('#follow_number').text(followers);*/
			} else {
				$('#profile_nav').text('unable to unfollow me!');
			}
		});
	});
	
	// Unfollow me account page
	$("a[id^=un-follow-user]").click(function() {
		var remove_id	= $(this).attr('name');
		$.get('/actions/users.php', {
			user_id:	$(this).attr('name'),
			q: 'unfollow_me'
		}, 
		function (response) { 
			if (response == 'nologin') {
				requireLogin();
				
				return false;
			}
		
			if (response == 'success') {
				$("div[name=unfollow-" + remove_id + ']').html('Removed');
			} else {
				$("div[name=unfollow-" + remove_id + ']').html('Removed');
			}
		});
	});
	
	// Block user 
	$("#block-user").click(function() {
		$.get('/actions/users.php', {
			user_id:	$('div[name=profile_id]').text(),
			q: 'block_user'
		}, 
		function (response) { 
			if (response == 'nologin') {
				requireLogin();
				
				return false;
			}
		
			if (response == 'success') {
				$("#block-user").fadeOut('slow', function() { $("#unblock-user").fadeIn('slow'); });
			} else {
				$('#profile_nav').text('unable to follow me!');
			}
		});
	});
	
	// Unblock user
	$("#unblock-user").click(function() {
		$.get('/actions/users.php', {
			user_id:	$('div[name=profile_id]').text(),
			q: 'unblock_user'
		}, 
		function (response) { 
			if (response == 'nologin') {
				requireLogin();
				
				return false;
			}
		
			if (response == 'success') {
				$("#unblock-user").fadeOut('slow', function() { $("#block-user").fadeIn('slow'); });
			} else {
				$('#profile_nav').text('unable to unfollow me!');
			}
		});
	});
	
	// Ban user 
	$("#ban-user").click(function() {
		$.get('/actions/admin.php', {
			user_id:	$('div[name=profile_id]').text(),
			q: 'ban_user'
		}, 
		function (response) { 
			if (response == 'nologin') {
				requireLogin();
				
				return false;
			}
		
			if (response == 'success') {
				$("#ban-user").fadeOut('slow', function() { $("#unban-user").fadeIn('slow'); });
			} else {
				$('#profile_nav').text('unable to ban me!');
			}
		});
	});
	
	// Unban user
	$("#unban-user").click(function() {
		$.get('/actions/admin.php', {
			user_id:	$('div[name=profile_id]').text(),
			q: 'unban_user'
		}, 
		function (response) { 
			if (response == 'nologin') {
				requireLogin();
				
				return false;
			}
		
			if (response == 'success') {
				$("#unban-user").fadeOut('slow', function() { $("#ban-user").fadeIn('slow'); });
			} else {
				$('#profile_nav').text('unable to unban me!');
			}
		});
	});
	
	// Blacklist user 
	$("#blacklist-user").click(function() {
		$.get('/actions/admin.php', {
			user_id:	$('div[name=profile_id]').text(),
			q: 'blacklist_user'
		}, 
		function (response) { 
			if (response == 'nologin') {
				requireLogin();
				
				return false;
			}
		
			if (response == 'success') {
				$("#blacklist-user").fadeOut('slow', function() { $("#unblacklist-user").fadeIn('slow'); });
			} else {
				$('#profile_nav').text('unable to blacklist me!');
			}
		});
	});
	
	// Unblacklist user
	$("#unblacklist-user").click(function() {
		$.get('/actions/admin.php', {
			user_id:	$('div[name=profile_id]').text(),
			q: 'unblacklist_user'
		}, 
		function (response) { 
			if (response == 'nologin') {
				requireLogin();
				
				return false;
			}
			
			if (response == 'success') {
				$("#unblacklist-user").fadeOut('slow', function() { $("#blacklist-user").fadeIn('slow'); });
			} else {
				$('#profile_nav').text('unable to unblacklist me!');
			}
		});
	});

	
	// Delete Comment Warning
	$("a[id^=delete_warning_comment]").click(function() {
		comment_id = $(this).attr('name');
		
		$("div[name=comment_notice_" + comment_id + "]").show();
		$("#error").show();
	});
	
	// Hide Delete Comment Warning
	$("a[id^=delete_cancel_comment]").click(function() {
		comment_id = $(this).attr('name');
		$("div[name=comment_notice_" + comment_id + "]").empty();
		$("#error").hide();
	});
	
	// Delete Comment
	$("a[id^=delete_comment]").click(function() {
		comment_id = $(this).attr('name');
		$.get('/actions/users.php', {
			com_id:	$(this).attr('name'),
			q: 'delete_comment'
		}, 
		function (response) { 
			if (response == 'nologin') {
				requireLogin();
				
				return false;
			}
		
			if (response == 'success') {
				$("div[name=comment_" + comment_id + "]").slideUp('slow', function() { $("div[name=comment_" + comment_id + "]").html('<div id="success-msg">The comment was successfully deleted.</div>'); });
				$("div[name=comment_" + comment_id + "]").fadeIn('slow');
			} 
		});
	});
	
	// Flag Content
	$("a[id^=flag_content]").click(function() {
		c_id = $(this).attr('name');
		$.get('/actions/users.php', {
			c_id:	$(this).attr('name'),
			q: 'flag_content'
		}, 
		function (response) { 
			if (response == 'nologin') {
				requireLogin();
				
				return false;
			}
		
			if (response == 'success') {
				$("div[name=content_body_" + c_id + "]").slideUp('slow', function() { 
					$("div[name=content_body_" + c_id + "]").html('<div id="error">Thank you for working with us to keep this site clean. The media has been flagged and will be reviwed by a site moderator. Any media that violates our TOS will be deleted.</div>'); 
					$("#error").show();				
				});
				
				$("div[name=content_body_" + c_id + "]").fadeIn('slow');
				
			} else {
				$("div[name=content_body_" + c_id + "]").slideUp('slow', function() { 
					$("div[name=content_body_" + c_id + "]").html('<div id="error">You have already flagged this content.</div>'); 
					$("#error").show();
				});
				
				$("div[name=content_body_" + c_id + "]").fadeIn('slow');
			}
		});
	});
	
	// Add Favorite
	$("a[id^=add_favorite]").click(function() {
		c_id = $(this).attr('name');
		$.get('/actions/users.php', {
			c_id:	$(this).attr('name'),
			c_action: 'add',
			q: 'favorite'
		}, 
		function (response) { 
			if (response == 'nologin') {
				requireLogin();
				
				return false;
			}
		
			if (response == 'success') {
				$('div[name=addfavoritebox_' + c_id + ']').hide();
				$('div[name=remfavoritebox_' + c_id + ']').show();
			} 
		});
	});
	
	// Remove Favorite
	$("a[id^=remove_favorite]").click(function() {
		c_id = $(this).attr('name');
		$.get('/actions/users.php', {
			c_id:	$(this).attr('name'),
			c_action: 'remove',
			q: 'favorite'
		}, 
		function (response) { 
			if (response == 'nologin') {
				requireLogin();
				
				return false;
			}

			if (response == 'success') {
				$('div[name=addfavoritebox_' + c_id + ']').show();
				$('div[name=remfavoritebox_' + c_id + ']').hide();
			} 
		});
	});
	
	// Vote
	/*$("a[id^=content_vote]").click(function() {
		c_id = $(this).attr('name');
		$.get('/actions/users.php', {
			c_id:	$(this).attr('name'),
			q: 'vote'
		}, 
		function (response) { 
			if (response == 'nologin') {
				requireLogin();
				
				return false;
			}			
			
			if (response == 'success') {
				votes = parseInt($('#profile_counter_' + c_id).text())+1;
				$('#profile_counter_' + c_id).text(votes);
				$('div [name=profile_counter_footname_' + c_id + ']').html('lmaos<br><p>voted!');
			} 
		});
	}); */
		
	// Retweet Promo
	$("a[id^=promo_retweet]").click(function() {
		c_id = $(this).attr('name');
		$.get('/actions/users.php', {
			c_id:	$(this).attr('name'),
			q: 'retweet'
		}, 
		function (response) { 
			if (response == 'nologin') {
				requireLogin();
				return false;
			}

			if (response == 'success') {
				$('div[name=tweet_promo').html('<div id="success">This has been retweeted on your Twitter profile!</div>');
			} else {
				$('div[name=tweet_promo').html('<div id="error">An error prevented us from retweeting this on your profile!</div>');
				$("#error").show();
			}
		});
	});
	
	// reset all the above themes for thumbs
	function unset_theme_thumbs() {
		$('img[name=default-thumb]').removeClass('select_thumb');
		$('img[name=twitter-thumb]').removeClass('select_thumb');
		$('img[name=dunkindonuts-thumb]').removeClass('select_thumb');
		$('img[name=flowers-thumb]').removeClass('select_thumb');
	}
	
	// clear input box if clicked
	$("input[name=login_name]").click(function() {
		if ($("input[name=login_name]").val() == 'username') {
			$("input[name=login_name]").val('');
		}
	});
	
	$("input[name=login_pass]").click(function() {
		if ($("input[name=login_pass]").val() == 'password') {
			$("input[name=login_pass]").val('');
		}
	});
	
	$("input[name=query]").click(function() {
		if ($("input[name=query]").val() == 'search media') {
			$("input[name=query]").val('');
		}
	});
	
	// mouse over main navigations
	$("div[id=logo_section_item_inactive]").mouseover(function() {
		$(this).addClass('logo_section_mouseover');
		$(this).find("a").css('color','#363636');
	});
	
	$("div[id=logo_section_item_inactive]").mouseout(function() {
		$(this).removeClass('logo_section_mouseover');
		$(this).find("a").css('color','#fff');
	});
	
	// mouse over filter navigations
	$("div[id=logo_filter_item_inactive]").mouseover(function() {
		$(this).addClass('logo_filter_item_mouseover');
	});
	
	$("div[id=logo_filter_item_inactive]").mouseout(function() {
		$(this).removeClass('logo_filter_item_mouseover');
	});
		
	
	function Left(str, n) {
		if (n <= 0)
		    return "";
		else if (n > String(str).length)
		    return str;
		else
		    return String(str).substring(0,n);
	}
	
	function SubStr(str, n) {
		if (n <= 0)
		    return "";
		else if (n > String(str).length)
		    return str;
		else
		    return String(str).substring(n,String(str).length);
	}

	
	
	//-------------------------------------------------------------------------
	// EDIT ACCOUNT JS
	//-------------------------------------------------------------------------
	var account_vars = {
	  	url:	'/actions/users.php?q=edit_account',
	   	type:	'POST',
	   	beforeSubmit: function() { 		// error checking
	   		var error = "0";
	   		$('#form_response').empty();
			 	
	   		if ($('input[name=change_email]').val() == "") {
	   			$('#form_response').append('<div id="error">You did not enter a valid email.</div>');
	       		error = "1";
	   		}
		   				   		
	   		// display error response
	   		if (error == "1") {
	          	$('#error').fadeIn('slow');
	          	return false;
	          } else {
	          	return true;
	          }
	  	},
	
   	success:	function(response) {
   		$('#form_response').empty();
   		
   		if (response == "success") {
   			$('form[name=edit_account_form]').fadeOut('slow');
				$('form[name=edit_account_form]').remove();
				$('#form_response').empty();
				$('#form_response').append('<div id="success">Your account changes have been saved.</div>');
				$('#success').fadeIn('slow');
   		} else {
   			$('#form_response').append('<div id="error">' + response + '</div>');
   			$('#error').fadeIn('slow');
   		}
   	}
	};
	
	// submit the form
	$('form[name=edit_account_form]').ajaxForm(account_vars);
	//-------------------------------------------------------------------------
	
	//-------------------------------------------------------------------------
	// EDIT SETTINGS JS
	//-------------------------------------------------------------------------
	var settings_vars = {
	  	url:	'/actions/users.php?q=settings',
	   	type:	'POST',
	   	beforeSubmit: function() { 		// error checking
	   		var error = "0";
	   		$('#form_response').empty();
			 			   				   		
	   		// display error response
	   		if (error == "1") {
	          	$('#error').fadeIn('slow');
	          	return false;
	          } else {
	          	return true;
	          }
	  	},
	
   	success:	function(response) {
   		$('#form_response').empty();
   		if (response == "success") {
   			$('form[name=settings_form]').fadeOut('slow');
				$('form[name=settings_form]').remove();
				$('#form_response').empty();
				$('#form_response').append('<div id="success">Your account settings have been saved.</div>');
				$('#success').fadeIn('slow');
   		} else {
   			$('#form_response').append('<div id="error">' + response + '</div>');
   			$('#error').fadeIn('slow');
   		}
   	}
	};
	
	// submit the form
	$('form[name=settings_form]').ajaxForm(settings_vars);
	//-------------------------------------------------------------------------


	//-------------------------------------------------------------------------
	// LOGIN JS
	//-------------------------------------------------------------------------
	var login_vars = {
	  	url:	'/actions/users.php?q=log_in',
	   	type:	'POST',
	   	beforeSubmit: function() { 		// error checking
	   		var error = "0";
	   		$('#form_response').empty();

	  		   		
	   		// display error response
	   		if (error == "1" && $('input[name=login_simple]').val() != '1') {
	          	$('#error').fadeIn('slow');
	          	return false;
	          } else {
	          	$('#login_form').hide();
	   			$('#login_progress').show();
	          	return true;
	          }
	  	},
	
   	success:	function(response) {
alert(response);
   		$('#form_response').empty();
   		if (response == "success") {
   			$('form[name=login_form]').fadeOut('slow');
				$('form[name=login_form]').remove();
				var current_url = document.location.href;
				if (current_url != '') {
					window.location = current_url;
				} else {
					window.location = "/home";
				}
			} else if ($('input[name=login_simple]').val() == '1') {
				window.location = "/login?response=" + response;
   		} else if (response == "unconfirmed") {
   			$('#form_response').append('<div id="error">You may not log in until you have confirmed your account through email.</div>');
   			$('#error').fadeIn('slow');
   			$('#login_form').show();
   			$('#login_progress').hide();
   		} else if (response == "twitfail") {
   			$('#form_response').append('<div id="error">Twitter is having issues. Please try again later.</div>');
   			$('#error').fadeIn('slow');
   			$('#login_form').show();
				$('#login_progress').hide();
   		} else {
   			$('#form_response').append('<div id="error">An account matching your details could not be found.</div>');
   			$('#error').fadeIn('slow');
   			$('#login_form').show();
   			$('#login_progress').hide();
   		}
   	}
	};
	
	// submit the form
	$('form[name=login_form]').ajaxForm(login_vars);
	//-------------------------------------------------------------------------
	
	//-------------------------------------------------------------------------
	// PROFILE THEME JS
	//-------------------------------------------------------------------------
	var profile_theme_vars = {
	  	url:	'/actions/users.php?q=profile_theme',
	   	type:	'POST',
	   	beforeSubmit: function() { 		// error checking
	   		var error = "0";
	   		$('#form_response').empty();

	   		if ($('input[name=theme_name]').val() == "") {
	   			$('#form_response').append('<div id="error">You did not enter a valid theme.</div>');
	       		error = "1";
	   		}
		   				  		   		
	   		// display error response
	   		if (error == "1") {
	          	$('#error').fadeIn('slow');
	          	return false;
	          } else {
	          	return true;
	          }
	  	},
	
   	success:	function(response) {
   		$('#form_response').empty();
   		if (response == "success") {
				$('#form_response').append('<div id="success">Your theme has been updated.</div>');
				$('#success').fadeIn('slow');
				
				// reset user defined values
				$('input[name=background_color]').val('');
				$('input[name=change_background]').val('');
				$('input[name=bar_bg_color]').val('');
				$('input[name=bar_text_color]').val('');
				$('input[name=link_color]').val('');
				$('input[name=text_color]').val('');
				
   		} else {
   			$('#form_response').append('<div id="error">You did not enter a valid theme.</div>');
   			$('#error').fadeIn('slow');
   		}
   	}
	};
	
	// submit the form
	$('form[name=profile_theme_form]').ajaxForm(profile_theme_vars);
	//-------------------------------------------------------------------------
	
	//-------------------------------------------------------------------------
	// PROFILE CUSTOM THEME JS
	//-------------------------------------------------------------------------
	var profile_custom_theme_vars = {
	  	url:	'/actions/users.php?q=profile_custom_theme',
	   	type:	'POST',
	   	beforeSubmit: function() { 		// error checking
	   		var error = "0";
	   		$('#form_response').empty();
	    	   		
	   		if ($('input[name=background_color]').val() == "") {
	   			$('#form_response').append('<div id="error">You did not enter a valid background color.</div>');
	       		error = "1";
	   		}
	   		
	   		if ($('input[name=bar_bg_color]').val() == "") {
	   			$('#form_response').append('<div id="error">You did not enter a valid bar background color.</div>');
	       		error = "1";
	   		}
	   		
	   		if ($('input[name=bar_text_color]').val() == "") {
	   			$('#form_response').append('<div id="error">You did not enter a valid bar text color.</div>');
	       		error = "1";
	   		}
	   		
	   		if ($('input[name=link_color]').val() == "") {
	   			$('#form_response').append('<div id="error">You did not enter a valid link color.</div>');
	       		error = "1";
	   		}
	   		
	   		if ($('input[name=text_color]').val() == "") {
	   			$('#form_response').append('<div id="error">You did not enter a valid text color.</div>');
	       		error = "1";
	   		}
		   				  		   		
	   		// display error response
	   		if (error == "1") {
	          	$('#error').fadeIn('slow');
	          	return false;
	          } else {
	          	$('#upload_background').hide();
	   			$('#upload_background_progress').show();
	          	return true;
	          }
	  	},
	
   	success:	function(response) {
   		$('#form_response').empty();
   		$('#upload_background').show();
	   	$('#upload_background_progress').hide();
   		if (response != "error") {
   			$('link.custom').attr("href",'/themes/custom/theme.css');
   			unset_theme_thumbs();
   			// update all user defined preferences
   			$('style').empty();
   			$('style').append('body { background-color: ' + $('input[name=background_color]').val() + '; }');
   			$('style').append('#profile_post a, a, #follow_count a { color: ' + $('input[name=link_color]').val() + '; }');
   			$('style').append('#content_body, #page_box_padding { color: ' + $('input[name=text_color]').val() + '; }');
   			$('style').append('#page_headline { background-color: ' + $('input[name=bar_bg_color]').val() + '; color: ' + $('input[name=bar_text_color]').val() + '; }');
   			$('style').append('#profile_tab a { color: ' + $('input[name=bar_text_color]').val() + '; }');
   			if (response != "success") { 
   				$('style').append('body { background-image: url(\'/media/backgrounds/' + response + '\'); }');
   			}
   			
   			
   			
				$('#form_response').append('<div id="success">Your theme has been updated.</div>');
				$('#success').fadeIn('slow');
   		} else {
   			$('#form_response').append('<div id="error">Theme not updated, please check you uploaded a valid image. ' + response + '</div>');
   			$('#error').fadeIn('slow');
   		}
   	}
	};
	
	// submit the form
	$('form[name=profile_custom_theme_form]').ajaxForm(profile_custom_theme_vars);
	//-------------------------------------------------------------------------
	
	
	//-------------------------------------------------------------------------
	// PROFILE PHOTO JS
	//-------------------------------------------------------------------------
	var profile_photo_vars = {
	  	url:	'/actions/users.php?q=profile_photo',
	   	type:	'POST',
	   	beforeSubmit: function() { 		// error checking
	   		var error = "0";
	   		$('#form_response').empty();
	    	   		
	   		if ($('input[name=change_photo]').val() == "") {
	   			$('#form_response').append('<div id="error">You did not enter an image to upload.</div>');
	       		error = "1";
	   		}
		   				  		   		
	   		// display error response
	   		if (error == "1") {
	          	$('#error').fadeIn('slow');
	          	return false;
	          } else {
	          	$('#upload_photo').hide();
	   			$('#upload_photo_progress').show();
	          	return true;
	          }
	  	},
	
   	success:	function(response) {
   		$('#form_response').empty();
	   	$('#upload_photo_progress').hide();
   		if (response == "success") {
				$('#form_response').append('<div id="success">Your photo has been updated.</div>');
				$('#success').fadeIn('slow');
   		} else {
   			$('#form_response').append('<div id="error">' + response + '.</div>');
   			$('#error').fadeIn('slow');
   			$('#upload_photo').show();
   		}
   	}
	};
	
	// submit the form
	$('form[name=profile_photo_form]').ajaxForm(profile_photo_vars);
	//-------------------------------------------------------------------------
	
	//-------------------------------------------------------------------------
	// EDIT CONTENT JS
	//-------------------------------------------------------------------------
	var edit_content_vars = {
	  	url:	'/actions/users.php?q=edit_content',
	   	type:	'POST',
	   	beforeSubmit: function() { 		// error checking
	   		var error = "0";
	   		$('#form_response').empty();
	   		
	   		if ($('input[name=submit_title]').val() == "") {
	   			$('#form_response').append('<div id="error">You did not enter a media title.</div>');
	       		error = "1";
	   		}
	   		
	   		if ($('input[name=submit_descr]').val() == "") {
	   			$('#form_response').append('<div id="error">You did not enter a media description.</div>');
	       		error = "1";
	   		}
	   				   				  		   		
	   		// display error response
	   		if (error == "1") {
	          	$('#error').fadeIn('slow');
	          	return false;
	          } else {
	          	$('#edit_content_form').hide();
	          	return true;
	          }
	  	},
	
   	success:	function(response) {

   		$('#form_response').empty();
   		if (Left(response,8) == "success|") {
   			window.location = SubStr(response,8);
				$('#form_response').append('<div id="success">Your content has been modified.</div>');
				$('#success').fadeIn('slow');
   		} else {
   			$('#form_response').append('<div id="error">' + response + '.</div>');
   			$('#error').fadeIn('slow');
   			$('#edit_content_form').show();
   		}
   	}
	};
	
	// submit the form
	$('form[name=edit_content_form]').ajaxForm(edit_content_vars);
	//-------------------------------------------------------------------------
	
	//-------------------------------------------------------------------------
	// SUBMIT JS
	//-------------------------------------------------------------------------
	var submit_vars = {
	  	url:	'/actions/users.php?q=submit',
	   	type:	'POST',
	   	beforeSubmit: function() { 		// error checking
	   		var error = "0";
	   		$('#form_response').empty();
	   		
	   		if ($('input[name=submit_title]').val() == "") {
	   			$('#form_response').append('<div id="error">You did not enter a media title.</div>');
	       		error = "1";
	   		}
	   		
	   		if ($('input[name=submit_descr]').val() == "") {
	   			$('#form_response').append('<div id="error">You did not enter a media description.</div>');
	       		error = "1";
	   		}
	   		
	   		if ($('input[name=submit_file]').val() == "") {
	   			$('#form_response').append('<div id="error">You did not enter an image to upload.</div>');
	       		error = "1";
	   		}
		   				  		   		
	   		// display error response
	   		if (error == "1") {
	          	$('#error').fadeIn('slow');
	          	return false;
	          } else {
	          	$('#submit_form').hide();
	   			$('#upload_progress').show();
	          	return true;
	          }
	  	},
	
   	success:	function(response) {

   		$('#form_response').empty();
	   	$('#upload_progress').hide();
   		if (Left(response,8) == "success|") {
   			window.location = SubStr(response,8);
				$('#form_response').append('<div id="success">Your content has been submitted.</div>');
				$('#success').fadeIn('slow');
   		} else {
   			$('#form_response').append('<div id="error">' + response + '.</div>');
   			$('#error').fadeIn('slow');
   			$('#submit_form').show();
   		}
   	}
	};
	
	// submit the form
	$('form[name=submit_form]').ajaxForm(submit_vars);
	//-------------------------------------------------------------------------
	
	//-------------------------------------------------------------------------
	// POST COMMENT JS
	//-------------------------------------------------------------------------
	var post_comment_vars = {
	  	url:	'/actions/users.php?q=post_comment',
	   	type:	'POST',
	   	beforeSubmit: function() { 		// error checking
	   		var error = "0";
	   		$('#form_response').empty();
	   		
	   		if ($('textarea[name=new_comment]').val() == "") {
	   			$('#form_response').append('<div id="error">You did not enter a comment.</div>');
	       		error = "1";
	   		}
		   				  		   		
	   		// display error response
	   		if (error == "1") {
	          	$('#error').fadeIn('slow');
	          	return false;
	          } else {
	          	$('#post_new_comment').hide();
	          	return true;
	          }
	  	},
	
   	success:	function(response) {
   		$('#form_response').empty();
   		if (Left(response,8) == "success|") {
 				$('#form_response').append('<div id="success">Your comment has been posted.</div>');
				$('#success').fadeIn('slow');
				$('#post_new_comment').remove();
				$('#new_comment_area').hide();
				$('#new_comment_area').append(SubStr(response,8));
				$('#new_comment_area').slideDown();
				
   		} else {
   			$('#form_response').append('<div id="error">Please enter a valid comment.</div>');
   			$('#error').fadeIn('slow');
   			$('#post_new_comment').show();
   		}
   	}
	};
	
	// submit the form
	$('form[name=post_comment]').ajaxForm(post_comment_vars);
	//-------------------------------------------------------------------------
	
	//-------------------------------------------------------------------------
	// SEND MESSAGE JS
	//-------------------------------------------------------------------------
	var message_send_vars = {
	  	url:	'/actions/users.php?q=message_send',
	   	type:	'POST',
	   	beforeSubmit: function() { 		// error checking
	   		var error = "0";
	   		$('#form_response').empty();
	   		
	   		if ($('input[name=sendto]').val() == "") {
	   			$('#form_response').append('<div id="error">You did not enter a recipient.</div>');
	       		error = "1";
	   		}
	   		
	   		if ($('input[name=subject]').val() == "") {
	   			$('#form_response').append('<div id="error">You did not enter a subject.</div>');
	       		error = "1";
	   		}
	   		
	   		if ($('textarea[name=message]').val() == "" && error != '1') {
	   			$('#form_response').append('<div id="error">You did not enter a message.</div>');
	       		error = "1";
	   		}
		   				  		   		
	   		// display error response
	   		if (error == "1") {
	          	$('#error').fadeIn('slow');
	          	return false;
	          } else {
	          	$('#message_send_form').hide();
	          	return true;
	          }
	  	},
	
   	success:	function(response) {
   		$('#form_response').empty();
   		if (Left(response,8) == "success|") {
 				$('#form_response').append('<div id="success">Your message has been sent.</div>');
				$('#success').fadeIn('slow');
				$('#message_send_form').remove();
   		} else {
   			$('#form_response').append('<div id="error">' + response + '</div>');
   			$('#error').fadeIn('slow');
   			$('#message_send_form').show();
   		}
   	}
	};
	
	// submit the form
	$('form[name=message_send_form]').ajaxForm(message_send_vars);
	//-------------------------------------------------------------------------
	
	//-------------------------------------------------------------------------
	// Retweet Form
	//-------------------------------------------------------------------------
	var retweet_form_vars = {
	  	url:	'/actions/users.php?q=retweet',
	   	type:	'POST',
	   	beforeSubmit: function() { 		// error checking
	   		var error = "0";
	   		var c_id = $('input[name=tweet_c_id]').val();
	   		$('#tweet_response').empty();
	   		
	   		if ($('textarea[name=tweet_text]').val() == "") {
	   			$('#tweet_response').append('<div id="error">You did not enter text to retweet.</div>');
	       		error = "1";
	   		}
	   		
	   		if ($('input[name=tweet_c_id]').val() == "") {
	   			$('#tweet_response').append('<div id="error">Retweet Failed.</div>');
	       		error = "1";
	   		}

		   				  		   		
	   		// display error response
	   		if (error == "1") {
	          	$('#error').fadeIn('slow');
	          	return false;
	          } else {
	          	$('#retweetArea').hide();
	          	$('#tweet_response').append('Posting to your Twitter... please wait...<p><img src="/images/progress.gif">');
	          	return true;
	          }
	  	},
	
   	success:	function(response) {
			
   		var c_id = $('input[name=tweet_c_id]').val();
   		var c_votes = parseInt($('#profile_counter_' + c_id).text())+1;
   		$('#tweet_response').empty();
   		if (Left(response,8) == "success|") {
 				$('a[id=retweet_link_' + c_id + ']').html('Tweeted!');
 				$('#profile_counter_' + c_id).text(c_votes);
				$.modal.close();
   		} else {
   			$('#tweet_response').append('<div id="error">' + SubStr(response,6) + '</div>');
   			$('#error').fadeIn('slow');
   			$('#retweetArea').show();
   		}
   	}
	};
	
	// submit the form
	$('form[name=retweet_form]').ajaxForm(retweet_form_vars);
	//-------------------------------------------------------------------------
	
	
	//-------------------------------------------------------------------------
	// Email Form
	//-------------------------------------------------------------------------
	var send_form_vars = {
	  	url:	'/actions/users.php?q=email_link',
	   	type:	'POST',
	   	beforeSubmit: function() { 		// error checking
	   		var error = "0";
	   		var c_id = $('input[name=send_c_id]').val();
	   		$('#email_response').empty();
		   				  		   		
	   		// display error response
	   		if (error == "1") {
	          	$('#error').fadeIn('slow');
	          	return false;
	          } else {
	          	$('#sendArea').hide();
	          	$('#email_response').append('Sending your emails... please wait...<p><img src="/images/progress.gif">');
	          	return true;
	          }
	  	},
	
   	success:	function(response) {

   		var c_id = $('input[name=send_c_id]').val();
   		$('#email_response').empty();
   		if (Left(response,8) == "success|") {
 				$('a[id=email_link_' + c_id + ']').html('Email Sent!');
				$.modal.close();
   		} else {
   			$('#email_response').append('<div id="error">Email Failed</div>');
   			$('#error').fadeIn('slow');
   			$('#sendArea').show();
   		}
   	}
	};
	
	// submit the form
	$('form[name=send_form]').ajaxForm(send_form_vars);
	//-------------------------------------------------------------------------

	
	
}); 

