/*
window.onload = function() {
	if(Shutterborg.loaded!=true) {
		Shutterborg.init();
		window.onresize();
	}
};
*/

window.onDOM = function() {
	//window.Shutterborg = new window.ShutterborgClass();
	if(window.Shutterborg && window.Shutterborg.loaded!=true) {
		window.Shutterborg.init();
		//window.onresize();
	}
};



window.ShowWizard = function() {
	if(window.pageTracker) window.pageTracker._trackPageview("/wizard");
	var blank = new Application();
	blank.setBackground("url('/images/overlay-gradient.png') 0 -20px repeat-x #000");
	if(!window.Shutterborg || !Shutterborg.editors || Shutterborg.editors.length==0)
		blank.setOpacity(30);
	else {
		blank.setOpacity(50);
		
		// refresh ads:
		//document.getElementById('main_gads').innerHTML = '<script>google_ad_client = "pub-7005333511440775";google_ad_slot = "8928617012";google_ad_width = 728;google_ad_height = 90;</script><script src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script><script>google_ad_client = "pub-7005333511440775";google_ad_slot = "3222275445";google_ad_width = 728;google_ad_height = 90;</script><script src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>';
	}
	blank.DisableMaximize();
	blank.DisableMinimize();
	blank.ToggleFullscreen();
	blank.setServiceState("invisible");
	blank.onFormFocus.push(function(app){
		if(Shutterborg.adwin)
			Shutterborg.adwin.focus();
		if(Shutterborg.sharingwin)
			Shutterborg.sharingwin.focus();
		if(app.parentDialogWindow)
			app.parentDialogWindow.focus();
		else
			app.Close();
		if(Shutterborg.openFromWebApp)
			Shutterborg.openFromWebApp.focus();
		this.formframe.style.zIndex = 40;
	});
	blank.onFormBlur.push(function() {
		this.formframe.style.zIndex = 40;
	});
	blank.init();
	blank.formframe.style.zIndex = 40;
	
	var app = new Application("Getting Started", 560, 180, null, null, null, null, null, null, "fixed");
	app.moveBy(0,-40);		// -80
	//if(!window.Shutterborg || !Shutterborg.editors || Shutterborg.editors.length==0)
	//	app.setOpacity(90);
	app.DisableMaximize();
	app.DisableMinimize();
	app.blank = blank;
	blank.parentDialogWindow = app;
	app.onclose.push(function(app){ app.blank.Close(); Shutterborg.wizard=null; });
	app.onclose.push(function(app){ if(!Shutterborg || Shutterborg.editors.length==0) window.ShowWizard(); });
	Shutterborg.wizard = app;
	app.setTitle("");
	
	app.onkeyup.push(function(keyCode){
		var key = String.fromCharCode(keyCode).toLowerCase();
		switch(key) {
			case "1":
				app.tasks.newDoc.onclick[0].apply(app.tasks.newDoc,[app.tasks.newDoc,{}]);
			break;
			case "2":
				app.tasks.localDoc.onclick[0].apply(app.tasks.localDoc,[app.tasks.localDoc,{}]);
			break;
			case "3":
				app.tasks.sorgDoc.onclick[0].apply(app.tasks.sorgDoc,[app.tasks.sorgDoc,{}]);
			break;
		}
	});
	
	app.expTitle = new app.Controls.Label("Welcome to Shutterborg","text-align:center; font-size:250%; font-weight:bold; font-family:calibri,helvetica,cambria,freesans; color:#4A5A68; display:block; border:none; padding:0; margin:0;");
	app.Controls.Add(app.expTitle);
	
	app.exp = new app.Controls.Label("Shutterborg is a free word processor that runs entirely in your web browser. Instead of using expensive desktop software, Shutterborg makes life easy by allowing you to edit documents online for free. It's easy to get started - just click an option from the list on the right.","font-size:110%; font-weight:normal; display:block; width:300px; border-width:0;");
	app.Controls.Add(app.exp);
	app.exp.setPosition(10,55);
	
	
	app.tasks = new app.Controls.Panel("height:114px; width:220px; background:#FFF; border:1px solid #888; padding:0; margin:0; cursor:pointer;");
	app.Controls.Add(app.tasks);
	app.tasks.setPosition(325,50);
	
	app.tasks.newDoc = new app.Controls.Panel("height:38px; color:#999; background:url('/images/selected-bg.jpg') -100px -100px repeat-x #FFF; border:none;");
	app.tasks.newDoc.onclick.push(function(e,control){ Shutterborg.CreateNew(); if(window.pageTracker) window.pageTracker._trackPageview("/new-doc"); });
	app.tasks.newDoc.onmouseover.push(function(e,control){ control.setStyle({ "backgroundPosition":"0 0" , "color":"#FFF" }); });
	app.tasks.newDoc.onmouseout.push(function(e,control){ control.setStyle({ "backgroundPosition":"-100px -100px" , "color":"#999" }); });
	app.tasks.Controls.Add(app.tasks.newDoc);
	
	app.tasks.newDoc.img = new app.Controls.Image("/images/icons/new.png",32,32,null,false);
	app.tasks.newDoc.Controls.Add(app.tasks.newDoc.img);
	app.tasks.newDoc.img.setPosition(5,3);
	
	app.tasks.newDoc.text = new app.Controls.Label("New Document","border:none; font-size:180%; margin-top:-1em;");
	app.tasks.newDoc.Controls.Add(app.tasks.newDoc.text);
	app.tasks.newDoc.text.setPosition(42,27);
	
	
	app.tasks.localDoc = new app.Controls.Panel("height:38px; color:#999; background:url('/images/selected-bg.jpg') -100px -100px repeat-x #FFF; border:none;");
	app.tasks.localDoc.onclick.push(function(e,control){ Shutterborg.OpenFromDisk(); if(window.pageTracker) window.pageTracker._trackPageview("/from-disk"); });
	app.tasks.localDoc.onmouseover.push(function(e,control){ control.setStyle({ "backgroundPosition":"0 0" , "color":"#FFF" }); });
	app.tasks.localDoc.onmouseout.push(function(e,control){ control.setStyle({ "backgroundPosition":"-100px -100px" , "color":"#999" }); });
	app.tasks.Controls.Add(app.tasks.localDoc);
	
	app.tasks.localDoc.img = new app.Controls.Image("/images/icons/disk.png",32,32,null,false);
	app.tasks.localDoc.Controls.Add(app.tasks.localDoc.img);
	app.tasks.localDoc.img.setPosition(5,3);
	
	app.tasks.localDoc.text = new app.Controls.Label("Open from Disk","border:none; font-size:180%; margin-top:-1em;");
	app.tasks.localDoc.Controls.Add(app.tasks.localDoc.text);
	app.tasks.localDoc.text.setPosition(42,27);
	
	
	app.tasks.sorgDoc = new app.Controls.Panel("height:38px; color:#999; background:url('/images/selected-bg.jpg') -100px -100px repeat-x #FFF; border:none;");
	app.tasks.sorgDoc.onclick.push(function(e,control){ Shutterborg.OpenFromWeb(); if(window.pageTracker) window.pageTracker._trackPageview("/from-web"); });
	app.tasks.sorgDoc.onmouseover.push(function(e,control){ control.setStyle({ "backgroundPosition":"0 0" , "color":"#FFF" }); });
	app.tasks.sorgDoc.onmouseout.push(function(e,control){ control.setStyle({ "backgroundPosition":"-100px -100px" , "color":"#999" }); });
	app.tasks.Controls.Add(app.tasks.sorgDoc);
	
	app.tasks.sorgDoc.img = new app.Controls.Image("/images/icons/web.png",32,32,null,false);
	app.tasks.sorgDoc.Controls.Add(app.tasks.sorgDoc.img);
	app.tasks.sorgDoc.img.setPosition(5,3);
	
	app.tasks.sorgDoc.text = new app.Controls.Label("Open from Web","border:none; font-size:180%; margin-top:-1em;");
	app.tasks.sorgDoc.Controls.Add(app.tasks.sorgDoc.text);
	app.tasks.sorgDoc.text.setPosition(42,27);
	
	app.btnloader = new app.Controls.Button("About");
	app.btnloader.setPosition(-999,-999);
	app.Controls.Add(app.btnloader);
	
	app.onFormFocus.push(function(app){
		if(Shutterborg.openFromWebApp && Shutterborg.openFromWebApp.Controls)
			Shutterborg.openFromWebApp.focus();
	});
	
	app.init();
};


