$(function() {
    /* set global variable for boxy window */
    var contactBoxy = null;
    /* what to do when click on contact us link */
    $('.contact_us').click(function(){
        var boxy_content;
        boxy_content += "<div style=\"width:410px; height:300px \"><form id=\"feedbacked\">";
        
        boxy_content += "<p>Subject<br /><input type=\"text\" name=\"subject\" id=\"subject\" size=\"41\" /></p><p>Your name and/or email:<br /><input type=\"text\" name=\"your_email\" size=\"41\" /></p><p>Comment:<br /><textarea name=\"comment\" id=\"comment\" style=\"max-width:400px \"></textarea></p><input type=\"submit\" class=\"submitbutton\" name=\"submit\" value=\" Send >>\" /><input type=\"reset\" class=\"submitbutton\" name=\"submit\" value=\" Clear \" />";
        
        boxy_content += "</form></div>";
        
        contactBoxy = new Boxy(boxy_content, {
            title: "Send us feedback",
            draggable: false,
            modal:true,
            behaviours: function(c) {
                c.find('#feedbacked').submit(function() {
                    Boxy.get(this).setContent("<div style=\"width: 410px; height: 300px\">Sending...</div>");
                    // submit form by ajax using post and send 3 values: subject, your_email, comment
                    $.post("inclu/suggest.php", { subject: c.find("input[name='subject']").val(), your_email: c.find("input[name='your_email']").val(), comment: c.find("#comment").val()},
                    function(data){
                        /*set boxy content to data from ajax call back*/
                        contactBoxy.setContent("<div style=\"width: 410px; height: 300px\">"+data+"</div>");
                    });
                    return false;
                });
            } 
        });
        return false;
    });
});
