 /**Used to register and display ads.
 * usage :
 * var ad =   new MotionBasedAdvertisement(...)
 * ad.registerForDisplay();
 * //system renders ad asynchronously.
 * 
 */
 function MotionBasedAdvertisement(id,channel,dimension,width,height,debug) {
 
 	this.id = id;
 	this.channel = channel;
 	this.dimension = dimension;
 	this.width = width;
 	this.height = height;
 	this.debug = debug == true;
 	/**the number of milliseconds the registration should wait to call the render method.*/
 	this.millisecondsDelay = 1000;
 	
 	
 	//==================== FUNCTIONS ============================
 	/**asynchronous calls render function to build the ads so that the initial page loading will not wait for ad to render.*/
 	this.registerForDisplay = function(){
	 	var tickMark = "'";
	 	var expression = "renderMotionBasedAdvertisement(" + tickMark + this.id + tickMark +  "," + tickMark + this.channel + tickMark +"," + this.dimension + "," + this.width + "," + this.height + "," + this.debug + ")";
	 	if(this.debug)
	 	{
			alert("setting timeout " + expression);
		}
	    window.setTimeout(expression,this.millisecondsDelay);
	 }
 }
 
 /** Advertisement banners should first call registerMotionBasedAdvertisement
 * Currently an iframe is rendering to talk to Zedo Ad Server.
 * <iframe 
      src="http://c5.zedo.com/jsc/c5/ff2.html?n=637;c=${param.channels};s=1;d=${param.dimension};w=${param.width};h=${param.height}" 
      frameborder="0" 
      marginheight="0" 
      marginwidth="0" 
      scrolling="no" 
      allowTransparency="true" 
      width="${param.width}" 
      height="${param.height}">&#160;</iframe>
 * Or if its ssl
 *<iframe src="https://ss1.zedo.com/jsc/ss1/ff2.html?n=637;c=91/89/1;s=1;d=9;w=300;h=250" frameborder=0 marginheight=0 marginwidth=0 scrolling="no" allowTransparency="true" width=300 height=250></iframe>
 */
 function renderMotionBasedAdvertisement(id,channels,dimension,width,height,debug){
 
 	var iframeElement  = document.getElementById(id);
 	var secure = new Boolean(this.window.location.protocol == "https:");
 	
 	if(secure.valueOf()){
 	var base = "https://ss1.zedo.com/jsc/ss1";
 	} else {
 	var base = "http://c5.zedo.com/jsc/c5";
 	}
 	var src = base;
	src +="/ff2.html?n=637;c=";
 	src += channels;
 	src += ";s=1;d=";
 	src += dimension;
 	src += ";w=";
 	src += width;
 	src += ";h=";
 	src += height;
 	if(debug){
 	 	alert("displaying src " + src);
 	 }
 	iframeElement.setAttribute("src",src);
 }