function Nedstat( sitestatpath, productName, pageCounter ) {

	ConfigParams = {

			SERVER_COUNTRY : 'uk',

			CUSTOMER : 'ladbrokes',

			LABEL_PREFIX : 'lb_',

			STATS_ENABLED : true,

			LINKTRACKING_ENABLED : true,

			DEV_PRODUCTNAME_PREFIX : 'dev-',

			LIVE_PRODUCTNAME_STAT_PREFIX : '',

			SCRIPT_URL_MIN_LENGTH : 1,

			JS_TECH_MEASURMENT_FILE : sitestatpath + 'sitestat.js',

			PRODUCT_NAMES : { 

							'games':{ 'stage' : 'test-games', 'live' : 'games','lang':true},

							'bingo':{ 'stage' : 'test-bingo', 'live' : 'bingo','lang':true},

							'casino':{ 'stage' : 'test-casino', 'live' : 'casino','lang':true},

							'betting':{ 'stage' : 'test-betting', 'live' : 'betting','lang':true},

							'backgammon':{ 'stage' : 'test-backgammon', 'live' : 'backgammon','lang':true},
              
              			                	'tavli':{ 'stage' : 'test-tavli', 'live' : 'tavli','lang':true}, 
                                                                                            
							'shops':{ 'stage' : 'test-shops', 'live' : 'shops','lang':true},	

							'poker':{ 'stage' : 'test-poker', 'live' : 'poker','lang':true},
							
							'lottos':{'stage' : 'test-lottos', 'live' : 'lottos','lang':true},

							'common':{ 'stage' : 'test-common', 'live' : 'common','lang':true},

							'sport':{ 'stage' : 'test-sports', 'live' : 'sports','lang':true},
							
							'financials':{'stage' : 'test-financials', 'live' : 'financials','lang':true},
							
							'pokerexe':{ 'stage' : 'test-pokerexe', 'live' : 'pokerexe','lang':false},
							
							'sports':{ 'stage' : 'test-sports', 'live' : 'sports','lang':true}

							}

	}



	function Labels() {

		this.labels = {};

		function get_cookie ( cookie_name ) {

			var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );

			return ( results ) ? ( unescape ( results[2] ) ) : null;

		} function delete_cookie ( cookie_name )	{

			var cookie_date = new Date ( );  // current date & time

			cookie_date.setTime ( cookie_date.getTime() - 1 );

			document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();

		} function set_cookie ( name, value, exp_y, exp_m, exp_d, path, domain, secure )	{

			var cookie_string = name + "=" + escape ( value );

			if ( exp_y ) {

				var expires = new Date ( exp_y, exp_m, exp_d );

				cookie_string += "; expires=" + expires.toGMTString();

			}

			if ( path ) cookie_string += "; path=" + escape ( path );

			if ( domain ) cookie_string += "; domain=" + escape ( domain );

			if ( secure ) cookie_string += "; secure";

			document.cookie = cookie_string;

		}

		

		if ( get_cookie('PLAYED') || false ) {

			this.labels.status = get_cookie('PLAYED').replace(/\|/g, '') ;

		}else{

			this.labels.status = '0000000' ;

		}

		if ( get_cookie('FLAGS') || false ) {

			var cookie_string 	= get_cookie('FLAGS');

			this.labels.lang 	= cookie_string.split('|')[0] ;

			this.labels.view 	= cookie_string.split('|')[2] ;

		}else{

			var logic = new Nedstat();

			this.labels.lang =logic.language;

			this.labels.view = 'uk' ;

		}

		this.labels.tid = '-1' ;

		var trackingId = get_cookie('TRACKING_ID') ;

		if( trackingId != null){

			this.labels.tid = trackingId  ;

		}







	}



	var url = document.location.toString();

	this.protocol = url.split('://')[0];

	this.domain = url.split('//')[1].split('/')[0];
	

	if (productName && productName != ''){

		subdomain = productName ;

	}else{

		var subdomain = url.split('://')[1].split('.')[0];

	}
	
	this.baseUrl = null;

	this.counterName = null;

	if ( ConfigParams.STATS_ENABLED ) {

		if(url.indexOf( this.protocol +  '://' + ConfigParams.DEV_PRODUCTNAME_PREFIX ) == 0){

			this.productName = ConfigParams.PRODUCT_NAMES[subdomain.replace(ConfigParams.DEV_PRODUCTNAME_PREFIX, '')]['stage'];
			this.languageInclude = ConfigParams.PRODUCT_NAMES[subdomain.replace(ConfigParams.DEV_PRODUCTNAME_PREFIX, '')]['lang'];

		}else{

			this.productName = ConfigParams.PRODUCT_NAMES[subdomain]['live'];
			this.languageInclude = ConfigParams.PRODUCT_NAMES[subdomain]['lang'];

		}

		this.baseUrl = 'https://' + ConfigParams.SERVER_COUNTRY + '.sitestat.com/' + ConfigParams.CUSTOMER + '/' + this.productName + '/s?';

	}

		    
	if(this.languageInclude )
	{
		pageUrl = url.split(this.domain)[1].split('?')[0];
		this.language = url.split('//')[1].split('/')[1].split('?')[0];
	    
	    if (pageUrl.length > 3) {
	    
	        this.pagePath = pageUrl.split('\/' + this.language + '\/')[1];
	    }
	    else {
	        this.pagePath = pageUrl.split('\/' + this.language)[1];
	    }

	}
	else
	{
		this.pagePath = url.split(this.domain)[1].split('?')[0];
	}	
	

	 this.pagePath = this.pagePath ? this.pagePath :'' ;
	
	if ( ( this.pagePath.charAt(0) ) && ( this.pagePath.charAt(0) == '/' ) ) this.pagePath = this.pagePath.substr(1);

	


  this.getCounterName = function() {

	  if ( !ConfigParams.STATS_ENABLED ) {	return null; }

	  if (pageCounter && pageCounter != ''){

		  return pageCounter;

	  }

	  if ( this.counterName != null ) { 

		  return this.counterName; 

		  }

	  this.counterName = this.pagePath.replace(/\//g, '.');

	  this.counterName = encodeURIComponent(this.counterName).replace("+", "%2B");

	  if ( this.counterName == '' ) { this.counterName = 'home'; }

	  this.counterName = this.counterName + '.page';

	  return this.counterName;

  }



  this.getBaseUrl = function() {

	  return this.baseUrl;

  }

  

  this.getCustomLabels = function() {

	  var qs = '';

	  var l = new Labels();

	  for ( var label in l.labels ) {

		  qs = qs + '&amp;' + ConfigParams.LABEL_PREFIX + label + '=' + l.labels[label];

	  }

	  return qs;

  }

  

  this.writeTechnicalMeasurementCode = function() {

	  if ( !ConfigParams.STATS_ENABLED ) { return null; }

	  document.write( "<script language='Javascript1.1' type='text/javascript' src='" + ConfigParams.JS_TECH_MEASURMENT_FILE + "'></script>");

  }

  

  this.writeLoadingMeasurementHeaderCode = function() {

	  if ((!ConfigParams.STATS_ENABLED) || (this.getCounterName() != 'home.page')) { return null; }

	  document.write("<script language='Javascript1.1' type='text/javascript'>ns_loadingtime1=(new Date()).getTime();</script>");

  }

  

  this.writeLoadingMeasurementFooterCode = function() {

	  if ((!ConfigParams.STATS_ENABLED) || (this.getCounterName() != 'home.page')) { return null; }

	  document.write("<script language='Javascript1.1' type='text/javascript'>ns_loadingtime2=(new Date()).getTime();</script>");

  }

 this.get404Label = function() {

	  var qs = '';

	  if(document.getElementById('error404')) 
			qs = '&amp;' + 'ns_http_status=404';

	  return qs;

  }



  

  this.getStatUrl = function() {

	  if (!ConfigParams.STATS_ENABLED) { return null; }

	  var statUrl = this.getBaseUrl() + this.getCounterName() + this.getCustomLabels() + this.get404Label();

	  return statUrl;

  }

  

}	function linkCounter(sText, sUrl, sLocation){		var stUrl = sNedStatUrl + "&amp;ns_type=hidden&amp;lb_lname="  + encodeURIComponent(sText) + "&amp;lb_lloc=" + encodeURIComponent(sLocation) + "&amp;lb_lurl=" + encodeURIComponent(sUrl);		sitestat(stUrl);	}




	function sitestat(u){var d=document,l=d.location;ns_pixelUrl=u+"&ns__t="+(new Date().getTime());u=ns_pixelUrl+"&ns_c="+((d.characterSet)?d.characterSet:d.defaultCharset)+"&ns_ti="+escape(d.title)+"&ns_jspageurl="+escape(l&&l.href?l.href:d.URL)+"&ns_referrer="+escape(d.referrer);(d.images)?new Image().src=u:d.write('<'+'p><img src="'+u+'" height="1" width="1" alt="*"><'+'/p>');}


