var loaded=false;
//var onload2=window.onload; window.onload=function() { if (onload2) onload2();setInterval("adsInit();",333);}

function adsPreloadClearDiv(e){
   if (e.getElementsByTagName('script')) {t=e.getElementsByTagName('script'); if(t[0]) t[0].parentNode.removeChild(t[0]);}
   if (e.getElementsByTagName('script')) {t=e.getElementsByTagName('script'); if(t[0]) t[0].parentNode.removeChild(t[0]);}      
}
function adsPreloadClear(){
   var e=document.getElementById('preloadAds');
   var t=e.getElementsByTagName('div');
   for(i=0;i<t.length;i++){
      var s=t[i].id;
      s=s.substring(0,10);
      if (s=='preloadAds')
      adsPreloadClearDiv(t[i]);
   }
}

function getFlashVars(id){
   var o=document.getElementById(id);
   var t=o.getElementsByTagName('param');
   for(var i=0;i<t.length;i++){
      if (t[i].name.toLowerCase()=='flashvars')
         return t[i].value;
   }
   return '';
}

function adsPutContent(s,id1){
   var id2=id1.replace('preloadAds','ads');
   s=s.replace(/^\s+|\s+$/g,''); //trim
   if ((document.getElementById(id2))&&(s.length>3)){
      var a=getFlashVars(id1);
      s=s.replace('<PARAM NAME="FlashVars" VALUE="">','<PARAM name="FlashVars" value="'+a+'">');   
      document.getElementById(id2).innerHTML=s;
   }
}

function adsPut(){
   var e=document.getElementById('preloadAds');
   var t=e.getElementsByTagName('div');
   for(i=0;i<t.length;i++){
      var id1=t[i].id;      
      var e1=document.getElementById(id1);             
      adsPutContent(e1.innerHTML,id1);
   }
}

function adsInit(){
   if (loaded)
      return;
   loaded=true;
   adsPreloadClear();
   adsPut();
}

function $() {
  var results = [], element;
  for (var i = 0; i < arguments.length; i++) {
    element = arguments[i];
    if (typeof element == 'string')
      element = document.getElementById(element);
    results.push(Element.extend(element));
  }
  return results.length < 2 ? results[0] : results;
}
