  // http://fdimages.fairfax.com.au/crtvs/code/digihub/ffxutils.js
  // ffx_swap unaltered. Will add the html to the innerHTML of the defined div
  // 081111 - built just for Digihub, don't use this elsewhere - dfinnecy@fairfaxdigital.com.au
  // 081201 - commented out escaping the target string - incompatible with atlas
  
  function ffx_swap(elName, html) {
      var d = document;
      if (!d.getElementById) {
          return;
      }
      var el = d.getElementById(elName);
      if (!el) {
          return;
      }
      var remove = false;
      if (typeof ffxAdExclusionList != "undefined") {
        var thisPage = window.location.pathname;
        for (var i=0; i<ffxAdExclusionList.length; i++) {
          var current = ffxAdExclusionList[i];
          if (current == 'remove_all_ads'){
            return;
          }
          else if (current == 'remove_article_ads'){
            if (thisPage.match(/\/news\/[a-zA-Z0-9-]+\/[a-zA-Z0-9-]+\/[0-9]{4}\/[0-9]{2}\/[0-9]{2}\/[0-9]+.html/) || thisPage.match(/\/articles\/.*?/)){
              remove = true;
            }
          }
          else if (current == 'remove_index_ads'){
            if  (thisPage.match(/\/index.html$/) || !thisPage.match(/.html$/)){
              remove = true;
            }
          }
          else if (current == thisPage) {
            return;
          }
        }
      }
      if (remove == true) {return;}
      el.innerHTML = html;
  }



var ad, x = 0;
while(ad = ffxAds[x]) {

if(typeof(ad.height) == "undefined")
	hei = "1";
else
   hei=ad.height;
if(typeof(ad.width) == "undefined")
	wid = "1";
else
   wid=ad.width;
  if(typeof(ad.adtype) != "undefined" && (ad.adtype.toLowerCase()=="panorama" || ad.adtype.toLowerCase()=="doubleisland"))
    call = "http://" + ffxpageVars.domain + "/adredirect.html?w="+wid+"&h="+hei+"&ad=http://direct.fairfax.com.au/jserver/";
  else
    call = "http://direct.fairfax.com.au/hserver/";

  var pageString = "";
  var adString = "";
  
  
  if ((typeof(ffxpageVars.site) == "string") && (ffxpageVars.site.length >= 1)){
  	pageString += "SITE="+ffxpageVars.site+"/";
  		}  
  if ((typeof(ffxpageVars.area) == "string") && (ffxpageVars.area.length >= 1)){
   	pageString += "AREA="+ffxpageVars.area+"/";
  		}  
  
  if(pageString.charAt(pageString.length-1)=='.')
  	pageString = pageString.substring(0,pageString.length-1);
  pageString+="/";



  for(i in ad)
  if(i!="height"&&i!="width")
    adString += i+"="+ad[i]+"/";

  if(adString.toLowerCase().indexOf("aamsz")==-1)
  	adString += "aamsz="+wid+"x"+hei+"/";

  var adspace = wid+"x"+hei;

  for(i in ffxpageVars){
  if(i.toLowerCase()!='site' && i.toLowerCase()!='area')
	pageString+= i+"="+ffxpageVars[i]+"/";
}
  if (typeof(ad.adtype) != "undefined" && ad.adtype.toLowerCase()=="panorama"){
    wid = '728';
    hei = '90';
  }

  var targetString = pageString+adString+"acc_random="+Math.floor(Math.random()*100000000000000000);
  targetString = targetString.toUpperCase();

  //if(typeof(ad.adtype) != "undefined" && (ad.adtype.toLowerCase()=="panorama" || ad.adtype.toLowerCase()=="doubleisland"))
  // targetString=escape(targetString);

  var iFrame = "<iframe id='ffxadiframe"+x+"' name='ffxadiframe"+x+"' allowtransparency='true' width="+wid+" height="+hei+" marginwidth=0 marginheight=0 hspace=0 VSPACE=0 frameborder=0 scrolling=no bordercolor='#000000' src='"+call+targetString+"'></iframe>";
  var holderDivId = "ffxad"+(x + 1);
  ffx_swap(holderDivId, iFrame);
  x++;
}

