// vars & functions for the dynamic flash content
/*global document, window */

var webhost = document.location.protocol + "//" + document.location.hostname;
// by default webhost is document's host unless loader.js is referenced by an
// absolute path (i.e. from the code for embedded graphs). In that case, the 
// hostname will be extracted from src of the loader.js script

var el = document.getElementsByTagName("script");
for (var i=0; i<el.length; i++) {
    if (el[i].src.lastIndexOf("loader.js") != -1) {
	var re = new RegExp('^(?:f|ht)tp(?:s)?://([^/]+)', 'im');
	var src = el[i].src.match(re);
	if (src) { 
	    //src is absolute path. reset webhost to same domain
	    webhost = src[0].toString();
	}
    }
}

var FLASH_SOURCE = webhost + "/fxeconostats/oandaGraph.swf";
var EXPRESS_INSTALL_SOURCE = webhost + "/shared/flash/expressInstall.swf";

// Note: do NOT remove webhost from jslib_url and img_url below
// because this file can be included by an external web page and having a 
// relative pathname to jslib folder will be resolved incorrectly
var MASTERTABLE_SRC = "/fxecon_app/cgi/fxeconostats/getdelta.pl";
var jslib_url = webhost + "/jslib";
var jslib_shared = webhost + "/shared/jslib";
var img_url = webhost + "/images";
var fxeconostats_url = webhost + "/fxeconostats/";
var maxButtonSrc = img_url + "/icon_maximize_up.gif";
var minButtonSrc = img_url + "/icon_minimize_up.gif";

// the graph embed code should refer to loader.js by absolute path
var loader_source = webhost + "/fxecon_loader.js";

// load the required libs (if not already loaded)
if (!window.Prototype) {
    document.write('<script type="text/javascript" src="'+jslib_shared+'/prototype.js"></script>');
}

if (!window.swfobject) {
    document.write('<script type="text/javascript" src="'+jslib_shared+'/swfobject2.js"></script>');
}

if (!window.LIBVER_COMMON) {
    document.write('<script type="text/javascript" src="'+jslib_url+'/fxeconostats/common.js"></script>');
}

if (!window.LIBVER_FXECONOSTATS) {
    document.write('<script type="text/javascript" src="'+jslib_url+'/fxeconostats/fxeconostats.js"></script>');
}

if (!window.LIBVER_PRINTF) {
    document.write('<script type="text/javascript" src="'+jslib_url+'/fxeconostats/printf.js"></script>');
}
