var $j = jQuery.noConflict();
	var post_val = '';
	var post_id = '';
	$j(document).ready(function(){
		//var current_path = '<?php echo get_option( 'siteurl' ).'/'.PLUGINDIR.'/'.dirname(plugin_basename(__FILE__)); ?>';
		$j(".tagthis").each(function(index,obj){
			//alert(<?php echo $posts[0]->ID ?>);
			post_id = obj.id.substring('tagthis-'.length);
			$j(this).html('<h4>Tag</h4><p>Recognize someone in this photo? Tag them.</p><form action="http://thefrosty.com/wp-content/plugins/community-tags/community-tags-add.php?addtag=go" method="post" id="tagthisform-'+index+'"><p>Separate multiple people with commas, example: Elvis Presley, Nick Blinko.</p><input type="text" id="ct_tag_'+index+'" name="ct_tag" size="30" class="ct_tag" value="" /><input type="hidden" value="'+post_id+'" name="post_id" id="post_'+index+'" class="post_id"/><input type="submit" value="Tag" id="tagthisbutt_'+index+'" class="tagthisbutt" /></form>');
		
			/*$j('#tagthisbutt_'+index).click(function(){
				ct_process_form(index);
			});*/
			var options = {
				// target identifies the element(s) to update with the server response 
				target: "#tagthis-"+post_id,
				// success identifies the function to invoke when the server response 
				// has been received; here we apply a fade-in effect to the new content 
				success: tagAddedResponse
			}
			$j("#tagthisform-"+index).ajaxForm(options);
			
			/*$j('#ct_tag_'+index).suggest('<?php echo get_option("siteurl")."/".PLUGINDIR."/".dirname(plugin_basename(__FILE__)); ?>/community-tags-suggest.php?suggesttag=go',{ 
				onSelect:function(data){ 
					//ct_process_form(index);
					$j('#ct_tag_'+index).val() += data+", ";
					//Figure out a way to use ajaxForm to submit
				}
			});*/
		});
		
		function tagAddedResponse(server_response){
			response = server_response.split(',');
			post_id = response[0];
			response = response[1];
			
			if(response == "notags"){
				jQuery("#tagthis-"+post_id).html("<p>There are no tags to add.</p>");
			}else if(response == "error"){
				jQuery("#tagthis-"+post_id).html("<p>There was a problem submitting your tags, try again later.</p>");
			}else{
				jQuery("#tagthis-"+post_id).html("<p>Thank you for your submission, it is in moderation and should appear shortly.</p>");	
			}
		
			//alert(post_id + " : " +response);
			jQuery('#tagthis-'+post_id).oneTime(5000,function(){
				jQuery(this).fadeOut('fast');
			});
		}
		
		/*function ct_process_form(index){
			var ct_tag = $j("#ct_tag");
			var ct_post = $j(".postid").val();
			//alert(ct_tag + " : " + ct_post);
			alert($j("#ct_tag_"+index+":input").val());
			$j.post('<?php bloginfo('home'); ?>/index.php?addtag=go',
					$j("#ct_tag_"+index).serializeArray(), 
						function(data){
							$j("#tagthis-"+index).html('<p>Thank you for your submission. It is currently being moderated.</p>'); 
						}
					);
		}*/
	});