"use strict";

/*jslint white: true, onevar: true, browser: true, undef: true, nomen: true, eqeqeq: true, plusplus: true, bitwise: true, regexp: true, strict: true, newcap: true, immed: true */

var SERGEYCHE = SERGEYCHE || { sources: {} };

// this function to be called on the page
SERGEYCHE.sources.ping = function () {
	var url, head, links, i, beacon;

	url = location.href;
	head = document.getElementsByTagName('head')[0];

	if (typeof(head) !== undefined) {
		links = head.getElementsByTagName('link');
		for (i = 0; i < links.length; i += 1) {
			if (links[i].attributes.rel === 'canonical') {
				url = links[i].attributes.href;
				break;
			}
		}

		beacon = document.createElement('img');
		beacon.src = 'http://www.sergeychernyshev.com/sources/ping.php?url=' + encodeURIComponent(url) + '&referrer=' + encodeURIComponent(document.referrer);
		beacon.style = 'visibility: hidden';
		beacon.id = 'sources_beacon';

		document.appendChild(beacon);
	}
};

SERGEYCHE.sources.ping();

