/** 
  2DayFM Custom Functionality
    CHANGELOG:
      20080118 - Born
      20080121 - Fixed Nav functionality so all dropdowns are independant
               - Added onload functionality to ammend the background gradient
                 depending on which (primary or secondary) is taller.
      20080122 - Updated background gradient resize to use scroll event on FF and IE7 (only once)
                 load was not firing reliably in IE7
      20080204 - Removed onmouseout behaviour to restart feature loop to improve readability.
      20080205 - Updated _initPrimaryHeight to use scroll event for ie6 and remove scroll events once fired.
	  20080222 - Fixed _initAutoInputs not to let event bubble into submit button.
      20080222 - Updated _initAutoInputs to add class userInput when there is a value
	  20080318 - Updated _initControlTabs to accept multiple classes rather than single id element. (Jens)
	  20080411 - Added _initValidateForm and _initRegistrationForm (show/hide form elements) (Jens)
	  20080523 - Added carousel (Stefan Evans)
	  20090804 - Removed cat1 from Area variable for ads
 **/
 
/*
  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 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 siteName = siteAdvertDesc.site;
    var site, area;
    var p = adObj.params; 
    if(p && p.network && p.site) {
      site = [siteAdvertDesc.group, p.network, p.site, siteAdvertDesc.section].join(".");
      area = [siteAdvertDesc.section, p.network, p.site].join(".");
      delete p.network;
      if(p.cat) {
        area += "."+p.cat;
      }

      if(p.adspace) {
        var adspace = p.adspace.toLowerCase();
        if(adspace in adSizes) {
          p.adspace = adSizes[adspace];
          delete p.adspace;
        }
      }
      
      adObj.site = site.toUpperCase();
      adObj.area = area.toUpperCase();
      adObj.redir = siteAdvertDesc.redir;
      
      return adObj
    }
  };
} 

if(window.FD){FD.MyTalk=new Class({Implements:Options,options:{},scrollJump:197,numOfItems:3,initialize:function(A){this.setOptions(A);this.initCarousels()},initCarousels:function(){var C=$$("div.carouselWrap"),B,A=0;while(A<C.length){C[A].addEvent("click",this.scrollCarousel.bindWithEvent(this));A++}},scrollCarousel:function(B){if(B&&B.target){var A=$(B.target);if(A.hasClass("next")){this.scrollElements(A,this.scrollJump*-1);B.stop()}else{if(A.hasClass("prev")){this.scrollElements(A,this.scrollJump);B.stop()}else{return true}}}},scrollElements:function(K,G){var E=K.getParent();var F=E.getElements("div")[0];if(F.hasClass("carousel")){var A=F.getElements("ul")[0];var B=A.getElements("li").length;var I=B%this.numOfItems;if(I>0){B=B+(this.numOfItems-I)}var H=A.getStyle("width").toInt();var D=A.getStyle("left").toInt();D+=(G*this.numOfItems);var J=(D/this.scrollJump)*-1;if(J>=B){D=0;A.setStyle("left",D+"px")}if(J<0){D=(B-this.numOfItems)*this.scrollJump*-1;A.setStyle("left",D+"px")}else{var C=new Fx.Morph(A,{duration:200});C.start({left:D})}}}});var myTalk;function initMyTalk(){myTalk=new FD.MyTalk()}FD.register("MyTalk")};