$(function() {

	var $parent = $('#menu-item-79'),
		 $child = $parent.children().next(),
		 $h2 = $('.title-porn h2');
		 $child.hide();
	var ofAge, nextyear;

	$parent.hover(function(event) {
		$child.stop(true,true).fadeIn('fast');
	}, function() {
		$child.stop(true,true).fadeOut('slow');
	});

	$h2.click(function(event) {
		return false;
	});

	$.ajax({
		url: "https://graph.facebook.com/taboolicious/feed&limit=3?access_token=265665023446663|rfYkgBG6uiNfu88LWmHwuDkylCI",
		type: "GET",
		data: {},
		success: function(ret) {
			var i, obj, appendItem;
			for (i in ret.data) {
				obj = ret.data[i];
				var pic = (typeof(obj.picture) !== 'undefined') ? '<img height="100px" src="' + obj.picture + '" />' : '';
				var anchor = (typeof(obj.link) !== 'undefined') ? '<a href="' + obj.link + '">' : '';
				if (anchor !== '') {
					anchor += (pic !== '') ? pic + "</a>" : "Link</a>";
				}
				appendItem='<ul>\
									<li id="fb-item">\ ' + anchor + '\ <div id="fb-message">' + obj.message + '</div>\</li>\
								</ul>';
				$("#facebook-feed").append(appendItem);
			}
		},
		dataType: 'jsonp',
		error: function() {
			$("#facebook-feed").append("<p>Facebook feed not available</p>");
		}
	});

	$('.kjo-link p').hide();

	$('#submit').click(function () {
		$('.error').hide();
		var hasError = false;
		var nameVal = $('#name').val();
		var emailReg = /^(\w|\.|-)+?@(\w|-)+?\.\w{2,4}($|\.\w{2,4})$/gim;
		var emailVal = $('#email').val();
		var commentVal = $('#comment').val();
		var botVal = $('#bot').val();
		var inputVal = $('.input');
		if (nameVal == '') 
		{
			$('#name').after('<span class="error">Please enter your name.</span>').parent().addClass('highlight');
			hasError = true;
		} else {
		 	$('#name').parent().removeClass('highlight');
		}
		if (emailVal == '')
		{
			$('#email').after('<span class="error">Please enter your email address.</span>').parent().addClass('highlight');
			hasError = true;
		} else if (!emailReg.test(emailVal)) {
			$('#email').after('<span class="error">Please enter a valid email address.</span>').parent().addClass('highlight');
			hasError = true;
		} else {
		 	$('#email').parent().removeClass('highlight');
		}
		if (commentVal == '')
		{		
			$('#comment').after('<span class="error">Please leave a comment.</span>').parent().addClass('highlight');
			hasError = true;
		} else {
		 	$('#comment').parent().removeClass('highlight');
		}
		if (botVal !== '') 
		{
			$('#bot').after('<span class="error">Your a bot, suck it.</span>').parent().addClass('highlight');
			hasError = true;
		}
		if (hasError == true) {
			$('#error').show();
		} else {
			$('#error').hide();
		}
		 if (hasError == false) {
			var dataString = $('#form').serialize();
			$('#submit').attr('disabled','true');
			$('#loading').show();
			$.ajax({
				url: 'http://www.taboolicious.com/wp-content/themes/taboo/mailer.php',
				type: 'GET',
				data: dataString,
				cache: false,
				success: function (data, jqXHR, textStatus) {
					$('form#form').fadeOut(2000);
					$('#confirm').fadeIn(4000);
				},
				error: function(jqXHR, errorThrown, textStatus) {
					$('form#form').fadeOut('fast');
					$('#problem').fadeIn(4000);
				}
			});
		}
		return false;
	});

	$("#twitter-feed").tweet({
		username: "TabooRVA",
		join_text: "auto",
		avatar_size: 48,
		count: 4,
		auto_join_text_default: "",
		auto_join_text_ed: "",
		auto_join_text_ing: "",
		auto_join_text_reply: "",
		auto_join_text_url: "",
		loading_text: "We're loading our tweets, please be patient. :)"
	});

	function verifyAge() {
		//This is what we want to ask the user.
		//Limited formatting is possible with underscores and newlines.
		var message = "______________________________________\n\n" +
						  "You must be of legal age in your state\n" +
						  "to view the content of this website.\n" +
						  "______________________________________\n\n" +
						  "By clicking Ok you agree to the laws as\n" +
						  "put forth by your state";

		//Ask for confirmation, if Ok continue to site.
		//Else redirect the user to net nanny.
		if(!confirm(message)) {
			window.location.href = "http://www.netnanny.com/";
		} else {
			$.cookie('legalage', 'ofage', { expires : 365, path : '/', domain : 'taboolicious.com' });
			return;
		}
	}

	if ($.cookie('legalage') == null) {
		verifyAge();
	} else {
		return;
	}

});
