/**
 * Banner class and functions
 *
 * Only load this if the fg_Banners variabable has not been set yet...
 */
if(typeof fg_Banners == 'undefined' || fg_Banners === null)
{
	/*
	 * (c)2006 Jesse Skinner/Dean Edwards/Matthias Miller/John Resig
	 * Special thanks to Dan Webb's domready.js Prototype extension
	 * and Simon Willison's addLoadEvent
	 *
	 * For more info, see:
	 * http://www.thefutureoftheweb.com/blog/adddomloadevent
	 * http://dean.edwards.name/weblog/2006/06/again/
	 * http://www.vivabit.com/bollocks/2006/06/21/a-dom-ready-extension-for-prototype
	 * http://simon.incutio.com/archive/2004/05/26/addLoadEvent
	 * 
	 *
	 * To use: call addDOMLoadEvent one or more times with functions, ie:
	 *
	 *    function something() {
	 *       // do something
	 *    }
	 *    addDOMLoadEvent(something);
	 *
	 *    addDOMLoadEvent(function() {
	 *        // do other stuff
	 *    });
	 *
	 */
	 
	addDOMLoadEvent = (function(){
	    // create event function stack
	    var load_events = [],
	        load_timer,
	        script,
	        done,
	        exec,
	        old_onload,
	        init = function () {
	            done = true;
	
	            // kill the timer
	            clearInterval(load_timer);
	
	            // execute each function in the stack in the order they were added
	            while (exec = load_events.shift()) {
	                exec();
	            }
	
	            if (script) { script.onreadystatechange = ''; }
	        };
	
	    return function (func) {
	        // if the init function was already ran, just run this function now and stop
	        if (done) { return func(); }
	
	        if (!load_events[0]) {
	            // for Mozilla/Opera9
	            if (document.addEventListener) {
	                document.addEventListener("DOMContentLoaded", init, false);
	            }
	
	            // for Internet Explorer
	            /*@cc_on @*/
	            /*@if (@_win32)
	                document.write("<script id=__ie_onload defer src=//0><\/scr"+"ipt>");
	                script = document.getElementById("__ie_onload");
	                script.onreadystatechange = function() {
	                    if (this.readyState == "complete") {
	                        init(); // call the onload handler
	                    }
	                };
	            /*@end @*/
	
	            // for Safari
	            if (/WebKit/i.test(navigator.userAgent)) { // sniff
	                load_timer = setInterval(function() {
	                    if (/loaded|complete/.test(document.readyState)) {
	                        init(); // call the onload handler
	                    }
	                }, 10);
	            }
	
	            // for other browsers set the window.onload, but also execute the old window.onload
	            old_onload = window.onload;
	            window.onload = function() {
	                init();
	                if (old_onload) { old_onload(); }
	            };
	        }
	
	        load_events.push(func);
	    };
	})();

	
	/**
	 * Set a BannerTag attribute for the Google Ad Manager
	 *
	 * @param	string	tag		The BannerTag to set
	 *
	 * @return void
	 */
	setEnvironment = function(tag)
	{
		if(typeof GETDATA['btag'] !== "undefined" && GETDATA['btag'] !== "") {
			Cookie.write("banner_env",GETDATA['btag'], {"path":"/"});
		}
		
		if(Cookie.read("banner_env")) {
			tag	= Cookie.read("banner_env");
			addDOMLoadEvent(function() { setTimeout("setNotifier('"+tag+"')",1500); });
		}
		
		if(typeof tag !== "undefined" && tag !== "") {
			GA_googleAddAttr("BannerTag", tag);
		}
	};
	
	setNotifier = function(tag) {
		var notify	= document.createElement('div');
		notify.style.position	= 'fixed';
		notify.style.top		= '0px';
		notify.style.right		= '0px';
		notify.style.width		= '150px';
		notify.style.height		= '50px';
		notify.style.border		= '1px solid red';
		notify.style.backgroundColor	= '#004D72';
		notify.style.color		= 'white';
		notify.style.textAlign	= 'center';
		notify.style.zIndex		= '2147483647';
		
		notify.innerHTML		= 'Current tag:<br/><strong>'+tag+'</strong><br/><a href="javascript:unsetEnvironment();" style="color: white;">Clear</a>';
		
		document.getElementById('index').appendChild(notify);
	}
	
	/**
	 * Clear the set BannerTag attribute for the Google Ad Manager
	 *
	 * @return void
	 */	
	unsetEnvironment = function () {
		Cookie.dispose("banner_env", {"path":"/"});
		url	= document.location.toString();
		if(url.indexOf('?') > 0) {
			url = url.substr(0,url.indexOf('?'));
		}
		document.location = url;
	};
	
	/**
	 * URL Encode a string
	 *
	 * @param	string	str		The string to URL encode
	 *
	 * @return string
	 */
	urlencode = function(str) {
	    var hexStr = function (dec) {
	        return '%' + (dec < 16 ? '0' : '') + dec.toString(16).toUpperCase();
	    };
	 
	    var ret = '',
	            unreserved = /[\w.-]/; // A-Za-z0-9_.- // Tilde is not here for historical reasons; to preserve it, use rawurlencode instead
	    str = (str+'').toString();
	 
	    for (var i = 0, dl = str.length; i < dl; i++) {
	        var ch = str.charAt(i);
	        if (unreserved.test(ch)) {
	            ret += ch;
	        }
	        else {
	            var code = str.charCodeAt(i);
	            if (0xD800 <= code && code <= 0xDBFF) { // High surrogate (could change last hex to 0xDB7F to treat high private surrogates as single characters); https://developer.mozilla.org/index.php?title=en/Core_JavaScript_1.5_Reference/Global_Objects/String/charCodeAt
	                ret += ((code - 0xD800) * 0x400) + (str.charCodeAt(i+1) - 0xDC00) + 0x10000;
	                i++; // skip the next one as we just retrieved it as a low surrogate
	            }
	            // We never come across a low surrogate because we skip them, unless invalid
	            // Reserved assumed to be in UTF-8, as in PHP
	            else if (code === 32) {
	                ret += '+'; // %20 in rawurlencode
	            }
	            else if (code < 128) { // 1 byte
	                ret += hexStr(code);
	            }
	            else if (code >= 128 && code < 2048) { // 2 bytes
	                ret += hexStr((code >> 6) | 0xC0);
	                ret += hexStr((code & 0x3F) | 0x80);
	            }
	            else if (code >= 2048) { // 3 bytes (code < 65536)
	                ret += hexStr((code >> 12) | 0xE0);
	                ret += hexStr(((code >> 6) & 0x3F) | 0x80);
	                ret += hexStr((code & 0x3F) | 0x80);
	            }
	        }
	    }
	    return ret;
	};

	/* A global variable to determine if the banner has been loaded */
	var	fg_banner_load		= false;
	
	/* A global variable to determine if the banners are complete */
	var	fg_banner_done		= false;
	
	/* A global variable to store the defaults in */
	var fg_banner_defaults	= {};

	/**
	 * The object that handles all banners in the page
	 */
	var fg_Banners = {
		/** LOCAL VARIABLES **/
			
		/* Items to be loaded after the DOM is ready */
		bloadItems		: [],
		
		/* Variable to keep a "top" style for error notices */
		b_top			: 0,		
		
		/* The z-index for the next item */
		b_zindex		: 1000,
		
		/* The unique number for the banner */
		b_id			: 1,
		
		/*	An array containing 3 anchors, on at the top ('anchor_top'), 
			center ('anchor_center') and bottom ('anchor_bottom') */
		b_anchor		: [],
		
		/* The position style for the anchors */
		b_anchorposition	: 'fixed',
		
		/* The DIV we're currently work on */
		b_div			: null,
		
		/* What type of content the current div has ('img' or 'swf') */
		b_type			: null,
		
		/* The URL of the file we want to add */
		b_file			: null,
		
		/* The options specified for this banner */
		b_options		: null,
		
		/* Is this banner expandable? */
		b_expandable	: false,
		
		/* Keeps track of the resizable banners and if we can resize them or not */
		b_allow_resize	: [],
			
		/* The sequence of the anchors */
		b_sequence		: {"top":10,"center":20,"bottom":30},
		
		/* Rerender these divs after completion */
		b_rerender		: [],
		
		/* The spelling for the clickTAG of the flash */
		b_cTAG			: 'clickTAG',
		
		/* Do we use percentages on this banner */
		b_usePercentage	: false,
		
		/* The default scaling type that is used in case of percentage */
		b_scaleType		: 'default',
		
		/** GLOBAL FUNCTIONS **/
		
		/**
		 * Function to set the default variables.
		 *
		 * @param	string/object	The parameters to set, passed as an object or written as JSON
		 * @return	void
		 */
		setDefaults: function(b_options) {
			for(var i in b_options) {
				fg_banner_defaults[i]	= b_options[i];
				
				if(i === 'background') {
					this.setPageBackground(b_options[i]);
				}
				
				if(i === 'scaling') {
					this.setScaleType(b_options[i]);
				}
			}
		},
		
		/**
		 * Function to set the default scale type.
		 *
		 * @param	string		The type we want to use, can be 'default', 'noscale', 'noorder' or 'exactfit'
		 * @return	boolean		True if set, false otherwise
		 */
		setScaleType: function(b_type)
		{
			switch(b_type.toString().toLowerCase())
			{
				case 'default': this.b_scaleType = 'showall'; break;
				case 'noscale': this.b_scaleType = 'noscale'; break;
				case 'noorder': this.b_scaleType = 'noorder'; break;
				case 'exactfit': this.b_scaleType = 'exactfit'; break;
				default: return false; break;
			}
			return true;
		},
		
		/**
		 * Function to retrieve the room in the browser. It returns an array containing
		 * two variables, one container the room between the edge of the broser and the
		 * 'uberholder' div, the second containing the height of the browser. Will return
		 * boolean false if unsuccesful.
		 *
		 * @return	array	An array with x and y value or false in case of error
		 */
		getAvailableSize: function() {
			try {
				var values	= new Array();
			
				x	= Math.floor((parseInt(screen.width) - 722)	/ 2);
				if(x < 0) x = 0;
				
				values.x	= x;
				values.y	= screen.height;
	
				return values;
			} catch(e) {
				console.log(e);
				
				return false;	
			}
		},
		
		/**
		 * Function to hide the DHTML if it is set. Callable from within a flash DHTML.
		 *
		 * @return	void
		 */
		hideDHTMLlayer: function() {
			if(document.getElementById("b_dhtml_layer")) {
				document.getElementById("b_dhtml_layer").style.display = 'none';
			}
		},
	
		/** WORKER FUNCTIONS **/
		
		/**
		 * Function to set the page background to a specific color or image
		 *
		 * @param	string	to	The URL or Hex color of the new background. It will set all strings
		 *						as image background, unless started by '#' for colors.
		 *
		 * @return void
		 */
		setPageBackground: function(to) {
			html	= document.getElementsByTagName('html')[0];
			if(to.substr(0,1) == '#') {
				// Set the value of 'to' as the new background color
				html.style.backgroundColor	= to;
				html.style.backgroundImage	= 'none';
				// -
			} else {
				// Set the value of 'to' as the new background image
				html.style.backgroundImage	= 'url('+to+')';
				// -
			}
		},
		
		/**
		 * Function to set the default anchor CSS position
		 *
		 * @param	string	value	The new CSS position for the anchors
		 *
		 * @return boolean	True if succesfull, false otherwise
		 */
		setAnchorPosition: function(val) {
			if(	val == 'absolute'	||
				val == 'fixed'		||				
				val == 'relative'	||
				val == 'static'		||
				val == 'inherit'
			) {
				this.b_anchorposition = val;
				return true;	
			} else {
				return false;	
			}
		},
		
		/**
		 * Function to add items to the page. For IE6 and lower, it will add items to the loader
		 * instead of directly to the DOM.
		 *
		 * @param	string	b_file		String location of the file to add
		 * @param	object	b_options	Options for this banner, see the description for '_addItem'
		 *								for more details.
		 *
		 * @return void
		 */
		add: function(b_file, b_options) {
			if(typeof b_options["position"] != 'undefined' && 
				b_options["position"] === 'rectangle') {
				this._addItem(b_file,b_options);
			} else {
			
				if (this._getVersion() <= 6) {
					this.b_anchorposition = 'absolute';
				}
				
				if(!fg_banner_load) {
					fg_banner_load = true;
					addDOMLoadEvent(function() { setTimeout(fg_Banners.loadItems,1); } );
					//function() { fg_Banners.loadItems(); });
				}
				
				this.bloadItems.push({"b_file":b_file,"b_options":b_options});
		
				if(!fg_banner_done) {
					fg_banner_done = true;
					addDOMLoadEvent(function() { fg_Banners._reRender(); });
				}
			}
		},
		
		/**
		 * Function that sets the sequence of the anchors, the higher the number, the "lower"
		 * the anchor will lay inside the page
		 *
		 * @param	integer	b_top		The integer representing the "height" of the top anchor
		 * @param	integer	b_center	The integer representing the "height" of the center anchor
		 * @param	integer	b_bottom	The integer representing the "height" of the bottom anchor
		 *
		 * @return	void
		 */
		setSequence: function(b_top,b_center,b_bottom)
		{
			this.b_sequence = {"top":b_top,"center":b_center,"bottom":b_bottom};
			
			if(typeof this.b_anchor["top"] !== 'undefined') {
				this.b_anchor["top"].style.zIndex	= 1000 - this.b_sequence["top"];
			}
			if(typeof this.b_anchor["center"] !== 'undefined') {
				this.b_anchor["center"].style.zIndex	= 1000 - this.b_sequence["center"];
			}
			if(typeof this.b_anchor["bottom"] !== 'undefined') {
				this.b_anchor["bottom"].style.zIndex	= 1000 - this.b_sequence["bottom"];
			}
		},
		
		/**
		 * Function to switch the size of the banner container to its expanded or normal state
		 *
		 * @param	element	container	The element containing the div with banner contents anchor
		 *
		 * @return	void
		 */
		expandBanner: function(container) {
			info	= document.getElementById(container.id).getElementsByTagName('input')[0].value;
			if(info.length > 70 && info.length < 80 && info.substr(0,16) == 'var fgb = {"i":"') {
				eval(info);
				if(this.b_allow_resize[fgb.i]) {
					obj	= document.getElementById(fgb.i);
					if(obj) {
						if(	parseInt(this._getStyle(fgb.i,"width","width")) == fgb.w && 
							parseInt(this._getStyle(fgb.i,"height","height")) == fgb.h ){
							// Object has original size, resize to large versions
							obj.style.width		= fgb.ew+'px';
							obj.style.height	= fgb.eh+'px';
						} else {
							// Resize to original version
							obj.style.width		= fgb.w+'px';
							obj.style.height	= fgb.h+'px';
						}
					}
				}
			}
		},
		
		/**
		 * Function to create a clear half banner (hide the square)
		 *
		 * @return void
		 */
		hideHalfBanner: function() {
			html	= '<div id="halfbanner_hide" style="';
			html	= html + 'width: 275px; ';
			html	= html + 'height: 95px; ';
			html	= html + 'position: absolute; ';
			html	= html + 'top: -19px; ';
			html	= html + 'left: -15px; ';
			html	= html + 'background-image: url(http://static.funnygames.nl/layout/funnygames/images/nl/empty_header.gif);';
			html	= html + 'background-position: top right;';
			html	= html + 'background-repeat: none;';
			html	= html + '">';
			html	= html + '</div>';
	
			document.write(html);
		},
		
		/**
		 * Function to create a clear full banner (hide the square)
		 *
		 * @return void
		 */
		hideFullBanner: function() {
			html	= '<div id="fullbanner_hide" style="';
			html	= html + 'width: 490px; ';
			html	= html + 'height: 70px; ';
			html	= html + 'position: absolute; ';
			html	= html + 'top: -5px; ';
			html	= html + 'left: 25px; ';
			html	= html + 'background-image: url(http://static.funnygames.nl/layout/funnygames/images/bottom_banner.gif);';
			html	= html + 'background-position: top right;';
			html	= html + 'background-repeat: none;';
			html	= html + '">';
			html	= html + '</div>';
	
			document.write(html);
		},
		
		/**
		 * Function to create a clear full banner (hide the square)
		 *
		 * @return void
		 */
		hideSkyScraper: function() {
			addDOMLoadEvent(function() {
				setTimeout("if(document.getElementById('skyScraper')) { document.getElementById('skyScraper').style.display = 'none'; }", 400);
				setTimeout("if(document.getElementById('google_ads_div_skyscraper')) { document.getElementById('google_ads_div_skyscraper').style.display = 'none'; } ", 500);
			});
		},
		
		/** PRIVATE FUNCTIONS **/
		
		/**
		 * Add all queued items to the DOM
		 *
		 * @return void
		 */
		loadItems: function() {
			if (fg_Banners._getVersion() <= 6) {
				fg_Banners.b_anchorposition = 'absolute';
			}
			for(var i = 0; i < fg_Banners.bloadItems.length; i++) {
				fg_Banners._addItem(fg_Banners.bloadItems[i].b_file,fg_Banners.bloadItems[i].b_options);
			}
		},
		
		/**
		 * Function to add an item to the page
		 *
		 * @param	string	file	The location of the item we want to add 
		 *							(e.g. 'http://www.tibaco.nl/ads/headers/header23.swf')
		 * @param	object	options	Additional parameters we need/can use. Currently accepts
		 *							the following keys:
		 *							+ position		String containing one of these values:
		 *											# top-left
		 *											# top
		 *											# top-right
		 *											# header
		 *											# left
		 *											# center
		 *											# right
		 *											# bottom-left
		 *											# bottom
		 *											# bottom-right
		 *											# rectangle
		 *											# slot
		 *							+ width			Integer representing the number of pixels the item
		 *											is wide
		 *							+ height		Integer representing the number of pixels the item
		 *											is high
		 *							- dock			String containing one of two values (default is
		 *											"frame"):
		 *											# "frame"	: Dock the item to the 'uberholder' div
		 *											# "browser"	: Dock the item to the browser
		 *							- left			Integer representing the number of pixels to shift
		 *											the item left (can be negative to shift right)
		 *							- top			Integer representing the number of pixels to shift
		 *											the item downwards from the top (can be negative to
		 *											shift upwards)
		 *							- wmode			If the file supplied is a flash, define the wmode of
		 *											the flash here (default is transparent).
		 *							- bgcolor		Hex color annotation (#AB4523) to set as background
		 *											if the file supplied is a flash. 
		 *							- clickTAG		String containing an URL used as clicktag in the flash/
		 *											as href around the image.
		 *							- cTAG			The name of the clicktag (default is clickTAG)
		 *							- embed			Should the object tag for flash elements contain a <embed>
		 *											tag (default is false)
		 *											# true		: The object tag will use a 'class' attribute
		 *														  and contain <embed>
		 *											# false		: The object tag will use a 'data' attribute
		 *														  and no <embed> tag.
		 *							- type			Should the URL of the file not be clear on the type, you can specifiy 
		 *											a specific type here.
		 *											# "swf"		: The banner is a Flash file
		 *											# "img"		: The banner is a image file
		 *							- tagtarget		Determines where the tag opens, defaults to "blank".
		 *											# "blank"	: Link opens in a new window
		 *											# "self"	: Link opens in the same window
		 *							- measureTAG	String containing an URL used as measuretag, adding
		 *											a measure pixel as image to the div.
		 *							- alwaysontop	Can be set to 'true' to fix to a high anchor, defaults
		 *											to false
		 *							- params		If any extra fields need to be passed to a flash
		 *											element, you can pass them as an object to the 
		 *											'params' option.
		 *							- bannertime	Integer representing the number of seconds before a
		 *											automated redirect, only works for position: rectangle!
		 *							- showbanner	Integer representing the number of seconds before the
		 *											redirect link will be added, only works for position:
		 *											rectangle!
		 *							- expandable	Is the banner expandable? Can be true or false, defaults
		 *											to false.
		 *							- width_exp		The width of the banner when the banner is expanded
		 *							- height_exp	The height of the banner when the banner is expanded
		 *							- start			Does the banner start 'normal', or 'expanded' (defaults 
		 *											to 'normal')?
		 *							- auto_resize	Should we automaticly switch to the other sizes after this
		 *											number of seconds?
		 *							- container		The location of the banner, defaults to "half"
		 *											# "half"
		 *											# "full"
		 *											# "skyscraper"
		 *											# "rectangle"
		 * 							Items marked with '+' are required, items with '-' are optional. In
		 *							case of a header banner, the width and height are also optional.
		 *
		 * @return	boolean		True if succesful, false otherwise.
		 *
		 */
		_addItem: function(b_file,b_options) {
			perform_write	= true;
			
			if (typeof this.overflowx === 'undefined') {
				this.overflowx = true;
				html	= document.getElementsByTagName('html')[0];
				html.style.overflowX = 'hidden';
			}
			
			// Get the current type from the file extension
			this.b_type	= this._getType(b_file,b_options);
			
			// If we do not get a file type, output an error
			if(!this.b_type) {
				this._writeError("Invalid file '"+b_file+"' !");
				perform_write	= false;	
			}
			// -
			
			// Validate the position value
			if(typeof b_options["position"] == 'undefined' || b_options["position"] == '' || (
				b_options["position"].toLowerCase() !== 'top-left' && 
				b_options["position"].toLowerCase() !== 'top' && 
				b_options["position"].toLowerCase() !== 'top-right' && 
				b_options["position"].toLowerCase() !== 'header' && 
				b_options["position"].toLowerCase() !== 'left' && 
				b_options["position"].toLowerCase() !== 'center' && 
				b_options["position"].toLowerCase() !== 'right' && 
				b_options["position"].toLowerCase() !== 'bottom-left' && 
				b_options["position"].toLowerCase() !== 'bottom' && 
				b_options["position"].toLowerCase() !== 'bottom-right' && 	
				b_options["position"].toLowerCase() !== 'rectangle' &&
				b_options["position"].toLowerCase() !== 'slot'
			)) {
				this._writeError("Invalid position for file '"+b_file+"' !");
				perform_write	= false;
			}
			// -
			
			// Check for width
			if(typeof b_options["width"] == 'undefined' || b_options["width"] <= 0) {
				if(b_options["position"] === 'header') {
					// If we do not have a width, but the position is a header, set a default value
					b_options["width"]	= 730;		
				} else if(b_options["position"] === 'rectangle') {
					// If we do not have a width, but the position is a header, set a default value
					b_options["width"]	= 336;		
				} else {
					this._writeError("Invalid width for file '"+b_file+"' !");
					perform_write	= false;
				}
			}
			// -
			
			// Check for height
			if(typeof b_options["height"] == 'undefined' || b_options["height"] <= 0) {
				if(b_options["position"] === 'header') {
					// If we do not have a height, but the position is a header, set a default value
					b_options["height"]	= 95;		
				} else if(b_options["position"] === 'rectangle') {
					// If we do not have a width, but the position is a header, set a default value
					b_options["height"]	= 280;		
				} else {
					this._writeError("Invalid height for file '"+b_file+"' !");
					perform_write	= false;
				}
			}
			// -
			
			// Check for a dock-type. If it is invalid or empty, default it to 'frame'
			if(	typeof b_options["dock"] == 'undefined' ||
				b_options["dock"] == '' || 
				b_options["position"].toLowerCase() === 'slot' || 
				(	b_options["dock"].toLowerCase() !== 'browser' && 
					b_options["dock"].toLowerCase() !== 'frame'
				)
			) {
				b_options["dock"]	= 'frame';
			}
			// -
	
			// Check for a dock-type. If it is invalid or empty, default it to 'frame'
			if(	typeof b_options["expandable"] != 'undefined' &&
				(b_options["expandable"] === true ||
				b_options["expandable"].toString().toLowerCase() === 'true')
				
			) {
				this.b_expandable	= true;
			} else {
				this.b_expandable	= false;	
			}
			// -
			
			// If we have a special clicktag, set it now
			if(	typeof b_options["cTAG"] != 'undefined')
			{
				this.b_cTAG	= b_options["cTAG"];
			} else if(typeof fg_banner_defaults["cTAG"] != 'undefined') {
				this.b_cTAG	= fg_banner_defaults["cTAG"];
			}
			// -
	
			if(perform_write) {
				// Store the parameters in the internal variables
				this.b_file		= b_file;
				this.b_options	= b_options;
				// -
				
				if(b_options["position"] === 'rectangle') {
					this._setRectangle();
				} else {
					addDOMLoadEvent(function() {
						if(document.getElementById('uberholder')) {
							document.getElementById('uberholder').style.zIndex	= 3000;
						}
					});
					
					// If we need to write the item, first check if we have initilized the anchors
					this._checkAnchors();
					
					// Create the base div inside the internal 'div' variable
					this.b_div				= document.createElement("div");
					this.b_div.id			= this._getId();
					if(b_options["width"].toString().substr(b_options["width"].length - 1) == '%') {
						this.b_div.style.width	= b_options["width"];
						this.b_usePercentage	= true;
					} else {
						this.b_div.style.width	= b_options["width"]+'px';
					}
					if(b_options["height"].toString().substr(b_options["height"].length - 1) == '%') {
						this.b_div.style.height	= b_options["height"];
						this.b_usePercentage	= true;
					} else {
						this.b_div.style.height	= b_options["height"]+'px';
					}
					this.b_div.style.zIndex	= this.b_zindex;		
					// -
										
					// Increase or z-index counter, leave room for other scripts to add items between layers
					this.b_zindex		= this.b_zindex + 10;
					
					// Add the item to the frame or to the browser
					switch(b_options["dock"]) {
						case 'frame':
							this.b_div.style.position	= 'absolute';
							this._placeToFrame();
							break;
						case 'browser':
							this.b_div.style.position	= this.b_anchorposition;
							this._placeInBrowser();
							break;
					}
					// -
					
					// Add the measure tag if needed
					if(typeof this.b_options["measureTAG"] !== 'undefined' && this.b_options["measureTAG"] !== '' &&  this.b_options["measureTAG"] !== '-') {
						this._addMeasureTag(this.b_options["measureTAG"]);
					} else if(	typeof this.setGlobalMeasureTag === 'undefined' && 
								typeof fg_banner_defaults["measureTAG"] !== 'undefined' &&
								fg_banner_defaults["measureTAG"] !== '' &&
								this.b_options["measureTAG"] !== '-') {
						this.setGlobalMeasureTag	= true;
						this._addMeasureTag(fg_banner_defaults["measureTAG"]);
					}
					// -
					
					// Force re-rendering of the current div
					this.b_rerender.push(this.b_div.id);
					// -
				}
				// Reset the stored variables
				this._resetVariables();
				// -
				
				// Return true
				return true;
			} else {
				// One of the checks failed, return false
				return false;
			}
		},
		
		/**
		 * Function to retrieve the version of IE used. If the used browser isn't IE, it will return 99.
		 *
		 * @return	float		The version of IE used or 99.
		 */
		_getVersion: function() {
			return ((navigator.appName=='Microsoft Internet Explorer')?parseFloat((new RegExp("MSIE ([0-9]{1,}[.0-9]{0,})")).exec(navigator.userAgent)[1]):99);	
		},
		
		/**
		 * Function to get the current style of an element. Returns the correct values,
		 * even if the style has only been declared inside an external CSS.
		 *
		 * @param	string	The ID of the element we want the style of
		 * @param	string	The camelcase/IE CSS notation of the value we need (e.g. "marginTop")
		 * @param	string	The official CSS notation of the value we need (e.g. "margin-top")
		 *
		 * @return	string	The value of the requested style, or false if not found.
		 */
		_getStyle: function(b_source, IEStyleName, CSSStyleName) {
			var elem = document.getElementById(b_source);
			
			if(elem) {
				if (elem.currentStyle) {
					return elem.currentStyle[IEStyleName];
				} else if (window.getComputedStyle) {
					var compStyle = window.getComputedStyle(elem, "");
					return compStyle.getPropertyValue(CSSStyleName);
				} else {
					return false;
				}
			} else {
				return false;	
			}
		},
		
		/**
		 * Function to reset all variables to their default values. Does NOT reset anchor, top
		 * and zindex, since they might be used for the next banner.
		 *
		 * @return	void
		 */
		_resetVariables: function() {
			this.b_div				= null;
			this.b_type				= null;
			this.b_file				= null;
			this.b_options			= null;
			this.b_expandable		= false;
			this.b_usePercentage	= false;
		},
		
		/**
		 * Find out the width of the item in its expanded state
		 *
		 * @return integer
		 */
		_getExpandedWidth: function() {
			if(typeof this.b_options["width_exp"] == 'undefined') {
				var w = this.b_options["width"];
			} else {
				var w = parseInt(this.b_options["width_exp"]);
			}
			if(w > 0) {
				return w;
			} else {
				return 0;
			}
		},
		
		/**
		 * Find out the height of the item in its expanded state
		 *
		 * @return integer
		 */
		_getExpandedHeight: function() {
			if(typeof this.b_options["height_exp"] == 'undefined') {
				var h = this.b_options["height"];
			} else {
				var h = parseInt(this.b_options["height_exp"]);
			}
			if(h > 0) {
				return h;
			} else {
				return 0;	
			}
		},
		
		/**
		 * Function that checks for the existance of the anchor divs. If the div has not been initilized,
		 * it creates them and adds them to the internal 'anchor' array.
		 *
		 * @return	void
		 */
		_checkAnchors: function()
		{
			par = document.getElementsByTagName('body')[0];
			
			if(par)
			{
				// Check for the top anchor
				if(this.b_options["position"].substr(0,3) === 'top') {
					if(typeof this.b_anchor["top"] === 'undefined' || this.b_anchor["top"] === null) {
						// Anchor not found, create the top anchor
						this.b_anchor["top"]					= document.createElement("div");
						this.b_anchor["top"].id					= 'anchor_top';
						this.b_anchor["top"].style.width		= this._getStyle('header_holder',"width","width");
						this.b_anchor["top"].style.height		= '0px';
						this.b_anchor["top"].style.position		= this.b_anchorposition;
						this.b_anchor["top"].style.left			= '50%';
						this.b_anchor["top"].style.marginTop	= this._getStyle('uberholder',"marginTop","margin-top");
						this.b_anchor["top"].style.marginLeft	= this._getStyle('uberholder',"marginLeft","margin-left");
						this.b_anchor["top"].style.zIndex		= this.b_zindex - this.b_sequence["top"];
			
						par.appendChild(this.b_anchor["top"]);
						// -
					}
				}
				// -
				
				if(this.b_options["position"] === 'left' || this.b_options["position"] === 'right') {
					// Check for the center anchor
					if(typeof this.b_anchor["center"] === 'undefined' || this.b_anchor["center"] === null) {
						// Anchor not found, create the center anchor
						this.b_anchor["center"]						= document.createElement("div");
						this.b_anchor["center"].id					= 'anchor_center';
						this.b_anchor["center"].style.width			= this._getStyle('header_holder',"width","width");
						this.b_anchor["center"].style.height		= '0px';
						this.b_anchor["center"].style.position		= this.b_anchorposition;
						this.b_anchor["center"].style.left			= '50%';
						this.b_anchor["center"].style.bottom		= '50%';
						this.b_anchor["center"].style.marginLeft	= this._getStyle('uberholder',"marginLeft","margin-left");
						this.b_anchor["center"].style.zIndex		= this.b_zindex - this.b_sequence["center"];
			
						par.appendChild(this.b_anchor["center"]);			
						// -
					}
					// -
				}
				
				if(this.b_options["position"] === 'center') {
					// Check for the center anchor
					if(typeof this.b_anchor["center_over"] === 'undefined' || this.b_anchor["center_over"] === null) {
						// Anchor not found, create the center anchor
						this.b_anchor["center_over"]					= document.createElement("div");
						this.b_anchor["center_over"].id					= 'anchor_center_over';
						this.b_anchor["center_over"].style.width		= '0px';
						this.b_anchor["center_over"].style.height		= '0px';
						this.b_anchor["center_over"].style.position		= this.b_anchorposition;
						this.b_anchor["center_over"].style.left			= '50%';
						this.b_anchor["center_over"].style.bottom		= '50%';
						this.b_anchor["center_over"].style.zIndex		= 5000;
			
						par.appendChild(this.b_anchor["center_over"]);
						// -
					}
					// -
				}
				
				// Check for the bottom anchor -- We always create a bottom anchor, to place the measure tags in.
				if(typeof this.b_anchor["bottom"] === 'undefined' || this.b_anchor["bottom"] === null) {
					// Anchor not found, create the bottom anchor
					this.b_anchor["bottom"]						= document.createElement("div");
					this.b_anchor["bottom"].id					= 'anchor_bottom';
					this.b_anchor["bottom"].style.width			= this._getStyle('header_holder',"width","width");
					this.b_anchor["bottom"].style.height		= '0px';
					this.b_anchor["bottom"].style.position		= this.b_anchorposition;
					this.b_anchor["bottom"].style.left			= '50%';
					this.b_anchor["bottom"].style.bottom		= '0px';
					this.b_anchor["bottom"].style.marginLeft	= this._getStyle('uberholder',"marginLeft","margin-left");
					this.b_anchor["bottom"].style.zIndex		= this.b_zindex - this.b_sequence["bottom"];
		
					par.appendChild(this.b_anchor["bottom"]);
					// -
				}
				// -
				
				// If the "alwaysontop" option is set, create an appropiate anchor
				if(	typeof this.b_options["alwaysontop"] !== 'undefined' && 
					(this.b_options["alwaysontop"] === 'true' || this.b_options["alwaysontop"] === true)
				) {
					if(this.b_options["position"].substr(0,3) === 'top') {
						// Check for the top anchor
						if(typeof this.b_anchor["alwaysontop_top"] === 'undefined' || this.b_anchor["alwaysontop_top"] === null) {
							// Anchor not found, create the top anchor
							this.b_anchor["alwaysontop_top"]					= document.createElement("div");
							this.b_anchor["alwaysontop_top"].id					= 'alwaysontop_anchor_top';
							this.b_anchor["alwaysontop_top"].style.width		= this._getStyle('header_holder',"width","width");
							this.b_anchor["alwaysontop_top"].style.height		= '0px';
							this.b_anchor["alwaysontop_top"].style.position		= this.b_anchorposition;
							this.b_anchor["alwaysontop_top"].style.left			= '50%';
							this.b_anchor["alwaysontop_top"].style.marginTop	= this._getStyle('uberholder',"marginTop","margin-top");
							this.b_anchor["alwaysontop_top"].style.marginLeft	= this._getStyle('uberholder',"marginLeft","margin-left");
							this.b_anchor["alwaysontop_top"].style.zIndex		= 6000 - this.b_sequence["top"];
				
							par.appendChild(this.b_anchor["alwaysontop_top"]);
							// -
						}
						// -
					}
					
					if(this.b_options["position"] === 'left' || this.b_options["position"] === 'right') {
						// Check for the center anchor
						if(typeof this.b_anchor["alwaysontop_center"] === 'undefined' || this.b_anchor["alwaysontop_center"] === null) {
							// Anchor not found, create the center anchor
							this.b_anchor["alwaysontop_center"]						= document.createElement("div");
							this.b_anchor["alwaysontop_center"].id					= 'alwaysontop_anchor_center';
							this.b_anchor["alwaysontop_center"].style.width			= this._getStyle('header_holder',"width","width");
							this.b_anchor["alwaysontop_center"].style.height		= '0px';
							this.b_anchor["alwaysontop_center"].style.position		= this.b_anchorposition;
							this.b_anchor["alwaysontop_center"].style.left			= '50%';
							this.b_anchor["alwaysontop_center"].style.bottom		= '50%';
							this.b_anchor["alwaysontop_center"].style.marginLeft	= this._getStyle('uberholder',"marginLeft","margin-left");
							this.b_anchor["alwaysontop_center"].style.zIndex		= 6000 - this.b_sequence["center"];
				
							par.appendChild(this.b_anchor["alwaysontop_center"]);			
							// -
						}
						// -
					}
					
					if(this.b_options["position"].substr(0,6) === 'bottom') {
						// Check for the center anchor
						if(typeof this.b_anchor["alwaysontop_bottom"] === 'undefined' || this.b_anchor["alwaysontop_bottom"] === null) {
							// Anchor not found, create the bottom anchor
							this.b_anchor["alwaysontop_bottom"]						= document.createElement("div");
							this.b_anchor["alwaysontop_bottom"].id					= 'alwaysontop_anchor_bottom';
							this.b_anchor["alwaysontop_bottom"].style.width			= this._getStyle('header_holder',"width","width");
							this.b_anchor["alwaysontop_bottom"].style.height		= '0px';
							this.b_anchor["alwaysontop_bottom"].style.position		= this.b_anchorposition;
							this.b_anchor["alwaysontop_bottom"].style.left			= '50%';
							this.b_anchor["alwaysontop_bottom"].style.bottom		= '0px';
							this.b_anchor["alwaysontop_bottom"].style.marginLeft	= this._getStyle('uberholder',"marginLeft","margin-left");
							this.b_anchor["alwaysontop_bottom"].style.zIndex		= 6000 - this.b_sequence["bottom"];
				
							par.appendChild(this.b_anchor["alwaysontop_bottom"]);
							// -
						}
						// -
					}
				}
			} else {
				this._writeError("Warning! Unable to write anchors.");	
			}
		},
		
		/**
		 * Function to add the current div to the page, adding it to 'obj_id'.
		 *
		 * @param	string	obj_id		The id of the object to add the div to.
		 * @param	boolean	is_anchor	If true, it will be added to the anchor with name 'obj_id'.
		 *
		 * @return	void
		 */
		_appendTo: function(obj_id, is_anchor) {
			if(typeof this.b_options["alwaysontop"] !== 'undefined' && (this.b_options["alwaysontop"] === true || this.b_options["alwaysontop"] === 'true')) {
				obj_id	= 'alwaysontop_'+obj_id;
			}
			
			if(typeof is_anchor === 'undefined' || !is_anchor) {
				if(document.getElementById(obj_id)) {
					document.getElementById(obj_id).appendChild(this.b_div);
				} else {
					if(document.getElementById('index')) {
						par = document.getElementById('index');	
					} else {
						par = document.getElementsByTagName('body')[0];
					}
					par.appendChild(this.b_div);
				}
			} else {
				if(this.b_usePercentage)
				{
					this.b_anchor[obj_id].style.height = '100%';
					this.b_anchor[obj_id].style.marginTop = '0px';
				}
				this.b_anchor[obj_id].appendChild(this.b_div);
			}
		},
		
		/**
		 * Function to add the current div relative to the frame. Uses the anchors to position the div.
		 *
		 * @return	void
		 */
		_placeToFrame: function() {
			switch(this.b_options["position"].toLowerCase()) {
				
				// Add the div to current banner slot
				case 'slot':
					if(!this.b_expandable) {
						this._fillSlot();
					} else {
						this._fillSlotExpandable();
					}
					break;
				// -
				
				// Add the div to the left side of the header
				case 'top-left':
					if(typeof this.b_options["left"] !== 'undefined') {
						this.b_options["left"]	= this.b_options["left"] + 4 - this.b_options["width"];
					} else {
						this.b_options["left"]	= -this.b_options["width"] + 4;
					}
					this.b_div.style.left	= this.b_options["left"]+'px';
					if(typeof this.b_options["top"] === 'undefined') {
						this.b_options["top"]	= 0;	
					}
					this.b_div.style.top	= this.b_options["top"]+'px';
					
					this.b_div.innerHTML	= this._getInnerHTML();
					this._appendTo('top',true);
					
					break;
				// -
				
				// Add the div in the center of the header
				case 'top':
					half_left	=  Math.floor(parseInt(this._getStyle('anchor_top',"width","width"))/2);
					if(typeof this.b_options["left"] !== 'undefined') {
						this.b_options["left"]	= half_left - Math.floor(this.b_options["width"]/2) + this.b_options["left"];
					} else {
						this.b_options["left"]	= half_left - Math.floor(this.b_options["width"]/2);
					}
					this.b_div.style.left	= this.b_options["left"]+'px';
					if(typeof this.b_options["top"] === 'undefined') {
						this.b_options["top"]	= 0;	
					}
					this.b_div.style.top	= this.b_options["top"]+'px';
					
					this.b_div.innerHTML	= this._getInnerHTML();
					this._appendTo('top',true);
					
					break;
				// -
				
				// Add the div to the right side of the header
				case 'top-right':
					if(typeof this.b_options["left"] !== 'undefined') {
						this.b_options["left"]	= this.b_options["left"] + 4 -this.b_options["width"];
					} else {
						this.b_options["left"]	= -this.b_options["width"] + 4;
					}
					this.b_div.style.right	= this.b_options["left"]+'px';
					if(typeof this.b_options["top"] === 'undefined') {
						this.b_options["top"]	= 0;	
					}
					this.b_div.style.top	= this.b_options["top"]+'px';
					
					this.b_div.innerHTML	= this._getInnerHTML();
					this._appendTo('top',true);
					
					break;
				// -
				
				// Add the div in the (top left) position of the header
				case 'header':
					this._setHeader();
					break;
				// -
				
				// Add the div to the left side contentframe, centered in height
				case 'left':
					if(typeof this.b_options["left"] !== 'undefined') {
						this.b_options["left"]	= this.b_options["left"] + 4 - this.b_options["width"];
					} else {
						this.b_options["left"]	= -this.b_options["width"] + 4;
					}
					this.b_div.style.left	= this.b_options["left"]+'px';
					if(typeof this.b_options["top"] !== 'undefined') {
						this.b_options["top"]	= this.b_options["top"] - Math.floor(this.b_options["height"]/2);
					} else {
						this.b_options["top"]	= -Math.floor(this.b_options["height"]/2);
					}
					this.b_div.style.top	= this.b_options["top"]+'px';
					
					this.b_div.innerHTML	= this._getInnerHTML();
					this._appendTo('center',true);
					
					break;
				// -
				
				// Add the div in the middle of the contentframe
				case 'center':
					this._setDHTMLlayer();
					break;
				// -
				
				// Add a pregame rectangle
				case 'rectangle':
					this._setRectangle();
					break;
				// -
				
				// Add the div to the right side contentframe, centered in height
				case 'right':
					if(typeof this.b_options["left"] !== 'undefined') {
						this.b_options["left"]	= this.b_options["left"] + 4 -this.b_options["width"];
					} else {
						this.b_options["left"]	= -this.b_options["width"] + 4;
					}
					this.b_div.style.right	= this.b_options["left"]+'px';
					if(typeof this.b_options["top"] !== 'undefined') {
						this.b_options["top"]	= this.b_options["top"] - Math.floor(this.b_options["height"]/2);
					} else {
						this.b_options["top"]	= -Math.floor(this.b_options["height"]/2);
					}
					this.b_div.style.top	= this.b_options["top"]+'px';
					
					this.b_div.innerHTML	= this._getInnerHTML();
					this._appendTo('center',true);
					
					break;
				// -
				
				// Add the item to the bottom of the page, it's right side placed left of the contentframe
				case 'bottom-left':
					if(typeof this.b_options["left"] !== 'undefined') {
						this.b_options["left"]	= this.b_options["left"] + 4 - this.b_options["width"];
					} else {
						this.b_options["left"]	= -this.b_options["width"] + 4;
					}
					this.b_div.style.left	= this.b_options["left"]+'px';
					if(typeof this.b_options["top"] !== 'undefined') {
						this.b_options["top"]	= this.b_options["top"] - this.b_options["height"];
					} else {
						this.b_options["top"]	= -this.b_options["height"];
					}
					this.b_div.style.top	= this.b_options["top"]+'px';
					
					this.b_div.innerHTML	= this._getInnerHTML();
					this._appendTo('bottom',true);
					
					break;
				// -
				
				// Add the item to the bottom of the page, centered
				case 'bottom':
					half_left	=  Math.floor(parseInt(this._getStyle('anchor_bottom',"width","width"))/2);
					if(typeof this.b_options["left"] !== 'undefined') {
						this.b_options["left"]	= half_left - Math.floor(this.b_options["width"]/2) + this.b_options["left"];
					} else {
						this.b_options["left"]	= half_left - Math.floor(this.b_options["width"]/2);
					}
					this.b_div.style.left	= this.b_options["left"]+'px';
					if(typeof this.b_options["top"] !== 'undefined') {
						this.b_options["top"]	= this.b_options["top"] - this.b_options["height"];
					} else {
						this.b_options["top"]	= -this.b_options["height"];
					}
					this.b_div.style.top	= this.b_options["top"]+'px';
					
					this.b_div.innerHTML	= this._getInnerHTML();
					this._appendTo('bottom',true);
					
					break;
				// -
				
				// Add the item to the bottom of the page, it's left side placed right of the contentframe
				case 'bottom-right':
					if(typeof this.b_options["left"] !== 'undefined') {
						this.b_options["left"]	= this.b_options["left"] + 4 -this.b_options["width"];
					} else {
						this.b_options["left"]	= -this.b_options["width"] + 4;
					}
					this.b_div.style.right	= this.b_options["left"]+'px';
					if(typeof this.b_options["top"] !== 'undefined') {
						this.b_options["top"]	= this.b_options["top"] - this.b_options["height"];
					} else {
						this.b_options["top"]	= -this.b_options["height"];
					}
					this.b_div.style.top	= this.b_options["top"]+'px';
					
					this.b_div.innerHTML	= this._getInnerHTML();
					this._appendTo('bottom',true);
					
					break;
				// -
				
				// In case of an invalid positioning, return false
				default:
					return false;
				// -
			}
		},
		
		/**
		 * Function to add the current div relative to the frame. Uses the anchors to position the div.
		 *
		 * @return	void
		 */
		_placeInBrowser: function(file,options) {
			switch(this.b_options["position"].toLowerCase()) {
				
				// Add the div to the top left of the browser window
				case 'top-left':
					if(typeof this.b_options["left"] === 'undefined') {
						this.b_options["left"]	= 0;	
					}
					this.b_div.style.left	= this.b_options["left"]+'px';
					if(typeof this.b_options["top"] === 'undefined') {
						this.b_options["top"]	= 0;	
					}
					this.b_div.style.top	= this.b_options["top"]+'px';
					
					this.b_div.innerHTML	= this._getInnerHTML();
					this._appendTo('index');
					
					break;
				// -
				
				// Add the div to the top center of the browser window
				case 'top':
					if(typeof this.b_options["left"] !== 'undefined') {
						this.b_options["left"]	= -Math.floor(this.b_options["width"]/2) + this.b_options["left"];
					} else {
						this.b_options["left"]	= -Math.floor(this.b_options["width"]/2);
					}
					this.b_div.style.left			= '50%';
					this.b_div.style.marginLeft	= this.b_options["left"]+'px';
					if(typeof this.b_options["top"] === 'undefined') {
						this.b_options["top"]	= 0;
					}
					this.b_div.style.top	= this.b_options["top"]+'px';
					
					this.b_div.innerHTML	= this._getInnerHTML();
					this._appendTo('index');
					
					break;
				// -
				
				// Add the div to the top right of the browser window
				case 'top-right':
					if(typeof this.b_options["left"] !== 'undefined') {
						this.b_options["left"]	= this.b_options["left"] * -1;
					} else {
						this.b_options["left"]	= 0;
					}
					this.b_div.style.right	= this.b_options["left"]+'px';
					if(typeof this.b_options["top"] === 'undefined') {
						this.b_options["top"]	= 0;	
					}
					this.b_div.style.top	= this.b_options["top"]+'px';
					
					this.b_div.innerHTML	= this._getInnerHTML();
					this._appendTo('index');
					
					break;
				// -
				
				// Add the div in the (top left) position of the header
				case 'header':
					this._setHeader();
					break;
				// -
				
				// Add the div to the left edge of the browser window, centered vertically	
				case 'left':
					if(typeof this.b_options["left"] === 'undefined') {
						this.b_options["left"]	= 0;
					}
					this.b_div.style.left	= this.b_options["left"]+'px';
					if(typeof this.b_options["top"] !== 'undefined') {
						this.b_options["top"]	= this.b_options["top"] - Math.floor(this.b_options["height"]/2);
					} else {
						this.b_options["top"]	= -Math.floor(this.b_options["height"]/2);
					}
					this.b_div.style.top	= '50%';
					this.b_div.style.marginTop	= this.b_options["top"]+'px';
					
					this.b_div.innerHTML	= this._getInnerHTML();
					this._appendTo('index');
					
					break;
				// -
				
				// Add the div in the middle of the contentframe
				case 'center':
					this._setDHTMLlayer();
					break;
				// -
				
				// Add a pregame rectangle
				case 'rectangle':
					this._setRectangle();
					break;
				// -
				
				// Add the div to the left edge of the browser window, centered vertically
				case 'right':
					if(typeof this.b_options["left"] !== 'undefined') {
						this.b_options["left"]	= this.b_options["left"] * -1;
					} else {
						this.b_options["left"]	= 0;
					}
					this.b_div.style.right	= this.b_options["left"]+'px';
					if(typeof this.b_options["top"] !== 'undefined') {
						this.b_options["top"]	= this.b_options["top"] - Math.floor(this.b_options["height"]/2);
					} else {
						this.b_options["top"]	= -Math.floor(this.b_options["height"]/2);
					}
					this.b_div.style.top	= '50%';
					this.b_div.style.marginTop	= this.b_options["top"]+'px';
					
					this.b_div.innerHTML	= this._getInnerHTML();
					this._appendTo('index');
					
					break;
				// -
				
				// Add the div to the bottom left corner of the browser window
				case 'bottom-left':
					if(typeof this.b_options["left"] === 'undefined') {
						this.b_options["left"]	= 0;
					}
					this.b_div.style.left	= this.b_options["left"]+'px';
					if(typeof this.b_options["top"] === 'undefined') {
						this.b_options["top"]		= 0;
					}
					this.b_div.style.bottom	= this.b_options["top"]+'px';
					
					this.b_div.innerHTML	= this._getInnerHTML();
					this._appendTo('index');
					
					break;
				// -
				
				// Add the div to the bottom corner of the browser window, centered horizontally
				case 'bottom':
					if(typeof this.b_options["left"] !== 'undefined') {
						this.b_options["left"]	= -Math.floor(this.b_options["width"]/2) + this.b_options["left"];
					} else {
						this.b_options["left"]	= -Math.floor(this.b_options["width"]/2);
					}
					this.b_div.style.left			= '50%';
					this.b_div.style.marginLeft	= this.b_options["left"]+'px';
					if(typeof this.b_options["top"] === 'undefined') {
						this.b_options["top"]	= 0;
					}
					this.b_div.style.bottom	= this.b_options["top"]+'px';
					
					this.b_div.innerHTML	= this._getInnerHTML();
					this._appendTo('index');
					
					break;
				// -
				
				// Add the div to the bottom right corner of the browser window
				case 'bottom-right':
					if(typeof this.b_options["left"] !== 'undefined') {
						this.b_options["left"]	= this.b_options["left"] * -1;
					} else {
						this.b_options["left"]	= 0;
					}
					this.b_div.style.right	= this.b_options["left"]+'px';
					if(typeof this.b_options["top"] === 'undefined') {
						this.b_options["top"]	= 0;
					}
					this.b_div.style.bottom	= this.b_options["top"]+'px';
					
					this.b_div.innerHTML	= this._getInnerHTML();
					this._appendTo('index');
					
					break;
				// -
				
				// In case of an invalid positioning, return false
				default:
					return false;
				// -
			}
		},
		
		/**
		 * Function that adds a measuretag image to the bottom anchor
		 *
		 * @param	string	m_src	The source/link of the measure tag
		 *
		 * @return	void
		 */
		_addMeasureTag: function(m_src)
		{
			measureTAG			= document.createElement("img");
			measureTAG.src		= m_src;
			measureTAG.width	= 1;
			measureTAG.height	= 1;
			this.b_anchor["bottom"].appendChild(measureTAG);
		},
		
		/**
		 * Function that returns whether the link should open in a new window, or in the same
		 *
		 * @param	string	forTag	the tag type for which to get the target
		 *
		 * @return	string
		 */
		_getTarget: function(forTag)
		{
			tar	= '_blank';
			if(typeof this.b_options["tagtarget"] !== 'undefined' && this.b_options["tagtarget"] !== '') {
				tar	= this.b_options["tagtarget"];
			} else if(typeof fg_banner_defaults["tagtarget"] !== 'undefined' && fg_banner_defaults["tagtarget"] !== '') {
				tar	= fg_banner_defaults["tagtarget"];
			}
			
			if(forTag === 'A' && tar === '_self') {
				return '_blank';
			}
			return tar;
		},
		
		/**
		 * Function that returns the html to be placed in a div
		 *
		 * @return	string	html
		 */
		_getInnerHTML: function()
		{
			if(this.b_type == 'img') {
				return this._getImageContent();
			} else if(this.b_type == 'swf') {
				return this._getFlashContent();
			} else {
				return false;	
			}
		},
		
		/**
		 * Function that returns the html to be placed in a div for images
		 *
		 * @return	string	html
		 */
		_getImageContent: function()
		{
			if(typeof this.b_options["bgcolor"] !== 'undefined' && this.b_options["bgcolor"] !== '') {
				this.b_div.style.backgroundColor = this.b_options["bgcolor"];
			}
			html	= '';
			
			aclose	= false;
			if(typeof this.b_options["clickTAG"] !== 'undefined' && this.b_options["clickTAG"] !== '' &&  this.b_options["clickTAG"] !== '-') {
				html	= html + '<a href="'+this.b_options["clickTAG"]+'" target="'+this._getTarget('A')+'">';
				aclose	= true;
			} else if(typeof fg_banner_defaults["clickTAG"] !== 'undefined' && fg_banner_defaults["clickTAG"] !== '' &&  this.b_options["clickTAG"] !== '-') {
				html	= html + '<a href="'+fg_banner_defaults["clickTAG"]+'" target="'+this._getTarget('A')+'">';
				aclose	= true;
			}
			
			html = html + '<img src="'+this.b_file+'" width="'+this.b_options["width"]+'" height="'+this.b_options["height"]+'" />';
			
			if(aclose) {
				html = html + '</a>';	
			}
			
			return html;
		},
		
		/**
		 * Function that returns the html to be placed in a div for flash elements
		 *
		 * @return	string	html
		 */
		_getFlashContent: function(sizes)
		{
			var embed	= false; if(this.b_options["embed"]	== true) { embed = true; }
			
			if(this.b_expandable) {
				sizes	= {"x":this._getExpandedWidth()+'px',"y":this._getExpandedHeight()+'px'};
			} else if(typeof sizes === 'undefined') {
				sizes	= {"x":"100%","y":"100%"};
			}
			
			src	= this.b_file;
			
			if(typeof this.b_options["params"] !== 'undefined') {
				for(var i in this.b_options["params"]) {
					src = src + ((src.indexOf('?') > 0)?'&':'?') +i+'='+urlencode(this.b_options["params"][i]);
				}
			}
			
			if(typeof this.b_options["clickTAG"] !== 'undefined' && this.b_options["clickTAG"] !== '') {
				src	= src+((src.indexOf('?') > 0)?'&':'?')+this.b_cTAG+"="+urlencode(this.b_options["clickTAG"]);
			} else if(typeof fg_banner_defaults["clickTAG"] !== 'undefined' && fg_banner_defaults["clickTAG"] !== '') {
				src	= src+((src.indexOf('?') > 0)?'&':'?')+this.b_cTAG+"="+urlencode(fg_banner_defaults["clickTAG"]);
			}
	
			if(this._getTarget() !== '_blank' && src.indexOf('?') > 0) {
				src = src + '&tagtarget='+this._getTarget();
			}
			
			flash_id	= 'flash_'+(this.b_options["position"].replace('-','_'))+'_'+this.b_options["width"]+'x'+this.b_options["height"];
			
			html = '<object ';
			html = html + 'style="outline-width:0;" ';
			html = html + 'id="'+flash_id+'" ';
			html = html + 'width="'+sizes.x+'" ';
			html = html + 'height="'+sizes.y+'" ';
			html = html + 'type="application/x-shockwave-flash" ';
			if(embed) {
				html = html + 'classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ';
			} else {
				html = html + 'data="'+src+'" ';
			}
			html = html + '>';
		    html = html + '<param name="movie" value="'+src+'"/>';
		    if(this.b_usePercentage) {
		    	html = html + '<param name="scale" value="'+this.b_scaleType+'"/>';
			}
		    if(typeof this.b_options["wmode"] !== 'undefined' && this.b_options["wmode"] !== '') {
				html = html + '<param name="wmode" value="'+this.b_options["wmode"]+'"/>';
			} else {
				html = html + '<param name="wmode" value="transparent"/>';
			}
			if(typeof this.b_options["bgcolor"] !== 'undefined' && this.b_options["bgcolor"] !== '') {
				html	= html + '<param name="bgcolor" value="'+this.b_options["bgcolor"]+'" />';
			}
			if(typeof this.b_options["clickTAG"] !== 'undefined' && this.b_options["clickTAG"] !== '') {
				html	= html + '<param name="'+this.b_cTAG+'" value="'+urlencode(this.b_options["clickTAG"])+'" />';
			} else if(typeof fg_banner_defaults["clickTAG"] !== 'undefined' && fg_banner_defaults["clickTAG"] !== '') {
				html	= html + '<param name="'+this.b_cTAG+'" value="'+urlencode(fg_banner_defaults["clickTAG"])+'" />';
			}
			if(this._getTarget() !== '_blank' && src.indexOf('?') > 0) {
				html = html + '<param name="tagtarget" value="'+this._getTarget('Flash')+'"/>';
			}
			html = html + '<param name="AllowScriptAccess" value="always"/>';
			
			if(typeof this.b_options["params"] !== 'undefined') {
				for(var i in this.b_options["params"]) {
					html = html + '<param name="'+i+'" value="'+this.b_options["params"][i]+'"/>';
				}
			}
			if(embed)
			{
				html = html + this._getEmbedTag(flash_id, src, sizes);	
			}
			html = html + '<param name="salign" value="tl"/>';
			html = html + '</object>';

			return html;
		},
		
		/**
		 * Function that returns the html to be placed in a div for flash elements that require the <embed> tag
		 *
		 * @return	string	html
		 */
		_getEmbedTag: function(flash_id, src, sizes)
		{
			var embed = '';
			embed = embed + '<embed ';
			embed = embed + 'width="'+sizes.x+'" ';
			embed = embed + 'height="'+sizes.y+'" ';
			embed = embed + 'allowscriptaccess="always" ';
			embed = embed + 'name="'+flash_id+'" ';
			embed = embed + 'wmode="opaque" ';
			embed = embed + 'swliveconnect="true" ';
			embed = embed + 'quality="high" ';
			embed = embed + 'type="application/x-shockwave-flash" ';
			
			var vars = false;
			if(typeof this.b_options["clickTAG"] !== 'undefined' && this.b_options["clickTAG"] !== '') {
				if(!vars) { embed = embed + 'flashvars="'; vars = true; }
				embed	= embed + this.b_cTAG+'='+urlencode(this.b_options["clickTAG"]);
			} else if(typeof fg_banner_defaults["clickTAG"] !== 'undefined' && fg_banner_defaults["clickTAG"] !== '') {
				if(!vars) { embed = embed + 'flashvars="'; vars = true; }
				embed	= embed + this.b_cTAG+'='+urlencode(fg_banner_defaults["clickTAG"]);
			}
			if(this._getTarget() !== '_blank' && src.indexOf('?') > 0) {
				if(!vars) { embed = embed + 'flashvars="'; vars = true; }
				embed = embed + '&tagtarget='+this._getTarget('Flash');
			}
			if(typeof this.b_options["params"] !== 'undefined') {
				for(var i in this.b_options["params"]) {
					if(!vars) { embed = embed + 'flashvars="'; vars = true; }
					embed = embed + '&' + i +'='+this.b_options["params"][i];
				}
			}
			if(this.b_usePercentage) {
		    	embed = embed + 'scale="'+this.b_scaleType+'" ';
			}
			if(vars) { embed = embed + '"'; }
			embed = embed + 'src="'+src+'"></embed>';
			
			return embed;
		},
		
		/**
		 * Function to add a header div to the half banner slot. Will issue a warning when
		 * a header has already been set.
		 *
		 * @return	void
		 */
		_setHeader: function() {
			if(typeof this.headerset === 'undefined') {
				this.headerset	= true;
				
				base_left	= Math.floor(((parseInt(document.getElementById('header_holder').offsetWidth)/2)-(Math.floor(this.b_options["width"]/2)))+470)*-1;
				
				this.b_div.id	= "b_header_center";
				if(typeof this.b_options["left"] !== 'undefined') {
					this.b_options["left"]	= this.b_options["left"] + base_left;
				} else {
					this.b_options["left"]	= base_left;
				}
				this.b_div.style.left	= this.b_options["left"]+'px';
				if(typeof this.b_options["top"] !== 'undefined') {
					this.b_options["top"]	= this.b_options["top"] - 19;
				} else {
					this.b_options["top"]	= -19;
				}
				this.b_div.style.top	= this.b_options["top"]+'px';
				
				left_div						= document.createElement("div");
				left_div.id						= "b_header_leftfiller";
				left_div.style.width			= '730px';
				left_div.style.height			= '95px';
				left_div.style.backgroundImage	= 'url(http://static.tibaco.nl/layout/funnygames/images/nl/empty_header.gif)';
				left_div.style.position			= 'absolute';
				left_div.style.left				= '0px';
				left_div.style.top				= '0px';
				
				right_div						= document.createElement("div");
				right_div.id					= "b_header_rightfiller";
				right_div.style.width			= '730px';
				right_div.style.height			= '95px';
				right_div.style.backgroundImage	= 'url(http://static.tibaco.nl/layout/funnygames/images/nl/empty_header.gif)';
				right_div.style.position		= 'absolute';
				right_div.style.right			= '0px';
				right_div.style.top				= '0px';
				
				this.b_div.innerHTML	= this._getInnerHTML();
				
				document.getElementById('header_holder').appendChild(left_div);
				document.getElementById('header_holder').appendChild(right_div);
				document.getElementById('halfbanner').appendChild(this.b_div);
			} else {
				this._writeError("Warning! Double header specified!");
			}
		},
		
		/**
		 * Function to add a header div to the half banner slot. Will issue a warning when
		 * a header has already been set.
		 *
		 * @return	void
		 */
		_setRectangle: function() {
			if(typeof this.rectangleset === 'undefined') {
				this.rectangleset	= true;
				
				if(typeof this.b_options["top"] === 'undefined') {
					this.b_options["top"]	= 0;	
				}
				if(typeof this.b_options["left"] === 'undefined') {
					this.b_options["left"]	= 0;	
				}
				
				id		= this._getId();
				html	= '<div id="'+id+'" style="' +
						'width: 336px; ' +
						'height: 280px; position: relative;">' +
						'<div id="'+id+'_content" style="' +
						'width: '+this.b_options["width"]+'px; ' +
						'height: '+this.b_options["height"]+'px; ' +
						'position: absolute; ' +
						'top: '+this.b_options["top"]+'px; ' +
						'left: '+this.b_options["left"]+'px; ' +
						'">' +
						this._getInnerHTML() +
						'</div></div>';

				document.write(html);
				
				if(typeof this.b_options["bannertime"] !== 'undefined' && this.b_options["bannertime"] !== '') {
					fg_banner_defaults["bannertime"]	= this.b_options["bannertime"];
				}
				if(typeof this.b_options["showbanner"] !== 'undefined' && this.b_options["showbanner"] !== '') {
					fg_banner_defaults["showbanner"]	= this.b_options["showbanner"];
				}
			} else {
				this._writeError("Warning! Double rectangle specified!");
			}
		},
		
		/**
		 * Function to add a DHTML div to the center of the page. Will issue a warning when
		 * another DHTML has already been set.
		 *
		 * @return	void
		 */
		_setDHTMLlayer: function() {
			if(typeof this.dhtmlset === 'undefined') {
				this.dhtmlset	= true;
				
				this.b_div.id	= "b_dhtml_layer";
				
				if(typeof this.b_options["left"] !== 'undefined') {
					this.b_options["left"]	= -Math.floor(this.b_options["width"]/2) + this.b_options["left"];
				} else {
					this.b_options["left"]	= -Math.floor(this.b_options["width"]/2);
				}
				this.b_div.style.left	= this.b_options["left"]+'px';
				if(typeof this.b_options["top"] !== 'undefined') {
					this.b_options["top"]	= this.b_options["top"] - Math.floor(this.b_options["height"]/2);
				} else {
					this.b_options["top"]	= -Math.floor(this.b_options["height"]/2);
				}
				this.b_div.style.top	= this.b_options["top"]+'px';
				
				this.b_div.innerHTML	= this._getInnerHTML();
				this.b_anchor["center_over"].appendChild(this.b_div);
			} else {
				this._writeError("Warning! Double DHTML specified!");
			}
		},
		
		/**
		 * Write a default banner into the page
		 *
		 * @return void
		 */
		_fillSlot: function() {
			if(typeof this.b_options["left"] === 'undefined') {
				this.b_options["left"]	= 0;
			}
			if(typeof this.b_options["top"] === 'undefined') {
				this.b_options["top"]	= 0;	
			}
			
			slot	= document.createElement('div');
			slot.id	= this._getId();
			
			slot.style.cssText =	'width: '+this.b_options["width"]+'px; ' +
									'height: '+this.b_options["height"]+'px; ' +
									'position: absolute; ' +
									'top: '+this.b_options["top"]+'px; ' +
									'left: '+this.b_options["left"]+'px; ' +
									'z-index: ' +this.b_zindex+';';
			
			this.b_zindex		= this.b_zindex + 10;
			
			slot.innerHTML	= this._getInnerHTML();
			
			this._addToContainer(slot);
		},
		
		/**
		 * Write an expandable banner into the page
		 *
		 * @return void
		 */
		_fillSlotExpandable: function() {
	
			banner_id	= this._getId();
						
			if(typeof this.b_options["left"] === 'undefined') {
				this.b_options["left"]	= 0;
			}
			if(typeof this.b_options["top"] === 'undefined') {
				this.b_options["top"]	= 0;	
			}
			
			if(typeof this.b_options['start'] == 'undefined' || this.b_options['start'] === 'normal') {
				s_width		= this.b_options["width"];
				s_height	= this.b_options["height"];
				e_width		= this._getExpandedWidth();
				e_height	= this._getExpandedHeight();
			} else {
				s_width		= this._getExpandedWidth();
				s_height	= this._getExpandedHeight();
				e_width		= this.b_options["width"];
				e_height	= this.b_options["height"];
			}
		
			fg_Banners.b_allow_resize[banner_id] = false;
			if(typeof this.b_options['auto_resize'] !== 'undefined') {
				setTimeout("document.getElementById('"+banner_id+"').style.width = '"+e_width+"px'; document.getElementById('"+banner_id+"').style.height = '"+e_height+"px'; fg_Banners.b_allow_resize['"+banner_id+"'] = true;", this.b_options['auto_resize'] * 1000);
			} else {
				this.b_allow_resize[banner_id] = true;
			}
			
			var info			= document.createElement('input');
			info.style.display	= 'none';
			info.type			= 'hidden';
			info.value			= 'var fgb = {"i":"'+banner_id+'","w":'+this.b_options["width"]+',"h":'+this.b_options["height"]+',"ew":'+this._getExpandedWidth()+',"eh":'+this._getExpandedHeight()+'}';
			this._addToContainer(info);
	
			var slot			= document.createElement('div');
			slot.id	= banner_id;
			slot.style.cssText	=	'width: '+s_width+'px; ' +
									'height: '+s_height+'px; ' +
									'position: absolute; ' +
									'top: '+this.b_options["top"]+'px; ' +
									'left: '+this.b_options["left"]+'px; ' +
									'overflow: hidden; ' +
									'z-index: ' +this.b_zindex+';';
			
			this.b_zindex		= this.b_zindex + 10;
			
			slot.onmouseover	= function() { fg_Banners.expandBanner(this.parentNode); };
			slot.onmouseout		= function() { fg_Banners.expandBanner(this.parentNode); };
			slot.innerHTML		= this._getInnerHTML();
			
			this._addToContainer(slot);
		},
	
		/**
		 * Adds the supplied object to the DOM on the location of the container
		 * 
		 * @param	element	obj		The element to add to the DOM
		 *
		 * @return void
		 */
		_addToContainer: function(obj) {
			if(typeof this.b_options["container"] == 'undefined') {
				this.b_options["container"] = 'half';
			}
			switch(this.b_options["container"].toString().toLowerCase()) {
				case 'full':
					if(document.getElementById('fullbanner')) {
						document.getElementById('fullbanner').appendChild(obj);
					} else {
						try {
							par	= document.createElement('div');
							par.id	= 'fullbanner';
							par.appendChild(obj);
							document.getElementsByTagName('body')[0].appendChild(par);	
						} catch(e) {
							return false;
						}
					}
					break;
				case 'skyscraper':
					if(document.getElementById('skyScraper')) {
						document.getElementById('skyScraper').appendChild(obj);
					} else {
						try {
							par	= document.createElement('div');
							par.id	= 'skyScraper';
							par.appendChild(obj);
							document.getElementsByTagName('body')[0].appendChild(par);	
						} catch(e) {
							return false;
						}
					}
					break;
				case 'rectangle':
					if(document.getElementById('banner').getElementsByTagName('div')[0]) {
						document.getElementById('banner').getElementsByTagName('div')[0].insertBefore(obj,$('banner').getElementsByTagName('div')[0].firstChild);
					} else {
						try {
							par	= document.createElement('div');
							par.id	= 'banner';
							par.appendChild(obj);
							document.getElementsByTagName('body')[0].appendChild(par);	
						} catch(e) {
							return false;
						}
					}
					break;
				case 'half':
				default:
					if(document.getElementById('halfbanner')) {
						document.getElementById('halfbanner').appendChild(obj);
					} else {
						try {
							par	= document.createElement('div');
							par.id	= 'halfbanner';
							par.appendChild(obj);
							document.getElementsByTagName('body')[0].appendChild(par);	
						} catch(e) {
							return false;
						}
					}
					break;
			}
			return true;
		},
		
		/**
		 * Function to force rerendering of a div
		 *
		 * @return void
		 */
		_reRender: function() {
			for(var i = 0; i < this.b_rerender.length; i++) {
				if(document.getElementById(this.b_rerender[i])) {
					document.getElementById(this.b_rerender[i]).parentNode.style.display = 'none';
					document.getElementById(this.b_rerender[i]).parentNode.style.display = 'block';
				}
			}
		},
		
		/**
		 * Returns a unique number for the ID of the banner.
		 *
		 * @return	integer
		 */
		_getId: function() {
			ret_id	= 'fg_b_i-'+parseInt(((this.b_id * 5000)/3.1415)+15)+'_p-'+this.b_options["position"].toLowerCase()+'_s-'+this.b_options["width"]+'x'+this.b_options["height"];
			
			this.b_id	= this.b_id + 1;
			
			return ret_id;
		},
		
		/**
		 * Function to determine the type of outing based on the filename supplied.
		 *
		 * @param	string	file	The filename to check
		 *
		 * @return	string	Either 'swf' or 'img', or false if neither
		 */
		_getType: function(file, b_options) {
			item_switch	= file.toString().substr(file.toString().length -4);
			
			if(	typeof b_options["type"] != 'undefined' && b_options["type"] !== null &&
				(b_options["type"] == 'swf' || b_options["type"] == 'img')
			) {
				return b_options["type"];
			}
			switch(item_switch.toLowerCase())
			{
				case '.swf':
					return 'swf';
				case '.png':
				case '.jpg':
				case 'jpeg':
				case '.gif':
					return 'img';
				default:
					return false;
			}
		},
		
		/**
		 * Function to write a block of HTML containing an error to the page. If multiple errors/
		 * warnings exist, it will output them under each other.
		 *
		 * @return	void
		 */
		_writeError:	function(line) {
			err = document.createElement('div');
			err.style.cssText = 'color: red;' + 
								'background-color: white;' +
								'position: absolute;' +
								'margin: 2px;' +
								'padding: 2px;' +
								'top: '+this.b_top+'px;' +
								'left: 0px;' +
								'width: 600px;' +
								'height: 20px;' +
								'z-index: 600000';
			err.innerHTML	= line;
			
			document.getElementsByTagName('body')[0].appendChild(err);
			
			this.b_top	= this.b_top + 30;
		}
	};
	
	/**
	 * In IE6, we are required to rerender the skyscraper, since it sometimes gets 'stuck' beneath
	 * the page
	 */
	addDOMLoadEvent(function() {
		if(((navigator.appName=='Microsoft Internet Explorer')?parseFloat((new RegExp("MSIE ([0-9]{1,}[.0-9]{0,})")).exec(navigator.userAgent)[1]):99) <= 6)
		{
			div		= document.getElementById('skyScraper');
			if(div)
			{
				elems	= div.getElementsByTagName('iframe');
				for(var i = 0; i < elems.length; i++) {
					elems[i].style.position	= 'absolute';
					elems[i].style.top		= '0px';
					elems[i].style.left		= '0px';
				}
				
				elems	= div.getElementsByTagName('object');
				for(var i = 0; i < elems.length; i++) {
					elems[i].style.position	= 'absolute';
					elems[i].style.top		= '0px';
					elems[i].style.left		= '0px';
				}
			}
		}
	});
	
	
	
	
	
	
	/* Set some old variables to their new counterparts */
	var	banner_load		= fg_banner_load;
	var banner_defaults	= fg_banner_defaults;
	var Banners			= fg_Banners;

// End if - typeof fg_Banners == 'undefined'
}