var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		}
	]			
};

RandomBanners = new Class({
	initialize: function(container, elementId, props) {
		this.props = Object.extend({
			images: []
		}, props || {});

		if (this.props.images.length < 1) { return; }

		var containerImgs = $$('#'+elementId);
		if (containerImgs.length > 0) containerImgs.each(function(image) { image.remove(); });
		
		bId = $random(0, this.props.images.length-1);
		
		BrowserDetect.init();
		
		if (this.props.images[bId][0]=='img')
		{
			var img = new Element('img');
			var a = new Element('a');
			
			img.setProperty('src', this.props.images[bId][1]);
			img.setProperty('width', this.props.images[bId][4]);
			img.setProperty('height', this.props.images[bId][5]);
			img.setProperty('alt', this.props.images[bId][3]);
			img.setProperty('id', elementId);

			if (this.props.images[bId][2].length>0)
			{
				a.setProperty('href', this.props.images[bId][2]);
				img.injectInside(a);
				a.injectInside($(container));
			}
			else
			{
				img.injectInside($(container));
			}
		}
		else if (this.props.images[bId][0]=='swf')
		{
			if (BrowserDetect.browser == "Explorer" && BrowserDetect.version<7)
			{
				var swfHTML = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+
											this.props.images[bId][4]+
											'" height="'+
											this.props.images[bId][5]+
											'" id="'+
											elementId+
											'"><param name="movie" value="'+
											this.props.images[bId][1]+
											'" /><param name="flashvars" value="xmlFile='+
											this.props.images[bId][2]+
											'" /></object>';
				$(container).innerHTML = swfHTML;
			}
			else
			{			
				var flashvars = {};
				flashvars.link = this.props.images[bId][2];
				var params = {};
				var attributes = {};
				attributes.id = elementId;
				swfobject.embedSWF(this.props.images[bId][1], container, this.props.images[bId][4], this.props.images[bId][5], (this.props.images[bId][6]=='')?(this.props.images[bId][6]):("8.0.0"), "typo3conf/ext/galmart_banners/res/expressInstall.swf", flashvars, params, attributes);
			}
		}
	}
});

