var FT = window.FT || {};

FT.env =
{
	// THIRD PARTY CUSTOMISATION HERE
	'dfp_site':		'gym.5887.money-gym',
	'dfp_zone':		'unclassified',
	'targeting':	'',
	
	'formats':   {
		'mpu':		'300x250'
	},
	'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.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');
	}
}

