function discoverCurrentURI() {
	if (typeof document.location.href != 'undefined' && document.location.href.length > 0) {
		return document.location.href;
	} else if (typeof window.location.href != 'undefined' && window.location.href.length > 0) {
		return window.location.href;
	} else if (typeof document.URL != 'undefined' && document.URL.length > 0) {
		return document.URL;
	}

	return '';
}

function discoverCurrentHash() {
	if (typeof document.location.hash != 'undefined') {
		return document.location.hash;
	} else if (typeof window.location.hash != 'undefined') {
		return window.location.hash;
	}

	return '';
}

function discoverReferer() {
	var isTopRefererDefined = false;
	try {
		isTopRefererDefined = typeof top.document.referrer != 'undefined'
	} catch (e) {
		// exception ocurs if top frameset is external (e.g. a google frameset)
	}

	if (isTopRefererDefined) {
		return top.document.referrer;
	} else if (typeof document.referrer != 'undefined') {
		return document.referrer;
	}

	return '';
}

function NaturalSearch() {
	var rotationId = '4284-30318-12262-0';
	var sref = discoverReferer();
	var currentURI = discoverCurrentURI();
	var currentHash = discoverCurrentHash();

	if (sref.length < 1)
		return false;

	var searchEngines = ["metager.de", "suche.infospace.de", "metacrawler.com", ".excite.com", "suche.fireball.", "search.yahoo.com", "search.msn.", ".altavista.com", "www.alltheweb.com", "search.lycos.com/default.asp", ".ask.com/web", "www.google.com.au", "images.google.com.au", "ninemsn.com.au", "search.aol.com.au", "www.goeureka.com.au", "au.anzwers.yahoo.com", "www.yellowpages.com.au/search/searchEntry.do", "search.bigpond.com", "www.google.be/search", "images.google.be/images", "maps.google.be/maps", "www.google.ba/search", "images.google.ba/images", "www.google.bg/search", "images.google.bg/images", "diri.bg/search.php", "web.search.bg/search.php", "www.all.bg", "www.baidu.com/", "image.baidu.com/", "site.baidu.com/", "seek.3721.com/", "page.zhongsou.com/", "hc360.zhongsou.com/", "site.zhongsou.com/", "search.sina.com.cn/", "pic.sina.com.cn/", "dir.sina.com.cn/", "search.sohu.com/", "image.search.sohu.com/", "www.sogou.com/", "nisearch.163.com/", "psearch.163.com/", "picsearch.163.com/", "search.tom.com/", "sitesearch.tom.com/", "cn.websearch.yahoo.com/", "cn.imagesearch.yahoo.com/", "www.yisou.com/search", "image.yisou.com/", "www.google.dk/search", "images.google.dk/images", "www.google.de/search", "www.google.de/product_url?q=", "images.google.de/images", "maps.google.de/maps", "www.google.de/imgres", "suche.aol.de/aol/search", "suche.aol.de/aol/image", "suche.freenet.de/suche", "shopping.freenet.de/suchergebnis/index.html", "suche.t-online.de/fast-cgi/tsc", "suche.web.de/search/", "dir.web.de", "suche.lycos.de", "webkatalog.lycos.de", "search.live.com/results.aspx", "www.google.ee/search", "images.google.ee/images", "www.google.fi/search", "images.google.fi/images", "www.google.fr/search", "images.google.fr/images", "maps.google.fr/maps", "www.recherche.aol.fr", "www.images.aol.fr", "vachercher.lycos.fr/cgi-bin/pursuit", "search.ke.voila.fr", "recherche.wanadoo.fr", "search1-2.free.fr", "www.google.ge/search", "images.google.ge/images", "www.google.gr/search", "images.google.gr/images", "www.google.co.uk/search", "images.google.co.uk/images", "maps.google.co.uk/maps", "search.aol.co.uk/web_uk.adp", "www.ask.co.uk/res.asp", "search.lycos.co.uk/cgi-bin/pursuit", "search.orange.co.uk/all", "www.google.it/search", "images.google.it/images", "maps.google.it/maps", "search.virgilio.it", "arianna.libero.it", "business.libero.it/arianna/", "search.tiscali.it", "www.google.ca", "ca.yahoo.com", "www.toile.qc.ca", "www.lycos.ca", "www.google.hr/search", "images.google.hr/images", "www.google.lt/search", "images.google.lt/images", "search.delfi.lt/search.php", "www.google.md/search", "images.google.md/images", "www.google.nl/search", "images.google.nl/images", "maps.google.nl/maps", "www.ilse.nl/searchresults.dbl", "pagina.nl", "www.google.no/search", "images.google.no/images", "suche.lycos.at", "www.google.at/search", "images.google.at/images", "maps.google.at/maps", "austronaut.at/page.php", "www.google.pl/search", "images.google.pl/images", "szukaj.onet.pl/query.html", "szukaj.wp.pl/szukaj.html", "www.google.pt/search", "images.google.pt/images", "www.google.ro/search", "images.google.ro/images", "www.google.ru/search", "images.google.ru/images", "yandex.ru/yandsearch", "www.rambler.ru/srch", "www.google.se/search", "images.google.se/images", "www.search.ch", "www.google.ch/search", "images.google.ch/images", "maps.google.ch/maps", "www.google.es/search", "images.google.es/images", "maps.google.es/maps", "buscador.terra.es", "buscar.ya.com", "www2.yatv.com", "busca.wanadoo.es/search", "www.google.sk/search", "images.google.sk/images", "best.sk/search.aspx", "search.centrum.sk", "www.zoznam.sk/hladaj.fcgi", "www.azet.sk/katalog/vyhladavanie/internet/", "www.pozri.sk/hladaj.php", "www.google.si/search", "images.google.si/images", "tw.yahoo.com", "www.google.com.tw", "images.google.com.tw", "www.pchome.com.tw", "image.pchome.com.tw", "dir.pchome.com.tw", "www.yam.com", "wps.yam.com", "dir.yam.com", "www.msn.com.tw", "www.google.cz/search", "images.google.cz/images", "search.seznam.cz", "search.centrum.cz", "www.google.ua/search", "images.google.ua/images", "www.google.hu/search", "images.google.hu/images", "ok.hu/katalogus", "www.looksmart.com", "www.google.com/search", "images.google.com/images", "maps.google.com/maps", "directory.google.com", "groups.google.com", "aolsearch.aol.com", "search.aol.com", "s.teoma.com/", "www.hotbot.com", "search.hotbot.de", "www.wisenut.com", "search.netscape.com", "www.bing.com/search", "www.bing.com/images/search", "www.bing.com/videos/search"];
	for (var i = 0; i < searchEngines.length; ++i) {
		if (sref.indexOf(searchEngines[i]) > -1) {
			if (currentHash.length > 0 && currentHash.indexOf('#skip_ns') > -1)
				break;

			var im = 'http://a' + 'dfarm.mediaplex.com/a' + 'd/lt/' + rotationId;
			im += '?mpt=' + escape((new Date()).toGMTString());

			if (typeof encodeURIComponent == 'function') {
				im += '&mpcl=' + encodeURIComponent(currentURI);
				im += '&mpvl=' + encodeURIComponent(sref);
			} else {
				im += '&mpcl=' + escape(currentURI);
				im += '&mpvl=' + escape(sref);
			}

			document.write('<img src="' + im + '" alt="" border="0" width="1" height="1" />');
			break;
		}
	}
}
NaturalSearch();

