//////////////////////////////////////////////////////////
/// SET DEFAULT VARIABLES FOR GENERIC STATION SETTINGS
//////////////////////////////////////////////////////////
var DEFAULT_SITE_NAME     = "none";
var DEFAULT_CATEGORY_NAME = "M25-54";
var DEFAULT_CHANNEL_NAME  = "radio";
var DEFAULT_ZONE          = "site";
var DEFAULT_HOMEPAGEPATH  = new Array("/index.aspx","","/home/default.aspx","/home/","/");
var DEFAULT_HOMEPAGEZONE  = "homepage";
var DEFAULT_DISPLAY_OTP   = "true";

/////////////////////////////////////////////////////////////////////////////
/// SET GLOBAL DEFAULT PATH MAPPINGS (Works for 1st Directory in Pathname)
/////////////////////////////////////////////////////////////////////////////

var ads_path_mapping = new Array();
ads_path_mapping["/shared/player"]      									= "player";
ads_path_mapping["/media"]      											= "video_player";
ads_path_mapping["/shared/corus_content/corus_player"]  	    			= "player";
ads_path_mapping["/shared/corus_third_party/b_stream/cfnyfm/edge2"]			= "player_edge2";
ads_path_mapping["/shared/corus_third_party/b_stream/cfnyfm/nextbigthing"]	= "player_nextbigthing";
ads_path_mapping["/shared/corus_third_party/b_stream/cfoxfm/nextbigthing"]	= "player_nextbigthing";
ads_path_mapping["/ShoppingExperience"]                                     = "corus_shopping";
ads_path_mapping["/home"]													= "homepage";
ads_path_mapping[""]														= "homepage";
ads_path_mapping["/"]														= "homepage";
ads_path_mapping["/index.aspx"]												= "homepage";
ads_path_mapping["/home/default.aspx"]										= "homepage";

function ConvertPathToZoneName (hp_zone, default_zone) {
    var ads_zone_name = DEFAULT_ZONE;
    if(document.location.hostname != "undefined"  && document.location.hostname != "") //&& document.location.hostname != "localhost"
    {
            var root_path = document.location.pathname.toLowerCase().substring(0,document.location.pathname.lastIndexOf('/'));
            if (ads_path_mapping[root_path]) {
                ads_zone_name = ads_path_mapping[root_path];
            }

    }
    return ads_zone_name;    
}


function GetFlashVersion() {
    var version = -1;

    if (navigator.plugins && navigator.mimeTypes.length)
    {
        if (navigator.plugins["Shockwave Flash"] && navigator.plugins["Shockwave Flash"].description)
        {
            version = parseInt(navigator.plugins["Shockwave Flash"].description.split('Shockwave Flash ')[1]);
        }           
    }
    else {
        var i = 4;
        while (1) {
            try {
                oFlash = eval("new ActiveXObject('ShockwaveFlash.ShockwaveFlash." + i + "');");
                if (oFlash) {
                    version = i;
                }
            }
            catch (e) {
                break;
            }
            i = i + 1;
        }
    }
    return version;
}