window.ShowSharing = function() {
	var app2 = new Application("Blog", 56, 72, 8, 4, null, null, null, null, "none");
	app2.setBackground("none");
	app2.form.style.textAlign="center";
	
	var p = new app2.Controls.Panel("width:56px; height:72px; background:none; border:none; z-index:10; cursor:pointer;");
	p.setPosition(0,0);
	p.onclick.push(function(){ window.open("http://blog.shutterb.org/"); });
	p.onmouseover.push(function(e,control){ control.parentApplication.img.setStyle({ border:"2px solid #AAA" , backgroundPosition:"center top" , padding:"2px" }); control.parentApplication.btn.setStyle({ backgroundPosition:"center bottom" , color:"#FFF" }); });
	p.onmouseout.push(function(e,control){ control.parentApplication.img.setStyle({ border:"none" , backgroundPosition:"-999em -999em" , padding:"4px" }); control.parentApplication.btn.setStyle({ backgroundPosition:"0 -999em" , color:"#444" }); });
	app2.Controls.Add(p);
	
	app2.img = new app2.Controls.Image("/images/icons/blog.png",32,32);
	app2.img.setStyle({ display:"block" , position:"relative" , float:"none" , margin:"6px 8px 4px" , border:"none" , background:"url('/images/loading-bezel.png') -999em -999em no-repeat" , padding:"4px" , MozBorderRadius:"4px" , WebkitBorderRadius:"4px" });
	app2.Controls.Add(app2.img);
	
	app2.btn = new app2.Controls.Label("Blog");
	app2.btn.setStyle({ display:"inline" , fontWeight:"bold" , position:"relative" , padding:"0 8px" , border:"none" , color:"#444" , background:"url('/images/selected-bg.jpg') 0 -999em repeat-x #BBB" , MozBorderRadius:"5px" , WebkitBorderRadius:"5px" });
	app2.Controls.Add(app2.btn);
	
	app2.init();
	
	
	
	
	var iconsize = 32;
	var u = encodeURIComponent("http://shutterb.org/");
	var t = encodeURIComponent(document.title);
	var services = [
		{ name:"twitter"	, icon : "twitter"	, newwin : true,	url : "http://twitter.com/home?status=I'm checking out the Shutterborg online word processor - "+u },
		{ name:"addthis"	, icon : "addthis"	, newwin : false,	url : "http://www.addthis.com/bookmark.php?wt=nw&pub=developit&url="+u+"&title="+t },
		{ name:"digg"		, icon : "digg"		, newwin : true,	url : "http://digg.com/submit?phase=2&url="+u+"&title="+t },
		{ name:"delicious"	, icon : "delicious", newwin : false,	url : "http://del.icio.us/post?v=4&noui&jump=close&url="+u },
		{ name:"igoogle"	, icon : "google"	, newwin : false,	url : "http://www.google.com/bookmarks/mark?op=edit&output=popup&bkmk="+u+"&title="+t },
		{ name:"reddit"		, icon : "reddit"	, newwin : false,	url : "http://reddit.com/submit?url="+u+"&title="+t },
		{ name:"myyahoo"	, icon : "yahoo"	, newwin : true,	url : "http://myweb.yahoo.com/myresults/bookmarklet?t="+t+"&u="+u+"&ei=UTF" },
		{ name:"live"		, icon : "live"		, newwin : true,	url : "https://favorites.live.com/quickadd.aspx?marklet=1&mkt=en-us&url="+u+"&title="+t+"&top=1" }
	];
	
	
	var leftTextWidth = 140;
	
	var winW = window.innerWidth?window.innerWidth:(document.documentElement?document.documentElement:document.body).offsetWidth;
	var app = new Application("Share", (iconsize+4)*7 + leftTextWidth, iconsize+12, null, null, null, null, null, null, "none");
	app.blogapp = app2;
	app.moveTo(winW-app.getWidth(),0);
	app.setBackground("none");
	app.DisableMaximize();
	app.DisableMinimize();
	app.onFormFocus.push(function(app){ app.blogapp.focus(); });
	app.onclose.push(function(app){ Shutterborg.sharingwin=null; });
	app.onclose.push(function(app){ app.blogapp.Close(); if(!Shutterborg || Shutterborg.editors.length==0) window.ShowSharing(); });
	Shutterborg.sharingwin = app;
	
	var icon;
	for(var x=0; x<services.length; x++) {
		icon = new app.Controls.Image("/images/sharing/"+services[x].icon+".png",iconsize,iconsize,"left",true,50);
		icon.setStyle({ cursor:"pointer" , margin:"6px 2px 0" , left:"-"+(iconsize/8)+"px" });
		if(x===0) {
			icon.setStyle({paddingLeft:leftTextWidth+'px'});
		}
		icon.onmouseover.push(function(e,control){ control.setOpacity(100); });
		icon.onmouseout.push(function(e,control){ control.setOpacity(50); });
		icon.onclick.push(function(e,control){
			if(control._newwin==true) {
				var win=window.open(control._url,control._name,"status=no,toolbars=no,toolbar=no");
				win.moveTo(1,1);
				win.moveTo(0,0);
				win.resizeTo(800,600);
			}
			else
				Shutterborg.ShowBrowser(control._url,control._name);
		});
		icon._newwin = services[x].newwin==true;
		icon._url = services[x].url;
		icon._name = services[x].name;
		app.Controls.Add(icon);
	}
	
	app.exp = new app.Controls.Label("Love Shutterborg?<br />Spread the word:","display:block; border:none; color:#DDD; text-align:right; width:"+(leftTextWidth-10)+"px; font-weight:bold; font-size:13px; text-shadow:0 1px 3px #000; -moz-text-shadow:0 1px 3px #000; -webkit-text-shadow:0 1px 3px #000;");
	app.Controls.Add(app.exp);
	app.exp.setPosition(0, app.getHeight()/2-app.exp.getHeight()/2);
	
	app.init();
};






