(function($){  
$.fn.typedoc = function(options){

var defaults = {
path: "file0.php"
},
settings = $.extend({}, defaults, options);

$(document).ready(function() {


var currentStyles = "";
$("style").each(function(i,obj){
currentStyles = currentStyles + $("style").eq(i).html();
});
$("style").remove();

var isMSIE = /*@cc_on!@*/false;

if(isMSIE == true){
var sheet = document.createElement("style");
sheet.type="text/css";
sheet.rel="stylesheet";
sheet.media="screen";
sheet.styleSheet.cssText = currentStyles;
document.getElementsByTagName("head")[0].appendChild(sheet);
}else{
$("head").append($(document.createElement("style")).attr({type:"text/css", rel:"stylesheet", media:"screen"}).append(currentStyles));
}

var currentContent = $("body").html();

$("body").empty();

$("body").append($(document.createElement("div")).attr("id","typedocDisplay"));
$("body").append($(document.createElement("div")).attr("id","typedoc"));
$("#typedoc").append($(document.createElement("form")).attr({method: "post",action:settings.path}));
var typeDocForm = $("#typedoc>form");
typeDocForm.append($(document.createElement("h1")).append($(document.createElement("span")).text("TypeDoc")));
typeDocForm.append($(document.createElement("h2")).text('<style type="text/css" media="screen">'));
typeDocForm.append($(document.createElement("p")).append($(document.createElement("textarea")).attr({id:"style",rows:5,cols:40, title:"CSS", name:"cssInput"})));
$("#style").text(jQuery.trim(currentStyles));
typeDocForm.append($(document.createElement("h2")).text("<body>"));
typeDocForm.append($(document.createElement("p")).append($(document.createElement("textarea")).attr({id:"body",rows:10,cols:40, title:"HTML", name:"htmlInput"})));
$("#body").text(jQuery.trim(currentContent));
$("#typedocDisplay").html(jQuery.trim(currentContent));
typeDocForm.append($(document.createElement("p")).append($(document.createElement("button")).attr("id","typedocSubmit").text("Save Document")));

$(window).resize(function(){
$("#typedoc").height($(window).height());
$("#typedocDisplay").width($(window).width()-300);
$("#typedocDisplay").height($(window).height());
});

$("#typedocDisplay").width($(window).width()-300);
$("#typedocDisplay").height($(document).height());
$("#typedoc").height($(document).height());

$("textarea#style").bind("keyup",processCSS);
$("textarea#body").bind("keyup",processHTML);

function processCSS(keyEvent){
$("style:last").empty();

if(isMSIE == true){
document.getElementsByTagName("style")[0].styleSheet.cssText = this.value;
}else{
$("style:last").append(this.value);	
}

}

function processHTML(keyEvent){
$("div#typedocDisplay").empty();
$("div#typedocDisplay").append(this.value);
}

$("button#typedocSubmit").bind("click", function(e){

$.ajax({type:"POST", url: "process.php", data: $("form").serialize(), beforeSend: disable, dataType: "html", success: response});

function disable(){
$("div#typedocPopup").remove();
$("button#typedocSubmit").attr("disabled", true); 
}
function response(data){

$("div#typedoc").append($(document.createElement("div")).attr("id","typedocPopup"));

$("div#typedocPopup").append($(document.createElement("p")).append($(document.createElement("a")).attr("href","http://www.dolfo.org/apps/typedoc/temp/"+data+".htm").text("View")));

var url = "fileServer.php?file=temp/"+data;
$("div#typedocPopup").append($(document.createElement("p")).append($(document.createElement("a")).attr("href",url).text("Download")));

$("button#typedocSubmit").removeAttr("disabled");
}

return false;
});

});

}
})(jQuery);
$("body").typedoc({ 'path': 'process.php' });