	var iPhonePopup;

	function displayWindow() {
		applyFade();
		displayDialog();
	}

	function applyFade() {
		var objBody = $$('body')[0];

		var faderDivRef = document.getElementById('faderDivRef');

		objBody.appendChild(Builder.node('div',{id:'faderDiv'}));
		document.getElementById('faderDiv').style.display = 'none';

		$$('select', 'object', 'embed').each(function(node){ node.style.visibility = 'hidden' });

		// stretch overlay to fill page and fade in
		var arrayPageSize = getPageSize();
		$('faderDiv').setStyle({ width: arrayPageSize[0] + 'px', height: arrayPageSize[1] + 'px' });

		new Effect.Appear($('faderDiv'), { duration: 1.5, from: 0.0, to: 0.8 });
	}

	function displayDialog() {
		var screenW = document.body.offsetWidth;
		// MAX SIZE is 480. Need to check if the screen is actually smaller than 480
		var width = 480;

		iPhonePopup = new UI.Window({
			theme: "black_hud",
			draggable: false,
			minimize: false,
			maximize: false,
			close: false,
			resizable: false,
			top: 100,
			left: (screenW / 2) - (width / 2),
			width: width,
			height: 500,
			show: Element.appear,
			hide: Element.fade
		}).setContent("<div class='windowPadding'><p>iPhones are simply no good sir/madam!</p>" +
			"<p><strong>Buckshot Sundae</strong> proudly endorses:</p>" +
			"<h2>Landline Telephones</h2>" +
			"<p>It takes only a few simple steps:</p>" +
			"<ul><li>Plug the fucker in</li>" +
			"<li>Call a motherfucker up</li>" +
			"<li>Hang up the fucking phone</li></ul>" +
			"<p><em>Benefits:</em></p>" +
			"<ul><li>No need for electricity! This thing runs on high levels of pure fucking awesomeness. No joke.</li>" +
			"<li>Designed so that even a small child can understand it. That's how they learn to make prank calls at such a young age.</li>" +
			"<li>Purely vocal communication. Don't spend another minute translating your friend's grammar abortions.</li>" +
			"<li>Talk on the phone and/or surf the internet. How fucking good is <em>that</em>?</li>" +
			"<li>Gain blissful neutrality from pointless arguments about superior cellular phone technology. Landlines beat the shit out of rock, paper, scissors <em>and</em> cell phones.</li>" +
			"<li>Heftier telephones can be used to swiftly bludgeon someone to death!</li>" +
			"<li>It's absolutely impossible to inadvertently message your father about your " +
			"<a href='http://www.inquisitr.com/11059/elizabeth-frisinger-lost-her-virginity-and-texted-her-dad/' target='_blank'>good-slut-times</a> while you're away at summer camp.</li></ul>" +
			"<p>So grow a goddamn pair and saddle up for a landline today!</p>" +
			"<p><em><strong>Buckshot Sundae:</strong> The authority on EVERYTHING.</em></p>" +
			"<a onclick='closeWindow()' style='float: right'><span class='closeX'>X</span><span class='closeText'> CLOSE</span></a></div>").show().focus();

		iPhonePopup.adapt.bind(iPhonePopup).delay(1);
	}

	function getPageSize() {
		 var xScroll, yScroll;

		if (window.innerHeight && window.scrollMaxY) {
			xScroll = window.innerWidth + window.scrollMaxX;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}

		var windowWidth, windowHeight;

		if (self.innerHeight) {	// all except Explorer
			if(document.documentElement.clientWidth){
				windowWidth = document.documentElement.clientWidth;
			} else {
				windowWidth = self.innerWidth;
			}
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}

		// for small pages with total height less then height of the viewport
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else {
			pageHeight = yScroll;
		}

		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth){
			pageWidth = xScroll;
		} else {
			pageWidth = windowWidth;
		}

		return [pageWidth,pageHeight];
	}

	function detectBrowser() {
		if(navigator.userAgent.match(/iPhone/i) && displayIPhoneMessage){
			displayWindow();
		}
	}

	function closeWindow() {
		iPhonePopup.hide();
		new Effect.Fade($('faderDiv'), { duration: 1.5, from: 0.8, to: 0.0 });
		var faderRef = document.getElementById('faderDiv');
		faderRef.parentNode.removeChild(faderRef);
	}
	
	function displayIE6Message() {
		var iexplorer = getIEVersion();

		if (iexplorer != -1 && iexplorer < 7) {
			document.write("<div class='iexplorerDiv'><strong>Note: </strong><em>Internet Explorer 6</em> is not currently supported by Buckshot Sundae.<br/><br/>" +
					"Why? Because I couldn't be fucked, that's why. Just download Firefox you whiny bitch. Firefox doesn't " +
					"care that you're running an illegal version of Windows</div>");
		}

	}
	
	function getIEVersion()
	// Returns the version of Internet Explorer or a -1
	{
	  var rv = -1; // Return value assumes failure.
	  if (navigator.appName == 'Microsoft Internet Explorer')
	  {
	    var ua = navigator.userAgent;
	    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
	    if (re.exec(ua) != null)
	      rv = parseFloat( RegExp.$1 );
	  }
	  return rv;
	}


	Event.observe(window, "load", detectBrowser);