var console_debug;
if (typeof(package_console_debug) == 'undefined') {

if (navigator.appVersion.indexOf("MSIE") != -1) {
// log4js-mini from http://log4js.sourceforge.net/
function Log(level,logger,prefix){var _currentLevel=Log.WARN;var _logger=Log.writeLogger;var _prefix=false;this.setPrefix=function(pre){if(pre!='undefined'){_prefix=pre;}
else{_prefix=false;}}
this.setLogger=function(logger){if(logger!='undefined'){_logger=logger;}}
this.setLevel=function(level){if(level!='undefined'&&typeof level=='number'){_currentLevel=level;}else if(level!='undefined'){if(level=='debug'){_currentLevel=Log.DEBUG;}
else if(level=='info'){_currentLevel=Log.INFO;}
else if(level=='error'){_currentLevel=Log.ERROR;}
else if(level=='fatal'){_currentLevel=Log.FATAL;}
else if(level=='warn'){_currentLevel=Log.WARN;}
else{_currentLevel=Log.NONE;}}}
this.getPrefix=function(){return _prefix;}
this.getLogger=function(){return _logger;}
this.getLevel=function(){return _currentLevel;}
if(level!='undefined'){this.setLevel(level);}
if(logger!='undefined'){this.setLogger(logger);}
if(prefix!='undefined'){this.setPrefix(prefix);}}
Log.prototype.debug=function(s){if(this.getLevel()<=Log.DEBUG){this._log(s,"DEBUG",this);}}
Log.prototype.info=function(s){if(this.getLevel()<=Log.INFO){this._log(s,"INFO",this);}}
Log.prototype.warn=function(s){if(this.getLevel()<=Log.WARN){this._log(s,"WARN",this);}}
Log.prototype.error=function(s){if(this.getLevel()<=Log.ERROR){this._log(s,"ERROR",this);}}
Log.prototype.fatal=function(s){if(this.getLevel()<=Log.FATAL){this._log(s,"FATAL",this);}}
Log.prototype._log=function(msg,level,obj){if(this.getPrefix()){this.getLogger()(this.getPrefix()+" - "+msg,level,obj);}else{this.getLogger()(msg,level,obj);}}
Log.DEBUG=1;Log.INFO=2;Log.WARN=3;Log.ERROR=4;Log.FATAL=5;Log.NONE=6;Log.alertLogger=function(msg,level){alert(level+" - "+msg);}
Log.writeLogger=function(msg,level){document.writeln(level+"&nbsp;-&nbsp;"+msg+"<br/>");}
Log.consoleLogger=function(msg,level,obj){if(window.console){window.console.log(level+" - "+msg);}else{Log.popupLogger(msg,level,obj);}}
Log.popupLogger=function(msg,level,obj){if(obj.popupBlocker){return;}
if(!obj._window||!obj._window.document){obj._window=window.open("",'logger_popup_window','width=420,height=320,scrollbars=1,status=0,toolbars=0,resizable=1');if(!obj._window){obj.popupBlocker=true;alert("You have a popup window manager blocking the log4js log popup display.\n\nThis must be disabled to properly see logged events.");return;}
if(!obj._window.document.getElementById('loggerTable')){obj._window.document.writeln("<table width='100%' id='loggerTable'><tr><th align='left'>Time</th><th width='100%' colspan='2' align='left'>Message</th></tr></table>");obj._window.document.close();}}
var tbl=obj._window.document.getElementById("loggerTable");var row=tbl.insertRow(-1);var cell_1=row.insertCell(-1);var cell_2=row.insertCell(-1);var cell_3=row.insertCell(-1);var d=new Date();var h=d.getHours();if(h<10){h="0"+h;}
var m=d.getMinutes();if(m<10){m="0"+m;}
var s=d.getSeconds();if(s<10){s="0"+s;}
var date=(d.getMonth()+1)+"/"+d.getDate()+"/"+d.getFullYear()+"&nbsp;-&nbsp;"+h+":"+m+":"+s;cell_1.style.fontSize="8pt";cell_1.style.fontWeight="bold";cell_1.style.paddingRight="6px";cell_2.style.fontSize="8pt";cell_3.style.fontSize="8pt";cell_3.style.whiteSpace="nowrap";cell_3.style.width="100%";if(tbl.rows.length%2==0){cell_1.style.backgroundColor="#eeeeee";cell_2.style.backgroundColor="#eeeeee";cell_3.style.backgroundColor="#eeeeee";}
cell_1.innerHTML=date
cell_2.innerHTML=level;cell_3.innerHTML=msg;}
Log.dumpObject=function(obj,indent){if(!indent){indent="";}
if(indent.length>20){return;}
var s="{\n";for(var p in obj){s+=indent+p+":";var type=typeof(obj[p]);type=type.toLowerCase();if(type=='object'){s+=Log.dumpObject(obj[p],indent+"----");}else{s+=obj[p];}
s+="\n";}
s+=indent+"}";return s;}
} //if

  package_console_debug = new (function() {
    var log;
    console_debug = function(message) {
      if (navigator.appVersion.indexOf("MSIE") != -1) {
        if (!log) 
          log = new Log(Log.DEBUG, Log.consoleLogger);
        log.debug(message);
      } else {
        console.debug(message);
      }
    }
  })();
}
var FlashHttpRequest_ready;
var FlashHttpRequest_objects;
var FlashHttpRequest_counter;
if (typeof(FlashHttpRequest_counter) == 'undefined'){
/*	SWFObject v2.0 <http://code.google.com/p/swfobject/>
	Copyright (c) 2007 Geoff Stearns, Michael Williams, and Bobby van der Sluis
	This software is released under the MIT License <http://www.opensource.org/licenses/mit-license.php>
*/
var swfobject=function(){var Z="undefined",P="object",B="Shockwave Flash",h="ShockwaveFlash.ShockwaveFlash",W="application/x-shockwave-flash",K="SWFObjectExprInst",G=window,g=document,N=navigator,f=[],H=[],Q=null,L=null,T=null,S=false,C=false;var a=function(){var l=typeof g.getElementById!=Z&&typeof g.getElementsByTagName!=Z&&typeof g.createElement!=Z&&typeof g.appendChild!=Z&&typeof g.replaceChild!=Z&&typeof g.removeChild!=Z&&typeof g.cloneNode!=Z,t=[0,0,0],n=null;if(typeof N.plugins!=Z&&typeof N.plugins[B]==P){n=N.plugins[B].description;if(n){n=n.replace(/^.*\s+(\S+\s+\S+$)/,"$1");t[0]=parseInt(n.replace(/^(.*)\..*$/,"$1"),10);t[1]=parseInt(n.replace(/^.*\.(.*)\s.*$/,"$1"),10);t[2]=/r/.test(n)?parseInt(n.replace(/^.*r(.*)$/,"$1"),10):0}}else{if(typeof G.ActiveXObject!=Z){var o=null,s=false;try{o=new ActiveXObject(h+".7")}catch(k){try{o=new ActiveXObject(h+".6");t=[6,0,21];o.AllowScriptAccess="always"}catch(k){if(t[0]==6){s=true}}if(!s){try{o=new ActiveXObject(h)}catch(k){}}}if(!s&&o){try{n=o.GetVariable("$version");if(n){n=n.split(" ")[1].split(",");t=[parseInt(n[0],10),parseInt(n[1],10),parseInt(n[2],10)]}}catch(k){}}}}var v=N.userAgent.toLowerCase(),j=N.platform.toLowerCase(),r=/webkit/.test(v)?parseFloat(v.replace(/^.*webkit\/(\d+(\.\d+)?).*$/,"$1")):false,i=false,q=j?/win/.test(j):/win/.test(v),m=j?/mac/.test(j):/mac/.test(v);/*@cc_on i=true;@if(@_win32)q=true;@elif(@_mac)m=true;@end@*/return{w3cdom:l,pv:t,webkit:r,ie:i,win:q,mac:m}}();var e=function(){if(!a.w3cdom){return }J(I);if(a.ie&&a.win){try{g.write("<script id=__ie_ondomload defer=true src=//:><\/script>");var i=c("__ie_ondomload");if(i){i.onreadystatechange=function(){if(this.readyState=="complete"){this.parentNode.removeChild(this);V()}}}}catch(j){}}if(a.webkit&&typeof g.readyState!=Z){Q=setInterval(function(){if(/loaded|complete/.test(g.readyState)){V()}},10)}if(typeof g.addEventListener!=Z){g.addEventListener("DOMContentLoaded",V,null)}M(V)}();function V(){if(S){return }if(a.ie&&a.win){var m=Y("span");try{var l=g.getElementsByTagName("body")[0].appendChild(m);l.parentNode.removeChild(l)}catch(n){return }}S=true;if(Q){clearInterval(Q);Q=null}var j=f.length;for(var k=0;k<j;k++){f[k]()}}function J(i){if(S){i()}else{f[f.length]=i}}function M(j){if(typeof G.addEventListener!=Z){G.addEventListener("load",j,false)}else{if(typeof g.addEventListener!=Z){g.addEventListener("load",j,false)}else{if(typeof G.attachEvent!=Z){G.attachEvent("onload",j)}else{if(typeof G.onload=="function"){var i=G.onload;G.onload=function(){i();j()}}else{G.onload=j}}}}}function I(){var l=H.length;for(var j=0;j<l;j++){var m=H[j].id;if(a.pv[0]>0){var k=c(m);if(k){H[j].width=k.getAttribute("width")?k.getAttribute("width"):"0";H[j].height=k.getAttribute("height")?k.getAttribute("height"):"0";if(O(H[j].swfVersion)){if(a.webkit&&a.webkit<312){U(k)}X(m,true)}else{if(H[j].expressInstall&&!C&&O("6.0.65")&&(a.win||a.mac)){D(H[j])}else{d(k)}}}}else{X(m,true)}}}function U(m){var k=m.getElementsByTagName(P)[0];if(k){var p=Y("embed"),r=k.attributes;if(r){var o=r.length;for(var n=0;n<o;n++){if(r[n].nodeName.toLowerCase()=="data"){p.setAttribute("src",r[n].nodeValue)}else{p.setAttribute(r[n].nodeName,r[n].nodeValue)}}}var q=k.childNodes;if(q){var s=q.length;for(var l=0;l<s;l++){if(q[l].nodeType==1&&q[l].nodeName.toLowerCase()=="param"){p.setAttribute(q[l].getAttribute("name"),q[l].getAttribute("value"))}}}m.parentNode.replaceChild(p,m)}}function F(i){if(a.ie&&a.win&&O("8.0.0")){G.attachEvent("onunload",function(){var k=c(i);if(k){for(var j in k){if(typeof k[j]=="function"){k[j]=function(){}}}k.parentNode.removeChild(k)}})}}function D(j){C=true;var o=c(j.id);if(o){if(j.altContentId){var l=c(j.altContentId);if(l){L=l;T=j.altContentId}}else{L=b(o)}if(!(/%$/.test(j.width))&&parseInt(j.width,10)<310){j.width="310"}if(!(/%$/.test(j.height))&&parseInt(j.height,10)<137){j.height="137"}g.title=g.title.slice(0,47)+" - Flash Player Installation";var n=a.ie&&a.win?"ActiveX":"PlugIn",k=g.title,m="MMredirectURL="+G.location+"&MMplayerType="+n+"&MMdoctitle="+k,p=j.id;if(a.ie&&a.win&&o.readyState!=4){var i=Y("div");p+="SWFObjectNew";i.setAttribute("id",p);o.parentNode.insertBefore(i,o);o.style.display="none";G.attachEvent("onload",function(){o.parentNode.removeChild(o)})}R({data:j.expressInstall,id:K,width:j.width,height:j.height},{flashvars:m},p)}}function d(j){if(a.ie&&a.win&&j.readyState!=4){var i=Y("div");j.parentNode.insertBefore(i,j);i.parentNode.replaceChild(b(j),i);j.style.display="none";G.attachEvent("onload",function(){j.parentNode.removeChild(j)})}else{j.parentNode.replaceChild(b(j),j)}}function b(n){var m=Y("div");if(a.win&&a.ie){m.innerHTML=n.innerHTML}else{var k=n.getElementsByTagName(P)[0];if(k){var o=k.childNodes;if(o){var j=o.length;for(var l=0;l<j;l++){if(!(o[l].nodeType==1&&o[l].nodeName.toLowerCase()=="param")&&!(o[l].nodeType==8)){m.appendChild(o[l].cloneNode(true))}}}}}return m}function R(AE,AC,q){var p,t=c(q);if(typeof AE.id==Z){AE.id=q}if(a.ie&&a.win){var AD="";for(var z in AE){if(AE[z]!=Object.prototype[z]){if(z=="data"){AC.movie=AE[z]}else{if(z.toLowerCase()=="styleclass"){AD+=' class="'+AE[z]+'"'}else{if(z!="classid"){AD+=" "+z+'="'+AE[z]+'"'}}}}}var AB="";for(var y in AC){if(AC[y]!=Object.prototype[y]){AB+='<param name="'+y+'" value="'+AC[y]+'" />'}}t.outerHTML='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'+AD+">"+AB+"</object>";F(AE.id);p=c(AE.id)}else{if(a.webkit&&a.webkit<312){var AA=Y("embed");AA.setAttribute("type",W);for(var x in AE){if(AE[x]!=Object.prototype[x]){if(x=="data"){AA.setAttribute("src",AE[x])}else{if(x.toLowerCase()=="styleclass"){AA.setAttribute("class",AE[x])}else{if(x!="classid"){AA.setAttribute(x,AE[x])}}}}}for(var w in AC){if(AC[w]!=Object.prototype[w]){if(w!="movie"){AA.setAttribute(w,AC[w])}}}t.parentNode.replaceChild(AA,t);p=AA}else{var s=Y(P);s.setAttribute("type",W);for(var v in AE){if(AE[v]!=Object.prototype[v]){if(v.toLowerCase()=="styleclass"){s.setAttribute("class",AE[v])}else{if(v!="classid"){s.setAttribute(v,AE[v])}}}}for(var u in AC){if(AC[u]!=Object.prototype[u]&&u!="movie"){E(s,u,AC[u])}}t.parentNode.replaceChild(s,t);p=s}}return p}function E(k,i,j){var l=Y("param");l.setAttribute("name",i);l.setAttribute("value",j);k.appendChild(l)}function c(i){return g.getElementById(i)}function Y(i){return g.createElement(i)}function O(k){var j=a.pv,i=k.split(".");i[0]=parseInt(i[0],10);i[1]=parseInt(i[1],10);i[2]=parseInt(i[2],10);return(j[0]>i[0]||(j[0]==i[0]&&j[1]>i[1])||(j[0]==i[0]&&j[1]==i[1]&&j[2]>=i[2]))?true:false}function A(m,j){if(a.ie&&a.mac){return }var l=g.getElementsByTagName("head")[0],k=Y("style");k.setAttribute("type","text/css");k.setAttribute("media","screen");if(!(a.ie&&a.win)&&typeof g.createTextNode!=Z){k.appendChild(g.createTextNode(m+" {"+j+"}"))}l.appendChild(k);if(a.ie&&a.win&&typeof g.styleSheets!=Z&&g.styleSheets.length>0){var i=g.styleSheets[g.styleSheets.length-1];if(typeof i.addRule==P){i.addRule(m,j)}}}function X(k,i){var j=i?"visible":"hidden";if(S){c(k).style.visibility=j}else{A("#"+k,"visibility:"+j)}}return{registerObject:function(l,i,k){if(!a.w3cdom||!l||!i){return }var j={};j.id=l;j.swfVersion=i;j.expressInstall=k?k:false;H[H.length]=j;X(l,false)},getObjectById:function(l){var i=null;if(a.w3cdom&&S){var j=c(l);if(j){var k=j.getElementsByTagName(P)[0];if(!k||(k&&typeof j.SetVariable!=Z)){i=j}else{if(typeof k.SetVariable!=Z){i=k}}}}return i},embedSWF:function(n,u,r,t,j,m,k,p,s){if(!a.w3cdom||!n||!u||!r||!t||!j){return }r+="";t+="";if(O(j)){X(u,false);var q=(typeof s==P)?s:{};q.data=n;q.width=r;q.height=t;var o=(typeof p==P)?p:{};if(typeof k==P){for(var l in k){if(k[l]!=Object.prototype[l]){if(typeof o.flashvars!=Z){o.flashvars+="&"+l+"="+k[l]}else{o.flashvars=l+"="+k[l]}}}}J(function(){R(q,o,u);if(q.id==u){X(u,true)}})}else{if(m&&!C&&O("6.0.65")&&(a.win||a.mac)){X(u,false);J(function(){var i={};i.id=i.altContentId=u;i.width=r;i.height=t;i.expressInstall=m;D(i)})}}},getFlashPlayerVersion:function(){return{major:a.pv[0],minor:a.pv[1],release:a.pv[2]}},hasFlashPlayerVersion:O,createSWF:function(k,j,i){if(a.w3cdom&&S){return R(k,j,i)}else{return undefined}},createCSS:function(j,i){if(a.w3cdom){A(j,i)}},addDomLoadEvent:J,addLoadEvent:M,getQueryParamValue:function(m){var l=g.location.search||g.location.hash;if(m==null){return l}if(l){var k=l.substring(1).split("&");for(var j=0;j<k.length;j++){if(k[j].substring(0,k[j].indexOf("="))==m){return k[j].substring((k[j].indexOf("=")+1))}}}return""},expressInstallCallback:function(){if(C&&L){var i=c(K);if(i){i.parentNode.replaceChild(L,i);if(T){X(T,true);if(a.ie&&a.win){L.style.display="block"}}L=null;T=null;C=false}}}}}();

////////////////

  var SWF_URL = "http://www.pliantcode.com/lib/xajax.swf"; // set if you want to hardcode path to xajax.swf

  FlashHttpRequest_objects = new Object();
  FlashHttpRequest_counter = 0;
  function FlashHttpRequest_(parent) {
    this.parent = parent;
    this.id = FlashHttpRequest_counter++;
    FlashHttpRequest_objects[this.id] = this;
    var gateway;
    this.open = function(method, url) {
      gateway = document.getElementById("FlashHttpRequest_gateway");
      gateway.create(this.id, method, url);
    }
    this.send = function(content) {
      gateway.send(this.id, content);
    }
    this.handler = function(status, data) {
      var obj = this.parent ? parent : this;
      obj.readyState = 4;
      obj.responseText = data;
      obj.status = status;

      var id = this.id;
      setTimeout(function(){  // must release flash
        gateway.finished(id); 
        obj.onreadystatechange.apply(obj); 
      }, 10);
    }
  }
  function FlashHttpRequest_handler(id, status, data) {
    FlashHttpRequest_objects[id].handler(status, data);
  }
  function FlashHttpRequest() {
    var obj;
    var queue = new Array();
    var max_wait = 100;
    var gateway = document.getElementById("FlashHttpRequest_gateway");
    if (gateway && gateway.create)
      if (typeof(FlashHttpRequest_ready) != 'undefined') 
        obj = new FlashHttpRequest_(this);
    if (!obj) {
      
      var self = this;
      queue.push( function() { obj = new FlashHttpRequest_(self) } );
      setTimeout(function(){ self._process_queue() }, 100);
    }
    
    this.open = function(arg1,arg2) {
      if (obj)
        obj.open(arg1,arg2);
      else {
        queue.push( function() { obj.open(arg1,arg2) } );
      }
    }
    this.send = function(arg1) {
      if (obj) {
        obj.send(arg1);
      } else {
        queue.push( function() { 
          obj.send(arg1) } );
      }
    }
    this._process_queue = function() {
      gateway = document.getElementById("FlashHttpRequest_gateway");
      var ok = obj ? true : false;
      if (!ok)
        if (gateway && gateway.create)
          if (typeof(FlashHttpRequest_ready) != 'undefined') 
            ok = true;
      if (!ok) {
        if (max_wait-- > 0)
          setTimeout(function(){ self._process_queue() }, 100);
      } else {
        while (queue.length > 0) {
          var task = queue.shift();
          task.apply(this);
        }
      }
    }
  }
           
  if (!SWF_URL) {
    var prefix="";
    var tags = document.getElementsByTagName("script");
    for ( var i = 0; i < tags.length; i++ ) {
      var pos = tags[i].src.toLowerCase().indexOf("xajax.js")
      if ( pos != -1 ) 
        prefix = tags[i].src.substring(0,pos);
    }
    SWF_URL = prefix+'xajax.swf';
  }

  document.write('<span style="position:absolute;top:0;left:0"><span id="FlashHttpRequest_gateway"></span></span>');
	swfobject.embedSWF(SWF_URL, "FlashHttpRequest_gateway", "1", "1", "9.0.0", "expressInstall.swf", {}, {allowscriptaccess:"always", bgcolor:"ffffff"} );
}
if (typeof(pliant_engine_instances) == 'undefined') {
  pliant_engine_instances = new Object();
}
function pliant(f){ // will overwrite itself if included twice
  var embed_section_header = "pliant-";
  var embed_main_header = "pliant_embed_";
  if (typeof(f.pliant_id)=='undefined') { // parse id from parent section /pliant/X/name
    var c = f;
    while ((c.parentNode.id || "").indexOf(embed_section_header)!=0) {
      if (c.pliant_id) { f.pliant_id = c.pliant_id; break }
      if (c.id.indexOf(embed_main_header)==0) { f.pliant_id = c.id.substr(embed_main_header.length); break }
      c = c.parentNode;
    }
    if (!f.pliant_id) {
      var subpath = c.parentNode.id.substr(embed_section_header.length);
      f.pliant_id  = subpath.substr(0, subpath.indexOf("-"));
    }
  }
  return pliant_engine_instances[f.pliant_id];
}
if (typeof(pliant_bootstrap_interface) == 'undefined') {
  pliant_bootstrap_interface = new(function() {
    this.embed_counter = 0;
    var requests = new Object();
    var embeds = new Object();
    var end_data_token = "$PLIANT$"; //TODO
    var embed_suffix = "pliant_embed";
    var embed_section_header = "pliant-";
    function load_script(url, callback) {
      var add_event = function(obj,evType,callback) {
        if (obj.addEventListener)
          obj.addEventListener(evType, callback, false);
        else if (obj.attachEvent)
          obj.attachEvent("on"+evType, callback );
      }
      var remove_event = function(obj, evType, func) {
        if (obj.removeEventListener)
          obj.removeEventListener(evType, func, false);
        else if (obj.detachEvent)
          obj.detachEvent("on" + evType, func);
      }
      var js = document.createElement('script');
      var handler = function ( e ) {
        // IE special script load check
        if ( e.type == 'readystatechange' && js.readyState != 'complete' && js.readyState != 'loaded' ) return;
        remove_event( js, 'load', handler );
        remove_event( js, 'readystatechange', handler );
        if (callback)
          callback.apply();
      }
      js.setAttribute('language','javascript');
      js.setAttribute('type','text/javascript');
      add_event(js,'load',handler);
      add_event(js,'readystatechange',handler);
      js.setAttribute('src',url);
      document.body.appendChild(js);
    }
    function run_scripts(scripts) { // structure returned by extract_scripts
      function load_scripts(i){
        if (i===scripts.length) 
          return;
        for (; scripts[i].type==='code' && i<scripts.length; i++)
          eval(scripts[i]);
        if (i < scripts.length && scripts[i].type === 'file') {
          var j = i+1;
          load_script(scripts[i].value, function(){ load_scripts(j)});
        }
      }
      load_scripts(0);
    }
    function extract_scripts(content) {
      var scripts = [];
      var tag_length = ("</scr"+"ipt>").length;
      var pos;
      while(true){
        pos = content.indexOf("<scr"+"ipt>");
        if (pos==-1) break;
        var pos2 = content.substr(pos).indexOf("</sc"+"ript>")+tag_length+pos;
        script = content.substring(pos+tag_length-1,pos2-tag_length);
        content = content.substr(0,pos)+content.substr(pos2);
        scripts[scripts.length] = { type: 'code', value: script };
      }
      while(true){
        pos = content.indexOf("<scr"+"ipt src=");
        if (pos==-1) break;
        var pos2 = content.substr(pos).indexOf("</sc"+"ript>")+tag_length+pos;
        script = content.substring(pos+tag_length-1,pos2-tag_length);
        content = content.substr(0,pos)+content.substr(pos2);
        script = script.substr(script.indexOf("=")+1);
        var quote = script.substr(0,1);
        script = script.substring(1, script.lastIndexOf(quote));
        scripts[scripts.length] = { type: 'file', value: script };
      }
      return scripts;
    }
    function init_embed(id, raw_content) {
      var e = embeds[id];
      var mark = raw_content.indexOf(end_data_token);
      var ui_path = raw_content.substring(0,mark);
      var empty_element="<span style='display:none'>&nbsp;</span>";
      var content = raw_content.substr(mark+end_data_token.length)
        .replace(/\{\{pliant_id\}\}/g, embeds[id].pliant_id)
        .replace(/\{embed_host\}/g, e.url_prefix) // from user-code templates
        .replace(/<style>/gi,empty_element+"<style>")
        .replace(/<link/gi,empty_element+"<link")
        .replace(/#pliant\-/gi,"#pliant-"+id+"-")
        .replace(/.embed_host/g,'.'+e.css_embed_host);
      var scripts = extract_scripts(content);

      var container = embeds[id].container;
      pliant_engine_instances[id]=new pliant_interface();
      pliant_engine_instances[id].startup(ui_path, embeds[id]);

      var tmp = document.createElement("DIV");
      tmp.innerHTML = content;
      var sections = tmp.getElementsByTagName("SPAN");
      for (var i=0; i<sections.length; i++)
        if ((sections[i].id||"").indexOf(embed_section_header)==0)
          if (sections[i].innerHTML.replace(/\r|\n|\s/g, '').length==0)
            sections[i].style.display = 'none';
      container.innerHTML = '';
      container.className = embeds[id].container_className;
      container.innerHTML = tmp.innerHTML;
      //container.innerHTML = "&nbsp;<style></style>";
      run_scripts(scripts);
    }
    function document_append(element) {
      var container=document.getElementsByTagName('script')[0];
      container.parentNode.appendChild(element);
    }
    function load_css(src) {
      var t=document.createElement('link'); 
      t.rel='stylesheet';
      t.type='text/css';
      t.href=src;
      document_append(t);
    }
    function load_javascript(src) {
      var t=document.createElement('script'); 
      t.src=src;
      document_append(t);
    }
    var max_wait = 1000;
    function wait_for_interface(id, content) {
      if (typeof(pliant_interface) == 'undefined') {
        if (max_wait-- > 0) 
          setTimeout(function(){wait_for_interface(id, content)}, 100);
        else
          alert('ERROR: Can\'t load pliant interface or it takes too long.');
      } else 
        init_embed(id, content);
    }
    function install_content(id) {
      var request = requests[id];
      if (request.readyState == 4) {
        try {
          if (request.status != 200) {
              alert('error');
          } else {
            var raw_content = request.responseText;
            if (typeof(pliant_interface)=='undefined')
              setTimeout(function(){wait_for_interface(id, raw_content)}, 100);
            else
              init_embed(id, raw_content);
          }
        } catch(e) {
            alert('error:'+e);
        }
      }
    }
    this.process = function() {
      var tags = document.getElementsByTagName("script");
      for ( var i = 0; i < tags.length; i++ ) 
        if ( tags[i].src.toLowerCase().indexOf(embed_suffix) != -1 ) 
          if (tags[i].id.indexOf("pliant_processed_") == -1) {
            var id = "e"+(this.embed_counter++);
            tags[i].id = "pliant_processed_"+id;
            var src = tags[i].src;
            var e = new Object();
            var s = 8+src.substr(8).indexOf('/'); // https:// = 8 chars
            e.url_prefix = src.substring(0,s);
            e.embed_host = e.url_prefix.substr(e.url_prefix.indexOf("/")+2); //remove protocol
            e.css_embed_host = e.embed_host.replace(/\./g,'_');
            var opts = { 
              mode: document.compatMode.toLowerCase(),
              query: escape(document.location.search.substr(1)),
              lang: navigator.language ? navigator.language : navigator.userLanguage,
              charset: (document.charset || document.characterSet).toLowerCase() }
            document.write("<div id='pliant_embed_"+id+"'>loading...</div>");
            var container = document.getElementById('pliant_embed_'+id);
            container.pliant_id = id;
            e.container_className = opts.mode+' '+e.css_embed_host+' pliant';
            container.style.position = 'relative';
            e.container = container;
            e.new_xhr = function() { return new FlashHttpRequest(); }
            var request = new FlashHttpRequest();
            requests[id] = request;
            embeds[id] = e;
            embeds[id].pliant_id = id;
            request.onreadystatechange = function() { install_content(id) }
            var extra="";
            for (var k in opts)
              extra += ' '+k+' "'+opts[k]+'"';
            if (document.location.search.indexOf("pliant_refresh")!=-1)
              extra += ' refresh'
            var l = src.indexOf("?"); if(l==-1) l = src.length;
            request.open('GET', src.substring(0,l)+"?pliant_load"+extra);
            request.send();
            if (typeof(pliant_requested_dependencies)=='undefined') {
              pliant_requested_dependencies = true;
              load_javascript(e.url_prefix+"/_embed/pliant_0ACKEA8.js"); //TODO
              load_css(e.url_prefix+"/_embed/pliant_0ACKEA8.css"); //TODO
            }
          }
    }
  })();
}
pliant_bootstrap_interface.process();
