/*
* jQuery iFramer
* By: Trent Richardson [http://trentrichardson.com]
* Version 0.1
* Last Modified: 6/5/2009
* 
* Copyright 2009 Trent Richardson
* Dual licensed under the MIT and GPL licenses.
* http://trentrichardson.com/Impromptu/GPL-LICENSE.txt
* http://trentrichardson.com/Impromptu/MIT-LICENSE.txt
* 
*/
(function($) {

    $.fn.extend({
        iframer: function(options) {
            options = $.extend({}, { iframe: 'iframer_iframe', returnType: 'html', onComplete: function() { } }, options);
            var $theframe = $('<iframe name=' + options.iframe + ' id="' + options.iframe + '" width="0" height="0" frameborder="0" style="border: none; display: none; visibility: hidden;"></iframe>');
            $(this).append($theframe).attr('target', options.iframe).submit(function() {
                $('#' + options.iframe).load(function() {
                    $("#dialog-modal1").dialog('close');
                    $("#dialog-modal2").dialog('open');
                    //            var data = $('#' + options.iframe).contents().find('body').html();
                    //            alert("5");
                    //            if (options.returnType.toLowerCase() == 'json')
                    //                alert("6");
                    //            eval('data=' + data);
                    //            alert("7");
                    //            options.onComplete(data);
                    //            alert("8");
                    //            $('#' + options.iframe).contents().find('body').html('');
                    //            alert("9");
                    //            $('#' + options.iframe).unbind('load');
                    //            alert("10");
                });
                   
                return true;
            });
        }
    });

})(jQuery);