window.ShowAds = function() {
	var debugLineStart = 0;
	var app = new Application("Sponsors", (125+2)*4, (125+2)*1, null, null, null, null, null, null, "none");
	var winH = window.innerHeight?window.innerHeight:(document.documentElement?document.documentElement:document.body).offseHeight;
	app.moveTo(0,winH-app.getHeight());
	app.setBackground("none");
	app.setOpacity(50);
	app.DisableMaximize();
	app.DisableMinimize();
	app.onclose.push(function(app){ Shutterborg.adwin=null; });
	app.onclose.push(function(app){ if(!Shutterborg || Shutterborg.editors.length==0) window.ShowAds(); });
	Shutterborg.adwin = app;
	
	app.mainArea = new app.Controls.Label("","text-align:left; display:block; position:absolute; width:100%; height:100%; border:none; background:none; margin:0; padding:0;");
	app.mainArea.onmouseover.push(function(e,control) { control.parentApplication.setOpacity(100); });
	app.mainArea.onmouseout.push(function(e,control) { control.parentApplication.setOpacity(50); });
	app.Controls.Add(app.mainArea);
	
	/*
	function r(){
		if(this.error==true)
			return this.parentApplication.mainArea.setText("Error loading ads. I guess it's free today :)");
		this.parentApplication.mainArea.setText(this.data);
	}
	app.req = HttpRequest.create("/include/adserve.php",null,r,r).Send();
	app.req.parentApplication = app;
	*/
	
	app.mainArea.setText("<a href=\"http://www.zagg.com/\" target=\"_blank\" onmousedown=\"return false;\" onmouseup=\"return false;\" onclick=\"window.open('http://www.anrdoezrs.net/6d103tenkem155BA68B13276485B'); return false;\" style=\"margin:2px;\"><img src=\"http://www.awltovhc.com/rf121g04tzxIMMSRNPSIKJONLPMS\" alt=\"\" border=\"0\"/></a>");
	
	app.init();
	
	// <a href="http://www.adbrite.com/mb/landing_both.php?spid=114376&afb=110x32-2"><img src="http://files.adbrite.com/mb/images/110x32-2.gif" border="0"></a>
};







window._shutterborg_oldresize = window.onresize ? window.onresize : function(){};
window.onresize = function() {
	var winW = window.innerWidth?window.innerWidth:(document.documentElement?document.documentElement:document.body).offsetWidth;
	var winH = window.innerHeight?window.innerHeight:(document.documentElement?document.documentElement:document.body).offseHeight;
	Shutterborg.windowHeight = winH;
	Shutterborg.windowWidth = winW;
	
	ApplicationFramework.reserveBottom = Shutterborg.statusBar.offsetHeight;
	
	if(window.Shutterborg && window.Shutterborg.editorWrapper)
		window.Shutterborg.editorWrapper.style.height = (winH-Shutterborg.statusBar.offsetHeight)+"px";
	
	for(var x=0; x<Shutterborg.editors.length; x++)
		window.Shutterborg_resize.apply(Shutterborg.editors[x], []);
	
	if(window.Shutterborg && Shutterborg.adwin && Shutterborg.adwin.moveTo)
		Shutterborg.adwin.moveTo( 0 , winH-Shutterborg.adwin.getHeight()-Shutterborg.statusBar.offsetHeight );
	if(window.Shutterborg && Shutterborg.sharingwin && Shutterborg.sharingwin.moveTo)
		Shutterborg.sharingwin.moveTo( winW-Shutterborg.sharingwin.getWidth() , 0 );
	
	window._shutterborg_oldresize();
};

window.Shutterborg_resize = function() {
	this.baseArea.style.height = (Shutterborg.windowHeight-Shutterborg.statusBar.offsetHeight)+"px";
	
	var oldView = this.view;
	this.codeview.style.display = "block";
	this.codeMenuBar.style.display = "block";
	var codeViewTop = this.codeMenuBar.offsetHeight;
	this.codeview.style.top = codeViewTop+"px";
	this.codeview.style.height = (this.baseArea.offsetHeight-codeViewTop)+"px";
	this.codeview.style.display = "none";
	this.codeMenuBar.style.display = "none";
	
	this.htmlview.style.display = "block";
	this.designMenuBar.style.display = "block";
	var designViewTop = this.designMenuBar.offsetHeight;
	this.htmlview.style.top = designViewTop+"px";
	this.htmlview.style.height = (this.baseArea.offsetHeight-designViewTop)+"px";
	
	this.view = "design";
	
	if(this.codeview.style.display=="block" && this.htmlview.style.display=="block") {
		this.codeview.style.top = (codeViewTop+designViewTop)+"px";
		this.codeview.style.height = (this.baseArea.offsetHeight-this.controlPanel.offsetHeight)/2+"px";
		this.htmlview.style.top = (this.codeview.offsetHeight+this.codeview.offsetTop+3)+"px";
		this.htmlview.style.height = ((this.baseArea.offsetHeight-this.controlPanel.offsetHeight)/2-3)+"px";
	}
	
	if(oldView!="design")
		this.toCodeView();
};



window.onbeforeunload = function() {
	if(Shutterborg.editors.length>0 && Shutterborg.editors[0].value.replace(/\<br \/\>/mgi,"").length>0 && Shutterborg.editors[0].htmlview.contentWindow.document.body.innerHTML.replace(/\<br \/\>/mgi,"").length>0)
		return '\n\n----------Shutterborg---------\nReally Exit Shutterborg?\nYou will lose any unsaved work.\n\nClick cancel to return to your document.\n-----------------------------\n\n';
};






window.ShutterborgClass = function() {
	this.version = "1.5.3";
	this.editors = [];
	this.editor_current = 0;
	this.loaded = false;
};

