var AddThreeTracker = function(url, conversion, conversionName, conversionValue) {
	
	this.url = url + "/tracker.php";

	this.info = {
		location: document.location ? encodeURIComponent(document.location) : '',
		referrer: document.referrer ? encodeURIComponent(document.referrer) : ''
	};
	
	this.isConversion = function() {
	  return !this.info.conversionName;
	};
	
	this.skipTracking = function() {
	  if (!document.cookie) {
	    return false;
	  }
    return document.cookie.match(/conversion/) || (!this.isConversion() && document.cookie.match(/hit/));
	};

	this.parseSearchString = function(searchString) {
		a = searchString.substring(1, searchString.length).split('&');
		for (var i = 0; i < a.length; i++) {
			b = a[i].split('=');
			if (b[0] == 'k') {
				this.info.keyword = decodeURI(b[1]);
			}
			else if (b[0] == 'a' || b[0] == 'g') {
				this.info.ad_group = decodeURI(b[1]);
			}
			else if (b[0] == 'c') {
				this.info.campaign = decodeURI(b[1]);
			}
		}
		return this;
	};
	
	this.writeImage = function() {
		var img = new Image(2,2);
		img.src = this.url + "?i=" + this.infoString();
		img.style.display = 'none';
		document.getElementsByTagName('body')[0].appendChild(img);
	};
	
	this.infoString = function() {
		this.parseSearchString(location.search);
		string = '';
		for(property in this.info) {
		  if (this.info.hasOwnProperty(property)) {
		    if (this.info[property]) {
			    string = string + encodeURIComponent(property) + '=' + encodeURIComponent(this.info[property]) + ';';
		    }
		  }
		}
		return string;
	};
	
	this.setConversionOptions = function(options) {
    if (undefined === options) {
      return;
    }
    if (options.conversionName !== undefined) {
      this.info.conversionName = options.conversionName;
    }
    if (options.conversionValue !== undefined) {
      this.info.conversionValue = options.conversionValue;
    }
	};
	
	this.track = function(options) {
    if (!this.skipTracking()) {
      this.setConversionOptions(options);
	    this.writeImage();
    }
	};
	
	return this;

};
