var xrx_hbx_proxy = function() {
	var hbx_mlc;
	var hbx_pn;
	var debug = false;

	function set_pn_mlc(pn, mlc)
	{
		if ( !pn || pn == '' ) {
			if ( hbx_pn != null ) {
				pn = hbx_pn;
				if (debug) console.log("DEFAULTING PN: "+pn);
			} else if ( typeof(hbx) != 'undefined' && hbx.pn ) {
				pn = hbx.pn;
			}
		}

		if ( !mlc || mlc == '' ) {
			if ( hbx_mlc != null ) {
				mlc = hbx_mlc;
				if (debug) console.log("DEFAULTING MLC: "+mlc);
			} else if ( typeof(hbx) != 'undefined' && hbx.mlc ) {
				mlc = hbx.mlc;
			}
		}

		return [pn, mlc];
	}

	return {
		debug: function(flag) {
			if (flag != null) debug = flag;
			return debug;
		},
		xrxLink: function(lid, pn, mlc) {
			var pn_mlc = set_pn_mlc(pn, mlc);
			pn  = pn_mlc[0];
			mlc = pn_mlc[1];
			if ( _hbSet != null ) {
				_hbSet('vcon', mlc);
				_hbSet('n', pn);
				_hbLink(lid); // assume that if we have _hbSet, we have _hbLink
				if (debug) console.log("LINK CLICK: pn("+pn+"), mlc("+mlc+"), lid("+lid+")");
			} else {
				if (debug) console.log("NO _hbSet DEFINED");
			}
		},
		xrxPageView: function(pn, mlc) {
			var pn_mlc = set_pn_mlc(pn, mlc);
			pn  = pn_mlc[0];
			mlc = pn_mlc[1];
			if ( typeof(_hbPageView) != 'undefined' ) {
				_hbPageView(pn, mlc);
				if (debug) console.log("PAGE VIEW: pn("+pn+"), mlc("+mlc+")");
			} else {
				if (debug) console.log("NO _hbPageView DEFINED");
			}
		},
		xrxAtlasTag: function(url) {
			if (debug) console.log("ATLAS: "+url);
			var img = new Image();
			img.src = 'http://switch.atdmt.com/action/' + url;
		},
		xrxMediaPlay: function(fileName, currPos, endPos, flashVersion) {
			if (debug) console.log("PLAY: filename("+fileName+"), currPos("+currPos+"), endPos("+endPos+"), flashVersion("+flashVersion+")");
			_hbSet('m.f',  fileName);
			_hbSet('m.cp', currPos);
			_hbSet('m.ep', endPos);
			_hbSet('m.s',  'play');
			_hbSet('m.cl', 'Flash Player');
			_hbSet('m.cv', flashVersion);
			_hbSet('m.tt', 'e');
			_hbSend();
		},
		xrxMediaPause: function(fileName, currPos, endPos, flashVersion) {
			if (debug) console.log("PAUSE: filename("+fileName+"), currPos("+currPos+"), endPos("+endPos+"), flashVersion("+flashVersion+")");
			_hbSet('m.f',  fileName);
			_hbSet('m.cp', currPos);
			_hbSet('m.ep', endPos);
			_hbSet('m.s',  'pause');
			_hbSet('m.cl', 'Flash Player');
			_hbSet('m.cv', flashVersion);
			_hbSet('m.tt', 'e');
			_hbSend();
		},
		xrxMediaStop: function(fileName, currPos, endPos, flashVersion) {
			if (debug) console.log("STOP: filename("+fileName+"), currPos("+currPos+"), endPos("+endPos+"), flashVersion("+flashVersion+")");
			_hbSet('m.f',  fileName);
			_hbSet('m.cp', currPos);
			_hbSet('m.ep', endPos);
			_hbSet('m.s',  'stop');
			_hbSet('m.cl', 'Flash Player');
			_hbSet('m.cv', flashVersion);
			_hbSet('m.tt', 'e');
			_hbSend();
		},
		xrxMediaPlayProgress: function(fileName, currPos, endPos, flashVersion) {
			if (debug) console.log("PROGRESS: filename("+fileName+"), currPos("+currPos+"), endPos("+endPos+"), flashVersion("+flashVersion+")");
			_hbSet('m.f',  fileName);
			_hbSet('m.cp', currPos);
			_hbSet('m.ep', endPos);
			_hbSet('m.s',  'playp');
			_hbSet('m.cl', 'Flash Player');
			_hbSet('m.cv', flashVersion);
			_hbSet('m.tt', 'e');
			_hbSend();
		}
	};
} ();