ShutterborgClass.prototype.init = function() {
	this.loaded = true;
	
	if(document.all	&& document.body.filters && !window.opera && parseFloat(navigator.appVersion)<8)
		this.setOpacity = function(el,o) { el.style.filter="alpha(opacity="+Math.round(o)+")"; };
	else
		this.setOpacity = function(el,o) { el.style.opacity=Math.round(o)/100; };
	
	document.getElementById("main_desc").style.top = "-999em";
	
	this.statusBar = document.getElementById("editor_statusbar");
	this.editorWrapper = document.getElementById("editor_placeholder");
	this.loading_cover = document.getElementById("loading_cover");
	this.loading_bezel = document.getElementById("loading_bezel");
	this.loading_bezel_text = document.getElementById("loading_bezel_text");
	
	var winW = window.innerWidth?window.innerWidth:(document.documentElement?document.documentElement:document.body).offsetWidth;
	var winH = window.innerHeight?window.innerHeight:(document.documentElement?document.documentElement:document.body).offseHeight;
	Shutterborg.windowHeight = winH;
	Shutterborg.windowWidth = winW;
	
	window.ShowSharing();
	//window.ShowAds();
	window.ShowWizard();
	
	this.preloadImages = [
		"/images/overlay-gradient.png",
		"/images/icons/new.png",
		"/images/icons/disk.png",
		"/images/icons/web.png"
	];
	this.imagesPreloaded = 0;
	var imgs = [];
	for(var x=0; x<this.preloadImages.length; x++) {
		imgs[x] = new Image();
		imgs[x].onload = imgs[x].onerror = function() {
			Shutterborg.imagesPreloaded++;
			if(Shutterborg.imagesPreloaded >= Shutterborg.preloadImages.length) {
				// init sequence
				Shutterborg.HideBezel(function(){ Shutterborg.HideCover(null,50); },100);
				var test = document.createElement("div");
				test.style.cssText = "position:absolute; left:-999em; top:-999em; width:100px; height:100px;";
				document.body.appendChild(test);
				Shutterborg._editor_preloader = test;
				var e = new Editor("shutterborg_editor_preloader_"+Math.floor(Math.random()*999999), "<br />", "http://shutterb.org/themes/default/style.css", null, "utf-8", "", ["imageuploader"], null);
				e.AppendTo(test);
				window.setTimeout("document.body.removeChild(Shutterborg._editor_preloader);",1000);
			}
		}
		imgs[x].src = this.preloadImages[x];
	}
	
	if(location.href.indexOf("?open=")>-1 || location.href.indexOf("#open=")>-1)
		window.setTimeout(function(){Shutterborg.LoadPageFromURL();},500);
};

ShutterborgClass.prototype.LoadPageFromURL = function() {
	if(location.href.indexOf("?open=")>-1)
		var url = location.href.substring(location.href.indexOf("?open=")+6,location.href.length);
	else if(location.href.indexOf("#open=")>-1)
		var url = location.href.substring(location.href.indexOf("#open=")+6,location.href.length);
	if(url.length>3) {
		url = decodeURIComponent(url.replace(/\&.+$/,''));
		var saveto = decodeURIComponent(location.href.substring(location.href.indexOf("&saveto=")+8, location.href.length).replace(/\&.+$/,''));
		if(saveto.length<4) {
			var saveto = null;
		}
		var w = Shutterborg.OpenFromWeb();
		w.inputfield.setText(url.replace(/</mgi,'&lt;').replace(/>/mgi,'&gt;'));
		Shutterborg.OpenFromWeb(url.replace(/</mgi,'&lt;').replace(/>/mgi,'&gt;'),w,{
			saveto	: saveto,
			simplesave	: (saveto?true:false),
			nocover : true
		});
	}
};

ShutterborgClass.prototype.ShowWizard = function() {
	return window.ShowWizard();
};

ShutterborgClass.prototype.ShowSharing = function() {
	return window.ShowSharing();
};

ShutterborgClass.prototype.CreateNew = function(args) {
	if(!args || !args.constructor || (args.constructor!=Object && args.constructor!=Function)) 
		args = {};
	
	if(args.nofocus!=true && this.editors.length==1 && this.editors[0].value.replace("<br />","").length==0) {
		this.editors[0].htmlview.focus();
		return false;
	}
	
	this.createnew_editor = new Editor("shutterborg_editor_"+this.editors.length, args.value?args.value:"<br />", args.stylesheet?args.stylesheet:"http://shutterb.org/themes/default/style.css", null, args.encoding?args.encoding:"UTF-8", "", ["imageuploader","insert-html"], null, "/include/editor.js/");
	this.createnew_editor.enableFullDocument = true;
	if(args.baseurl && args.baseurl.length && args.baseurl.length>0)
		this.createnew_editor.setBaseURL(args.baseurl);
	this.createnew_args = args;
	
	if(args.nocover==true)
		this.createnew_complete();
	else {
		this.ShowCover(function(){
			this.createnew_complete();
			window.setTimeout("Shutterborg.HideLoading(); Shutterborg.HideCover();", 100);
		});
	}
	
	return this.createnew_editor;
};
ShutterborgClass.prototype.createnew_complete = function() {
	var editor = this.createnew_editor;
	var args = this.createnew_args;
	
	var ph = document.getElementById("editor_placeholder");
	
	var form = document.createElement("form");
	form.className = "editor_parentform";
	form.setAttribute("action", args.saveto || "/download/");
	form.setAttribute("method", "post");
	ph.appendChild(form);
	
	editor.enableCleanHTML = true;
	editor.parentForm = form;
	
	var items = {};
	if(args.simplesave===true) {
		items["Save"] = function(){ Shutterborg.Save(this.editor); };
	}
	else {
		items["Save as HTML"] = function(){ Shutterborg.Save(this.editor,"HTML"); };
		items["Save as PDF"] = function(){ Shutterborg.Save(this.editor,"PDF"); };
		items["Save as DOC"] = function(){ Shutterborg.Save(this.editor,"DOC"); };
	}
	var items2 = {
		"saparator1"		: "separator",
		"New Document"		: function(){ Shutterborg.ShowWizard(); },
		"Close Document"	: function(){ Shutterborg.CloseCurrent(); },
		"saparator2"		: "separator",
		"Feedback / Bugs"	: function(){ Shutterborg.FeedbackForm(); },
		"About developIT"	: function(){ Shutterborg.AboutDevelopit(); },
		"Load Drawing Plugin": function(){ this.editor.LoadPlugin("/include/editor.js/plugins/drawing.plugin"); }
	};
	for(var p in items2) {
		if(items2.hasOwnProperty(p)) {
			items[p] = items2[p];
		}
	}
	editor.AddMenu("File", items, function(){  }, "both", editor.designMenuBar.menus["Edit"]);
	
	
	editor.AddMenu("Switch", {
		"Next Document"		: function(){ Shutterborg.SwitchEditor("next"); },
		"Previous Document"	: function(){ Shutterborg.SwitchEditor("prev"); },
		"New Document"		: function(){ Shutterborg.ShowWizard(); },
		"Close Document"	: function(){ Shutterborg.CloseCurrent(); },
		"separator1"		: "separator"
	}, function(){
		var e,t;
		for(var x=0; x<Shutterborg.editors.length; x++) {
			t = Shutterborg.editors[x].title ? Shutterborg.editors[x].title : "Untitled Document"
			e = this.AddItem(t.length>30?(t.substring(0,28)+"..."):t, function(){
				Shutterborg.SwitchEditor(this.__assoc_editor);
			});
			e.__assoc_editor = x;
			this.editor.AddClass(e,"switch__doc");
			if(Shutterborg.editors[x]==Shutterborg.editor_current)
				this.editor.AddClass(e,"active");
			else
				this.editor.AddClass(e,"inactive");
		}
	}, "design", editor.designMenuBar.menus["Edit"]);
	
	editor.AppendTo(form);
	if(args.nofocus!=true)
		window.setTimeout("Shutterborg.editors["+this.editors.length+"].htmlview.focus();", 100);
	this.editors.push(editor);
	this.SwitchEditor(this.editors.length-1);
	
	editor.shutterborg_filetypefield = document.createElement("input");
	editor.shutterborg_filetypefield.setAttribute("type","hidden");
	editor.shutterborg_filetypefield.setAttribute("value","html");
	editor.shutterborg_filetypefield.setAttribute("name","document_type");
	form.appendChild(editor.shutterborg_filetypefield);
	
	editor.shutterborg_filenamefield = document.createElement("input");
	editor.shutterborg_filenamefield.parentEditor = editor;
	editor.shutterborg_filenamefield.setAttribute("type","text");
	editor.shutterborg_filenamefield.setAttribute("value",args.name?args.name:"Untitled Document");
	editor.shutterborg_filenamefield.setAttribute("name","document_name");
	editor.shutterborg_filenamefield.className = "shutterborg_filenamefield";
	editor.shutterborg_filenamefield.onfocus = function(){ this.className = this.className.replace(/\s+focussed/mgi,"")+" focussed"; };
	editor.shutterborg_filenamefield.onblur = function(){ this.className = this.className.replace(/\s+focussed/mgi,""); };
	editor.shutterborg_filenamefield.onchange = function(){
		this.parentEditor.title = this.value;
		if(this.parentEditor.view=="code")
			this.parentEditor.codeview.value = this.parentEditor.codeview.value.replace(/\<title\>.*?<\/title\>/mgi,"<title>"+this.value+"</title>");
		else
			this.parentEditor.setValue(this.parentEditor.htmlview.getValue(),"code");
	};
	editor.shutterborg_filenamefield.onkeyup = function(){ this.onchange(); };
	editor.shutterborg_filenamefield.onmouseup = function(){ this.onchange(); };
	form.appendChild(editor.shutterborg_filenamefield);
	
	editor.ontitlechanged.push(function(title){
		this.shutterborg_filenamefield.value = title;
	});
	
	window.onresize();
	
	if(this.wizard && this.wizard.Controls)
		this.wizard.Close();
	if(this.sharingwin && this.sharingwin.Controls)
		this.sharingwin.Close();
	if(this.adwin && this.adwin.Controls)
		this.adwin.Close();
};


