require('http://theu.net/ad_resources/wraparound/getElementsByClassName-1.0.1.js');

function require(url) {
    document.write('<script type="text/javascript" src="'+url+'"><\/script>');
	}

function vIE(){
	return (navigator.appName=='Microsoft Internet Explorer')?parseFloat((new RegExp("MSIE ([0-9]{1,}[.0-9]{0,})")).exec(navigator.userAgent)[1]):-1;
	}
 
function wraparound() {
	
	var leftCorner = 0;
	var wrapper = null;
	var flashContainerId = 'theu_bgflash';
	var flashBanner = null;
	var topPadding = 0;
	var redirectUrl = '';
	var cursor;

	this.init = function() {

		/*	Relatively static variables (these should not generally be changed)	*/
		wrapper = document.getElementById(this.siteContainerId);
		flashContainerId = 'theu_bgflash';										//	Container div for the flash banner
		topPadding = 100;													//	Margin at the top (should be same as upper banner height)
		redirectUrl = this.redirectUrl;

		//	Attach mouse events to the body
		if ( (vIE() == -1) || (vIE() >= 6) ) {

			if (typeof(document.body.attachEvent) != 'undefined') {
				document.body.attachEvent('onmousedown', this.processEvent);
				document.body.attachEvent('onmousemove', this.processEvent);
				}
			else {
				document.body.onmousedown = this.processEvent;
				document.body.onmousemove = this.processEvent;
				}
			}

		}	//	End method init



	this.getCorner = function() {
		//	 Get left corner and width of the main site element
		var cur = wrapper;
		var curleft = 0;		
		if (cur.offsetParent) {
			do { curleft += cur.offsetLeft; }
			while (cur = cur.offsetParent);
			}
		leftCorner = curleft;

		}	//	End method getCorners



	this.display = function() {
		// Do site-specific stuff
		if (typeof(this.siteSpecific) != 'undefined') { this.siteSpecific(); }
		/*	Style our new body (IE doesn't apply the CSS body selector to our replacement) */
		document.body.style.position = 'absolute';
//		document.body.style.top = '-' + topPadding + 'px';
		document.body.style.textAlign = 'center';
		document.body.style.width = '100%';
		wrapper.style.textAlign = 'left';
		wrapper.style.width = this.siteWidth + 'px';
		wrapper.style.margin = topPadding + 'px auto 0px auto';
		this.getCorner();

		/*	Actually set the background image	*/
		if (this.adType == 'img') {
			document.body.style.background = this.bgColor + ' url("'+ this.imgUrl +'") top center no-repeat';
			}
		/*	Create the flash object if in SWF mode	*/
		else if (this.adType == 'swf') {			//	Without this IE-specific event handler, IE will ignore all clicks on a flash object
			//	Flash wrapper div
			var flashDiv = document.createElement('div');
				flashDiv.setAttribute('id', flashContainerId);
			
			var objectTag =
//			'<object id="theu_flashobj" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="1200" height="800" id="160x600_dell" align="middle">' +
			'<object id="theu_flashobj" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="1200" height="600" id="160x600_dell" align="middle">' +
			'		<param name="allowScriptAccess" value="always" />' + 
			'		<param name="movie" value="' + this.imgUrl+ '" />' + 
			'		<param name="wmode" value="opaque" />' +
			'		<param name="quality" value="low" />' +
			'		<param name="bgcolor" value="' + this.bgColor + '" />' +
//			'		<embed src="' + this.imgUrl +'" quality="low" wmode="opaque" bgcolor="' + this.bgColor + '" width="1200" height="800" name="160x600_dell" align="middle" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />' + 
			'		<embed src="' + this.imgUrl +'" quality="low" wmode="opaque" bgcolor="' + this.bgColor + '" width="1200" height="600" name="160x600_dell" align="middle" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />' + 
			'	</object>';
			flashDiv.innerHTML = objectTag;
			document.body.insertBefore(flashDiv, document.body.firstChild);
			flashBanner = flashDiv.firstChild;		
			wrapper.style.position = 'relative';

			if (flashDiv.clientHeight == 0) {
				offset = flashDiv.firstChild.clientHeight;
				}
			else {
				offset = flashDiv.clientHeight;
				}
			wrapper.style.top = '-' + offset + 'px';

			if (flashBanner.attachEvent) {
				flashBanner.attachEvent("onfocus",this.processEvent);
				}
			else {

				}

			}
		}	//	End method display



	this.processEvent = function(e) {
		var posx = 0;
		var posy = 0;
		//	Get the location of the click
		if (typeof(e.pageX) == 'undefined') {
			posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
			posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
			}
		else {
			posx = e.pageX;
			posy = e.pageY;
			}


		//	For mousedowns
		if ( e.type == 'mousedown') {

			if ( (posx < leftCorner) || (posx > leftCorner + wrapper.clientWidth) || (posy < topPadding) ) {
				if (flashBanner) { flashBanner.blur(); }							//	For IE: blur the bg banner to allow subsequent clicks to work
				window.open(redirectUrl, '', '');
				}
			}	//	End mousedown condition


		//	For mouse movement
		else if (e.type == 'mousemove') {
			if ( (posx < leftCorner) || (posx > leftCorner + wrapper.clientWidth) || (posy < topPadding) ) {
				document.documentElement.style.cursor = 'pointer';
				}

			else {
				document.documentElement.style.cursor = 'auto';
				}
			}	//	End mouse move condition
		
		}	//	End function processEvent


	}  //	End function theu_init