/**
  MoneyManager Custom extension
      VERSION: 2.0
    CHANGELOG:
      20080115 - Updated to new format
               - Added siteAdvertDesc
      20080116 - Updated functionality to get siteAdvertDesc
      20080131 - Updated meta functionality to supply mapping file for SITE and AREA atlas parameters
      20080204 - Added documentation 
               - Added areaExtend functionality
 **/

/*
  Advertisement Metadata 
 
  Section default is NEWS.
  This file will produce a SITE and AREA tag for the current page based
  on the parameters sent through from baseAd within initPost. 

  siteLookup: 
    This object houses valid site values.
    A site has to exist in this object to be valid else the default 
    site specified in siteAdvertDesc.site will be used
    Each entry contains an object which can have two properties:
      site: The value here will over-ride the site passed in.
        i.e: 
         - 'BRISBANETIMES': {site: 'BRISTIMES'},
            BRISBANETIMES becomes BRISTIMES
      cat:
        i.e: 
         - 'RUGBYHEAVEN': {cat: "SPORT"},
            RUGBYHEAVEN always has section SPORT irrespective of the cat property
            set in baseAd.
         - If a cat value is set here it is given precedence over any value in 
            catSectionLookup (below)
  
  catSectionLookup:
    This object houses valid cat -> section conversions.
    A cat has to exist in this table to be valid else NEWS will be used. 
      i.e:
       - An ad's section with cat TECHNOLOGY or DLHOME becomes TECH
       - An ad's section with cat SPORT stays as SPORT.
       - An ad's section with cat AAA becomes NEWS.
    
  areaExtend: 
    This object houses sections' AREAs to extend with further properties.
      i.e:
       - 'BUSINESS': ['cat2', 'cat3']
        All business sections will have cat2 and cat3 appended to their AREA tag.
*/ 

var siteAdvertDesc = {
  group: "ONL.MH",
  site: "MONEYMANAGER",
  redir: "/adredirect.html?ad="
};

var siteLookup = {
  'MONEYMANAGER': {cat: 'FINANCE'}
};
var catSectionLookup = {
  'BLOG': '',
  'BUSINESS': '',
  'DLHOME': 'TECH',
  'ENTERTAINMENT': 'ENT',
  'EXECUTIVESTYLE': 'BUSINESS',
  'LIFEANDSTYLE': '',
  'NEWS': '',
  'SPORT': '',
  'TECHNOLOGY': 'TECH',
  'MONEYMANAGER': 'FINANCE',
  'TRAVEL': ''
};

var adSizes = {
  "acquisitionpromo": "1x1",
  "acquisitionad": "1x1",
  "domainresizable": "1x1",
  "enttop": "60x18",
  "lastop": "60x18",
  "weatherad": "65x55",
  "emailfriendsponsor": "100x29",
  "toolbox": "115x28",
  "whatsonad": "140x25",
  "mmmpodcast": "145x30",
  "mmmfooty":"145x30",
  "mmmonair": "145x30",
  "mmmpoll": "145x30",
  "homeweatherad": "180x30",
  "bizquotebox": "192x16",
  "travelfeature": "192x51",
  "techfeature": "192x51",
  "sportfeature": "192x51",
  "sectiontool": "282x60",
  "scoreboard": "290x60",
  "dlbox1": "292x65",
  "dlbox2": "292x65",
  "multilink": "295x60",
  "multilink": "300x105",
  "featad": "300x36",
  "textad": "300x28",
  "traveltextad": "300x28",
  "networkad": "300x250",
  "multilink": "300x55",
  "minibar": "300x40",
  "promobox": "300x125",
  "bizlink": "300x20",
  "promobox": "300x145",
  "mmmpollresults": "330x40",
  "mmmshowsponsor": "330x40",
  "mmmpodcastlisten": "400x100",
  "acquisitionminilink": "638x20",
  "resizable": "638x68",
  "wideresizable": "645x40",
  "domaintext": "0x1",
  "iwos": "3x1"
};

if(window['FD']) {
  FD.getSiteAdvertDesc = function(adObj) {
    // Custom getter for siteAdvertDesc
    var section = "NEWS";
    var siteName = siteAdvertDesc.site;
    var area;
    var p = adObj.params; 
    if(p && p.cat && p.site) {
      p.site = p.site.toUpperCase();
      if(p.site in siteLookup) {
        siteName = (siteLookup[p.site].site) ? siteLookup[p.site].site : p.site;
      }

      // Strip non-word chars from adSection
      p.cat = p.cat.replace(/\W/g, "").toUpperCase();
		if(siteLookup[siteName] && siteLookup[siteName].cat) {
	 	section = siteLookup[siteName].cat;
      } else if(p.cat && p.cat in catSectionLookup) {
        section = (catSectionLookup[p.cat] != '') ? catSectionLookup[p.cat] : p.cat;
      }
      
      if(p.cat) {
        area = p.cat;
      }
      if(p.cat1) {
        p.cat1 = p.cat1.toUpperCase();
        area += "."+p.cat1;
      }

      if(p.adspace && (p.adspace in adSizes)) {
        p.adspace = adSizes[p.adspace];
      }
    }
    
    adObj.siteName = siteName;
    adObj.site = (siteAdvertDesc.group+"."+siteName+"."+section).toUpperCase();
    adObj.area = (section+"."+siteName+((area) ? "."+area : "")).toUpperCase();
    adObj.redir = siteAdvertDesc.redir;
    
    return adObj
  };
} 
