$(document).ready(function(){
		
			$("#switch-view-dialog").dialog({
				bgiframe: true,
                resizable: false,
                autoOpen: false,
                width:830,
                height:160,
                modal: true,
                overlay: {
                    backgroundColor: '#000',
                    opacity: 0.5
                },
                buttons: {
                    "Back": function() {
    					$(this).dialog("close");
                    }
                }
			});
	
            $("#site-edit-popup").dialog({
                bgiframe: true,
                resizable: false,
                autoOpen: false,
                width:600,
                height:420,
                modal: true,
                overlay: {
                    backgroundColor: '#000',
                    opacity: 0.5
                },
                buttons: {
                    "Post Feedback": function() {

                        var options = {
                            success:       feedbackProcessResponse,
                            dataType:  'json'
                        };

                        jQuery('#siteFeedbackForm').ajaxForm(options);
                        jQuery("#siteFeedbackForm").submit();

                        $(this).dialog("close");
                    },
                    "Back": function() {

                        $(this).dialog("close");
                    }
                }
            });
			

            $("#page-feedback-popup").dialog({
                bgiframe: true,
                resizable: false,
                autoOpen: false,
                width:600,
                height:420,
                modal: true,
                overlay: {
                    backgroundColor: '#000',
                    opacity: 0.5
                },
                buttons: {
                    "Post Feedback": function() {

                        var options = {
                            success:       feedbackProcessResponse,  // post-submit callback
                            dataType:  'json'
                        };

                        jQuery('#pageFeedbackForm').ajaxForm(options);
                        jQuery("#pageFeedbackForm").submit();

                        $(this).dialog("close");
                    },
                    "Back": function() {

                        $(this).dialog("close");
                    }
                }
            });

            $("#feedback-success-popup").dialog({
                bgiframe: true,
                resizable: false,
                autoOpen: false,
                width:380,
                height:200,
                modal: true,
                overlay: {
                    backgroundColor: '#000',
                    opacity: 0.5
                },
                buttons: {
                    "Ok": function() {

                        $(this).dialog("close");
                    }
                }
            });

        	$("#right_container .box a").click(function(){
				if(!$("#right_container .box a").hasClass("up"))
				{
					$("#right_container .box a").addClass("up");
					$("#right_container .box a").html('&nbsp;');
					$("#right_container .box h3:first").text("If both matchees accept, contact info is sent to each one");
					$("#right_container .box h3 span").text("Also, matchers are notified by email");
					
				}
				else
				{
					$("#right_container .box a").removeClass("up");
					$("#right_container .box a").html('then...');
					$("#right_container .box h3:first").text("MATCHTHEM determines if two people (matchees) are a match");
					$("#right_container .box h3 span").text("MatchThem notifies them by email (using nicknames)");
				}
			});
			
			$("#header .top_link").click(function(){
				if($("#feedback").is(":hidden"))
				{
					$("#feedback").show();
				}
				else
				{
					$("#feedback").hide();
				}
				
			});
			$("ul#feedback li.close-button").click(function(){
				$("#feedback").hide();
			});
			
});

function postSiteFeedback()
{
    $("#site-edit-popup").dialog('open');
}

function postPageFeedback()
{
    $("#page-feedback-popup").dialog('open');
}

function feedbackProcessResponse(data, statusText)
{
    //document.location.reload();
    if(data[0].status == "ok")
    {
        $("#feedback-success-popup").dialog('open');
    }

}

function showInformationPopup()
{
    $("#switch-view-dialog").dialog('open');
}
