// look for action key in the calling document
var action = (action ? action : 'none');
var fadeout = (fadeout ? fadeout : 'fadeout');

var svgDiv;

function onLoadSVGFuncs() {
  // call from an external script (onLoadInit is rather generic)
  onLoadInit();
}

function onLoadInit() {
  svgDiv = document.createElement('div');
  initSVG();
}
function initSVG() {
	// functions that pull in an SVG on load.
	try {
		if (new XMLHttpRequest()) {
			asyncInsertDoc(url=svgURL,type='svg');
		}
	}
	catch (e) {
		//stick in the fallback image instead
		img = document.createElement('img');
		img.src = svgURL.fallback;
		img.style.position = 'absolute';
		img.style.left = '10em';
		img.style.top = '2em';
		document.appendChild(img,document.getElementById('svg-div'));
	}
}
function asyncInsertDoc(url,type) {
	// insert SVG: wrapper
	var arequest = new XMLHttpRequest();
	arequest.open('GET', url[type], true);
	arequest.onreadystatechange = function () {insertSVG(arequest,action,fadeout)};
	arequest.send(null);
}
function insertSVG(arequest,action,fadeout) {
	// insert the SVG as a child of another node, adding it to the document
	if (arequest.readyState == 4 && arequest.status == 200) {
		var svgDoc = arequest.responseXML;
		var svg = document.importNode(svgDoc.childNodes[0],1);
		svgDiv.setAttribute('id','svg');
		document.getElementById('svg-div').appendChild(svgDiv);
		svgDiv.appendChild(svg);
	}
}
