 
jQuery(function( $ ){
        var bottom_bar={
                init: function () {
		        var menuRoot = $( "#menu-root" );
		        var menu = $( "#menu" );
 
                        // since we don't know the user login status, the first thing we do is hide the authentication_form
                        $( "#authentication_form").hide(); 

			// Hook up menu root click event.
			menuRoot
				.attr( "href", "javascript:void( 0 )" )
				.click(
					function(){
						// Toggle the menu display.
						menu.toggle();
 
						// Blur the link to remove focus.
						menuRoot.blur();
 
						// Cancel event (and its bubbling).
						return( false );
					}
				)
			;
 
                        menu
                            .slideUp(300).delay(3000).fadeIn(400);

                        //$( "#quick_reply_box").attr("disabled", true);
                        // if user is clicks quick reply link, enable the link
                        $( "#quick_reply_box, #reply_link").click( function(){
                            //if user is not logged in, show authentication form. Else enable quick_reply_box
                            //$.post("http://ngmix.net/includes/phpbb_auth_helper_temp.php", "&action=is_registered", function(data){
                            $.post("http://ngmix.net/includes/phpbb_auth_helper_temp.php", "&action=is_registered", function(data){
                                    if( data != 1){ 
                                        //alert("you are now logged in");
                                        $( "#reply_form").hide();
                                        $( "#authentication_form").show();
                                    }else{
                                        bottom_bar.enable_textarea();
                                    }
                            });
                            // if user is logged in
                            //bottom_bar.enable_textarea();

                            //else
                            //show authentication form
                            //$( "#quick_reply_box").attr("disabled", true);
                            //$( "#quick_reply_box").hide();
                            return( false);
                        });

			// Hook up a click handler on the document so that
			// we can hide the menu if it is not the target of
			// the mouse click.
			$( document ).click(
				function( event ){
					// Check to see if this came from the menu.
					if (
						menu.is( ":visible" ) &&
						!$( event.target ).closest( "#menu" ).size()
						){
 
						// The click came outside the menu, so
						// close the menu.
						menu.hide();
 
					}
				}
			);

                        //if user click submit, process the submit
                        $('#submit_quick_reply').click( function(){
                            $.post("http://ngmix.net/includes/phpbb_auth_helper_temp.php", "&action=is_registered", function(data){
                                    if( data != 1){
                                        $( "#reply_form").hide();
                                        $( "#authentication_form").show();
                                    }else{
                                        if( $( "#quick_reply_box").val() == null ||  $( "#quick_reply_box").val() == ''){
                                            alert("Oops, you forgot to enter reply");
                                        }else{
                                            bottom_bar.process_reply();
                                        }
                                    }
                            });
                            return(false);
                        });
                },

                enable_textarea: function () {

                        $( "#quick_reply_box").attr("disabled", false);
                },

                process_reply: function() {
                        var wrap_status=$("textarea#quick_reply_box").val().replace(/[^a-zA-Z 0-9]+/g,'');
                        var wrap_topic_subject=$("input#quick_subject").val();
                        var wrap_email='';
                        var wrap_forum_id=$("input#quick_forum_id").val();
                        var wrap_topic_id=$("input#quick_topic_id").val();

                        var dataString = 'reply_text='+wrap_status+'&poster_email='+wrap_email+'&forum_id='+wrap_forum_id+'&topic_id='+wrap_topic_id+'&topic_subject='+wrap_topic_subject;
                        $.ajax({
                            type: "GET",
                            url: "http://ngmix.net/ng_working/SCRIPTS/branch/alpha/yindex/data/process_phpbb_reply.php",
                            data: dataString,
                            success: function(data) {
                                $("#reply_link").html("<i>You Posted</i>: <div style='font-weight:normal; '>&raquo; "+wrap_status+"<br></div>").delay('6000').fadeOut('200');
                                $("textarea#quick_reply_box").val('').hide();
                                $('#submit_quick_reply').hide();
                                $('#menu').delay('6000').fadeOut('200');
                                //alert("thank you, \n\n your post is now awaiting moderation");
                            },
                            error: function(data){
                                alert("thank you, \n\n but an error has occurred"+data);
                            }
                        });
                        menu.delay("6000").hide();
                        return false;
                        //$.post("http://ngmix.net/ng_working/SCRIPTS/branch/alpha/yindex/data/process_phpbb_reply_with_post.php", 
                        //$.post("http:../../ng_working/SCRIPTS/branch/alpha/yindex/data/process_phpbb_reply_with_post.php", 
                        //$.post("http:../../includes/test.php", 
                        //    "reply_text="+wrap_status+"&poster_email="+wrap_email+"&forum_id="+wrap_forum_id+"&topic_id="+wrap_topic_id+"&topic_subject="+wrap_topic_subject, 
                        //    function(data){
                        //        alert(data);
                        //});
                        //return false;
                },

                submitHandler: function(form) { alert("not submitting form");
                    //// do other stuff for a valid form
                    //$.post('process.php', $("#reply_form").serialize(), function(data) {
                    //    //$('#reply_link').html(data);
                    //    alert(data);
                    //});
                }
        };
        bottom_bar.init();

});
 