//////////////////////////////////////////////////////////
/// Ad Object
//////////////////////////////////////////////////////////
if(Ad == "undefined") var Ad = new Object();
function Ad(site, category, display_otp, zone, homepage_path, homepage_zone) {
    var axel = Math.random() + ""; var ord = axel * 1000000000000000000;
    this.attributes = new Array(); 
    
    //Site Attribute
    if (site)           {this.setAttribute('site',     site);}
    else                {this.setAttribute('site',     DEFAULT_SITE_NAME);}
    
    //Category Attribute
    if (category)       {this.setAttribute('category', category);}
    else                {this.setAttribute('category', DEFAULT_CATEGORY_NAME);}
    
    if (display_otp)    {
			 if (display_otp.toLowerCase() == "false") {
				this.setAttribute('displayotp',  "false");
			 }
			 else {
				
				this.setAttribute('displayotp',  "true");
			 }
			}
    else                {this.setAttribute('displayotp',  DEFAULT_DISPLAY_OTP);}

    //edited - 16/03/09 - Dimitry Chertkov
    //Home Page Path Attribute commented out
    //variable is never used
    //this.getAttribute("homepagepath") parameter taken out of ConvertPathToZoneName function call
    //if (homepage_path)  {this.setAttribute('homepagepath',  homepage_path);}
    //else                {this.setAttribute('homepagepath',  DEFAULT_HOMEPAGEPATH);}

    //Home Page Path Attribute
    if (homepage_zone)  {this.setAttribute('homepagezone',  homepage_zone);}
    else                {this.setAttribute('homepagezone',  DEFAULT_HOMEPAGEZONE);}

    //Zone Attribute
    if (zone)           {this.setAttribute('zone',  zone);}
    else                {
                            this.setAttribute('zone',  DEFAULT_ZONE);
                            this.setAttribute('zone',  ConvertPathToZoneName (this.getAttribute("homepagezone"), DEFAULT_ZONE));
                        }
  
    //DART Attributes used in write method
    this.setAttribute('tile', 1);
    this.setAttribute('ord', ord);
    this.setAttribute('partner', '');
}
Ad.prototype = {
  setAttribute: function(name, value){
    this.attributes[name] = value;
  },
  getAttribute: function(name){
    return this.attributes[name];
  },
  render: function(size, elementid) {

    var str_tiles = "ptile=1;dcopt=ist;";

    if (this.getAttribute("displayotp") == "false") {
        str_tiles = "ptile=1;"; 
    }  
    if (this.getAttribute("tile") != 1) {
	var str_tiles = "ptile=1;"; // + this.getAttribute("tile") + ";";
    }


	var e = document.getElementsByTagName('head').item(0);
	if (elementid) {
		e = document.getElementById(elementid);
        }
        var js_url = 'http://ad.doubleclick.net/adj/' + this.getAttribute("site") + '.site112.tmus/' + this.getAttribute("zone") + ';genre=' + this.getAttribute("category") + ';part=' + this.getAttribute("partner") + ';page=' + window.location.pathname + ';flsh=' + GetFlashVersion() + ';' + str_tiles + 'sz=' + size + ';ord=' + this.getAttribute("ord") + '?';
	var js = document.createElement('script');
            js.setAttribute('language', 'javascript');
            js.setAttribute('type', 'text/javascript');
            js.setAttribute('src', js_url);
        e.appendChild(js);
        return false;
  },
  write: function(size, tiles, direction, zone){
   if (ads) {
    var str_tiles = "ptile=1;dcopt=ist;";

    if (this.getAttribute("displayotp") == "false") {
        str_tiles = "ptile=1;"; 
    }  
    if (this.getAttribute("tile") != 1) {
	var str_tiles = "ptile=1;"; // + this.getAttribute("tile") + ";";
    }   
    if (tiles) {
        if (direction) {str_tiles = "tn="+tiles+";to="+direction+";tp=1;tbw=0;tsw=0x0;";}
        else           {str_tiles = "tn="+tiles+";to=v;tp=1;tbw=0;tsw=0x0;";}
    }

	var tempZone=this.getAttribute("zone");
	if (zone) {
		this.setAttribute('zone',zone);
	}

    document.write('<SCR'+'IPT LANGUAGE="JavaScript1.1" SRC="http://ad.doubleclick.net/adj/' + this.getAttribute("site") + '.site112.tmus/' + this.getAttribute("zone") + ';genre=' + this.getAttribute("category") + ';part=' + this.getAttribute("partner") + ';page=' + window.location.pathname + ';flsh=' + GetFlashVersion() + ';' + str_tiles + 'sz=' + size + ';ord=' + this.getAttribute("ord") + '?"><\/SCRIPT>');
    if ((!document.images && navigator.userAgent.indexOf("Mozilla/2.") >= 0)  || navigator.userAgent.indexOf("WebTV")>= 0) {
        document.write('<A HREF="http://ad.doubleclick.net/jump/' + this.getAttribute("site") + '.site112.tmus/' + this.getAttribute("zone") + ';genre=' + this.getAttribute("category") +';part=' + this.getAttribute("partner") + ';page=' + window.location.pathname+ ';flsh=-1;' + str_tiles + 'sz=' + size + ';ord=' + this.getAttribute("ord") + '?" TARGET="_blank">');
        document.write('<IMG SRC="http://ad.doubleclick.net/ad/' + this.getAttribute("site") + '.site112.tmus/' + this.getAttribute("zone") +  ';genre=' + this.getAttribute("category") + ';part=' + this.getAttribute("partner") + ';page=' + window.location.pathname + ';flsh=-1;' + str_tiles + 'sz=' + size + ';ord=' + this.getAttribute("ord") + '?" BORDER="0" ALT=""></A>');
    }
    this.setAttribute('tile', this.getAttribute("tile") + 1); 
    this.setAttribute('zone',tempZone);
   }
  }
}


//////////////////////////////////////////////////////////
/// DEPRECIATED FUNCTIONS - NOT USED BY DFP
//////////////////////////////////////////////////////////
function WriteAdZone(id, unique)  {}
function splice_adjs(z,n)         {}
function splice_adjs_unique(z,n)  {}
function splice_adjs_source(z,n,s){}
function splice_adpop(z,n)        {}


/**********************************************************************************
 * Created By: Colin Elion (2006)
 * Added: 032409
 *********************************************************************************/