ShutterborgClass.prototype.CloseCurrent = function() {
	var editor = null;
	for(var x=0; x<this.editors.length; x++)
		if(this.editors[x]==this.editor_current)
			editor = x;
	this.editor_current.parentForm.parentNode.removeChild(this.editor_current.parentForm);
	this.editors.splice(editor,1);
	
	if(editor>0 && this.editors.length>0)
		this.editor_current = this.editors[editor-1];
	else if(this.editors.length>0)
		this.editor_current = this.editors[0];
	else {
		this.ShowSharing();
		this.ShowWizard();
	}
};


ShutterborgClass.prototype.SwitchEditor = function(index) {
	if(index==null || index=="undefined")
		return false;
	
	if((index+"").toLowerCase()=="next") {
		index = null;
		for(var x=0; x<this.editors.length; x++)
			if(this.editors[x]==this.editor_current)
				index = x;
		if(index==null || index=="undefined")
			return false;
		else if(index>=this.editors.length-1)
			index = 0;
		else
			index++;
	}
	if((index+"").toLowerCase().substring(0,4).replace("back","prev")=="prev") {
		index = null;
		for(var x=0; x<this.editors.length; x++)
			if(this.editors[x]==this.editor_current)
				index = x;
		if(index==null || index=="undefined")
			return false;
		else if(index==0)
			index = this.editors.length-1;
		else
			index--;
	}
	
	if(index>=0 && index<this.editors.length) {
		for(var x=0; x<this.editors.length; x++)
			this.editors[x].parentForm.style.zIndex = x==index ? "110" : "100";
		
		this.editor_current = this.editors[index];
		
		window.onresize();
	}
};


ShutterborgClass.prototype.OpenFromDisk = function() {
	alert("The <strong>Open from Disk</strong> feature is currently under development. While we're finishing this feature, it is still possible to copy and paste (or drag!) documents open in any other application into the design view.","Coming Soon!");
	return false;
};


