$(window).load(function() { $('div[id*="google_ads_div"]').each(politeSetup); });
function politeSetup() {
	var iframe = $(this).find("iframe");
	var div = iframe.contents().find("#google_flash_div");
	if(typeof(div) == 'undefined' || iframe.width()<200 || iframe.width()>750) return;
	var swf = div.find("param[name='movie']").attr("value");
	var clicktag = div.find("param[name='FlashVars']").attr("value");
	if(typeof(clicktag)=='undefined') return;
	var flashvars = { clickTAG: div.find("param[name='FlashVars']").attr("value").split("clickTAG=")[1] };

	// hack to only put 'wmode' if not firefox
	var params;
	if ($.browser.mozilla) {
		params = { play:"true", quality:"high", allowscriptaccess:"always" };
	} else {
		params = { play:"true", quality:"high", allowscriptaccess:"always", wmode:"transparent" };
	}
	var attributes = { id:$(this).attr("id").replace("div","flash") };
	var id = $(this).attr("id").replace("div","polite");
	$(this).append('<div id="'+id+'"></div>');
	$(this).attr("polite","true");
	$(this).addClass('google_ads_ins');
	swfobject.embedSWF(swf, id, String(iframe.width()), String(iframe.height()), "8.0.0", false, flashvars, params, attributes);
	iframe.remove();

	$('div.google_ads_ins ins').hide();
} 
function swapBanner(swf,rich,clicktag) {
	$("div[id*='google_ads_div']").each(function() {
		if($(this).attr("polite")!='true') return;
		var flash = $(this).find("object");
		if(flash.attr("data") == swf || $(this).find("param[name='movie']").val() == swf) {
			var flashvars = { clickTAG: escape(clicktag) };
			// hack to only put 'wmode' if not firefox
			var params;
			if ($.browser.mozilla) {
				params = { play:"true", quality:"high", allowscriptaccess:"never", allownetworking:"all" };
			} else {
				params = { play:"true", quality:"high", allowscriptaccess:"never", allownetworking:"all", wmode:"transparent" };
			}
			var attributes = { id:$(this).attr("id").replace("div","flash") };
			var id = $(this).attr("id").replace("div","polite");
			var w = String(flash.width()); var h = String(flash.height());
			$(this).append('<div id="'+id+'"></div>');
			flash.remove();
			swfobject.embedSWF(rich, id, w, h, "8.0.0", false, flashvars, params, attributes);
		}
	});
}
function checkLoaded() { return true; }
