/**
 * 
 */

var FT = window.FT || {};
FT.env =
{
   // THIRD PARTY CUSTOMISATION HERE
   'dfp_site': '',
   'dfp_zone': 'unclassified',
   'targeting': '',
   'job_title': '',
   'formats': {
	 //------FT Advisor-------//
 	  'intro' : '1x1', 
 	  'ban' : '468x60',
 	  'banlb' : '468x60,728x90;dcopt=ist',
 	  'newssubs' : '239x90',
 	  'searchbox' : '200x28',
 	  'tlbxrib' : '336x60',
 	  'hlfmpu' : '300x600,336x850,300x250,336x280',
 	  'mpu' : '300x250,336x280',
 	  'mpu2' : '300x600,336x850,300x250,336x280',
 	  'doublet' : '342x200',
 	  'wdesky' : '120x600,160x600',
 	  'button1' : '120x60',
 	  'emktbox1' : '294x145',
 	  'emktbox2' : '294x145',
 	  'triplet' : '982x140',
 	  'banlb2' : '468x60,728x90',
 	  'sponsor' : '200x35'
   },
   'audSciLimit': 10,
   // END THIRD PARTY CUSTOMISATION
   'server': '',
   'method': '/adj/',
   'ord': Math.floor(Math.random() * 1E16),
   'tile': 0,
   'Requests': {},
   'getAudSci': function (cookie)
   {
	   var ft = this;
	   ft.cookie = cookie === undefined ? document.cookie : cookie;
	   ft.audSci = '';
	   if (ft.audSciLimit)
	   {
		   var rsiSegs = ft.cookie.replace(/^.*\brsi_segs=([^;]*).*$/, '$1');
		   if (rsiSegs !== ft.cookie)
		   {
			   var Segments = rsiSegs.split(/\|/);
			   var Found = [];
			   for (var idx = 0; Found.length < ft.audSciLimit && idx < Segments.length; ++idx)
			   {
				   var segment = Segments[idx];
				   if (segment.match(/^J07717_/))
				   {
					   segment = segment.replace(/^J07717_/, '');
					   segment = ';a=z' + (parseInt(segment, 10) - 10000);
					   Found.push(segment);
				   }
			   }
			   ft.audSci = Found.join('');
		   }
	   }
	   return ft.audSci;
   },
   'getURL': function (pos)
   {
	   var ft = this;
	   ft.url = undefined;
	   ft.URLParts = undefined;
	   ft.pos = pos;
	   ft.sz = ft.formats[ft.pos];
	   if (ft.audSci === undefined)
	   {
		   ft.audSci = ft.getAudSci(ft.cookie);
	   }
	   if (ft.sz)
	   {
		   ft.URLParts = ['http://ad.', ft.server, 'doubleclick.net', ft.method, ft.dfp_site, '/', ft.dfp_zone, ';sz=', ft.sz, ';pos=', ft.pos, ft.targeting, ft.job_title, ft.audSci, ';tile=', ++ft.tile, ';ord=', ft.ord, '?'];
		   ft.url = ft.URLParts.join('');
	   }
	   ft.Requests[ft.pos] = ft.url;
	   return ft.url;
   },
	'getTag': function (pos)
	{
		var ft = this;
		ft.tag = undefined;
		ft.Parts = undefined;
		var url = ft.getURL(pos);
		if (url)
		{
			ft.Parts = ['<', 'script type="text/javascript" src="', url, '"><', '/script>'];
			ft.tag = ft.Parts.join('');
		}
		return ft.tag;
	},
	'adCall': function (pos)
	{
		var tag = this.getTag(pos);
		if (tag)
		{
			document.write(tag);
		}
	},
	'_': '_'
};
/**
* Deal with Methode handled articles MPU still using OAS_AD function
*/
function OAS_AD(position) {
	if (position == 'Middle') {
		FT.env.adCall('mpu');
	}
} 

    	
    	
