<!--
// Create and instantiate the class only if not already created:
try {
if(top.channels_refresher == null) {

	// channels_refresher constructor:
	 top.channels_refresher = function() {
	 	this.add_impression.domains = new Object();
		this.ads_list = new Array();
		var body = top.document.body;
		var inner_elem = body;
		while((inner_elem = inner_elem.lastChild).tagName.toLowerCase() != "script");
		var container_elem = inner_elem.parentNode;
		while(container_elem.tagName.toLowerCase() != "div" 
							&& container_elem.tagName.toLowerCase() != "body") {
			container_elem = inner_elem.parentNode;
		}
		this.container = container_elem;
	}
	
	top.channels_refresher.prototype = {
		/** 
		 * add_ad
		 * @param index - ZERO-BASED number indicating the declared order of the ad.
		 * @param id    - Magic Number of the ad
		 * @param w     - width of the ad in pixels
		 * @param h     - height of the ad in pixels
		 * @param s     - spot of the ad in string (e.g. 300x250_2)
		 *		  Special values: 0 (Default) - always refresh, -1 - do not refresh
		 */
		add_ad:function(id, w, h, index, s) {
			if(s == null) {
				s = 0;
			}
			if(index == null) {
				this.ads_list.push({id:id, width:w, height:h, spot:s});
			} else {
				this.ads_list[index] = {id:id, width:w, height:h, spot:s};
			}
		},
		
		// add_impression
		add_impression:function(url) {
			var domains = this.add_impression.domains;
			var make_sequential_name = function(name) {
				if(domains[name] == null) {
					domains[name] = true;
					return name;
				} else {
					var seq = 0;
					var _name = name + "_" + (++seq);
					while(domains[_name] != null) {
						_name = name + "_" + (++seq);
					}
					domains[_name] = true;
					return _name;
				}
			}
			if(url != null && url.length) {
				var frame_name = make_sequential_name("frame_" + new Date().getTime());
				var i_frame = top.document.createElement("iframe");
				i_frame.id = frame_name;
				i_frame.width = 1;
				i_frame.height = 1;
				i_frame.style.position = "absolute";
				i_frame.style.top = "-10px";
				i_frame.style.left = "-10px";
				i_frame.style.visibility = "hidden";
				i_frame.src = url;
				this.container.appendChild(i_frame);
				return frame_name;
			}
		},
		
		// add_url
		add_url:function(f_name, url) {
			//	If the target_frames object is null, create it:
			if(!this.target_frames) this.target_frames = new Object();
			//	If this frame name has not been used before, then...
			if(!this.target_frames[f_name]) {
				//	Create a new frame repository:
				this.target_frames[f_name] = new Object();
				//	Create a new list for frame urls:
				this.target_frames[f_name].urls = new Array();
				//	Create a default index of zero for this frame:
				this.target_frames[f_name].current_index = 0;
			}
			//	Add the url to the frame's url list:
			if(url && url.length) this.target_frames[f_name].urls.push(url);
		},
		
		// refresh_ads
		refresh_ads:function() {	
				adsReloadIframeAll();
		},
		
		// refresh_ad
		refresh_ad:function(index) {
			if(this.ads_list[index] != null) {
				try {
						adsReloadIframe('adsF'+i);
				} catch(e) {}
			}
		},
		
		// refresh_ads_string
		refresh_ads_string:function(str) {
			var ads = str.split(",");
			for(var i = 0; i < ads.length; i++) {
				var index = parseInt(ads[i]);
				if(!isNaN(index) && index >= 0 && index < this.ads_list.length) {
					this.refresh_ad(index);
				}
			}
		},
		
		// refresh_ads_by_spot
		refresh_ads_by_spot:function(str) {
			if (str == '-1') return;
			var spots = new Array();
			if (str == null || str == 'undefined' || str == '0') {
				for(var i = 0; i < this.ads_list.length; i++) {
					spots.push(this.ads_list[i].spot);
				}
			} else {
				spots = str.split(",");
			}
			spots = spots.sort();
			var oldVar = '';
			for(var i = 0; i < spots.length; i++) {
				var spot = spots[i];
				if (oldVar == spot) break;
				oldVar = spot;
				for(var j = 0; j < this.ads_list.length; j++) {
					if (spot == this.ads_list[j].spot) {
						this.refresh_ad(j);
						break;
					}
				}
			}
		},

		// refresh_all
		refresh_all:function() {
			//	Loop through the ads and refresh them:
			this.refresh_ads();
			//	If there are target_frames:
			this.refresh_frames();
		},
		
		// refresh_all
		refresh_frames:function() {
			if(this.target_frames) {
				for(var f in this.target_frames) {
					var frame = this.target_frames[f];
					var i_frame = top.document.getElementById(f);
					if(frame.urls.length) {
						var url = frame.urls[frame.current_index++];
						if(frame.current_index >= frame.urls.length) frame.current_index = 0;
						this.refresh_frame(f, url);	
					}
				}
			}
		},
		
		// refresh_frame
		refresh_frame:function(f_name, url) {
			if(url != null && url.length) {
				var elem = (top.frames[f_name] 
						|| top.document.getElementById(f_name).contentWindow 
						|| top.document.getElementById(f_name));
				try {
					if(elem.location) {
						if((url == elem.location.href) && elem.location.reload) {
							elem.location.reload(true);
						} else {
							elem.location.href = url;
						}
					} else {
						elem.src = url;
					}
					
				} catch(e) {}
			}
		}
	
	}
	
	// Instantiate the default refresher
	window.ch_refresher = new channels_refresher();
}
} catch(e) {}
//-->


