(function(w) { 
	var App_Banner = function() {
		
	};

	App_Banner.prototype = {
		width: null,
		height: null,
		type: null,
		path: null,
		url: null,
		params: null,

		__constructor: function() {
		},

		setSize: function(width, height) {
			this.width = width;
			this.height = height;

			return this;
		},

		setStringSize: function(size) {
			if (size.indexOf('x') > 0) {
				var temp = size.split("x");
				this.width = temp[0];
				this.height = temp[1];
			}
			else {
				throw "Incorrect size";
			}
			
			return this;
		},

		setMaxWidth: function(maxWidth) {
			if (maxWidth > 0) {
				if (this.width > maxWidth) {
					this.height = Math.round((this.height / this.width)*maxWidth);
					this.width = maxWidth;
				}
			}

			return this;
		},

		setType: function(type) {
			this.type = type;

			return this;
		},

		setPath: function(path) {
			this.path = path;

			return this;
		},

		setParams: function(params) {
			this.params = params;

			return this;
		},

		setUrl: function(url) {
			this.url = url;

			return this;
		},

		getHTML: function() {
			if (this.height == null
				|| this.width == null
				|| this.type == null
				|| this.path == null
				|| this.url == null) {
				throw "Not all params are set";
			}

			var returnData = '';
			switch (this.type) {
				case 'swf':
					var bgcolor = null;
					if (this.params) {
						if (bgcolor = this.params.match(/bgcolor=([0-9a-f]{6})/i)) {
							bgcolor = bgcolor[1];
						}
					}

					var flashVars = "clickTAG="+encodeURI(this.url)+"&clickTag="+encodeURI(this.url)+"&clicktag="+encodeURI(this.url)+'&'+this.params;
					returnData = ' '
						+'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '
						+'		codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" '
						+'		width="'+this.width+'" height="'+this.height+'">'
						+'	<param name="movie" value="'+this.path+'">'
						+'	<param name="play" value=true>'
						+'	<param name="menu" value=false>'
						+'	<param name="quality" value=high>'
						+'	<param name="wmode" value="Opaque" />'
						+(bgcolor ? '	<param name="bgcolor" value="#'+bgcolor+'" />' : '')
						+'	<param name="FlashVars" value="'+flashVars+'">'
						+'	<embed src="'+this.path+'"  menu="false" quality="high" '
						+'		pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" '
						+'		type="application/x-shockwave-flash" width="'+this.width+'" height="'+this.height+'" wmode="Opaque"'
						+'		FlashVars="'+flashVars+'" '
						+(bgcolor ? '	bgcolor="#'+bgcolor+'" ' : '')
						+'></embed>'
						+'</object>';



				break;
				default:
					returnData = " "
						+"<a href='"+this.url+"' target='_blank'>"
						+"	<img src='"+this.path+"' width='"+this.width+"' height='"+this.height+"' border='0' alt='' />"
						+"</a>";
			}
			return returnData;
		}

	}

	w.App_Banner = App_Banner;
})(window);