ShutterborgClass.prototype.OpenFromWeb = function(location,dialog,args) {
	if(location==null || location=="undefined") {
		if(this.openFromWebApp && this.openFromWebApp.Controls)
			return false;
		var app = new Application("Enter a Web Address", 500, 100, null,null,null,null,null,null,"fixed");
		if(app.DisableMaximize)
			app.DisableMaximize();
		if(app.DisableMinimize)
			app.DisableMinimize();
		app.moveBy(0,-80);
		this.openFromWebApp = app;
		
		app.onFormFocus.push(function(app){
			app.inputfield.focus();
		});
		
		app.explainer = new app.Controls.Label("Enter the URL of a document you want to open:", "display:block; margin:5px; padding:3px;");
		app.Controls.Add(app.explainer);
		
		app.inputfield = new app.Controls.TextInput("","display:block; width:"+(app.getWidth()-16)+"px; font-size:16px; text-align:left; font-weight:normal; margin:5px; padding:3px;");
		app.inputfield.onkeyup.push(function(e,control){
			var key = e.keyCode?e.keyCode:e.which;
			if(control.text.length>4 && control.text.indexOf(".")>0 && control.text.indexOf(".")<control.text.length-2)
				control.parentApplication.openbtn.Enable();
			else
				control.parentApplication.openbtn.Disable();
			if(key==13)
				control.parentApplication.Finish();
			else if(key==27)
				control.parentApplication.Close();
		});
		app.Controls.Add(app.inputfield);
		
		app.messagebox = new app.Controls.Label("","display:none; margin:5px; padding:3px; border:1px solid #833; background:#EDD; overflow:hidden;");
		app.Controls.Add(app.messagebox);
		
		app.openbtn = new app.Controls.Button(" Open ","position:absolute; top:auto; left:auto; bottom:5px; right:5px;");
		app.openbtn.Disable();
		app.openbtn.onclick.push(function(e,control){ control.parentApplication.Finish(); });
		app.Controls.Add(app.openbtn);
		
		app.cancelbtn = new app.Controls.Button("Cancel","position:absolute; top:auto; left:5px; bottom:5px; right:auto;");
		app.cancelbtn.onclick.push(function(e,control){ control.parentApplication.Close(); });
		app.Controls.Add(app.cancelbtn);
		
		app.ShowCannotFindMessage = function() {
			if(this.messagevisible==true) {
				this.messagebox.setStyle({ visibility:"hidden" });
				window.setTimeout("ApplicationFramework.getApplicationById("+this.appid+").messagebox.setStyle({ visibility:'visible' });", 100);
				window.setTimeout("ApplicationFramework.getApplicationById("+this.appid+").messagebox.setStyle({ visibility:'hidden' });", 200);
				window.setTimeout("ApplicationFramework.getApplicationById("+this.appid+").messagebox.setStyle({ visibility:'visible' });", 300);
				return false;
			}
			this.messagevisible = true;
			this.messagebox.setText("Shutterborg can't load that page. If you're absolutely sure it exists, it might be guarded by an authentication gateway. In that case, just copy and paste the file, or even drag and drop the bits you want into a new document.");
			this.messagebox.setStyle({ visibility:"hidden" , display:"block" });
			var h = this.messagebox.getHeight()-6;
			var max = h/2;
			this.messagebox.setStyle({ height:"0" , visibility:"visible" });
			for(var x=0; x<max; x++)
				window.setTimeout("var app=ApplicationFramework.getApplicationById("+this.appid+"); app.messagebox.setStyle({height:'" + Math.round((Math.sin(Math.PI*(x/max-1/2))+1)/2*h, 2) + "px'}); app.resizeTo(null," + Math.round(this.getHeight()+(Math.sin(Math.PI*(x/max-1/2))+1)/2*h,2) + ");", x*15);
		};
		
		app.Finish = function() {
			if(this.working==true || this.openbtn.disabled==true)
				return false;
			this.working = true;
			var location = this.inputfield.text;
			if(location.length==0 || location=="http://" || location=="about:blank;" || location.replace(/[(a-z)]+/mgi,"").length==location.length)
				return this.ShowCannotFindMessage();
			
			if(location.indexOf("://")==-1 || location.indexOf("://")>7)
				location = "http://" + location;
			Shutterborg.OpenFromWeb(location,this,args);
		};
		
		app.onclose.push(function(app) {
			if(app.req && app.working==true)
				try{ app.req.Abort(); }catch(e){}
			if(Shutterborg.openFromWebApp == app)
				Shutterborg.openFromWebApp = null;
		});
		
		app.onresize.push(function(app,w,h) {
			app.inputfield.setStyle({ width:(w-16)+"px" });
		});
		
		app.init();
		app.inputfield.focus();
		
		return app;
	}
	
	Shutterborg.ShowLoading();
	
	function onComplete() {
		this.dialog.working = false;
		if(this.error==true || this.status>=300 || this.status==0 || !this.data || this.data.replace(/[\s]+/mgi,"").length<2) {
			Shutterborg.HideLoading();
			this.dialog.ShowCannotFindMessage();
			return true;
		}
		
		var origBase = unescape(this.url.replace(/^\/from\-web\/\?/mgi,""));
		var reg = new RegExp(/(?:\<meta\s+http\-equiv\s*=\s*"\s*content\-type\s*"\s+content\s*=\s*".*?charset\s*=\s*)(.*?)(?:"\s*\/?\s*\>)/mgi);
		
		//var matches = reg.exec(this.data);
		// force utf-8 encoding:
		this.data = this.data.replace(reg,"");
		var matches = [];
		
		Shutterborg.ofw_encoding = (matches && matches.length>1 && matches[1].length>1) ? (matches[1]+"") : "utf-8";
		Shutterborg.ofw_origBase = origBase;
		Shutterborg.ofw_doc = this.data;
		Shutterborg.ofw_dialog = this.dialog;
		
		var args = this._args || {};
		
		Shutterborg.ShowCover(function(){
			var docName = "Untitled Document";
			if(this.ofw_doc.indexOf("<title>")>-1) {
				var t=document.createElement("textarea");
				t.innerHTML = this.ofw_doc.substring(this.ofw_doc.indexOf("<title>")+7, this.ofw_doc.indexOf("</title>",this.ofw_doc.indexOf("<title>")+7)).replace(/[\<\>\"\']+/mgi,"");
				document.body.appendChild(t);
				docName = t.value+"";
				document.body.removeChild(t);
			}
			var configs = { name:docName , nocover:true , encoding:this.ofw_encoding , baseurl:this.ofw_origBase , value:this.ofw_doc , stylesheet:"http://shutterb.org/themes/none/style.css" };
			if(args) {
				for(var p in args) {
					if(args.hasOwnProperty(p)) {
						configs[p] = args[p];
					}
				}
			}
			var editor = Shutterborg.CreateNew(configs);
			this.ofw_dialog.Close();
			window.setTimeout("Shutterborg.HideLoading(function(){ Shutterborg.HideCover(); });", 250);
		});
	}
	var req = HttpRequest.create("/from-web/?"+escape(location),null,onComplete,onComplete).Send();
	dialog.req = req;
	req.dialog = dialog;
	req._args = args;
};




ShutterborgClass.prototype.Save = function(editor, type) {
	var types = {
		"html"	: "HTML Document",
		"pdf"	: "PDF Document",
		"doc"	: "MS Word Document"
	};
	if(type==null || type=="undefined" || !types[(type+"").toLowerCase()])
		type = "html";
	type = type.toLowerCase();
	
	window.oldbeforeunload=window.onbeforeunload; window.onbeforeunload=function(){}; 
	editor.shutterborg_filetypefield.value = type;
	editor.parentForm.submit();
	window.onbeforeunload=window.oldbeforeunload;
};





ShutterborgClass.prototype.FeedbackForm = function() {
	var app = new Application("Give Feedback", 652, 438, null,null,null,null,null,null,"fixed");
	app.browser = new app.Controls.WebBrowser("http://getsatisfaction.com/developit/feedback/topics/new?display=overlay&style=idea","display:block; width:100%; height:100%; border:none; background:url('/include/editor.js/themes/leoparditis/images/loading.gif') center no-repeat #FFF; overflow:hidden;");
	app.browser.baseArea.setAttribute("frameBorder","0");
	app.browser.baseArea.setAttribute("scrolling","no");
	app.Controls.Add(app.browser);
	app.init();
};


/*
ShutterborgClass.prototype.ReportBug = function() {
	var app = new Application("Report a Bug", 652, 438, null,null,null,null,null,null,"fixed");
	app.browser = new app.Controls.WebBrowser("http://getsatisfaction.com/developit/feedback/topics/new?display=overlay&style=problem","display:block; width:100%; height:100%; border:none; background:url('/include/editor.js/themes/leoparditis/images/loading.gif') center no-repeat #FFF; overflow:hidden;");
	app.browser.baseArea.setAttribute("frameBorder","0");
	app.browser.baseArea.setAttribute("scrolling","no");
	app.Controls.Add(app.browser);
	app.init();
};
*/


ShutterborgClass.prototype.AboutDevelopit = function() {
	var about = "developIT is a privately-owned small business based in Waterloo, Ontario, Canada. The owner and creator, Jason Miller, spent several years working with JavaScript, PHP, MySQL, XHTML, and CSS as a hobby before formally initiating the business in 2008. developIT strives on innovation and usability; from creating the first online &quot;mac&quot;-style dock, to integrating user-friendly content management systems into pre-existing websites. Online Operating Systems, Cloud Computing, SEO (Search Engine Optimization), and Linux web hosting are also specialties of developIT.<br /><a href=\"http://developit.ca/\">Visit the developIT Website</a>";
	
	var app = new Application("About developIT", 550, 286);
	app.DisableMinimize();
	app.DisableMaximize();
	
	app.dlogo = new app.Controls.Image("/images/developit.png",128,128,"left",true);
	app.dlogo.setPosition(10,10);
	app.Controls.Add(app.dlogo);
	
	app.slogo = new app.Controls.Image("/images/logo-128.png",128,128,"left",true);
	app.slogo.setPosition(10,148);
	app.Controls.Add(app.slogo);
	
	app.content = new app.Controls.Label(about, "border:1px solid #666; border-bottom-color:#999; background:#FFF; display:block; position:relative; height:"+(app.getHeight()-40)+"px; margin:10px 10px 10px 148px; padding:10px; font-size:120%; overflow:auto;");
	app.Controls.Add(app.content);
	
	app.onresize.push(function(app,w,h){
		app.content.setStyle({ height:(h-40)+"px" });
	});
	
	app.init();
	
	if(window.pageTracker) window.pageTracker._trackPageview("/about-developit");
	
	return app;
};



ShutterborgClass.prototype.ShowBrowser = function(url,title) {
	if(url==null || url=="undefined")
		return false;
	if(title==null || title=="undefined")
		title = "Web";
	var app = new Application(title, 650, 500);
	app.browser = new app.Controls.WebBrowser(url,"display:block; width:100%; height:100%; border:none; background:#FFF;");
	app.browser.baseArea.setAttribute("frameBorder","0");
	app.Controls.Add(app.browser);
	app.init();
	return app;
};



/*
if(document.all	&& document.body.filters && !window.opera && parseFloat(navigator.appVersion)<8)
	ShutterborgClass.prototype.setOpacity = function(el,o) { el.style.filter = "alpha(opacity="+Math.round(o)+")"; };
else
	ShutterborgClass.prototype.setOpacity = function(el,o) { el.style.opacity = Math.round(o)/100; };
*/
ShutterborgClass.prototype.setOpacity = function(el,o) {
	if(document.all	&& document.body.filters && !window.opera && parseFloat(navigator.appVersion)<8)
		el.style.filter = "alpha(opacity="+Math.round(o)+")";
	else
		ShutterborgClass.prototype.setOpacity = function(el,o) { el.style.opacity = Math.round(o)/100; };
};


ShutterborgClass.prototype.ShowCover = function(oncomplete,speed) {
	try{ window.clearTimeout(this._coverTimer); }catch(e){}
	if(this.loading_cover._viz==true)
		return false;
	this.loading_cover._viz = true;
	this.ShowCover_oncomplete = oncomplete?oncomplete:function(){};
	if(!this._coverOpac)
		this._coverOpac = 0;
	this.loading_cover.style.visibility = "visible";
	this._coverTimer = window.setInterval("Shutterborg._coverOpac+="+Math.abs(speed?speed:35)+"; if(Shutterborg._coverOpac>=100){ try{window.clearInterval(Shutterborg._coverTimer);}catch(err){} Shutterborg.setOpacity(Shutterborg.loading_cover,Shutterborg._coverOpac=100); Shutterborg.ShowCover_oncomplete(); } else Shutterborg.setOpacity(Shutterborg.loading_cover,Shutterborg._coverOpac);", 15);
	return true;
};

ShutterborgClass.prototype.HideCover = function(oncomplete,speed) {
	try{ window.clearTimeout(this._coverTimer); }catch(e){}
	if(this.loading_cover._viz==false)
		return false;
	this.loading_cover._viz = false;
	this.HideCover_oncomplete = oncomplete?oncomplete:function(){};
	if(!this._coverOpac)
		this._coverOpac = 100;
	this._coverTimer = window.setInterval("Shutterborg._coverOpac-="+Math.abs(speed?speed:35)+"; if(Shutterborg._coverOpac<=0){ try{window.clearInterval(Shutterborg._coverTimer);}catch(err){} Shutterborg.setOpacity(Shutterborg.loading_cover,Shutterborg._coverOpac=0); Shutterborg.loading_cover.style.visibility='hidden'; Shutterborg.HideCover_oncomplete(); } else Shutterborg.setOpacity(Shutterborg.loading_cover,Shutterborg._coverOpac);", 15);
	return true;
};

ShutterborgClass.prototype.ShowBezel = function(bezelText,oncomplete,speed) {
	try{ window.clearTimeout(this._lbzTimer); }catch(e){}
	if(bezelText!=null && (bezelText+"")!="undefined" && (bezelText+"").length>1)
		this.loading_bezel_text.innerHTML = bezelText+"";
	if(this.loading_bezel._viz==true)
		return false;
	this.loading_bezel._viz = true;
	this.ShowBezel_oncomplete = oncomplete?oncomplete:function(){};
	if(!this._lbzOpac)
		this._lbzOpac = 0;
	this._lbzOpac += Math.abs(speed?speed:25);
	this.loading_bezel.style.visibility = "visible";
	this._lbzTimer = window.setInterval("Shutterborg._lbzOpac+="+Math.abs(speed?speed:25)+"; if(Shutterborg._lbzOpac>85){ try{window.clearInterval(Shutterborg._lbzTimer);}catch(err){} Shutterborg._lbzOpac=100; Shutterborg.ShowBezel_oncomplete(); } Shutterborg.setOpacity(Shutterborg.loading_bezel,Shutterborg._lbzOpac);", 15);
	return true;
};

ShutterborgClass.prototype.HideBezel = function(oncomplete,speed) {
	try{ window.clearTimeout(this._lbzTimer); }catch(e){}
	if(this.loading_bezel._viz==false)
		return false;
	this.loading_bezel._viz = false;
	this.HideBezel_oncomplete = oncomplete?oncomplete:function(){};
	if(this._lbzOpac==null || this._lbzOpac=="undefined" || !this._lbzOpac)
		this._lbzOpac = 100;
	this._lbzOpac -= Math.abs(speed?speed:25);
	this._lbzTimer = window.setInterval("Shutterborg._lbzOpac-="+Math.abs(speed?speed:25)+"; if(Shutterborg._lbzOpac<15){ try{window.clearInterval(Shutterborg._lbzTimer);}catch(err){} Shutterborg._lbzOpac=0; Shutterborg.loading_bezel.style.visibility='hidden'; Shutterborg.HideBezel_oncomplete(); } Shutterborg.setOpacity(Shutterborg.loading_bezel,Shutterborg._lbzOpac);", 15);
	return true;
};

ShutterborgClass.prototype.ShowLoading = function(oncomplete,speed) {
	this.ShowBezel("Loading...",oncomplete,speed);
};

ShutterborgClass.prototype.HideLoading = function(oncomplete,speed) {
	this.HideBezel(oncomplete,speed);
};


Shutterborg = new window.ShutterborgClass();










ApplicationFramework.reserveBottom = 0;

function alert(text,title,returnFunction) {
	var a = new Application(title?title:"Information", 400, 160);
	a.icon = "http://amoebaos.com/images/icons/alert-dialog.png";
	
	a.img = new a.Controls.Image(a.icon, 64, 64, "left", false);
	a.img.setPosition(10,10);
	a.Controls.Add(a.img);
	
	a.t = new a.Controls.Label(text, "border:none; display:block; position:relative; margin:10px 10px 10px 84px;");
	a.Controls.Add(a.t);
	a.ok = new a.Controls.Button("&nbsp;&nbsp;&nbsp;Ok&nbsp;&nbsp;&nbsp;","position:absolute; left:auto; top:auto; bottom:10px; right:10px;");
	a.ok.onclick.push(function(e,control){ control.parentApplication.Close(); });
	a.Controls.Add(a.ok);
	a.resizeTo(null, a.t.getY()+(a.t.getHeight()>64?a.t.getHeight():64)+a.ok.getHeight()+10);
	
	a.onclose.push(function(app){
		if(app.returnFunction && app.returnFunction.constructor==Function)
			app.returnFunction();
	});
	a.returnFunction = returnFunction
	a.init();
	
	return a;
};





























window.HttpRequest = {
	"create"	: function(url,postdata,oncomplete,onerror,autoDelete){ return new this._obj(this,url,postdata,oncomplete,onerror,autoDelete); },
	"stop"		: function(request){ if(request&&request.type=="request") request.abort(); },
	"init"		: function(request,url){ if(request&&request.type=="request"){ request.get(url); } },
	"close"		: function(request){
		if(!request||request.type!="request")
			return false;
		try{ request.abort(); }catch(err){}
		for(var x=0; x<this._requests.length; x++)
			if(this._requests[x]==request)
				this._requests = this._requests.splice(x,1);
		try{ delete request; } catch(err){ request = null; }
	},
	"_obj"		: function(parent,url,postdata,oncomplete,onerror,autoDelete) {
		this.type = "request";
		this.parent = parent;
		this.url = url;
		this.postdata = (postdata && postdata.constructor && (postdata.constructor==Object || postdata.constructor==Function)) ? postdata : {};
		this.poststring = (postdata && typeof(postdata)==String) ? postdata : "";
		this.autoDelete = autoDelete!=false;
		this.data = null;
		this.async = true;
		this.http_code = null;
		this.status = null;
		this.responseText = null;
		this.responseXML = null;
		this.complete = false;
		this.oncomplete = oncomplete?oncomplete:function(){};
		this.onerror = onerror?onerror:function(){};
		this.request = this.parent.XMLHttpRequestObj();
		this.request.parent = this;
		this.request.onreadystatechange = function() {
			this.parent.readyState = this.readyState;
			if(this.readyState==4) {
				this.parent.http_code = this.status;
				this.parent.status = this.status;
				this.parent.responseText = this.responseText;
				this.parent.responseXML = this.responseXML;
				this.parent.data = this.responseText;
				this.parent.complete = true;
				this.parent.error = this.status!=200;
				if(this.status==200 && this.parent.oncomplete)
					try{ this.parent.oncomplete(); }catch(err){ window.setTimeout("throw(new Error(\"request.oncomplete > "+err.toString()+"\"));",1); }
				else if(this.status!=200 && this.parent.onerror)
					try{ this.parent.onerror(); }catch(err){ window.setTimeout("throw(new Error(\"request.oncomplete > "+err.toString()+"\"));",1); }
				if(this.parent.autoDelete==true)
					this.parent.parent.close(this);
			}
		};
		this.get = function(url){
			if(url!=null && url==url+"" && url.length>0)
				this.url = url;
			
			var requrl = this.url;
			/*
			if(this.url.indexOf("://")>-1 && this.url.indexOf("://")<8 && (this.url.toLowerCase().indexOf("://shutterb.org")<0 || this.url.toLowerCase().indexOf("://shutterb.org")>5))
				requrl = "http://shutterb.org/httprequest.php/"+encodeURIComponent(this.url.replace(/^(http|https):\/\//mgi,""));
			
			//requrl = requrl.replace(/(http|https):\/\/shutterb\.org/mgi, document.location.protocol+"\/\/shutterb.org");
			*/
			
			this._poststring = this.poststring?this.poststring:"";
			for(var x in this.postdata)
				this._poststring += "&" + escape(x) + "=" + escape(this.postdata[x]);
			if(this._poststring.indexOf("&")==0)
				this._poststring = this._poststring.substring(1,this._poststring.length);
			this.request.open(this._poststring.length>2?"POST":"GET", requrl, this.async);
			this.request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			try {
				this.request.setRequestHeader("Content-length", this._poststring.length);
				this.request.setRequestHeader("Connection", "close");
			}catch(e){}
			this.request.send(this._poststring.length>2?this._poststring:null);
			return this;
		};
		this.send = this.get;
		this.Send = this.get;
		this.Get = this.get;
		this.abort = function(){
			if(this.readyState!=4)
				return this;
			this._oldOnError = this.onerror;
			this.onerror = function(){};
			this.request.abort();
			this.onerror = this._oldOnError;
			try{ delete this._oldOnError; }catch(e){ this._oldOnError=null; }
			return this;
		};
		this.Abort = this.abort;
		this.cancel = this.abort;
		this.Cancel = this.abort;
		this.stop = this.abort;
		this.Stop = this.abort;
		this.parent._requests.push(this);
	},
	"XMLHttpRequestObj" : function() {
		var xmlHttp=null;
		try { xmlHttp=new XMLHttpRequest(); }
		catch (e) {
			try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }
			catch (e) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
		}
		return xmlHttp;
	},
	"_requests" : []
};
























/*






<script type="text/javascript"><!--
google_ad_client = "pub-7005333511440775";
google_ad_slot = "0559436978";
google_ad_width = 125;
google_ad_height = 125;
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>




*/
