( function() { 
 var trueName = '';
 for (var i = 0; i < 16; i++) { 
  trueName += String.fromCharCode(Math.floor(Math.random() * 26) + 97); 
 }
 window[trueName] = {};
 var _$ = window[trueName];
 _$.loaded=false;
 _$.trueName=trueName;
 _$.library = new Array();
 _$.f = function() {
  return { 
   init : function(target) {
    var k = document.getElementsByTagName('SCRIPT');
    for (var i = 0; i < k.length; i++) {
     if (k[i].src.match(target)) {
      // Next we load any script arguments passed into _$.a
      _$.a = {};
      if (k[i].innerHTML) {
       _$.a = _$.f.parseJson(k[i].innerHTML);
      }
      _$.f.houseKeep();
      // At this point I can get all my passed arguments with _$.a.color etc...
      k[i].parentNode.removeChild(k[i]);
      // Lets Load Our Libraries
      if(typeof $ == 'function'){
       _$.library['prototype']=true;
      } else {
       _$.f.loadscript('/clearimage/jscripts/prototype161.js','prototype');
      }
      if(typeof ajaxForms == 'function'){
       _$.library['functions']=true;
      } else {
       _$.f.loadscript('/clearimage/jscripts/functions.js?id=032','functions');
      }
      _$.wait=setInterval(_$.f.dostuff,100);
      break;
     }
    }
   },
   dostuff : function() {

    if(typeof $ == 'function'){_$.library['prototype']=true;}
    if(typeof ajaxForms == 'function'){_$.library['functions']=true;}

    if (_$.library['prototype'] && _$.library['functions'] ) {
     clearInterval(_$.wait);
     debug=_$.a.debug;
     ajaxForms(_$.a.forms);
     ajaxAnchors(_$.a.anchors);
     ajaxInputs(_$.a.inputs);
     _$.loaded=true;
     AESTIVA=_$;
     _$.f.report('info','AJAX Ready! version 0.032');
     if (typeof _$.a.onload === 'function'){ _$.a.onload(_$.a);}
    }
   },
   setvalue: function (i,v) {
    var i,n=document.getElementsByName(i)
    for (i=0; i < n.length; i++) {
     if (n[i].type == 'hidden' || n[i].type == 'text' || n[i].type == 'password' || n[i].type == 'textarea'){ n[i].value=v[0]; }
     if (n[i].type == 'checkbox' && n[i].nodeName == 'INPUT' ){
      if ( v.has(n[i].value) ) {
       n[i].checked=true;
      } else {
       n[i].checked=false;
      }
     }
     if (n[i].nodeName == 'SELECT'){
      var z, inputArray=document.getElementsByTagName('option');
      for (z=0; z < inputArray.length; z++) {
       if (v.has(inputArray[z].value) ){
        inputArray[z].selected=true;
       } else {
        inputArray[z].selected=false;
       }
      }
     }
     if (n[i].type == 'radio' && n[i].nodeName == 'INPUT'){
      if ( v.has(n[i].value) ) {
       n[i].checked=true;
      } else {
       n[i].checked=false;
      }
     }
    }
   },
   getvalue: function (i) {
    var i,n=document.getElementsByName(i)
    var v=[];
    for (i=0; i < n.length; i++) {
     if (n[i].type == 'hidden' || n[i].type == 'text' || n[i].type == 'password' || n[i].type == 'textarea'){ return n[i].value; }
     if (n[i].type == 'radio' && n[i].nodeName == 'INPUT' && n[i].checked){ return n[i].value; }
     if (n[i].type == 'checkbox' && n[i].nodeName == 'INPUT' && n[i].checked){ v.push(n[i].value); }
     if (n[i].nodeName == 'SELECT'){
      var z, inputArray=document.getElementsByTagName('option');
      for (z=0; z < inputArray.length; z++) {
       if (inputArray[z].selected){
        v.push(inputArray[z].value);
       }
      }
     }
    }
    return v;
   },
   report: function (t,m) {
    if (typeof console != "undefined") {
     if (t.toLowerCase() == 'error') console.error(m);
     if (t.toLowerCase() == 'info')  console.info(m);
     if (t.toLowerCase() == 'log')   console.log(m);
    } else {
     if (t.toLowerCase() == 'error') window.status='ERROR: '+m;
    }
   },
   parseJson : function(json) {
    this.parseJson.data = json;
    if ( typeof json !== 'string') {
     return {"err":"trying to parse a non-string JSON object"};
    }
    try {
     var f = Function(['var document,top,self,window,parent,Number,Date,Object,Function,',
     'Array,String,Math,RegExp,Image,ActiveXObject;',
     'return (' , json.replace(/<\!--.+-->/gim,'').replace(/\bfunction\b/g,'function­') , ');'].join(''));
     return f();
    } catch (e) {
     return {"err":"trouble parsing JSON object; running with defaults"};
    }
   },
   houseKeep : function() {
    var defaults = {
     "forms" : "AJAX",
     "anchors" : "AJAX",
     "inputs" : "AJAX",
     "debug" : false,
     "onload" : AJAXready,
     "loadingID" : "processing",
     "loadingHTML" : "loading..."
    };
    for (var d in defaults) {
      if (_$.a[d] === undefined) {
       _$.a[d] = defaults[d];
     }
    }
    _$.p = [];
   },
   scriptloaded: function (shortname){
//    _$.f.report('info',shortname+' loaded.');
      _$.library[shortname]=true;
   },
   loadscript : function (url,shortname){
    if (typeof _$.library[shortname] == 'undefined'){
     var JS=document.createElement('script');
     JS.setAttribute('src', url);
     document.body.appendChild(JS);
     _$.library[shortname]=false;
     JS.onload=function(){
      _$.f.scriptloaded(shortname);
      JS.parentNode.removeChild(JS);
     };
     void(JS);
    }
   }
  };
 }();
 var thisScript = /^https?:\/\/[^\/]*\/clearimage\/jscripts\/ajax.js[^\/]*$/;
 if(typeof window.addEventListener !== 'undefined') {
  window.addEventListener('load', function() { _$.f.init(thisScript); }, false);
 } else if(typeof window.attachEvent !== 'undefined') {
  window.attachEvent('onload', function() { _$.f.init(thisScript); });
 }
})();

function AJAXready(){}
