$.fn.load_random_banner = function (_config)
{
	this.each (function ()
	{
		_config = $.extend ({
		}, _config);
		
		var $banner = $(this);

		$.ajax ({
			'dataType' : 'jsonp',
			'url' : '//www.dialogic.com/cgi/get_banners.aspx',
			'success' : function (_data)
			{
				var sample = [];

				for (var i in _data)
					if (_data[i].type == _config.type)
						sample.push (_data[i]);

				var banner = sample [Math.floor (Math.random () * sample.length)];

				switch (_config.type)
				{
					case 'leaderboard': $banner.css ({'height' : '90px', 'width' : '728px'}); break;
					case 'banner': $banner.css ({'height' : '60px', 'width' : '468px'}); break;
					case 'square': $banner.css ({'height' : '250px', 'width' : '250px'}); break;
					case 'skyscraper': $banner.css ({'height' : '600px', 'width' : '120px'});
					default:
				}

				$banner.css ({
					'background' : 'url(\'' + banner.src + '\')',
					'display' : 'block'
				}).attr ({
					'href' : banner.href,
					'target' : banner.target,
					'title' : banner.title
				}).click (function ()
				{
					var pos = banner.src.lastIndexOf ('/')
	
					if (pos > -1)
						var file = banner.src.substr (pos + 1);
					else
						var file = banner.src;
				
					_gaq.push (['_trackEvent', 'Banner', 'Click', file]);
				});
			}
		});
	});

	return this;
};

