﻿
function AdRefresh() {
	$(function() {
		if (typeof cosmoAds == 'undefined') return;
		for (var i = 0; i < cosmoAds.length; i++) {
			if (cosmoAds[i].Type == '' || cosmoAds[i].ContainerID == '') continue;
			var iframe = $('<iframe></iframe>').attr('id', 'adRefreshIframe' + i).css('display', 'none').data('ad', cosmoAds[i])
				.attr('src', window.location.href+ '?AdOnly=1&Ad=' + cosmoAds[i].Type)
				.bind('load', function() {
					var ad = $(this).data('ad');
					if ($.isFunction(document.getElementById($(this).attr('id')).contentWindow.GetAd)) {
						var adHtml = document.getElementById($(this).attr('id')).contentWindow.GetAd();
						$('#' + ad.ContainerID).html(adHtml + '<br />');
						$(this).remove();
					}
				});
			$('body').append(iframe);
		}
	});
}
