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 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"	: ''
		},
		
		/* The options specified for this banner */
		b_options		: null,
		
		/* Is this banner expandable? */
		b_expandable	: false,
		
		/* Keeps track of the resizable banners and if we can resize them or not */
		b_allow_resize	: [],
			
		/* The sequence of the anchors */
		b_sequence		: {"top":10,"center":20,"bottom":30},
		
		/* Rerender these divs after completion */
		b_rerender		: [],
		
		/* The spelling for the clickTAG of the flash */
		b_cTAG			: 'clickTAG',
		
		/* Do we use percentages on this banner */
		b_usePercentage	: false,
		
		/* The default scaling type that is used in case of percentage */
		b_scaleType		: 'default',
		
		/* Show errors in the script on page */
		b_showErrors	: false,
		
/** 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 = callback;
	    },
	     
	    /**
	     *
	     */
	    startLoader: function(gameid, linktxt)
	    {
	    	if(this.movietime > 0 && document.getElementById('tws_syndication_loadbar_'+gameid))
	    	{
	    		this.percentage = 0;
	    		
	    		document.getElementById('tws_syndication_loadbar_'+gameid).style.width = '0%';
				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
			{
				try{console.log('No banner timers set, redirecting!');} catch(e) {}
				this.hideBanners(gameid);	
			}
	    },
	    
	    updateLoader: function(gameid, linktxt)
	    {
	    	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;
                tws_Banners.percentage = this._getIntval((diffTime / (tws_Banners.movietime * 1000)) * 100);

		    	document.getElementById('tws_syndication_loadbar_'+gameid).style.width = tws_Banners.percentage+'%';
				document.getElementById('tws_syndication_loadpercent_'+gameid).innerHTML = tws_Banners.percentage+'%';
	
				if(!tws_Banners.redirectlinkshow && (tws_Banners.linktime * 1000) <= diffTime)
				{
                    if(typeof tws_Banners.b_defaults['redirectshow'] != 'undefined' && tws_Banners.b_defaults['redirectshow'])
                    {
                        tws_Banners.hideBanners(gameid);
                    }
                    else
                    {
                        document.getElementById('tws_syndication_redirectlink_'+gameid).innerHTML = '<a href="#" onclick="tws_Banners.hideBanners('+gameid+'); return false;">'+linktxt+'</a>';
                        tws_Banners.redirectlinkshow = true;
                    }
		    	}
		    	
		    	if(tws_Banners.percentage >= 100)
		    	{
		    		tws_Banners.hideBanners(gameid);
		    	}
		    }
	    },
	    
	    hideBanners: function(gameid)
	    {
	    	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);
				}
			}
			
			clearInterval(tws_Banners.updateInterval);
			tws_Banners.updateInterval = null;
            if (typeof this.callback != "undefined" && this.callback != null) this.callback();
	    },
	    
	    /**
	     * 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) {
			for(var i in b_options) {
				this.b_defaults[i]	= b_options[i];
				
				if(i === 'setSite')
				{
					eval("addDOMLoadEvent(function() { tws_Banners._setSiteTakeover('"+b_options[i]+"'); });");
				}
				
				if(i === 'background') {
					this.setPageBackground(b_options[i]);
				}
				
				if(i === 'scaling') {
					this.setScaleType(b_options[i]);
				}
				
				if(i === 'loadTimer')
				{
					this.loadTimer = Math.round(b_options[i] * 1000);
				}
				
				if(i === 'redirectshow')
				{
					if(b_options[i] == 'true' || b_options[i] == true)
					{
						if(typeof this.b_defaults['showbanner'] != 'undefined' && this.b_defaults['showbanner'] != null)
							this.loadTimer = Math.round(this.b_defaults['showbanner'] * 1000);
                        else if(typeof this.linktime != 'undefined' && this.linktime != null)
							this.loadTimer = Math.round(this.linktime * 1000);
						else
							this.loadTimer = Math.round(2000);
					}
				}
				
				if(i === 'footertext') {
					var ftr = document.getElementById('footer');
					if(ftr)
					{
						ftr.style.color = b_options[i];
					}
				}
				if(i === 'footerlinks') {
					try {
						stl = document.createElement('style');
						stl.type = "text/css";
						stl.innerHTML = '#footer a { color: ' + b_options[i] + '; }';
						document.getElementsByTagName('head')[0].appendChild(stl);
					} catch(e) {
						document.createStyleSheet().addRule('#footer a', 'color: ' + b_options[i] + ' !important;');
					}
					
				}
				if(i === 'footerhover') {
					try {
						stl = document.createElement('style');
						stl.type = "text/css";
						stl.innerHTML = '#footer a:hover { color: ' + b_options[i] + '; }';
						document.getElementsByTagName('head')[0].appendChild(stl);
					} catch(e) {
						document.createStyleSheet().addRule('#footer a:hover', 'color: ' + b_options[i] + ' !important;');	
					}
				}
			}
		},
		
		/**
		 * Function to set the default scale type.
		 *
		 * @param	string		The type we want to use, can be 'default', 'noscale', 'noorder' or 'exactfit'
		 * @return	boolean		True if set, false otherwise
		 */
		setScaleType: function(b_type)
		{
			switch(b_type.toString().toLowerCase())
			{
				case 'default':this.b_scaleType = 'showall';break;
				case 'noscale':this.b_scaleType = 'noscale';break;
				case 'noorder':this.b_scaleType = 'noorder';break;
				case 'exactfit':this.b_scaleType = 'exactfit';break;
				default:return false;break;
			}
			return true;
		},
		
		/**
		 * Function to retrieve the room in the browser. It returns an array containing
		 * two variables, one container the room between the edge of the broser and the
		 * 'uberholder' div, the second containing the height of the browser. Will return
		 * boolean false if unsuccesful.
		 *
		 * @return	array	An array with x and y value or false in case of error
		 */
		getAvailableSize: function() {
			try {
				var values	= new Array();
				x	= Math.floor((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() {
			if(document.getElementById("tws_Banners_b_dhtml_layer")) {
				document.getElementById("tws_Banners_b_dhtml_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;	
			}
		},

/** WORKER FUNCTIONS **/
		
		/**
		 * Function to set the page background to a specific color or image
		 *
		 * @param	string	to	The URL or Hex color of the new background. It will set all strings
		 *						as image background, unless started by '#' for colors.
		 *
		 * @return void
		 */
		setPageBackground: function(to) {
			html	= document.getElementsByTagName('html')[0];
			if(to.substr(0,1) == '#') {
				// Set the value of 'to' as the new background color
				html.style.backgroundColor	= to;
				html.style.backgroundImage	= 'none';
				// -
			} else {
				// Set the value of 'to' as the new background image
				html.style.backgroundImage	= 'url('+to+')';
				// -
			}
		},
		
		/**
		 * Function to set the default anchor CSS position
		 *
		 * @param	string	value	The new CSS position for the anchors
		 *
		 * @return boolean	True if succesfull, false otherwise
		 */
		setAnchorPosition: function(val) {
			if(	val == 'absolute'	||
				val == 'fixed'		||				
				val == 'relative'	||
				val == 'static'		||
				val == 'inherit'
			) {
				this.b_anchorposition = val;
				return true;	
			} else {
				return false;	
			}
		},
		
		/**
		 * Function to add items to the page. For IE6 and lower, it will add items to the loader
		 * instead of directly to the DOM.
		 *
		 * @param	string	b_file		String location of the file to add
		 * @param	object	b_options	Options for this banner, see the description for '_addItem'
		 *								for more details.
		 *
		 * @return void
		 */
		add: function(b_file, b_options) {
			if(typeof b_options["position"] != 'undefined' && 
				b_options["position"] === 'rectangle') {
				this._addItem(b_file,b_options);
			} else {
				if (this._getVersion() <= 6) {
					this.b_anchorposition = 'absolute';
				}

				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
		 *
		 * @param	element	container	The element containing the div with banner contents anchor
		 *
		 * @return	void
		 */
		expandBanner: function(container) {
			info	= document.getElementById(container.id).getElementsByTagName('input')[0].value;
			if(info.length > 73 && info.length < 83 && info.substr(0,20) == 'var tws_exp = {"i":"') {
				eval(info);
				if(this.b_allow_resize[tws_exp.i]) {
					obj	= document.getElementById(tws_exp.i);
					if(obj) {
						if(	this._getIntval(this.getStyle(tws_exp.i,"width","width")) == tws_exp.w && 
							this._getIntval(this.getStyle(tws_exp.i,"height","height")) == tws_exp.h ){
							// Object has original size, resize to large versions
							obj.style.width		= tws_exp.ew+'px';
							obj.style.height	= tws_exp.eh+'px';
						} else {
							// Resize to original version
							obj.style.width		= tws_exp.w+'px';
							obj.style.height	= tws_exp.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() {
			if(document.getElementById(this.b_defaults['skyscraperID'])) {
				document.getElementById(this.b_defaults['skyscraperID']).style.display = 'none';
			}
		},
		
/** 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';
			}
			
			// Get the current type from the file extension
			this.b_type	= this._getType(b_file,b_options);
			
			// If we do not get a file type, output an error
			if(!this.b_type) {
				this._writeError("Invalid file '"+b_file+"' !");
				perform_write	= false;	
			}
			// -
			
			// Validate the position value
			if(typeof b_options["position"] == 'undefined' || b_options["position"] == '' || (
				b_options["position"].toLowerCase() !== 'top-left' && 
				b_options["position"].toLowerCase() !== 'top' && 
				b_options["position"].toLowerCase() !== 'top-right' && 
				b_options["position"].toLowerCase() !== 'header' && 
				b_options["position"].toLowerCase() !== 'left' && 
				b_options["position"].toLowerCase() !== 'center' && 
				b_options["position"].toLowerCase() !== 'right' && 
				b_options["position"].toLowerCase() !== 'bottom-left' && 
				b_options["position"].toLowerCase() !== 'bottom' && 
				b_options["position"].toLowerCase() !== 'bottom-right' && 	
				b_options["position"].toLowerCase() !== 'rectangle' &&
				b_options["position"].toLowerCase() !== 'slot' &&
				b_options["position"].toLowerCase() !== 'floor'
			)) {
				this._writeError("Invalid position for file '"+b_file+"' !");
				perform_write	= false;
			}
			// -
			
			// Check for width
			if(typeof b_options["width"] == 'undefined' || b_options["width"] <= 0) {
				if(b_options["position"] === 'header') {
					// If we do not have a width, but the position is a header, set a default value
					b_options["width"]	= 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;
				// -

				// 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 {
					addDOMLoadEvent(function() {
						if(document.getElementById('uberholder')) {
							document.getElementById('uberholder').style.zIndex	= 3000;
						}
					});
					
					// If we need to write the item, first check if we have initilized the anchors
					this._checkAnchors();
					
					// Create the base div inside the internal 'div' variable
					this.b_div				= document.createElement("div");
					this.b_div.id			= this._getId();
					if(b_options["width"].toString().substr(b_options["width"].length - 1) == '%') {
						this.b_div.style.width	= b_options["width"];
						this.b_usePercentage	= true;
					} else {
						this.b_div.style.width	= 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"] !== '' &&
							this.b_options["measureTAG"] !== '-') {
					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 camelcase/IE CSS notation of the value we need (e.g. "marginTop")
		 * @param	string	The official CSS notation of the value we need (e.g. "margin-top")
		 *
		 * @return	string	The value of the requested style, or false if not found.
		 */
		_getStyle: function(b_source, IEStyleName, CSSStyleName) {
			var elem = document.getElementById(b_source);
			
			if(elem) {
				if (elem.currentStyle) {
					return elem.currentStyle[IEStyleName];
				} else if (window.getComputedStyle) {
					var compStyle = window.getComputedStyle(elem, "");
					return compStyle.getPropertyValue(CSSStyleName);
				} else {
					return false;
				}
			} else {
				return false;	
			}
		},
		
		/**
		 * Function to reset all variables to their default values. Does NOT reset anchor, top
		 * and zindex, since they might be used for the next banner.
		 *
		 * @return	void
		 */
		_resetVariables: function() {
			this.b_div				= null;
			this.b_type				= null;
			this.b_file				= null;
			this.b_options			= null;
			this.b_expandable		= false;
			this.b_usePercentage	= false;
		},
		
		/**
		 * Find out the width of the item in its expanded state
		 *
		 * @return integer
		 */
		_getExpandedWidth: function() {
			if(typeof this.b_options["width_exp"] == 'undefined') {
				var w = this.b_options["width"];
			} else {
				var w = 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.b_defaults['contentMarginLeft'];
							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.b_defaults['contentMarginLeft'];
							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.b_defaults['contentMarginLeft'];
							this.b_anchor["alwaysontop_bottom"].style.zIndex		= 6000 - this.b_sequence["bottom"];
				
							par.appendChild(this.b_anchor["alwaysontop_bottom"]);
							// -
						}
						// -
					}
				}
			} else {
				this._writeError("Warning! Unable to write anchors.");	
			}
		},
		
		/**
		 * Function to add the current div to the page, adding it to 'obj_id'.
		 *
		 * @param	string	obj_id		The id of the object to add the div to.
		 * @param	boolean	is_anchor	If true, it will be added to the anchor with name 'obj_id'.
		 *
		 * @return	void
		 */
		_appendTo: function(obj_id, is_anchor) {
			if(typeof this.b_options["alwaysontop"] !== 'undefined' && (this.b_options["alwaysontop"] === true || this.b_options["alwaysontop"] === 'true')) {
				obj_id	= 'alwaysontop_'+obj_id;
			}
			
			if(typeof is_anchor === 'undefined' || !is_anchor) {
				if(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)
		{
			measureTAG			= document.createElement("img");
			measureTAG.src		= m_src;
			measureTAG.width	= 1;
			measureTAG.height	= 1;
			this.b_anchor["bottom"].appendChild(measureTAG);
		},
		
		/**
		 * Function that returns whether the link should open in a new window, or in the same
		 *
		 * @param	string	forTag	the tag type for which to get the target
		 *
		 * @return	string
		 */
		_getTarget: function(forTag)
		{
			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"] !== '') {
				this.b_div.style.backgroundColor = this.b_options["bgcolor"];
			}
			html	= '';
			
			aclose	= false;
			if(typeof this.b_options["clickTAG"] !== 'undefined' && this.b_options["clickTAG"] !== '' &&  this.b_options["clickTAG"] !== '-') {
				html	= html + '<a href="'+this.b_options["clickTAG"]+'" target="'+this._getTarget('A')+'">';
				aclose	= true;
			} else if(typeof 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')+'">';
				aclose	= true;
			}
			
			html = html + '<img src="'+this.b_file+'" width="'+this.b_options["width"]+'" height="'+this.b_options["height"]+'" />';
			
			if(aclose) {
				html = html + '</a>';	
			}
			
			return html;
		},
		
		/**
		 * Function that returns the html to be placed in a div for flash elements
		 *
		 * @return	string	html
		 */
		_getFlashContent: function(sizes)
		{
			var embed	= false;if(this.b_options["embed"]	== true) {embed = true;}
			
			if(this.b_expandable) {
				sizes	= {"x":this._getExpandedWidth()+'px',"y":this._getExpandedHeight()+'px'};
			} else if(typeof sizes === 'undefined') {
				sizes	= {"x":"100%","y":"100%"};
			}
			
			src	= this.b_file;
			if(typeof this.b_options["clickTAG"] !== 'undefined' && this.b_options["clickTAG"] !== '') {
				src	= src+"?"+this.b_cTAG+"="+this._urlencode(this.b_options["clickTAG"]);
			} else if(typeof this.b_defaults["clickTAG"] !== 'undefined' && this.b_defaults["clickTAG"] !== '') {
				src	= src+"?"+this.b_cTAG+"="+this._urlencode(this.b_defaults["clickTAG"]);
			}
			
			if(typeof this.b_options["params"] !== 'undefined') {
				for(var i in this.b_options["params"]) {
					if(src.indexOf('?') > 0) {
						src = src + '&'+i+'='+this._urlencode(this.b_options["params"][i]);
					} else {
						src = src + '?'+i+'='+this._urlencode(this.b_options["params"][i]);	
					}
				}
			}
	
			if(this._getTarget() !== '_blank' && src.indexOf('?') > 0) {
				src = src + '&tagtarget='+this._getTarget();
			}
			
			flash_id	= 'flash_'+(this.b_options["position"].replace('-','_'))+'_'+this.b_options["width"]+'x'+this.b_options["height"];
			
			html = '<object ';
			html = html + 'style="outline-width:0;" ';
			html = html + 'id="'+flash_id+'" ';
			html = html + 'width="'+sizes.x+'" ';
			html = html + 'height="'+sizes.y+'" ';
			html = html + 'type="application/x-shockwave-flash" ';
			if(embed) {
				html = html + 'classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ';
			} else {
				html = html + 'data="'+src+'" ';
			}
			html = html + '>';
		    html = html + '<param name="movie" value="'+src+'"/>';
		    if(this.b_usePercentage) {
		    	html = html + '<param name="scale" value="'+this.b_scaleType+'"/>';
			}
		    if(typeof this.b_options["wmode"] !== 'undefined' && this.b_options["wmode"] !== '') {
				html = html + '<param name="wmode" value="'+this.b_options["wmode"]+'"/>';
			} else {
				html = html + '<param name="wmode" value="transparent"/>';
			}
			if(typeof this.b_options["bgcolor"] !== 'undefined' && this.b_options["bgcolor"] !== '') {
				html	= html + '<param name="bgcolor" value="'+this.b_options["bgcolor"]+'" />';
			}
			if(typeof this.b_options["clickTAG"] !== 'undefined' && this.b_options["clickTAG"] !== '') {
				html	= html + '<param name="'+this.b_cTAG+'" value="'+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"])+'" />';
			}
			if(this._getTarget() !== '_blank' && src.indexOf('?') > 0) {
				html = html + '<param name="tagtarget" value="'+this._getTarget('Flash')+'"/>';
			}
			html = html + '<param name="AllowScriptAccess" value="always"/>';
			
			if(typeof this.b_options["params"] !== 'undefined') {
				for(var i in this.b_options["params"]) {
					html = html + '<param name="'+i+'" value="'+this.b_options["params"][i]+'"/>';
				}
			}
			if(embed)
			{
				html = html + this._getEmbedTag(flash_id, src, sizes);	
			}
			
			html = html + '</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" ';
			
			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 + '"';}
			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';
				
				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';
				}
				if(typeof this.b_options["width"] !== 'undefined' && this._getIntval(this.b_options["width"]) > 0) {
					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("Warning! Double header specified!");
			}
		},
		
		/**
		 * Function to add a header div to the half banner slot. Will issue a warning when
		 * a header has already been set.
		 *
		 * @return	void
		 */
		_setRectangle: function() {
			if(typeof this.rectangleset === 'undefined') {
				this.rectangleset	= true;
				
				if(typeof this.b_options["top"] === 'undefined') {
					this.b_options["top"]	= 0;	
				}
				if(typeof this.b_options["left"] === 'undefined') {
					this.b_options["left"]	= 0;	
				}
				
				id		= this._getId();
				html	= '<div id="'+id+'" style="' +
						'width: '+this.b_defaults['rectangleWidth']+'px; ' +
						'height: '+this.b_defaults['rectangleHeight']+'px; position: relative;">' +
						'<div id="'+id+'_content" style="' +
						'width: '+this.b_options["width"]+'px; ' +
						'height: '+this.b_options["height"]+'px; ' +
						'position: absolute; ' +
						'top: '+this.b_options["top"]+'px; ' +
						'left: '+this.b_options["left"]+'px; ' +
						'">' +
						this._getInnerHTML() +
						'</div></div>';

				document.write(html);
				
				if(typeof this.b_options["bannertime"] !== 'undefined' && this.b_options["bannertime"] !== '') {
					this.b_defaults["bannertime"]	= this.b_options["bannertime"];
				}
				if(typeof this.b_options["showbanner"] !== 'undefined' && this.b_options["showbanner"] !== '') {
					this.b_defaults["showbanner"]	= this.b_options["showbanner"];
				}
			} else {
				this._writeError("Warning! Double rectangle specified!");
			}
		},
		
		/**
		 * Function to add a DHTML div to the center of the page. Will issue a warning when
		 * another DHTML has already been set.
		 *
		 * @return	void
		 */
		_setDHTMLlayer: function() {
			if(typeof this.dhtmlset === 'undefined') {
				this.dhtmlset	= true;
				
				this.b_div.id	= "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("Warning! Double DHTML specified!");
			}
		},
		
		/**
		 * Write a default banner into the page
		 *
		 * @return void
		 */
		_fillSlot: function() {
			if(typeof this.b_options["left"] === 'undefined') {
				this.b_options["left"]	= 0;
			}
			if(typeof this.b_options["top"] === 'undefined') {
				this.b_options["top"]	= 0;	
			}
			
			slot	= document.createElement('div');
			slot.id	= this._getId();
			
			slot.style.cssText =	'width: '+this.b_options["width"]+'px; ' +
									'height: '+this.b_options["height"]+'px; ' +
									'position: absolute; ' +
									'top: '+this.b_options["top"]+'px; ' +
									'left: '+this.b_options["left"]+'px; ' +
									'z-index: ' +this.b_zindex+';';
			
			this.b_zindex		= this.b_zindex + 10;
			
			slot.innerHTML	= this._getInnerHTML();
			
			this._addToContainer(slot);
		},
		
		/**
		 * Write an expandable banner into the page
		 *
		 * @return void
		 */
		_fillSlotExpandable: function() {
	
			banner_id	= this._getId();
						
			if(typeof this.b_options["left"] === 'undefined') {
				this.b_options["left"]	= 0;
			}
			if(typeof this.b_options["top"] === 'undefined') {
				this.b_options["top"]	= 0;	
			}
			
			if(typeof this.b_options['start'] == 'undefined' || this.b_options['start'] === 'normal') {
				s_width		= this.b_options["width"];
				s_height	= this.b_options["height"];
				e_width		= this._getExpandedWidth();
				e_height	= this._getExpandedHeight();
			} else {
				s_width		= this._getExpandedWidth();
				s_height	= this._getExpandedHeight();
				e_width		= this.b_options["width"];
				e_height	= this.b_options["height"];
			}
		
			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;
			}
			
			info	= document.createElement('input');
			info.style.display	= 'none';
			info.type			= 'hidden';
			info.value			= 'var tws_exp = {"i":"'+banner_id+'","w":'+this.b_options["width"]+',"h":'+this.b_options["height"]+',"ew":'+this._getExpandedWidth()+',"eh":'+this._getExpandedHeight()+'}';
			this._addToContainer(info);
	
			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(this.parentNode);};
			slot.onmouseout		= function() {tws_Banners.expandBanner(this.parentNode);};
			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');
				floorcontainer.style.cssText = "width: "+this.b_options['width']+"; height: "+this.b_defaults['flooradheight']+"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: "+this.b_options['width']+"; 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 'full':
					if(document.getElementById('fullbanner')) {
						document.getElementById('fullbanner').appendChild(obj);
					} else {
						try {
							par	= document.createElement('div');
							par.id	= 'fullbanner';
							par.appendChild(obj);
							document.getElementsByTagName('body')[0].appendChild(par);	
						} catch(e) {
							return false;
						}
					}
					break;
				case 'skyscraper':
					if(document.getElementById('skyScraper')) {
						document.getElementById('skyScraper').appendChild(obj);
					} else {
						try {
							par	= document.createElement('div');
							par.id	= 'skyScraper';
							par.appendChild(obj);
							document.getElementsByTagName('body')[0].appendChild(par);	
						} catch(e) {
							return false;
						}
					}
					break;
				case 'rectangle':
					if(document.getElementById('banner').getElementsByTagName('div')[0]) {
						document.getElementById('banner').getElementsByTagName('div')[0].insertBefore(obj,$('banner').getElementsByTagName('div')[0].firstChild);
					} else {
						try {
							par	= document.createElement('div');
							par.id	= 'banner';
							par.appendChild(obj);
							document.getElementsByTagName('body')[0].appendChild(par);	
						} catch(e) {
							return false;
						}
					}
					break;
				case 'half':
				default:
					if(document.getElementById('halfbanner')) {
						document.getElementById('halfbanner').appendChild(obj);
					} else {
						try {
							par	= document.createElement('div');
							par.id	= 'halfbanner';
							par.appendChild(obj);
							document.getElementsByTagName('body')[0].appendChild(par);	
						} catch(e) {
							return false;
						}
					}
					break;
			}
			return true;
		},
		
		/**
		 * Function to force rerendering of a div
		 *
		 * @return void
		 */
		_reRender: function() {
			for(var i = 0; i < this.b_rerender.length; i++) {
				if(document.getElementById(this.b_rerender[i])) {
					document.getElementById(this.b_rerender[i]).parentNode.style.display = 'none';
					document.getElementById(this.b_rerender[i]).parentNode.style.display = 'block';
				}
			}
		},
		
		/**
		 * Returns a unique number for the ID of the banner.
		 *
		 * @return	integer
		 */
		_getId: function() {
			ret_id	= '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) {
			var err = document.createElement('div');
			err.style.cssText = 'color: red;' + 
								'background-color: white;' +
								'position: absolute;' +
								'margin: 2px;' +
								'padding: 2px;' +
								'top: '+this.b_top+'px;' +
								'left: 0px;' +
								'width: 600px;' +
								'height: 20px;' +
								'z-index: 600000';
			err.innerHTML	= line;
			
			try { console.warn(line); } catch(e) {}
			
			document.getElementsByTagName('body')[0].appendChild(err);
			
			this.b_top	= this.b_top + 30;
		},
		
		/**
		 * 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;
    	},
    	
    	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")) {
			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;
			GA_googleAddAttr("BannerTag", tag);
		}	
	};
	
	/**
	 * 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;