if (typeof tws_Global == 'undefined' || typeof tws_Global === null) {
	var tws_Global = {
		loaded: [],
		callbacks: [],
		
		scriptLoaded: function(objName)
		{
			tws_Global.loaded.push(objName);
			setTimeout("tws_Global.runCallbacks()",1);
		},
		
		runCallbacks: function()
		{
			for(var i =0 ; i < tws_Global.callbacks.length; i++)
			{
				if(tws_Global.callbacks[i] !== true)
				{
					try
					{
						tws_Global.callbacks[i]();
						tws_Global.callbacks[i] = true;
					}
					catch(e)
					{
						try {console.log(e);} catch(e) {}
					}
				}
			}
		},
		
		setCallback: function(func)
		{
			try
			{
				if(!func())
				{
					tws_Global.callbacks.push(func);
				}
			}
			catch(e)
			{
				tws_Global.callbacks.push(func);
			}
		}
	}
}

if (typeof tws_Banners == 'undefined' || tws_Banners === null)
{
	/**
	 * Add a DOM loaded event
	 *
	 * @param	function	The function to execute when the DOM has loaded
	 *
	 * @return void
	 */
	var 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)
	                var head = document.getElementsByTagName("head")[0];
			        var script = document.createElement('script');
			        script.id = '__ie_onload';
			        script.src = '//0';
			        script.type = 'text/javascript';
			        script.defer = true;
			        script.onreadystatechange = function() {
	                    if (this.readyState == "complete") {
	                        init(); // call the onload handler
	                    }
	                };
	                
			        head.appendChild(script);
	            /*@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);
	    };
	})();

	/**
	 * The object that handles all banners in the page
	 */
	var tws_Banners = 
	{
		/** LOCAL VARIABLES **/
		
		/* The syndication siteID */
		siteID 			: ((typeof tws_Global.siteID != 'undefined' && tws_Global.siteID !== null)?tws_Global.siteID:null),
		
		/* The base URL of the script */
		baseURL			: 'http://ads.tibaco.net/',
		
		/* A counter ID for keeping track of the banner placements */
		counterID		: 0,
		
		/* Keeps track of all hidden banners (can be checked by other functions to prevent re-showing them) */
		hiddenBanners	: [],
		
		/* Keeps track of the slots that will be used in the page */
		b_used_slots	: [],
		
		/* Do we have the site settings loaded */
		b_siteLoaded	: false,
		
		/* Do we have the _loadItems() on the DOM load? */
		b_DOMloader		: false,
		
		/* Items to be loaded after the DOM is ready */
		b_loaditems		: [],
		
		/* 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,
		
		/* A global variable to store the defaults in */
		b_defaults	: {
			"contentMarginTop"		: 0,
			"contentMarginLeft"		: 0,
			"pagewidth" 			: 0,
			"headerWidth"			: 730,
			"headerHolderWidth"		: 730,
			"headerHeight"			: 95,
			"rectangleWidth"		: 336,
			"rectangleHeight"		: 280,
			"headerBaseLeft"		: 0,
			"flooradheight"			: 90,
			"headerID"				: 'header_holder',
			"halfbannerID"			: 'halfbanner',
			"halfbannerHTML"		: '',
			"fullbannerID"			: 'fullbanner',
			"fullbannerHTML"		: '',
			"skyscraperID"			: 'skyScraper',
			"headerFillBackground"	: '',
			"textlinkID"			: 'textlink_container',
			"measureTAG"			: []
		},
		b_default_settings	: 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',
		
		/* Keeps track of the already shown measureTAGs, we do not want to show the same one twice */
		b_measureTAGs	: [],
		
		/* Do we use percentages on this banner */
		b_usePercentage	: false,
		
		/* The default scaling type that is used in case of percentage */
		b_scaleType		: 'default',
		
		/* Show errors in the script on page */
		b_showErrors	: false,
		
		b_googleAttributes : [],
		
/** GLOBAL FUNCTIONS **/
		
		/**
		 * Set the siteID to the specified parameter.
		 * This function also calls the function to load site defaults (if they have not been set yet)
		 *
		 * @param	integer	siteID	The ID for the current site
		 *
		 * @return	void
		 */
		setSiteID: function(siteID)
	    {
	    	tws_Global.siteID = siteID;
	        this.siteID = siteID;
	        
	        if(!this.b_siteLoaded)
	        {
	        	this.loadSiteDefaults();	
	        }
	    },
	    
	    /**
		 * Tells the object which banners will be used in this page
		 *
		 * @param	string	slotcode	The code for the slot used
		 *
		 * @return	void
		 */
	    addSlot: function(slotcode)
	    {
	        if(this.getSiteID() !== null && !this._inArray(slotcode,this.b_used_slots))
	    	{
	    		this.b_used_slots.push(slotcode);
	    		
	    		var now = new Date();    		
	        	var url	= this.baseURL + 'script?siteid=' + escape(this.getSiteID()) + '&placement='+slotcode+'&nocache=' + now.getTime();

	    		var head = document.getElementsByTagName("head")[0];
		        var script = document.createElement('script');
		        script.src = url;
		        script.type = 'text/javascript';

		       	head.appendChild(script);
	    	}
	    },
	    
	    /**
		 * Add the script headers for a site to the head
		 *
		 * @param	string	siteid	The siteid to set the headers for (should be the current siteID or 0 for tibaco.net)
		 *
		 * @return	void
		 */
	    addHeaders: function(siteid)
	    {
	        if(this.getSiteID() !== null && !this._inArray(siteid,this.b_used_slots, true))
	    	{
	    		this.b_used_slots.push(siteid);
	    		
	    		var now = new Date();    		
	        	var url	= this.baseURL + 'headers?siteid=' + escape(this.getSiteID()) + '&for='+siteid+'&nocache=' + now.getTime();

	    		var head = document.getElementsByTagName("head")[0];
		        var script = document.createElement('script');
		        script.src = url;
		        script.type = 'text/javascript';

		       	head.appendChild(script);
	    	}
	    },
	    
	    /**
		 * Process a piece of HTML as though it were tags for the head of the page
		 *
		 * @param	string	html	The HTML that should be injected into the head
		 *
		 * @return	void
		 */
	    setHeaders: function(obj)
	    {
			var head = document.getElementsByTagName("head")[0];
			for(var i = 0; i < obj.numbers.length; i++)
			{
				var script = document.createElement('script');
		        if(obj.numbers[i].substr(0,4) == 'http')
		        {
		        	script.src = obj.numbers[i];
		        }
		        else
		        {
		        	script.src = this.baseURL + obj.numbers[i];
		        }
		        script.type = 'text/javascript';

		       	head.appendChild(script);
			}
	    },
	    
	    /**
	     * Retrieve the current siteID. Will return tws_Syndication siteID if set, tws_Global otherwise
	     * or NULL if neither are set
	     *
	     * @return	integer|null	The current siteID
	     */
	    getSiteID: function()
	    {
	    	if(typeof this.siteID != 'undefined' && this.siteID !== null)
	    	{
	    		return this.siteID;
	    	}
	    	else if(typeof tws_Global.siteID != 'undefined' && tws_Global.siteID !== null)
	    	{
	    		return tws_Global.siteID;
	    	}
	    	else
	    	{
	    		return null;
	    	}
	    },
	    
	    /**
	     * 
	     */
	    getBanner: function(placement, params)
	    {
	    	if (this.getSiteID() == null) throw "siteID not defined";
			if (placement == null || placement == '') throw "placement not defined";
			
	    	this.counterID++;
	    	
	    	// Construct the URL to fetch the contents from	    	
	    	var now = new Date();
	        var url = this.baseURL + "content?siteid=" + escape(this.getSiteID());
	        url += "&counter=" + this.counterID + "&slot=" + escape(placement) + '&nocache=' + now.getTime();
	        
	        if(typeof params != 'undefined')
	        {
	        	for(var i = 0; i < params.length; i++)
	        	{
	        		url += '&TWS_'+ params[i];
	        	}
	        }
	        // Find the script tag that called this request
	    	scripts	= document.getElementsByTagName('script');
	    	var classCounter = 0;
	    	for(var i = 0; i < scripts.length; i++)
	    	{
	    		if(scripts[i].className == 'tws_Banners' && (classCounter + 1) == this.counterID)
	    		{
	    			var div = document.createElement('div');
	    			div.id = 'tws_Banner_placement_'+this.counterID;
	    			scripts[i].parentNode.insertBefore(div,scripts[i]);
	    			
	    			var now = new Date();
			        var script = document.getElementById('tws_Banners_content');
			        var head = document.getElementsByTagName("head")[0];
			        if (script) head.removeChild(script);
			        script = document.createElement('script');
			        script.id = 'tws_Banners_content';
			        script.src = url;
			        script.type = 'text/javascript';
			        head.appendChild(script);
	
	    			classCounter++;
	    		}
	    	}
	    },
	    
	    /**
	     *
	     */
	    setTimers: function(linktime, movietime, callback)
	    {
	    	this.redirected = false;
            this.redirectlinkshow = false;
            this.linktime = linktime;
            this.movietime = movietime;
            this.callback = (typeof callback != "undefined") ? callback : this.callback;
            
            var params = this._getParameters();
	    	if(typeof params["tws_debug"] != 'undefined' && (params["tws_debug"] == 'true' || params["tws_debug"] == 'banners'))
			{
			    console.log("BANNERS: Setting timers:");
			    console.log("BANNERS: linktime: "+this.linktime);
			    console.log("BANNERS: movietime "+this.movietime);
			    console.log("BANNERS: callback "+this.callback);
			}
	    },

        resetMovieTimer: function(newmovietime)
        {
            var diffTime = new Date().getTime() - tws_Banners.startTime;
            if (diffTime > 0 && (newmovietime >= this.movetime || this.movietime - diffTime < newmovietime))
            {
                this.movietime += (diffTime / 1000);
            }
        },
	     
	    /**
	     * Starts the visualisation of the load bar
	     *
	     * @param integer gameid	The gameid for which to show the load bar
	     * @param string  linktxt	The text to show with the link to skip the rest of the banner
	     *
	     * @return void	
	     */
	    startLoader: function(gameid, linktxt)
	    {
            var params = this._getParameters();
	    	if(typeof params["tws_debug"] != 'undefined' && (params["tws_debug"] == 'true' || params["tws_debug"] == 'banners'))
			{
			    console.log("BANNERS: Starting loader");
			    console.log("BANNERS: Movietime: "+this.movietime);
			    console.log("BANNERS: Banner DIV found? "+document.getElementById('tws_syndication_loadbar_'+gameid));
			}			
	    	if(this.movietime > 0 && document.getElementById('tws_syndication_loadbar_'+gameid))
	    	{
	    		this.percentage = 0;
	    		
	    		document.getElementById('tws_syndication_loadbar_'+gameid).style.width = '0%';
				if(document.getElementById('tws_syndication_loadpercent_'+gameid))
					document.getElementById('tws_syndication_loadpercent_'+gameid).innerHTML = '0%';
				
                tws_Banners.startTime = new Date().getTime();
				if(typeof tws_Banners.updateInterval == 'undefined' || tws_Banners.updateInterval == null)
				{					
					tws_Banners.updateInterval = setInterval("tws_Banners.updateLoader("+gameid+",'"+linktxt+"')", 60);
				}
			}
			else
			{
				if(typeof params["tws_debug"] != 'undefined' && (params["tws_debug"] == 'true' || params["tws_debug"] == 'banners'))
				{
    				console.warn("BANNERS: No timing set for loaders, aborting");
				}
				this.hideBanners(gameid);	
			}
	    },
	    
	    /**
	     * Updates the visualisation of the load bar
	     *
	     * @param integer gameid	The gameid for which to show the load bar
	     * @param string  linktxt	The text to show with the link to skip the rest of the banner
	     *
	     * @return void	
	     */
	    updateLoader: function(gameid, linktxt)
	    {
            var params = this._getParameters();            
	    	if(typeof tws_Banners.redirected != 'undefined' && tws_Banners.redirected == false)
	    	{
                if(typeof tws_Banners.b_defaults['redirectshow'] != 'undefined' && tws_Banners.b_defaults['redirectshow'])
                {
                    tws_Banners.movietime = tws_Banners.linktime;
                }
				
                diffTime = new Date().getTime() - tws_Banners.startTime;
                var lastTime = (typeof tws_Banners.percentage != 'undefined') ? tws_Banners.percentage : 0;
                tws_Banners.percentage = this._getIntval((diffTime / (tws_Banners.movietime * 1000)) * 100);
                if(typeof params["tws_debug"] != 'undefined' && (params["tws_debug"] == 'true' || params["tws_debug"] == 'banners') && lastTime != tws_Banners.percentage)
				{
					if(typeof String.prototype.repeat == "undefined") { String.prototype.repeat = function(num) { return new Array(isNaN(num)? 1 : ++num).join(this); } }
					
    				console.log("BANNERS: Movietime: "+tws_Banners.movietime+";"+ (" ".repeat(10-tws_Banners.movietime.toString().length)) +"DiffTime: "+diffTime+";" + (" ".repeat(10-diffTime.toString().length)) + "Percentage: "+tws_Banners.percentage+"%;" + (" ".repeat(10-tws_Banners.percentage.toString().length)) + "Redirectlinkshow: "+tws_Banners.redirectlinkshow+";" + (" ".repeat(10-tws_Banners.redirectlinkshow.toString().length)) + "Linktime "+tws_Banners.linktime);
				}
				
				if(document.getElementById('tws_syndication_loadbar_'+gameid))
		    		document.getElementById('tws_syndication_loadbar_'+gameid).style.width = tws_Banners.percentage+'%';
				if(document.getElementById('tws_syndication_loadpercent_'+gameid))
					document.getElementById('tws_syndication_loadpercent_'+gameid).innerHTML = tws_Banners.percentage+'%';

				if((typeof tws_Banners.originalLinkText == "undefined" || tws_Banners.originalLinkText == "") && document.getElementById('tws_syndication_redirectlink_'+gameid))
				{
					tws_Banners.originalLinkText	= document.getElementById('tws_syndication_redirectlink_'+gameid).innerHTML;
				}
				if(!tws_Banners.redirectlinkshow && (tws_Banners.linktime * 1000) <= diffTime)
				{
                    if(typeof tws_Banners.b_defaults['redirectshow'] != 'undefined' && tws_Banners.b_defaults['redirectshow'])
                    {
                    	if(typeof params["tws_debug"] != 'undefined' && (params["tws_debug"] == 'true' || params["tws_debug"] == 'banners'))
						{	
    						console.log("BANNERS: Hiding banner, tws_Banners.b_defaults['redirectshow'] was set to: "+tws_Banners.b_defaults['redirectshow']);
						}
                        tws_Banners.hideBanners(gameid);
                    }
                    else
                    {
                    	if(typeof params["tws_debug"] != 'undefined' && (params["tws_debug"] == 'true' || params["tws_debug"] == 'banners'))
						{
						    console.log("BANNERS: Showing redirectlink");
						}
						document.getElementById('tws_syndication_redirectlink_'+gameid).innerHTML = '<a href="javascript:;" onclick="tws_Banners.hideBanners('+gameid+'); return false;">'+linktxt+'</a>';
                        tws_Banners.redirectlinkshow = true;
                    }
		    	}
		    	
		    	var secondsdiv = document.getElementById('tws_syndication_redirectseconds');
		    	if(secondsdiv) secondsdiv.innerHTML = Math.round(tws_Banners.movietime - (diffTime / 1000));
		    	
		    	if(tws_Banners.redirectlinkshow)
		    	{
		    		if(diffTime < (tws_Banners.linktime * 1000))
		    		{
			    		if(typeof this.welcomedivid == "undefined")
						{
							if(typeof params["tws_debug"] != 'undefined' && (params["tws_debug"] == 'true' || params["tws_debug"] == 'banners'))
							{
							    console.log("BANNERS: Resetting link to original text: '"+tws_Banners.originalLinkText+"'");
							}
				    		// Timing set later than banner start, reset to origingal	
							document.getElementById('tws_syndication_redirectlink_'+gameid).innerHTML = tws_Banners.originalLinkText;
						}
			    		tws_Banners.redirectlinkshow	= false;
			    	}
			    	else if((typeof tws_Banners.bannersAreHidden == "undefined" || !tws_Banners.bannersAreHidden) && tws_Banners.b_defaults['redirectshow'] == true)
		    		{
		    			if(typeof params["tws_debug"] != 'undefined' && (params["tws_debug"] == 'true' || params["tws_debug"] == 'banners'))
						{
						    console.log("BANNERS: Hiding banner, tws_Banners.b_defaults['redirectshow'] was set to: "+tws_Banners.b_defaults['redirectshow']);
						}
		    			tws_Banners.hideBanners(gameid);
		    		}
		    	}
		    	
		    	if(parseInt(tws_Banners.percentage) >= 100)
		    	{
		    		if(typeof params["tws_debug"] != 'undefined' && (params["tws_debug"] == 'true' || params["tws_debug"] == 'banners'))
					{
					    console.log("BANNERS: Loading complete, hiding banner");
					}
		    		tws_Banners.hideBanners(gameid);
		    	}
		    }
	    },
	    
	    /**
	     * Removes the pre-roll (rectangle/welcomead) banners from the page
	     *
	     * @param string gameid			The gameid for which to remove the banners
	     * @param string skip_welcome	Set to 'true' if you do not want to check for an active welcome ad
	     *
	     * @return void
	     */
	    hideBanners: function(gameid, skip_welcome)
	    {
	    	var params = this._getParameters();
	    	if(typeof params["tws_debug"] != 'undefined' && (params["tws_debug"] == 'true' || params["tws_debug"] == 'banners'))
			{
			    console.log("BANNERS: Hiding banners");
			}
			
	    	if((typeof skip_welcome == "undefined" || skip_welcome !== true) &&
	    		typeof this.welcomeset !== "undefined" &&
	    		typeof this.welcomedivid !== "undefined")
			{
				if(typeof params["tws_debug"] != 'undefined' && (params["tws_debug"] == 'true' || params["tws_debug"] == 'banners'))
				{
					console.log("BANNERS: Welcome ad defined, running clearWelcomeAd();");
				}
				
				clearInterval(tws_Banners.updateInterval);
				tws_Banners.updateInterval = null;
				
				if(typeof document._gameId != "undefined" && parseInt(document._gameId,10) > 0)
				{
					tws_Banners.hideBanners(document._gameId, true);
				}
				
				tws_Banners.clearWelcomeAd();
				return;
			}
			
	    	var objs = [
	    					'tws_syndication_bannercontainer_'+gameid,
	    					'tws_syndication_bannerframe_'+gameid
	    				];
	    	this.redirected = true;
	    	for(var i = 0; i < objs.length; i++)
	    	{
	    		obj = document.getElementById(objs[i]);
	    		if(obj)
	    		{
	    			obj.style.display = 'none';
					obj.parentNode.removeChild(obj);
				}
			}
			
			tws_Banners.bannersAreHidden = true;
			clearInterval(tws_Banners.updateInterval);
			tws_Banners.updateInterval = null;
            if (typeof this.callback != "undefined" && this.callback != null) {
            	if(typeof params["tws_debug"] != 'undefined' && (params["tws_debug"] == 'true' || params["tws_debug"] == 'banners'))
				{
					console.log("BANNERS: Executing callback:");
					console.log(this.callback);
				}
            	this.callback();
            }
            
	    },
        
        /**
	     * Removes the welcome ad banners from the page and shows the original content
	     *
	     * @return void
	     */
		clearWelcomeAd: function()
		{
			var params = this._getParameters();
	    	if(typeof params["tws_debug"] != 'undefined' && (params["tws_debug"] == 'true' || params["tws_debug"] == 'banners'))
			{
			    console.log("BANNERS: Clearing Welcome Ad");
			}
			if(typeof this.welcomeset !== "undefined" &&  typeof this.welcomedivid !== "undefined")
			{
				var ad = document.getElementById(this.welcomedivid);
				if(ad)
				{
					ad.parentNode.removeChild(ad);
				}
				
				if(typeof params["tws_debug"] != 'undefined' && (params["tws_debug"] == 'true' || params["tws_debug"] == 'banners'))
				{
				    console.log("BANNERS: Setting display of main_content to 'block'");
				}
				var maincontent = document.getElementById('main_content');
				if(maincontent) {
					maincontent.style.display = 'block';
					maincontent.removeAttribute("welcomeAdActive");
				}

				if(typeof params["tws_debug"] != 'undefined' && (params["tws_debug"] == 'true' || params["tws_debug"] == 'banners'))
				{
				    console.log("BANNERS: Removing DIV with class 'blockdiv'");
				}
				var divs = document.getElementsByTagName("div");
				for(var i = 0; i < divs.length; i++)
				{
					if(divs[i].className == 'blockdiv') {
						divs[i].parentNode.removeChild(divs[i]);
					}
				}
				var footer = document.getElementById("footer");
				if(footer.tagName == 'IFRAME')
				{
					try {					
						if(typeof params["tws_debug"] != 'undefined' && (params["tws_debug"] == 'true' || params["tws_debug"] == 'banners'))
						{
						    console.log("BANNERS: Removing DIV with class 'blockdiv' in footer iframe");
						}
					    var oDoc = footer.contentWindow || footer.contentDocument;
					    if (oDoc.document) {
					        oDoc = oDoc.document;
					    }
						var divs = oDoc.getElementsByTagName("div");
						for(var i = 0; i < divs.length; i++)
						{
							if(divs[i].className == 'blockdiv') {
								divs[i].parentNode.removeChild(divs[i]);
							}
						}
					} catch(e) {
						try {
							console.log(e);
						} catch(f) {}
					}
				}
				
				try {
					redirect();	
				} catch(e) {}
				tws_Banners.hideSkyScraper(false);
			}
		},
        
        /**
	     * Function to fake a click on a banner by adding an image with the specified clicktag to the document
	     *
	     * @param string clickTag	The clicktag to request
	     *
	     * @return void
	     */
        clickBanner: function(clickTag)
        {
            var img = new Image();
            img.src = decodeURIComponent(clickTag);
        },
	    
	    /**
	     * Evals all script tags written by a getBanner call
	     *
	     * @param integer counter	The ID for the banner div to process tags for
	     *
	     * @return void
	     */
	    evalTags: function(counter)
	    {
	    	if(document.getElementById('tws_Banner_placement_'+counter))
	    	{
	    		try {console.log('Element with ID "tws_Banner_placement_'+counter+'" found!');} catch(e) {}
	    		var scripts = document.getElementById('tws_Banner_placement_'+counter).getElementsByTagName('script');
	    		// Skip the first scripts, since that is our caller
	    		for(var i = 1; i < scripts.length; i++)
	    		{
	    			try {
	    				eval(scripts[i].innerHTML);
	    			} catch(e) {
	    				try {console.warn('[[ Error detected during eval() of counter '+counter+' ]]:\n'+e+'\n\n[[ Executed code ]]:');} catch(e) {}
	    				try {console.log(scripts[i].innerHTML);} catch(e) {}
	    			}
	    		}
	    	}
	    	else
	    	{
	    		try {console.warn('Element with ID "tws_Banner_placement_'+counter+'" not found!');} catch(e) {}
	    	}
	    },
	    
	    
		parseFilters: function(prefix, code)
		{
			var params = new Array();
			var sGet = window.location.search;
			if (sGet)
			{
			    sGet = sGet.substr(1);
			    var nvPairs = sGet.split('&');
			    for (var i = 0; i < nvPairs.length; i++)
			    {
			    	if(nvPairs[i].substr(0,prefix.length) == prefix)
			    	{
			    		var nv = nvPairs[i].split('=');	
			        	codeStr = code.replace(/\{name\}/gi, nv[0].replace(prefix,'')).replace(/\{value\}/gi, nv[1]);
			        	eval(codeStr);
			    	}
			    }
			}
		},
		
		checkRedirect: function()
		{
			if(	document.getElementById('tws_banners_measure').offsetHeight < 15 &&
				document.getElementById('tws_banners_measure').getElementsByTagName('script').length <= 1
			) {
				// We have a banner that is too tiny, try to redirect
				try {
					parent.hide_tws_Banners();
				}
				catch(e)
				{
					try {console.warn('Unable to remove banner!\n'+(e));} catch(e) {}
				}
			}
		},
	    
	    /**
	     * Attempts to load a script that sets several default variables for the site
	     *
	     * @return void
	     */
	    loadSiteDefaults: function()
	    {
	    	if(this.getSiteID() !== null && this.getSiteID() >= 10000 && !this.b_siteLoaded)
	    	{
	    		var now = new Date();
	        	var url	= this.baseURL + 'settings?siteid=' + escape(this.getSiteID()) + '&nocache=' + now.getTime();

	    		var head = document.getElementsByTagName("head")[0];
		        var script = document.createElement('script');
		        script.id = 'tws_Banner_defaults';
		        script.src = url;
		        script.type = 'text/javascript';
	
		       	head.appendChild(script);
		       	
	    		this.b_siteLoaded = true;
	    	}	
	    },
    	
		/**
		 * 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)
		{
			if(this.b_default_settings === null)
			{
				this.b_default_settings = {};
				for(var i in this.b_defaults)
				{
					this.b_default_settings[i] = this.b_defaults[i];
				}
			}
			
			if(typeof this._getParameters()["tws_debug"] != 'undefined' && (this._getParameters()["tws_debug"] == 'true' || this._getParameters()["tws_debug"] == 'banners'))
			{
			    console.log("BANNERS: Setting default values:");
			    console.log(b_options);
			}
			for(var i in b_options)
			{
				switch(i.toString().toLowerCase())
				{
					case 'setsite':
						eval("addDOMLoadEvent(function() { tws_Banners._setSiteTakeover('"+b_options[i]+"'); });");
						break;
					case 'background':
						this.setPageBackground(b_options[i]);
						break;
					case 'bannertime':
						tws_Banners.movietime = b_options[i];
						break;
					case 'footertext':
					case 'footerlinks':
					case 'footerhover':
						this._setFooterColors(i, b_options[i]);
						break;
					case 'measuretag':
						this.b_defaults['measureTAG'].push(b_options[i]);
						break;
					case 'redirectbanner':
						tws_Banners.linktime = parseInt(b_options[i]);
						this.b_defaults['redirectshow']	= true;
						break;
					case 'redirectshow':
						if(b_options[i] == 'true' || b_options[i] == true || b_options[i] == 1)
						{
							this.b_defaults[i]	= true;
						}
						else
						{
							this.b_defaults[i]	= false;
						}
						break;
					case 'scaling':
						this.setScaleType(b_options[i]);
						break;
					case 'showbanner':
						tws_Banners.linktime = parseInt(b_options[i]);
						break;
					default:
						if(typeof this.b_defaults[i] == "undefined" || (typeof this.b_default_settings[i] != "undefined" && this.b_default_settings[i] == this.b_defaults[i]))
						{
							this.b_defaults[i]	= b_options[i];
							if(i == "clickTAG" && typeof this.b_defaults["noclick"] == "undefined")
							{
								this.createClickableBackground();
							}							
						}
						else if(this.b_defaults[i] == b_options[i])
						{
						}
						else
						{
							this._writeError("The value '"+i+"' has been specified twice! Current '"+i+"' ('"+this.b_defaults[i]+"') <strong>has NOT been set to</strong> '"+b_options[i]+"'");
						}
						break;
				}
			}
		},
		
		/**
		 * Function to set the default scale type.
		 *
		 * @param	string		The type we want to use, can be 'default', 'noscale', 'noborder' 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 'noborder':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((this._getIntval(screen.width) - this.b_defaults['pagewidth'])	/ 2);
				if(x < 0) x = 0;
				
				values.x	= x;
				values.y	= screen.height;
	
				return values;
			} catch(e) {
				try {console.log(e);} catch(e) {}
				return false;	
			}
		},
		
		/**
		 * Function to hide the DHTML if it is set. Callable from within a flash DHTML.
		 *
		 * @return	void
		 */
		hideDHTMLlayer: function(layer) {
			if(typeof layer == "undefined") layer = "tws_Banners_b_dhtml_layer";
			if(document.getElementById(layer)) {
				document.getElementById(layer).style.display = 'none';
			}
		},		
		
		/**
		 * Function to remove the floor ad.
		 *
		 * @return	void
		 */
		removeFloorAd: function()
		{
			document.getElementById('tws_Banners_floor_ad').parentNode.removeChild(document.getElementById('tws_Banners_floor_ad'));	
		},
		
		setFloorAdHeight: function(h)
		{
			if(h.toString().indexOf('%') > 0)
			{
				document.getElementById('tws_Banners_floor_ad').style.height = h;
			}
			else
			{
				document.getElementById('tws_Banners_floor_ad').style.height = h+'px';
			}
		},
		
		getParameters: function()
        {
            var string  = window.location.href.substring(window.location.href.indexOf("?") + 1);
            var pars    = string.replace("&amp;", "&").split("&");
            var params  = new Array();
            for (var i = 0; i < pars.length; i++)
            {
                var arr = pars[i].split("=");
                params[arr[0]] = arr[1];
            }
            return params;
        },

		/**
	     * Retrieve the contents of the cookie
	     *
	     * @param	string	name	The name of the cookie
	     *
	     * @return	string|null		The content of the cookie or NULL if the cookie was not found
	     */
		getCookie: function(check_name)
	    {
	        // first we'll split this cookie up into name/value pairs
	        // note: document.cookie only returns name=value, not the other components
	        var a_all_cookies = document.cookie.split( ';' );
	        var a_temp_cookie = '';
	        var cookie_name = '';
	        var cookie_value = '';
	
	        for ( i = 0; i < a_all_cookies.length; i++ )
	        {
	            // now we'll split apart each name=value pair
	            a_temp_cookie = a_all_cookies[i].split( '=' );
	
	            // and trim left/right whitespace while we're at it
	            cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
	
	            // if the extracted name matches passed check_name
	            if ( cookie_name == check_name )
	            {
	                // we need to handle case where cookie has no value but exists (no = sign, that is):
	                if ( a_temp_cookie.length > 1 )
	                {
	                        cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
	                }
	                // note that in cases where cookie is initialized but no value, null is returned
	                return cookie_value;
	                break;
	            }
	            a_temp_cookie = null;
	            cookie_name = '';
	        }
	        return null;
	    },
		
		/**
	     * Set the contents of a cookie
	     *
	     * @param	string		name	The name of the cookie
	     * @param	string		value	The contents for the cookie
	     * @param	integer		expires	The number of days before the cookie expires
	     * @param	string		path	The path to use
	     * @param	string		domain	The domain to use
	     * @param	string		secure	Store the cookie secure
	     *
	     * @return	void
	     */
		setCookie: function(name, value, expires, path, domain, secure)
	    {
	        // set time, it's in milliseconds
	        var today = new Date();
	        today.setTime( today.getTime() );
	
	        /*
	        if the expires variable is set, make the correct
	        expires time, the current script below will set
	        it for x number of days, to make it for hours,
	        delete * 24, for minutes, delete * 60 * 24
	        */
	        if ( expires )
	        {
	            expires = expires * 1000 * 60 * 60 * 24;
	        }
	        var expires_date = new Date( today.getTime() + (expires) );
	
	        document.cookie = name + "=" +escape( value ) +
	        ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
	        ( ( path ) ? ";path=" + path : "" ) +
	        ( ( domain ) ? ";domain=" + domain : "" ) +
	        ( ( secure ) ? ";secure" : "" );
	    },	    
	    		
		/**
		 * 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;	
			}
		},

		set_GA_googleAddAttr: function(name, value)
	    {
	    	GA_googleAddAttr(name, value);
			try {
				top.tws_Banners.b_googleAttributes.push([name,value]);
			} catch(e) {}
		},
		
		reloadBanner: function(type)
		{
			switch(type)
			{
				case 'skyscraper':
					var banner = top.document.getElementById('skyScraper');
					break;
				case 'textlink':
					var banner = top.document.getElementById('textLink');
					break;
				case 'leaderboard':
					var banner = top.document.getElementById('leaderBoard');
					break;
				default:
					return false;
			}
			
			if(banner)
			{
				// Create a new iframe
				var iframe = top.document.createElement("iframe");
				iframe.setAttribute("scrolling","no");
				iframe.setAttribute("frameborder","0");
				iframe.setAttribute("allowtransparency","true");
				iframe.style.width	= "100%";
				iframe.style.height	= "100%";
				var url = "/banner.html?type="+type;
				for(var i = 0; i < top.tws_Banners.b_googleAttributes.length; i++)
				{
					url += "&GA_"+top.tws_Banners.b_googleAttributes[i][0]+"="+top.tws_Banners.b_googleAttributes[i][1];
				}
				url += "&nc="+new Date().getTime();
				iframe.src = url;
				
				banner.innerHTML = "";
				banner.appendChild(iframe);
			}
			else
			{
				return false;
			}
		},
		
		reloadTimer: function(type, minutes)
		{
			setTimeout("tws_Banners.reloadBanner('"+type+"');",minutes*60*1000);
		},

/** 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 make the whole background clickable
		 *
		 * @return void
		 */
		createClickableBackground: function()
		{
			if(typeof this.b_defaults["clickTAG"] != "undefined")
			{
				var hiddenDiv = document.createElement("div");
				hiddenDiv.onclick = function() 
									{
										window.open(tws_Banners.b_defaults["clickTAG"]);
									}
				hiddenDiv.style.position	= this.b_anchorposition;
				hiddenDiv.style.width		= '100%';
				hiddenDiv.style.height		= '100%';
				hiddenDiv.style.top			= 0;
				hiddenDiv.style.left		= 0;
				hiddenDiv.style.zIndex		= 0;
				hiddenDiv.style.cursor		= 'pointer';
				var body = document.getElementsByTagName("body")[0];
				if(body)
				{
					if(body.firstChild)
						body.insertBefore(hiddenDiv, body.firstChild);
					else
						body.appendChild(hiddenDiv);
				}
			}			
		},
		
		/**
		 * 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 this._getParameters()["tws_debug"] != 'undefined' && (this._getParameters()["tws_debug"] == 'true' || this._getParameters()["tws_debug"] == 'banners'))
			{
			    console.log("BANNERS: Adding banner '"+b_file+"' with following options:");
			    console.log(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';
				}

				this.b_loaditems.push({"b_file":b_file,"b_options":b_options});
								
				if(!this.b_DOMloader) {
					this.b_DOMloader = true;
					addDOMLoadEvent(function() {tws_Banners._loadItems();});
					addDOMLoadEvent(function() {tws_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
		 *
		 * @return	void
		 */
		expandBanner: function() {
			info	= tws_Banners.expandInfo;
			if(info) {
				if(this.b_allow_resize[info.i]) {
					obj	= document.getElementById(info.i);
					if(obj) {
						if(	this._getIntval(this.getStyle(info.i,"width","width")) == info.w && 
							this._getIntval(this.getStyle(info.i,"height","height")) == info.h ){
							// Object has original size, resize to large versions
							obj.style.width		= info.ew+'px';
							obj.style.height	= info.eh+'px';
						} else {
							// Resize to original version
							obj.style.width		= info.w+'px';
							obj.style.height	= info.h+'px';
						}
					}
				}
			}
		},
		
		/**
		 * Function to create a clear half banner (hide the square)
		 *
		 * @return void
		 */
		hideHalfBanner: function() {},
		
		/**
		 * Function to create a clear full banner (hide the square)
		 *
		 * @return void
		 */
		hideFullBanner: function() {},
		
		/**
		 * Function to hide the skyscraper banner (hide the square)
		 *
		 * @return void
		 */
		hideSkyScraper: function(hide) 
		{
			if(typeof hide == "undefined" || (hide != false && hide != true)) hide = true;
			
			if(typeof this._getParameters()["tws_debug"] != 'undefined' && (this._getParameters()["tws_debug"] == 'true' || this._getParameters()["tws_debug"] == 'banners'))
			{
			    console.log("BANNERS: "+((hide)?"Hiding":"Showing")+" Skyscraper: "+document.getElementById(this.b_defaults['skyscraperID']));
			}
			if(document.getElementById(this.b_defaults['skyscraperID']))
			{
				document.getElementById(this.b_defaults['skyscraperID']).style.display = ((hide)?'none':'block');
				if(hide)
				{
					tws_Banners.hiddenBanners.push("skyscraper");
				}
				else
				{
					for(var i = 0; i < tws_Banners.hiddenBanners.length; i++)
					{
						if(tws_Banners.hiddenBanners[i] == "skyscraper")
						{
							tws_Banners.hiddenBanners.splice(i,1);
						}
					}
				}
			}
		},
		
		/**
		 * Function to switch skyscraper banner from left positioning to right
		 *
		 * @param	string	side	'left' or 'right'
		 *
		 * @return boolean
		 */
		showSkyScraper: function(side) 
		{
			if(typeof side == "undefined" || (side != "left" && side != "right")) side = "right";
			
			var skyscraper = document.getElementById(this.b_defaults['skyscraperID']);
			if(skyscraper)
			{
				var margin		= parseInt(this._getStyle(skyscraper, 'margin-left'));
				var newmargin	= false;
				switch(side)
				{
					case 'left':
						if(margin > 0)
						{
							newmargin = (margin + parseInt(this._getStyle(skyscraper, 'width'))) * -1;
						}
						break;
					case 'right':
						if(margin < 0)
						{
							newmargin = (margin + parseInt(this._getStyle(skyscraper, 'width'))) * -1;
						}
						break;
				}
				if(newmargin)
				{
					skyscraper.style.marginLeft = newmargin + "px";
					return true;
				}
			}
			return false;
		},
		
		/**
		 * Function to set the width for the skyscraper banner
		 *
		 * @param	integer	wpx		the new width of the skyscraper div (in pixels)
		 *
		 * @return boolean
		 */
		skyScraperWidth: function(wpx) 
		{
			if(typeof wpx == "undefined") wpx = 120;
			
			var skyscraper = document.getElementById(this.b_defaults['skyscraperID']);
			if(skyscraper && !isNaN(parseInt(wpx)))
			{				
				var margin		= parseInt(this._getStyle(skyscraper, 'margin-left'));
				if(margin < 0)
				{
					var newmargin = margin - (wpx - parseInt(this._getStyle(skyscraper, 'width')));
					skyscraper.style.marginLeft = newmargin + "px";
				}
				
				skyscraper.style.width = parseInt(wpx) + "px";	
				
				return true;
			}
			
			return false;
		},
		
		/**
		 * Function to hide the textlink banner
		 *
		 * @return void
		 */
		hideTextlink: function()
		{
			if(typeof this._getParameters()["tws_debug"] != 'undefined' && (this._getParameters()["tws_debug"] == 'true' || this._getParameters()["tws_debug"] == 'banners'))
			{
			    console.log("BANNERS: Hiding Textlink: "+document.getElementById(this.b_defaults['textlinkID']));
			}
			if(document.getElementById(this.b_defaults['textlinkID'])) {
				document.getElementById(this.b_defaults['textlinkID']).style.display = 'none';
				document.getElementById(this.b_defaults['textlinkID']).style.margin = '0';
				tws_Banners.hiddenBanners.push("textlink");
			}
		},
		
		/**
		 * Function to maximize the textlink banner
		 *
		 * @return void
		 */
		maximizeTextlink: function()
		{
			var target = document.documentElement; // start at the root element
			while (target.childNodes.length && target.lastChild.nodeType == 1) { // find last HTMLElement child node
			    target = target.lastChild;
			}
			if(target.parentNode)
			{
				var div = target.parentNode;
				while(div.id != "textLink" && div.parentNode)
				{
					div = div.parentNode;
				}
			
				if(div.id == "textLink")
				{
					div.style.marginTop		= '-20px';
					div.style.marginLeft	= '-30px';
					div.style.width			= document.getElementById("menu_holder").offsetWidth + 'px';
				}
			}
		},
		
		/**
		 * Function to adjust the margin of top-aligned anchors by h pixels.
		 *
		 * @param integer h		The height to adjust the top aligned elements with
		 *
		 * @return void
		 */
		setTopMargin: function(h)
		{
		 	for(var i in this.b_anchor)
		 	{
		 		if(i.indexOf("top") >= 0)
			 		{
			 		var curtop 		= parseInt(this.b_anchor[i].style.top,10);
			 		if(isNaN(curtop)) curtop = 0;
			 		var starttop	= this.b_anchor[i].getAttribute("startTop");
					if(!starttop)
					{
						this.b_anchor[i].setAttribute("startTop", curtop);
						starttop = curtop;
					}
					
					this.b_anchor[i].style.top =	(starttop + h) + 'px';
				}
		 	}
		},
		
/** PRIVATE FUNCTIONS **/
		
		/**
		 * Sets the defualt variables for specific sites
		 */
		_setSiteTakeover: function(site)
		{
			try {console.log('Site: '+site);} catch(e) {}
			switch(site)
			{
				case 'KNT':
					document.getElementById("uberholder").onclick = checkOpenTarget;
					document.getElementById("uberholder").onmouseover = stopLink;
					document.getElementById("uberholder").onmouseout = allowLink;
					document.getElementById("main").style.backgroundImage = "url(/layout/images/mainBackgroundTakeover.gif)";
					document.getElementById("bottom").style.backgroundImage = "url(/layout/images/mainBottomTakeover.gif)";
					document.getElementById("bottom").style.height = '26px';
					document.getElementById("menu").style.backgroundImage = "url(/layout/images/mainMenuTakeover.gif)";
					document.getElementById("footer").style.position = "relative";
					document.getElementById("footer").style.height = "20px";
					document.getElementById("footer").style.margin = "2px 0px 0px 8px";
					document.getElementById("footer").style.padding = "0px";
					this.b_defaults["headerID"] =  "headerMain";
					if(document.getElementById('headerSub'))
						this.b_defaults["headerID"] =  "headerSub";
					document.getElementById(this.b_defaults.headerID).style.backgroundImage = "url(/layout/images/mainHeaderTakeover.gif)";
					break;	
			}
			return true;
		},
		
		/**
		 * Check for a specific variable inside an array
		 * 
		 * @param	object	needle		The needle to look for in our haystack
		 * @param	array	haystack	The array to look in
		 * @param	boolean	checktype	Set to true to also check for element type (defaults to false)
		 *
		 * @return	boolean			Returns true if needle is found, false otherwise
		 */
		_inArray: function(needle,haystack,checktype)
		{
			for(var i = 0; i < haystack.length; i++)
			{
				if(typeof checktype == 'undefined' || checktype == null || !checktype)
				{
					if(haystack[i] == needle) return true;
				}
				else
				{
					if(haystack[i] === needle) return true;
				}
			}
			return false;
		},
		
		/**
		 * Add all queued items to the DOM
		 *
		 * @return void
		 */
		_loadItems: function() {
			if (this._getVersion() <= 6) {
				this.b_anchorposition = 'absolute';
			}
			for(var i = 0; i < this.b_loaditems.length; i++) {
				this._addItem(this.b_loaditems[i].b_file,this.b_loaditems[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';
			}
			
			// 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() !== 'welcome' &&
				b_options["position"].toLowerCase() !== 'slot' &&
				b_options["position"].toLowerCase() !== 'floor'
			)) {
				this._writeError("Invalid position for file '"+b_file+"' !");
				perform_write	= false;
			}
			// -
			
			// 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 && b_options["position"].toLowerCase() != 'welcome') {
				this._writeError("Invalid 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"]	= this._getIntval(this.b_defaults['headerWidth'])+'px';		
				} 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"]	= this.b_defaults['rectangleWidth'];		
				} else if(b_options["position"] === 'floor') {
					// Floor ads don't need a specified width
				}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"]	= this._getIntval(this.b_defaults['headerHeight'])+'px';		
				} 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"]	= this.b_defaults['rectangleHeight'];
				} else if(b_options["position"] === 'floor') {
					// Floor ads don't need a specified height
				}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 an 'expandable' option, if it is not set or does not evaluate as true, set it to false
			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 this.b_defaults["cTAG"] != 'undefined') {
				this.b_cTAG	= this.b_defaults["cTAG"];
			}
			// -
			if(perform_write) {		
				// Store the parameters in the internal variables
				this.b_file		= b_file;
				this.b_options	= b_options;
				// -
				
				// If we need to write the item, first check if we have initilized the anchors
				this._checkAnchors();
				
				// We need to write rectangles directly into the page
				if(b_options["position"] === 'rectangle') {
					this._setRectangle();
				} else if(b_options["position"] === 'floor') {
					this._setFloorAd();
				} else if(b_options["position"] === 'welcome') {
					this._setWelcome();
				} else {
					addDOMLoadEvent(function() {
						if(document.getElementById('uberholder')) {
							document.getElementById('uberholder').style.zIndex	= 3000;
						}
						if(document.getElementById('country_holder')) {
							document.getElementById('country_holder').style.zIndex	= 3000;
						}
					});
					
					// 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	= this._getIntval(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	= this._getIntval(b_options["height"])+'px';
					}
					this.b_div.style.zIndex	= this.b_zindex;		
					// -
										
					// Increase our 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;
					}
					// -
					
					// Force re-rendering of the current div
					this.b_rerender.push(this.b_div.id);
					// -
				}
				
				// 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 this.b_defaults["measureTAG"] !== 'undefined' &&
							this.b_defaults["measureTAG"].length > 0) {
					this.setGlobalMeasureTag	= true;
					this._addMeasureTag(this.b_defaults["measureTAG"]);
				}
				// -
				
				// 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 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, CSSStyleName) {
			if(typeof b_source == "string")
			{
				var elem = document.getElementById(b_source);
			}
			else
			{
				var elem = b_source;
			}
			
			if(elem) {
				if (elem.currentStyle) {
					return elem.currentStyle[this._camelCase(CSSStyleName)];
				} else if (window.getComputedStyle) {
					var compStyle = window.getComputedStyle(elem, "");
					return compStyle.getPropertyValue(CSSStyleName);
				} else {
					return false;
				}
			} else {
				return false;	
			}
		},
		
		_camelCase: function(s)
		{
			for(var exp=/-([a-z])/; exp.test(s); s=s.replace(exp,RegExp.$1.toUpperCase()));
			return s;
		},

		/**
		 * 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 = this._getIntval(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 = this._getIntval(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					= 'tws_Banners_anchor_top';
						this.b_anchor["top"].style.width		= this._getIntval(this.b_defaults['headerHolderWidth'])+'px';
						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.b_defaults['contentMarginTop'];
						this.b_anchor["top"].style.marginLeft	= '-'+this._getIntval((this.b_defaults['headerHolderWidth']/2))+'px';
						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					= 'tws_Banners_anchor_center';
						this.b_anchor["center"].style.width			= this._getIntval(this.b_defaults['headerHolderWidth'])+'px';
						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.b_defaults['contentMarginLeft'];
						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					= 'tws_Banners_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					= 'tws_Banners_anchor_bottom';
					this.b_anchor["bottom"].style.width			= this._getIntval(this.b_defaults['headerHolderWidth'])+'px';
					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._getIntval((this.b_defaults['headerHolderWidth']/2))+'px';;
					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_tws_Banners_anchor_top';
							this.b_anchor["alwaysontop_top"].style.width		= this._getIntval(this.b_defaults['headerHolderWidth'])+'px';
							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.b_defaults['contentMarginTop'];
							this.b_anchor["alwaysontop_top"].style.marginLeft	= '-'+this._getIntval((this.b_defaults['headerHolderWidth']/2))+'px';
							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_tws_Banners_anchor_center';
							this.b_anchor["alwaysontop_center"].style.width			= this._getIntval(this.b_defaults['headerHolderWidth'])+'px';
							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._getIntval((this.b_defaults['headerHolderWidth']/2))+'px';
							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_tws_Banners_anchor_bottom';
							this.b_anchor["alwaysontop_bottom"].style.width			= this._getIntval(this.b_defaults['headerHolderWidth'])+'px';
							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._getIntval((this.b_defaults['headerHolderWidth']/2))+'px';
							this.b_anchor["alwaysontop_bottom"].style.zIndex		= 6000 - this.b_sequence["bottom"];
				
							par.appendChild(this.b_anchor["alwaysontop_bottom"]);
							// -
						}
						// -
					}
				}
			} else {
				this._writeError("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(typeof obj_id != 'undefined' && document.getElementById(obj_id)) {
					document.getElementById(obj_id).appendChild(this.b_div);
				} 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(this._getIntval(this.getStyle('tws_Banners_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(this._getIntval(this.getStyle('tws_Banners_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)
		{
			if(typeof m_src == "string")
			{
				if(!this._inArray(m_src, this.b_measureTAGs))
				{
					// Add timestamp to the tag
					m_src = (m_src.indexOf("?") > 0) ? m_src + "&" + new Date().getTime() : m_src + "?" + new Date().getTime();
					measureTAG			= document.createElement("img");
					measureTAG.src		= m_src;
					this.b_measureTAGs.push(m_src);
					measureTAG.width	= 1;
					measureTAG.height	= 1;
		            if (typeof this.b_anchor["bottom"] != 'undefined' && this.b_anchor["bottom"] != null)
		            {
		            	this.b_anchor["bottom"].appendChild(measureTAG);
		            }
		            if(typeof this._getParameters()["tws_debug"] != 'undefined' && (this._getParameters()["tws_debug"] == 'true' || this._getParameters()["tws_debug"] == 'banners'))
					{
					    console.log("BANNERS: Adding measure <IMG> with src: "+m_src);
					}
				}
	        }
	        else
        	{
        		for(var i = 0; i < m_src.length; i++)
        		{
        			this._addMeasureTag(m_src[i]);
        		}
        	}
		},
		
		/**
		 * 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)
		{
			var tar	= '_blank';
			if(typeof this.b_options["tagtarget"] !== 'undefined' && this.b_options["tagtarget"] !== '') {
				tar	= this.b_options["tagtarget"];
			} else if(typeof this.b_defaults["tagtarget"] !== 'undefined' && this.b_defaults["tagtarget"] !== '') {
				tar	= this.b_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"] !== '') {
				if(this.b_div) this.b_div.style.backgroundColor = this.b_options["bgcolor"];
			}
			html	= '';
			
			activea	= 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')+'"';
				activea = true;
			} else if(typeof this.b_defaults["clickTAG"] !== 'undefined' && this.b_defaults["clickTAG"] !== '' &&  this.b_options["clickTAG"] !== '-') {
				html	= html + '<a href="'+this.b_defaults["clickTAG"]+'" target="'+this._getTarget('A')+'"';
				activea = true;
			}
			if(activea)
			{
				if(typeof this.b_options["track"] !== 'undefined' && this.b_options["track"] !== '') {
					html	= html + ' onclick="if(typeof tws_Session != \'undefined\') { tws_Session.ping(\''+this.b_options["track"]+'\'); }"';
				}
				html	= html + '>';
			}
			
			html = html + '<img src="'+this.b_file+'" width="'+this.b_options["width"]+'" height="'+this.b_options["height"]+'"';
			if(typeof this.b_options["bgcolor"] !== 'undefined' && this.b_options["bgcolor"] !== '') {
				html = html + ' style="background-color: '+this.b_options["bgcolor"]+';"';
			}
			html = html + ' />';
			
			if(activea) {
				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(),"y":this._getExpandedHeight()};
			} else if(typeof sizes === 'undefined') {
				sizes	= {"x":"100%","y":"100%"};
			}
			
			src	= this.b_file;
			var merge = '?';
			if(src.indexOf('?') > 0) { merge = '&'; }
			if(typeof this.b_options["clickTAG"] !== 'undefined' && this.b_options["clickTAG"] !== '') {
				src	= src + merge + this.b_cTAG+"="+this._urlencode(this.b_options["clickTAG"]);
			} else if(typeof this.b_defaults["clickTAG"] !== 'undefined' && this.b_defaults["clickTAG"] !== '') {
				src	= src + merge + this.b_cTAG+"="+this._urlencode(this.b_defaults["clickTAG"]);
			}
			
			if(src.indexOf('?') > 0) { merge = '&'; }
			if(typeof this.b_options["params"] !== 'undefined') {
				for(var i in this.b_options["params"]) {
					src = src + merge +i+'='+this._urlencode(this.b_options["params"][i]);
					merge = '&';
				}
			}
			
			if(this._getTarget() !== '_blank' && src.indexOf('?') > 0) {
				src = src + merge + 'tagtarget='+this._getTarget();
			}
			
			flash_id	= 'flash_'+(this.b_options["position"].replace('-','_'))+'_'+this.b_options["width"]+'x'+this.b_options["height"];
			
			var vars = "";
			var html = '<object ';
			if(this.b_options['position'] == 'floor' && sizes.x.toString().indexOf("%") < 0)
			{
				html = html + 'style="outline-width:0; position: absolute; left: 50%; margin-left: -'+Math.floor(sizes.x / 2)+'px;" ';
			}
			else
			{
				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 || this.b_scaleType != "default" || typeof this.b_options["scaling"] != "undefined") {
		    	html = html + '<param name="scale" value="'+((typeof this.b_options["scaling"] != "undefined") ? this.b_options["scaling"] : 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="'+this._urlencode(this.b_options["clickTAG"])+'" />';
				vars = vars + ((vars == "")?"":"&")+this.b_cTAG+"="+this._urlencode(this.b_options["clickTAG"]);
			} else if(typeof this.b_defaults["clickTAG"] !== 'undefined' && this.b_defaults["clickTAG"] !== '') {
				html	= html + '<param name="'+this.b_cTAG+'" value="'+this._urlencode(this.b_defaults["clickTAG"])+'" />';
				vars = vars + ((vars == "")?"":"&")+this.b_cTAG+"="+this._urlencode(this.b_defaults["clickTAG"]);
			}
			if(this._getTarget() !== '_blank' && src.indexOf('?') > 0) {
				html = html + '<param name="tagtarget" value="'+this._getTarget('Flash')+'"/>';
				vars = vars + ((vars == "")?"":"&")+"tagtarget="+this._getTarget('Flash');
			}
			html = html + '<param name="AllowScriptAccess" value="always"/>';
			
			if(typeof this.b_options["salign"] !== 'undefined' && (
				this.b_options["salign"] == 'l' ||
				this.b_options["salign"] == 't' ||
				this.b_options["salign"] == 'r' ||
				this.b_options["salign"] == 'tl' ||
				this.b_options["salign"] == 'tr'
			)) {
				html = html + '<param name="salign" value="'+this.b_options["salign"]+'"/>';
			}
			
			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]+'"/>';
					vars = vars + ((vars == "")?"":"&")+i+"="+this.b_options["params"][i];
				}
			}
			if(vars != "")
			{
				html = html + '<param name="flashvars" value="'+vars+'"/>';
			}
			if(embed)
			{
				html = html + this._getEmbedTag(flash_id, src, sizes);	
			}
			
			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+'" ';
			if(typeof this.b_options["wmode"] !== 'undefined' && this.b_options["wmode"] !== '') {
				embed = embed + 'wmode="'+this.b_options["wmode"]+'" ';
			} else {
				embed = embed + 'wmode="transparent" ';
			}
			embed = embed + 'swliveconnect="true" ';
			embed = embed + 'quality="high" ';
			embed = embed + 'type="application/x-shockwave-flash" ';
			if(this.b_usePercentage || this.b_scaleType != "default" || typeof this.b_options["scaling"] != "undefined") {
		    	embed = embed + 'scale="'+((typeof this.b_options["scaling"] != "undefined") ? this.b_options["scaling"] : this.b_scaleType)+'" ';
			}
			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+'='+this._urlencode(this.b_options["clickTAG"]);
			} else if(typeof this.b_defaults["clickTAG"] !== 'undefined' && this.b_defaults["clickTAG"] !== '') {
				if(!vars) {embed = embed + 'flashvars="';vars = true;}
				embed	= embed + this.b_cTAG+'='+this._urlencode(this.b_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(vars) {embed = embed + '" ';}
			
			if(typeof this.b_options["salign"] !== 'undefined' && (
				this.b_options["salign"] == 'l' ||
				this.b_options["salign"] == 't' ||
				this.b_options["salign"] == 'r' ||
				this.b_options["salign"] == 'tl' ||
				this.b_options["salign"] == 'tr'
			)) {
				embed = embed + 'salign="'+this.b_options["salign"]+'" ';
			}
			
			if(typeof this.b_options["params"] !== 'undefined') {
				for(var i in this.b_options["params"]) {
					embed = embed + i +'="'+this.b_options["params"][i]+'" ';
				}
			}
			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(((this._getIntval(document.getElementById(this.b_defaults['headerID']).offsetWidth)/2)-(Math.floor(this.b_options["width"]/2)))+this.b_defaults['headerBaseLeft'])*-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._getIntval(this.b_options["left"])+'px';
				if(typeof this.b_options["top"] !== 'undefined') {
					this.b_options["top"]	= this.b_options["top"];
				} else {
					this.b_options["top"]	= 0;
				}
				this.b_div.style.top	= this._getIntval(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.background		= this.b_defaults['headerFillBackground'];
				left_div.style.position			= 'absolute';
				left_div.style.left				= '0px';
				left_div.style.top				= '0px';
				left_div.style.zIndex			= '-1';
				
				right_div						= document.createElement("div");
				right_div.id					= "b_header_rightfiller";
				right_div.style.width			= '730px';
				right_div.style.height			= '95px';
				right_div.style.background		= this.b_defaults['headerFillBackground'];
				right_div.style.position		= 'absolute';
				right_div.style.right			= '0px';
				right_div.style.top				= '0px';
				right_div.style.zIndex			= '-1';
				
				for(var i = 0; i < document.getElementById(this.b_defaults.headerID).childNodes.length; i++)
				{
					document.getElementById(this.b_defaults.headerID).removeChild(document.getElementById(this.b_defaults.headerID).childNodes[0]);
				}
				document.getElementById(this.b_defaults.headerID).innerHTML = this._getInnerHTML();
				document.getElementById(this.b_defaults.headerID).style.background = 'none';
				document.getElementById(this.b_defaults.headerID).style.position = "relative";
				
				if(typeof this.b_options["height"] !== 'undefined' && this._getIntval(this.b_options["height"]) > 0) {
					document.getElementById(this.b_defaults.headerID).style.height = this._getIntval(this.b_options["height"])+'px';
				}
				document.getElementById(this.b_defaults.headerID).style.width = '100%';
				if(typeof this.b_options["width"] !== 'undefined' && this._getIntval(this.b_options["width"]) > 0 && this._getIntval(this.b_options["width"]) != this._getIntval(this.b_defaults['headerWidth']))
				{
					document.getElementById(this.b_defaults.headerID).style.width = this._getIntval(this.b_options["width"])+'px';
				}
				
				document.getElementById(this.b_defaults.headerID).appendChild(left_div);
				document.getElementById(this.b_defaults.headerID).appendChild(right_div);

			} else {
				this._writeError("Double header specified!");
			}
		},
		
		/**
		 * Function to add a rectangle banner slot. Will issue a warning when
		 * a rectangle or welcome ad has already been set.
		 *
		 * @return	void
		 */
		_setRectangle: function() {
			if(typeof this.rectangleset === 'undefined' && typeof this.welcomeset === "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: '+this.b_options["width"]+'px; ' +
						'height: '+this.b_options["height"]+'px; position: relative;';
				if(typeof this.b_options["center"] != "undefined" && tws_Banners._getVersion() == 99)
					html += ' left: 50%; margin-left: -' + Math.floor(this.b_options["width"]/2) + 'px;';
				html += '">' +
						'<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"] !== '') {
					this.b_defaults["bannertime"]	= this.b_options["bannertime"];
					tws_Banners.movietime = this.b_options["bannertime"];
				}
				if(typeof this.b_options["showbanner"] !== 'undefined' && this.b_options["showbanner"] !== '') {
					this.b_defaults["showbanner"]	= this.b_options["showbanner"];
					tws_Banners.linktime = this.b_options["showbanner"];
				}
			} else {
				this._writeError("Double rectangle or welcome ad specified!");
			}
		},
		
		/**
		 * Function to add a welcome banner. Will issue a warning when
		 * a rectangle or welcome ad has already been set.
		 *
		 * @return	void
		 */
		_setWelcome: function() {
			var params = this._getParameters();
			if(typeof params["tws_debug"] != 'undefined' && (params["tws_debug"] == 'true' || params["tws_debug"] == 'banners'))
			{
				console.log("BANNERS: Starting welcome ad");
			}
			if(typeof this.rectangleset === 'undefined' && typeof this.welcomeset === "undefined") {
				this.welcomeset		= true;
				this.welcomedivid	= this._getId();
				
				// Hide the current content
				var maincontent = document.getElementById('main_content');
				if(!maincontent)
				{
					if(typeof params["tws_debug"] != 'undefined' && (params["tws_debug"] == 'true' || params["tws_debug"] == 'banners')) 
						console.warn("BANNERS: 'main_content' div not found!");
				}
				else
				{
					// Block all other actions/links
					if(typeof this.b_options["allowlinks"] == "undefined" || this.b_options["allowlinks"] !== true)
					{
						if(typeof params["tws_debug"] != 'undefined' && (params["tws_debug"] == 'true' || params["tws_debug"] == 'banners'))
						{
							console.log("BANNERS: Placing layers over the header, menu and footer to prevent clicks");
						}
						// Header
						var header = document.getElementById("header_holder");
						if(typeof header.style.position == "undefined" || header.style.position == "") header.style.position = 'relative';
						var blockdiv = document.createElement("div");
						blockdiv.className = "blockdiv";
						header.appendChild(blockdiv);
						// Menu
						var menu = document.getElementById("menu_holder");
						if(typeof menu.style.position == "undefined" || menu.style.position == "") menu.style.position = 'relative';
						var blockdiv2 = document.createElement("div");
						blockdiv2.className = "blockdiv";
						menu.appendChild(blockdiv2);
						// Footer
						var footer = document.getElementById("footer");
						if(footer.tagName == 'IFRAME')
						{
							try {							
							    var oDoc = footer.contentWindow || footer.contentDocument;
							    if (oDoc.document) {
							        oDoc = oDoc.document;
							    }
								var blockdiv3 = oDoc.createElement("div");
								blockdiv3.className = "blockdiv";
								oDoc.getElementsByTagName("body")[0].appendChild(blockdiv3);
							} catch(e) {
								try {
									console.log(e);
								} catch(f) {}
							}
						} else {
							var blockdiv3 = document.createElement("div");
							blockdiv3.className = "blockdiv";
							footer.appendChild(blockdiv3);
						}
					} 
					// Create the new content DIV
					var welcomediv = document.createElement("div");
					welcomediv.innerHTML = '' +
					'<div class="box">' +
						'<div class="box_top">' +
							'<div class="icon_empty'+ ( (typeof this.b_options["icon"] !== "undefined") ? ' icon_'+this.b_options["icon"] : '') +'"></'+'div>' +
							'<div class="box_top_right"></'+'div>' +
							( (typeof this.b_options["title"] !== "undefined") ? '<h3>' + this.b_options["title"] + '</'+'h3>' : '') +
						'</'+'div>' +
						'<div class="box_content" style="height: '+(parseInt(this.b_options["height"],10)+100) + 'px;">' +
								'<div style="' +
									'width: '+this.b_options["width"]+'px; ' +
									'height: '+this.b_options["height"]+'px; ' +
									'position: absolute; ' +
									'left: 50%; ' +
									'margin-left: -' + parseInt(this.b_options["width"]/2) + 'px; ' +
									'">' +
									this._getFlashContent() +
								'</div>' +
								'<br/>' +
								'<div id="loading_large" class="loading" style="' +
									'position: absolute; ' +
									'top: '+(parseInt(this.b_options["height"],10)+65)+'px; ' +
									'left: 0; ' +
									'width: 100%;' +
									'">' + 
                                    '<div class="bar_large" style="width: '+((parseInt(this.b_options["width"],10) <= 400) ? this.b_options["width"] : 400) +'px;">' +
                                    	'<div class="loadbar_dark"></'+'div>' +
                                        '<div id="tws_syndication_loadbar_9999999" class="loadbar"></'+'div>' +
                                        '<div class="topleft"></'+'div>' +
                                    	'<div class="topright"></'+'div>' +
                                    	'<div class="bottomleft"></'+'div>' +
                                    	'<div class="bottomright"></'+'div>' +
                                        '<div id="tws_syndication_redirectlink_9999999" class="redirectlink"></'+'div>'+
                                    '</'+'div>' +
                                    '<div class="redirect_large">' +
                                        ((typeof this.b_options["waittext"] != "undefined") ? this.b_options["waittext"].replace('{seconds}','<span id="tws_syndication_redirectseconds"></'+'span>').replace('{percent}','<span id="tws_syndication_loadpercent_9999999"></'+'span>').replace('</'+'span> ','</'+'span>&nbsp;') : "")+
                                    '</'+'div>' +
                                    '<div class="clear"></'+'div>' +
                                '</'+'div>' + 
						'</'+'div>' +
						'<div class="box_bottom">' +
							'<div class="box_bottom_left"></'+'div>' +
							'<div class="box_bottom_right"></'+'div>' +
						'</'+'div>' +
					'</'+'div>';
					welcomediv.id = this.welcomedivid;
					welcomediv.style.padding = '20px 30px';
					welcomediv.style.overflow = 'hidden';
					welcomediv.style.position = 'relative';
					
					this.setTimers(
						(typeof this.b_options["showbanner"] !== 'undefined' && this.b_options["showbanner"] !== '') ? this.b_options["showbanner"] : 15,
						(typeof this.b_options["bannertime"] !== 'undefined' && this.b_options["bannertime"] !== '') ? this.b_options["bannertime"] : 30
						);
					
					if(typeof params["tws_debug"] != 'undefined' && (params["tws_debug"] == 'true' || params["tws_debug"] == 'banners'))
					{
						console.log("BANNERS: Writing Welcome Ad into page");
					}
					document.getElementById("main_holder").insertBefore(welcomediv,maincontent.nextSibling);
					maincontent.style.display = 'none';
					maincontent.setAttribute("welcomeAdActive","true");
					
					if(typeof tws_Banners.updateInterval != "undefined" && tws_Banners.updateInterval !== null) clearInterval(tws_Banners.updateInterval);
					tws_Banners.updateInterval = null;
					tws_Banners.startLoader(9999999, ((typeof this.b_options["linktext"] != "undefined") ? this.b_options["linktext"] : '') );
					
                    setTimeout(function() {
                        var loading = document.getElementById("loading_large");
                        if (loading)
                        {
                            loading.style.visibility = "visible";
                        }
                    }, 750);
				}
			} else {
				this._writeError("Double welcome ad or 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	= "tws_Banners_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("Double DHTML specified!");
			}
		},
		
		_setFooterColors: function(pos, val)
		{
			var elem = document;
			var ftr = elem.getElementById('footer');
			if(ftr)
			{
				
				if(ftr.tagName == "IFRAME")
				{
					if(ftr.id && window.frames && window.frames[ftr.id] && window.frames[ftr.id].document)
					{
						elem = window.frames[ftr.id].document;
					}
					else if(ftr.contentDocument)
					{
						if(ftr.contentDocument.document)
						{
							elem = ftr.contentDocument.document;
						}
						else
						{
							elem = ftr.contentDocument;
						}
					}
					else if(ftr.contentWindow)
					{
						if(ftr.contentWindow.document)
						{
							elem = ftr.contentWindow.document;
						}
						else
						{
							elem = ftr.contentWindow;
						}
					}
				}
				
				var elemname = ""
				switch(pos)
				{
					case 'footertext':
						elemname = "footer";
						break;
					case 'footerlinks':
						elemname = "footer a";
						break;
					case 'footerhover':
						elemname = "footer a:hover";
						break;
				}
				try {
					stl = elem.createElement('style');
					stl.type = "text/css";
					stl.innerHTML = '.'+elemname+' { color: ' + val + '; }\n#'+elemname+' { color: ' + val + '; }';
					elem.getElementsByTagName('head')[0].appendChild(stl);
				} catch(e) {
					try {
						elem.createStyleSheet().addRule('.'+elemname, 'color: ' + val + ' !important;');
						elem.createStyleSheet().addRule('#'+elemname, 'color: ' + val + ' !important;');
					} catch(f) {
						try {
							console.log(e.description);
							console.log(f.description);
						} catch(g) {}
					}
				}
			}
		},
		
		/**
		 * 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"];
			}
		
			tws_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'; tws_Banners.b_allow_resize['"+banner_id+"'] = true;", this.b_options['auto_resize'] * 1000);
			} else {
				this.b_allow_resize[banner_id] = true;
			}
			
			tws_Banners.expandInfo = {"i":banner_id,"w":this.b_options["width"],"h":this.b_options["height"],"ew":this._getExpandedWidth(),"eh":this._getExpandedHeight()};
	
			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() {tws_Banners.expandBanner();};
			slot.onmouseout		= function() {tws_Banners.expandBanner();};
			slot.innerHTML		= this._getInnerHTML();
			
			this._addToContainer(slot);
		},
		
		/**
		 * Adds a floor ad directly fo the body of the browser
		 *
		 * @return void
		 */
		_setFloorAd: function() {
			if(typeof this.flooradset === 'undefined')
			{
				this._checkAnchors();
				
				this.flooradset = true;
				
				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["bottom"] === 'undefined') {
					this.b_options["bottom"]	= 0;	
				}

				var floorcontainer = document.createElement('div');
				var startHeight = (this.b_expandable && typeof this.b_options['start'] != "undefined" && this.b_options['start'] == "expanded") ? this.b_options['height'] : this.b_defaults['flooradheight'];
				
				floorcontainer.style.cssText = "width: 100%; height: "+ startHeight +"px; position: fixed; bottom: 0px; overflow: hidden; z-index: 999999;";
				floorcontainer.id = 'tws_Banners_floor_ad';
				var floorcontent = document.createElement('div');
				floorcontent.style.cssText = "width: 100%; height: "+this.b_options['height']+"px; position: absolute; left: 0px; bottom: 0px;";
				floorcontent.innerHTML = this._getInnerHTML();
				floorcontainer.appendChild(floorcontent);
				document.getElementsByTagName('body')[0].appendChild(floorcontainer);
			}
		},
		
		/**
		 * 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 '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 'leaderboard':
					if(document.getElementById('leaderBoard')) {
						
						document.getElementById('leaderBoard').appendChild(obj);
					} else {				
						try {
							par	= document.createElement('div');
							par.id	= 'leaderBoard';
							par.appendChild(obj);
							document.getElementsByTagName('body')[0].appendChild(par);	
						} catch(e) {
							return false;
						}
					}
					break;
				case 'text-link':
					if(document.getElementById('textLink')) {
						
						document.getElementById('textLink').appendChild(obj);
					} else {				
						try {
							par	= document.createElement('div');
							par.id	= 'textLink';
							par.appendChild(obj);
							document.getElementsByTagName('body')[0].appendChild(par);	
						} catch(e) {
							return false;
						}
					}
					break;
				case 'half':
					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;
				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':
				default:
					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;
					
			}
			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	= 'tws_Banners_i-'+this._getIntval(((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) {
			var 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)
		{
			try
			{
				var re	= /<\S[^><]*>/g
				console.warn(line.replace(re, ""));
			}
			catch(e) {}
			
			if(typeof tws_GEO != "undefined" && (	tws_GEO.getIPAddress() == '212.61.72.179'	||
													tws_GEO.getIPAddress() == '212.61.72.180'	||
													tws_GEO.getIPAddress() == '212.61.72.181'	||
													tws_GEO.getIPAddress() == '212.61.72.182'	||
													tws_GEO.getIPAddress() == '80.113.170.130'	||
													tws_GEO.getIPAddress() == '62.194.141.157'	||
													tws_GEO.getIPAddress().toString().substr(0,10) == '192.168.92'))
			{
				var err = document.createElement('div');
				err.style.cssText = 'color: white;' + 
									'background-color: red;' +
									'position: absolute;' +
									'margin: 2px;' +
									'padding: 2px;' +
									'top: '+this.b_top+'px;' +
									'left: 0px;' +
									'width: 99%;' +
									'height: 15px;' +
									'z-index: 600000;' +
									'white-space: nowrap;' + 
									'overflow: hidden;';
				err.innerHTML	= "<strong>ERROR:</strong>"+line;
				
				document.getElementsByTagName('body')[0].appendChild(err);
				this.b_top	= this.b_top + 25;
			}
		},
		
		/**
		 * 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 rawthis._urlencode instead
		    var 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 rawthis._urlencode
		            }
		            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;
		},
    	
    	_getIntval: function(val)
    	{
    		val = parseInt(val, 10);
    		if(isNaN(val)) return 0;
    		return val;
    	},
    	
    	_getParameters: function()
		{
		   var string  = window.location.href.substring(window.location.href.indexOf("?") + 1);
		   var pars    = string.replace("&amp;", "&").split("&");
		   var params  = new Array();
		   for (var i = 0; i < pars.length; i++)
		   {
                if (pars[i].indexOf("=") != -1)
                {
                    var name = pars[i].substr(0, pars[i].indexOf("="));
                    var value = pars[i].substr(pars[i].indexOf("=") + 1);
                    params[name] = value;
                }
		   }
		   return params;
		},

    	loaded: tws_Global.scriptLoaded('tws_Banners')
	};
	
	/**
	 * Set a BannerTag attribute for the Google Ad Manager
	 *
	 * @param	string	tag		The BannerTag to set
	 *
	 * @return void
	 */
	var setEnvironment = function(tag)
	{
        var btag = tws_Banners.getParameters()["btag"];
		if(typeof btag != "undefined" && btag !== "") {
			tws_Banners.setCookie("banner_env", btag, null, "/");
		}
		
		if(tws_Banners.getCookie("banner_env") && document.location.href == top.document.location.href) {
			tag	= tws_Banners.getCookie("banner_env");
			
			addDOMLoadEvent(function() {
				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.getElementsByTagName('body')[0].appendChild(notify);
			});
		}
		
		if(typeof tag !== "undefined" && tag !== "") {
			this.showErrors = true;
			tws_Banners.set_GA_googleAddAttr("BannerTag", tag);
		}
		else
		{
			tws_Banners.set_GA_googleAddAttr("BannerTag", "none");
		}
	};
	
	/**
	 * Clear the set BannerTag attribute for the Google Ad Manager
	 *
	 * @return void
	 */	
	var unsetEnvironment = function () {
		tws_Banners.setCookie("banner_env", "deleted", -1, "/");
		url	= document.location.toString();
		if(url.indexOf('?') > 0) {
			url = url.substr(0,url.indexOf('?'));
		}
		document.location.href = url;
	};
	
	/**
	 * 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(tws_Banners.b_defaults['skyscraperID']);
			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';
				}
			}
		}
	});
	
	//Attempt to load 
	tws_Banners.loadSiteDefaults();
	
} // End if - typeof tws_Banners == 'undefined'

fg_Banners = tws_Banners;
