var extsc = function() {

	var $P = [];
	$P.scstats = scstats;

	return {
		init:function() {
			if(!scstats) { return; }

			scstats.url = encodeURIComponent(window.location.href);

			this.generateIframe();
		},

		generateIframe : function() {
			var iframe = document.createElement('iframe');

			var host = 'www.cbc.ca';
            var src = 'http://'+host+'/g/stats/ext.html?' + this.generateQueryString();

			iframe.src = src;
			iframe.style.border = '0px solid #FFFFFF';
			iframe.style.height = '0px';
			iframe.style.width = '0px';

            setTimeout(function() {
                document.body.appendChild(iframe);
            },1000);
		},

		generateQueryString : function() {
			
			var qs = '';
			var qsSize = this.objSize($P.scstats);
			var count = 0;
			for(var statkey in $P.scstats) {

				if($P.scstats.hasOwnProperty(statkey)) {
					
					count++;
					var val = $P.scstats[statkey];

					qs += statkey + '=' + val;
					if(count < qsSize) {
						qs += '&';
					}
				}

			}

			return qs;

		},

		objSize : function(obj) {
			
			var count = 0;

			for(property in obj) {
				if(obj.hasOwnProperty(property)) {
					count++;
				}
			}

			return count;

		}
	};

}();
extsc.init();

