sopablackout_on = [2012, 1, 18, 7];
function closeBlackout()
{
	document.body.style['margin']='0px auto';
	document.body.style['backgroundColor']='#fff';
	$('#blackout').remove();
	$("#outerwrap-head,#outerwrap,#footer").show();
}
(function (){
	var root = this;

	var SopaBlackout = function(){};
	var	addEvent = function(obj, type, fn, ref_obj){
		if (obj.addEventListener){
			obj.addEventListener(type, fn, false);
		}else if (obj.attachEvent){
			obj["e"+type+fn] = fn;
			obj[type+fn] = function(){
				obj["e"+type+fn](window.event,ref_obj);
			};
			obj.attachEvent("on"+type, obj[type+fn]);
		}
	};
	// Thanks http://javascript.nwbox.com/IEContentLoaded/
	// for this
	var IEContentLoaded = function(w, fn) {
		var d = w.document, done = false,
		init = function () {
			if (!done) {
				done = true;
				fn();
			}
		};
		(function () {
			try {
				d.documentElement.doScroll('left');
			} catch (e) {
				setTimeout(arguments.callee, 50);
				return;
			}
			init();
		})();
		d.onreadystatechange = function() {
			if (d.readyState == 'complete') {
				d.onreadystatechange = null;
				init();
			}
		};
	}
	var onDomReady = function(fn){
		if (document.addEventListener){
			document.addEventListener('DOMContentLoaded', fn, false);
		}else{
			IEContentLoaded(window, fn);
		}
	};
	var getStyle = function(e, prop){
		if (e.currentStyle){
			return e.currentStyle[prop];
		}else if (document.defaultView && document.defaultView.getComputedStyle){
			return document.defaultView.getComputedStyle(e, "")[prop];
		}else{
			return e.style[prop];
		}
	};
	var findPos = function(obj){
		var curleft = 0;
		var curtop = 0;
		if (obj.offsetParent){
			do{
				curleft += obj.offsetLeft;
				curtop += obj.offsetTop;
			}while(obj = obj.offsetParent);
		}
		return [curleft, curtop];
	};
	var txt = function(s){
		return document.createTextNode(s);
	};
	var create = function(e, props){
		var elem = document.createElement(e);
		var props = props !== null ? props : {};
		var attrs = ['href','src','id','target','onclick'];
		for (var key in props){
			if ($.inArray(key, attrs) >= 0){
				elem.setAttribute(key, props[key]);
			}else{
				elem.style[key] = props[key];
			}
		}
		l = arguments.length;
		for (var i=2; i<l; i++){
			elem.appendChild(arguments[i]);
		}
		return elem;
	};
	var getOpts = function(){
		var ret = {};
		for (var key in SopaBlackout.DEFAULTS){
			var k = 'sopablackout_' + key;
			ret[key] = (typeof window[k] === 'undefined') ? SopaBlackout.DEFAULTS[key] : window[k];
		}
		return ret;
	};
	var dateMatches = function(spec){
		spec.push(false); spec.push(false); spec.push(false);
		var today = new Date();
		if ((spec[0] !== false && today.getFullYear() !== spec[0]) || 
				(spec[1] !== false && today.getMonth() + 1 !== spec[1]) ||
				(spec[2] !== false && today.getDate() !== spec[2]) ||
				(spec[3] !== false && today.getHours() < spec[3]) || 
				(spec[3] !== false && today.getHours() > spec[3]+11)
			){
			return false;
		}
		return true;
	};

	SopaBlackout.VERSION = '0.2.0';
	SopaBlackout.MIN_HEIGHT = 100;
	SopaBlackout.HEADER_TEXT = "PROTECT THE INTERNET.";
	SopaBlackout.CONTINUE_TEXT = "Proceed to DrivingSales.com";
	SopaBlackout.HEADER2_TEXT = "ACT NOW.";
	SopaBlackout.ZINDEX = Math.pow(2, 31) - 2;
	SopaBlackout.DEFAULTS = {
		'id': false,
		'srsbzns': false,
		'on': false
	};
	SopaBlackout.blackout = function(opts){
		var obj;
		var body = document.body;
		body.style['margin'] = '0px 0px';
		body.style['backgroundColor']='#111111';
		if (opts['id'] === false){
			obj = body;
			height = "100%";
		}else{
			obj = document.getElementById(opts['id']);
			var height = parseInt(getStyle(obj, 'height'), 10);
			height = height > SopaBlackout.MIN_HEIGHT ? height : SopaBlackout.MIN_HEIGHT;
		}
		var offsets = findPos(obj);

		var blackout = create('div', {
				id:'blackout',
				position: 'absolute',
				top: offsets[1],
				width: '100%',
				backgroundColor: '#111111',
				textAlign: 'center',
				paddingTop: '0px',
				zIndex: SopaBlackout.ZINDEX,
				height: height,
				color: '#fff',
				fontFamily: 'Arial',
				fontSize: '18px'
			},
			create('div', {
				width: '100%',
				backgroundColor: 'white'
			},
				create('img', {
					src: 'http://www.drivingsales.com/images/logo.png',
					margin: '0px auto'
				})
			),
			create('div', {padding: '25px', borderTop: 'solid white 2px', borderBottom: 'solid white 2px', margin: '25px auto', width: '50%'},
				create('h1', {fontSize: '64px',fontFamily: "Times New Roman",paddingBottom: '25px'}, txt(SopaBlackout.HEADER_TEXT)),
				create('p', {fontSize: '18px',marginBottom: '18px'},
					txt("With growing concerns surrounding US House and Senate bills "),
					create('a', {color: '#fff', textDecoration: 'underline', href: 'http://thomas.loc.gov/cgi-bin/bdquery/z?d112:h.r.3261:', target: "_blank"}, txt('SOPA')),
					txt(' and '),
					create('a', {color: '#fff', textDecoration: 'underline', href: 'http://www.opencongress.org/bill/112-s968/show', target: "_blank"}, txt('PIPA')),
					txt(','),
					create('br', null),
					txt('DrivingSales is joining thousands of other websites in calling attention to and helping'),
					create('br', null),
					txt('inform Internet users at large about the implications involved.')
				),
				create('p', {fontSize: '18px'}, 
					txt('There are significant censorship and free-speech issues that would be violated should the'),
					create('br', null),
					txt('bills pass as they are written now. Your favorite sites (like DrivingSales.com) could be'),
					create('br', null),
					txt('dramatically altered and potentially even blocked entirely.')
				)
			),
			create('div', {padding: '25px', margin: '25px auto', width: '50%'},
				create('h1', {fontSize: '100px',fontFamily: "Times New Roman",color: '#eecc00'}, txt(SopaBlackout.HEADER2_TEXT)),
				create('p', {fontSize: '18px',marginBottom: '18px'},
					create('a', {color: '#c3b76c', textDecoration: 'underline', href: "http://fightforthefuture.org/pipa", target: "_blank"}, txt("LEARN MORE ABOUT THE SOPA BLACKOUT"))
				),
				create('p', {fontSize: '18px'},
					create('a', {fontSize: '18px', textDecoration: 'underline', color: '#c3b76c',marginTop: '25px', href: "#",onclick:'closeBlackout();return false;'}, txt(SopaBlackout.CONTINUE_TEXT))
				)
			)
		);
		
		$("#outerwrap-head,#outerwrap,#footer").hide();
		
		body.appendChild(blackout);
	};
	SopaBlackout.go = function(){
		var opts = getOpts();
		if (opts['on'] !== false && !dateMatches(opts['on'])){
			return;
		}
		SopaBlackout.blackout(opts);
	};

	onDomReady(SopaBlackout.go);
}).call(this);

