(function(){

	var myInterval = setInterval(
		function(){
			if (typeof jQuery != 'undefined')
			{
				clearInterval(myInterval);
				proceed(jQuery);
			}
		},
		100
	);
	
	if (typeof jQuery == 'undefined')
	{
		var e = document.createElement('script');
		e.src = 'http://code.jquery.com/jquery-1.5.1.min.js';
		document.getElementsByTagName('head')[0].appendChild(e);
	}
	
	function proceed($)
	{
		$(function(){
			var box = $('#game_swf_container');
			
			if (box.length == 1)
			{
				var filter = $('iframe,object,embed', box);
				
				// Try again later
				if (filter.length == 0)
				{
					myInterval = setInterval(
						function(){
							if (jQuery('iframe,object,embed', jQuery('#game_swf_container')).length > 0)
							{
								clearInterval(myInterval);
								proceed(jQuery);
							}
						},
						100
					);
					
					return;
				}
			}
			else
				var filter = $('iframe[src$=swf],'+($.browser.msie||$.browser.safari?'object':'embed')+':not([src^="http://ads.rebubbled.com"])');
			
			filter.hide().each(function(i,e){
				e = $(e);
				
				if (e.attr('width') >= 400)
				{
					var c = e.clone();
					var h = e.attr('height');
					
					e.before('<div id="igre_pre_ad" style="margin:0;padding:0;border:0;position:relative"></div>');
					e.remove();
					
					var p = $('#igre_pre_ad');
					
					p.css({position:'relative'}).append('\
						<div class="ad" style="border:0;padding:0;height:'+h+'px;margin:0;text-align:center">\
							<iframe src="http://static.igre.hr/banners/300x250.html?host='+document.location.hostname+'" width="300" height="250" scrolling="no" frameborder="0" allowtransparency="true" style="padding:0;margin:20px 0 17px;border:0;width:300px;height:250px"></iframe>\
							<div class="loader" style="background:#ccc;margin:0 auto;padding:0;border:0;font-weight:bold;height:28px;width:151px;clear:both;position:relative;top:0;left:0;text-align:center">\
								<p style="background:#555;padding:0;margin:0;border:0;left:0;top:0;position:absolute;width:0;height:28px"></p>\
								<a style="color:#fff;font:bold 14px/28px Arial,Helvetica,sans-serif;position:relative;top:0;left:0;text-decoration:none">U&#268;ITAVAM...</a>\
							</div>\
						</div>');
					
					$('.ad .loader p', p).animate({width:'151px'},10000,null,function(){
						$(this).siblings().css('cursor',$.browser.msie?'hand':'pointer').text('POKRENI IGRU').click(function(){$('.ad', p).remove();p.append(c.show());return false;});
						return false;
					});
					
					return false;
				}
			});
		});
	}

}());
