/**
  SMH Custom extension
      VERSION: 1.0 
    CHANGELOG:
      20071207 - Updated to Mootools v1.2 syntax
               - Removed need for countless plugins by creating custom versions.
               - Compressed file
      20080111 - Updated Fader to use a display:none class on the li rather than scroll the whole ul left or right.
      20080310 - Added Advertisement Metadata
 **/

/*
  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: "SMH",
  redir: "/adredirect.html?ad="
};

var siteLookup = {
  'BRISBANETIMES': {site: 'BRISTIMES'},
  'AGE': '',
  'SMH': '',
  'MONEYMANAGER': {cat: "FINANCE"},
  'LEAGUEHQ': {cat: "SPORT"},
  'REALFOOTY': {cat: "SPORT"},
  'RUGBYHEAVEN': {cat: "SPORT"},
  'RUGBYHEAVEN07': {site: "RUGBYHEAVEN", cat: "SPORT"},
  'TRAVELSECTION': {site: 'TRAVEL'},
  'WALKABOUT': {site: 'TRAVEL'}
};
var catSectionLookup = {
  'BLOG': '',
  'BUSINESS': '',
  'DLHOME': 'TECH',
  'ENTERTAINMENT': 'ENT',
  'EXECUTIVESTYLE': 'BUSINESS',
  'LIFEANDSTYLE': '',
  'NEWS': '',
  'SPORT': '',
  'TECHNOLOGY': 'TECH',
  'TRAVEL': ''
};
var areaExtend = {
  'BUSINESS': ['cat2']
};
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",
  "toolbox": "115x28",
  "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.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
      if(p.cat) {
        p.cat = p.cat.replace(/\W/g, "").toUpperCase();
        if(siteLookup[p.site] && siteLookup[p.site].cat) {
          section = siteLookup[p.site].cat;
        } else if(p.cat && p.cat in catSectionLookup) {
          section = (catSectionLookup[p.cat] != '') ? catSectionLookup[p.cat] : p.cat;
        }
        area = p.cat;
      }
      
      if(p.cat1) {
        p.cat1 = p.cat1.toUpperCase();
        area += "."+p.cat1;
      }

      if(p.adspace) {
        var adspace = p.adspace.toLowerCase();
        if(adspace in adSizes) {
          p.adspace = adSizes[adspace];
          delete p.adspace;
        }
      }
      
      // Determine whether this section has additionally appended properties on its AREA prop
      if(section in areaExtend) {
        var x = 0, pName;
        while(pName = areaExtend[section][x]) {
          if(p[pName]) {
            area += "."+p[pName].toUpperCase();
          }
          x++;
        }
      }
    }
    
    adObj.siteName = siteName;
    adObj.site = (siteAdvertDesc.group+"."+siteName+"."+section).toUpperCase();
    adObj.area = (section+"."+siteName+((area) ? "."+area : "")).toUpperCase();
    adObj.redir = siteAdvertDesc.redir;
    
    return adObj
  };
} 
 
if(window["FD"]){if(window["Fx"]&&Fx.Styles){Fx.Morph=Fx.Styles}if(!window["Client"]&&window["Browser"]){Client=Browser}FD.smhage=new Class({options:{aSHeight:366,duration:250,classCurrent:"current"},initialize:function(){this._initSlider();this._initQuotes();this._initAllSections();this._initTabs();this._initTempTVWrapOverlay()},_initQuotes:function(){var A=$("masthead").getElements("blockquote");
if(A){var B=(A.length>1)?Math.floor(Math.random()*(A.length)+1)-1:0;if(A[B]){A[B].setStyles({"display":"block","visibility":"visible"})}}},_initAllSections:function(){var A=$("allSections");var C=$("allSectionsWrap");var B=$("allSectionsContent");if(A&&C&&B){this.options.aSOpenText=A.innerHTML;A.addEvent("click",this.toggleAllSections.bindWithEvent(this));C.empty().innerHTML=B.innerHTML}},getASW:function(){return $("allSectionsWrap")
},toggleAllSections:function(B){new Event(B).stop();var A=this.getASW();if(A&&!this.asChanging){if(A.getStyle("height").toInt()==0){this.openAllSections(A)}else{this.closeAllSections(A)}}},openAllSections:function(B){this.asChanging=true;B.setStyle("border-width","1px 1px 1px 1px");var A=new Fx.Morph(B,$extend(this.options,{onComplete:this.allSectionsComplete.bind(this)}));A.start({"height":[0,this.options.aSHeight]})
},closeAllSections:function(B){this.asChanging=true;var A=new Fx.Morph(B,$extend(this.options,{onComplete:this.allSectionsComplete.bind(this,B)}));A.start({"height":[this.options.aSHeight,0]})},allSectionsComplete:function(A){if(A){this.asChanging=false;var B=A.innerHTML;if(A.getStyle("height").toInt()!=this.options.aSHeight){A.empty().innerHTML=B.replace(/Hide/ig,"Show");A.setStyle("border-width","1px 0 0 0")
}else{A.empty().innerHTML=B.replace(/Show/ig,"Hide")}}},_initSlider:function(){this.sliderPos=0;var A=$("woffRotator_parent");if(A){this.slCount=A.getElements("li").length;this.addSliderTimeout();A.addEvent("mouseover",function(){$clear(this.sliderTimeout)}.bind(this));A.addEvent("mouseleave",this.addSliderTimeout.bind(this));A.getElements("a.fdScrollPrevItem").addEvent("click",this._moveSlider.bind(this,-1));
A.getElements("a.fdScrollNextItem").addEvent("click",this._moveSlider.bind(this,1))}},_moveSlider:function(A){if(!this.sliding&A){this.sliding=true;var B=new Fx.Morph($("woffRotator_holder"),$merge(this.options,{duration:550,onComplete:this._moveSliderComplete.bind(this,A)})).start({"opacity":0})}},_moveSliderComplete:function(B){var C=this.sliderPos+B;var F=0;var E=$("woffRotator");var A=E.getElements("li");
A[this.sliderPos].removeClass(this.options.classCurrent);if(C==this.slCount){C=0}else{if(C<0){C=this.slCount-1}}this.sliderPos=C;A[this.sliderPos].addClass(this.options.classCurrent);var D=new Fx.Morph($("woffRotator_holder"),$merge(this.options,{duration:450,onComplete:this._setFadeComplete.bind(this)})).start({"opacity":1})},_setFadeComplete:function(){this.sliding=false},addSliderTimeout:function(){this.sliderTimeout=this._moveSlider.periodical(7000,this,1)
},_initTabs:function(){var B=$$("ul.fdTabs");this.tabIDs=[];if(B){for(var A=0,C=B.length;A<C;A++){B[A].addEvent("click",this._swapTab.create({bind:this,event:true,arguments:B[A].id}));this.tabIDs.push(B[A].id)}}},_swapTab:function(E,F){if(E&&E.target&&$(F)){new Event(E).stop();var B=$(E.target);var D=$(F).getChildren().removeClass("selected");if(!B.href){B=B.getFirst()}B.getParent().addClass("selected");
var A=$(F+"Pane");var C=$(B.href.substr(B.href.lastIndexOf("#")+1));if(A&&C){A.getChildren().setStyle("display","none");C.setStyle("display","block")}}},_initTempTVWrapOverlay:function(){var A=$("tvWrap");if(A&&A.getElements("span.overlay-button").length==0){var C=A.getElement("a.video-play");if(C){var B=new Element("span",{"class":"overlay-button"}).inject(C).innerHTML="Play"}}}});var smhage;function initSMHAGE(){smhage=new FD.smhage()
}FD.register("SMHAGE")}
