/***** iframeAd Library *****/
/***** This library needs the TII Ad library *****/
var iframeAd = {};
iframeAd.parseAndCall = function (pairArray, callingObject, callingFunction)
	{
		var wrapper = {};
		wrapper.callingObject = callingObject;
		for (var i = 0, l = pairArray.length; i < l; i++)
		{
			var pair = pairArray [i].split ('=');
			var property = pair [0];
			if (property && property.length > 0)
			{
				var value = pair [1];
				if (value == null) { value = ''; }
				value = value == 'true' ? true : (value == 'false' ? false : value);
				wrapper.property = property;
				wrapper.value = value;
				callingFunction.call (this, wrapper);
				value = null;
			}
			property = pair = null;
		}
	};
iframeAd.assignPropertyAndValue = function (wrapper) { wrapper.callingObject [wrapper.property] = wrapper.value; };
iframeAd.applyPropertyCall = function (wrapper) { wrapper.callingObject [wrapper.property].call (wrapper.callingObject, wrapper.value); };
iframeAd.setParam = function (wrapper) { wrapper.callingObject.setParam (wrapper.property, wrapper.value); };
iframeAd.writeIframeAd = function ()
{
	var pairs = {};
	this.parseAndCall (location.search.substring (1).split ('&'), pairs, this.assignPropertyAndValue);
	if (isNaN (pairs.getAdX) || isNaN (pairs.getAdY) && parseInt (pairs.getAdX) <= 0 || parseInt (pairs.getAdY) <= 0) { return; }
	this.adConfig = new TiiAdConfig (pairs.TiiAdConfig);
	var adConfigPairs = decodeURIComponent (pairs.adConfigPairs).split ('&');
	this.parseAndCall (adConfigPairs, this.adConfig, this.applyPropertyCall);
	this.adFactory = new TiiAdFactory (this.adConfig, decodeURIComponent (pairs.TiiAdFactory));
	var adFactoryPairs = decodeURIComponent (pairs.adFactoryPairs).split ('&');
	this.parseAndCall (adFactoryPairs, this.adFactory, this.applyPropertyCall);
	var adFactoryPropertyPairs = decodeURIComponent (pairs.adFactoryPropertyPairs).split ('&');
	this.parseAndCall (adFactoryPropertyPairs, this.adFactory, this.assignPropertyAndValue);
	var paramPairs = decodeURIComponent (pairs.paramPairs).split ('&');
	this.parseAndCall (paramPairs, this.adFactory, this.setParam);
	this.adFactory.randomNumber = pairs.randomNumber;
	var synchronizedDomain = pairs.synchronizedDomain;
	if (typeof synchronizedDomain != 'undefined' && synchronizedDomain.length > 0) { document.domain = synchronizedDomain; }
	var multiAdSizes = pairs.multiAdSizes;
	var ad;
	if (typeof multiAdSizes != 'undefined' && multiAdSizes && multiAdSizes.length > 0)
	{
		ad = this.adFactory.getMultiAd (multiAdSizes.split (','));
	}
	else { ad = this.adFactory.getAd (pairs.getAdX, pairs.getAdY); }
	ad.removePgUrl = true;
	ad.write ();
	
	/* Clear memory */
	adConfigPairs = adFactoryPairs = adFactoryPropertyPairs = paramPairs = synchronizedDomain = multiAdSizes = ad = null;
	this.clearMemory ();
};
iframeAd.clearMemory = function ()
{
	this.parseAndCall = null;
	this.assignPropertyAndValue = null;
	this.applyPropertyCall = null;
	this.setParam = null;
	this.adConfig = null;
	this.adFactory = null;
	this.writeIframeAd = null;
	writeIframeAd = null;
	this.writeQuigoIframeAd = null;
};

/* For backward compatibility */
var writeIframeAd = function () { iframeAd.writeIframeAd (); };

/* Quigo ads */
iframeAd.writeQuigoIframeAd = function ()
{
	var pairs = {};
	this.parseAndCall (location.search.substring (1).split ('&'), pairs, this.assignPropertyAndValue);
	qas_writeAd (pairs.placementId, pairs.pid, pairs.ps, pairs.zw, pairs.zh, pairs.jw);
};