$(window).resize(function(){
	$('#18OnlyMsgContainerBG').css('width', $(document).width());
	$('#18OnlyMsgContainerBG').css('height', $(document).height());
	reposDiv();
});

$(window).scroll(function(){
	$('#18OnlyMsgContainerBG').css('width', $(document).width());
	$('#18OnlyMsgContainerBG').css('height', $(document).height());
	reposDiv();
});

$(document).ready(function(){
	adultsOnlyPopup();	
	reposDiv();
});

function reposDiv(){
	offset = $(window).scrollTop();
	xPos = ($(window).width() - $('#18OnlyMsgContainer').width())/2;
	yPos = ($(window).height() - $('#18OnlyMsgContainer').height())/2 + offset;
	if(yPos < 0){
		yPos = 0;
	}if(xPos < 0){
		xPos = 0;
	}
	$('#18OnlyMsgContainer').css({'position' : 'absolute', 'left' : xPos, 'top' : yPos});
}

function validateAge(userAge){
	var age = userAge;	
	
	if(age < 18){
		ageVerified = false;
	}else {
		ageVerified = true;	
	}
	if(ageVerified === true){
		// sets cookie and destroys divs
		$.cookie("fuckordate", "1", { expires: 1000000 });
		destroyDivs();
		setErr("");
	}else if(ageVerified === false){
		setErr("Not 18+");
	}
}

function destroyDivs(){
	$('#18OnlyMsgContainer').remove();
	$('#18OnlyMsgContainerBG').remove();
}

function setErr(errStr){
	$("#errMsg").html(errStr);
}

function adultsOnlyPopup(){
	if(!$.cookie('fuckordate')){
		$('body').append('<div id="18OnlyMsgContainerBG" style="width:100%; height:100%; background-color:black; position: absolute; left:0px; top:0px;"></div>');
		
		selectOptions = '';
		for(i = 1; i < 100; i++){
			selectOptions += '<option value="'+i+'">'+i+'</option>';
		}
		$('body').append('<div id="18OnlyMsgContainer" style="width:500px; height:460px; background-color:#222222; color:white; text-align:center;"><h1 style="color:red"><b>WARNING: ADULT CONTENT</b></h1><textarea style="width: 450px; height:160px; background-color:#777777; color:#EEEEEE; border:0; padding-left:3px;">This Website contains sexually-oriented adult content which may include visual images and verbal descriptions of nude adults, adults engaging in sexual acts, and other audio and visual materials of a sexually-explicit nature.\n\nPermission to enter this Website and to view and download its contents is strictly limited only to consenting adults who affirm that the following conditions apply:\n\n1. That you are at least 18 years of age or older, and that you are voluntarily choosing to view and access such sexually-explicit images and content for your own personal use.\n\n2. That you intend to view the sexually-explicit material in the privacy of your home, or in a place where there are no other persons viewing this material who are either minors, or who may be offended by viewing such material.\n\n3. That you are familiar with your local community standards and that the sexually-explicit materials which you have chosen to view and/or download from this Website are well within the contemporary community standards of acceptance and tolerance of your community for sexually-explicit materials of that nature.\n\n4. That you understand that many of the events and situations described and depicted herein are fictional, and that all models have been paid in full and knowingly participated in these fictional acts.\n\nIf all of these conditions apply to you, you are given permission to enter . If any of these conditions do not apply to you, you are not given permission to enter and view the contents of this Website and you should now leave.\n\nThese web pages are not intended to be viewed by minors.</textarea><div style="margin-left:25px; margin-top:10px; width:450px; font-size:11px; text-align:left;">By clicking below you indicate your acceptance and understanding of the above terms and conditions.<br/><br/>I hereby affirm, under the penalties of perjury pursuant to 28 U.S.C. § 1746, that I am of legal age to enter this website. Submitting a false declaration under penalties of perjury is a criminal offense. This transaction constitutes a sworn declaration under federal law, and is governed by the electronic signatures in Global & National Commerce Act. (E-SIGN ACT), 15 U.S.C. §7000, ET SEQ.<br/><table cellpadding="2" cellspacing="5"><tr><td style="text-align:left; font-size:14px;">Enter Your Age:</td><td style="text-align:center"><select id="age">'+selectOptions+'</select></td><td style="padding-left:5px;"><button id="enterBTN">ENTER</button></td><td style="color:red; font-size:14px;" id="errMsg"></td></tr></table><br/><span style="float:left"><button id="leaveBTN">I WANT TO LEAVE</button></span></div></div>');
		$(".clearDefault").select(function(){$(this).attr('value', ""); $(this).focus();});
		$("#enterBTN").click(function(){validateAge($("#age").attr('value'))});
		$("#leaveBTN").click(function(){$(window).attr('location', "http://www.google.com");});
	}
	if($.cookie('fuckordate')){
		$.cookie("fuckordate", "1", {expires:1000000});
	}
}
