$(document).ready(function()
{
	$('#menu').hover(
		function() {
			$('#menu ul').removeClass('hidden');
		},
		function() {
			$('#menu ul').addClass('hidden');
		}
	);
	
	$('#sidenav a, #download_link').click(function() {
		var id = $(this).attr('href');
		var offset = $(id).offset().top - 20;
		$('html, body').animate( {scrollTop: offset} );
		return false;
	});
	
	// individual lightboxes
	$('#content a').each(function() {
		if($(this).attr('rel') == 'lightbox') {
			$(this).lightBox();
		}
	});
	
	// lightbox groups
	$('#content a.lightbox').lightBox({fixedNavigation: true});
});


function sendDownloadRequest(project) 
{
	if ($('#email').val() && $('#code').val()) {
		$('#download_response').html('');
		$('#download_indicator').show();
		$.post('http://www.putyourlightson.net/projects/'+project, { email: $('#email').val(), code: $('#code').val() }, 
			function(data) {
				$('#download_indicator').hide();
				$('#download_response').show();
				if (data == "denied") {
					$('#download_response').html('Incorrect email address or code');
					return false;
				}
				else {
					$('#download_response').html('Your download will begin shortly...');
					$('#download_form').submit();
				}
			}
		);
	}
}


function sendLoginRequest() 
{
	$('#login_response').html('');
	$('#login_indicator').show();
	$.post('http://www.putyourlightson.net/login/', { secret: $('#secret').val() }, 
		function(data) {
			$('#login_indicator').hide();
			if (data == "denied") {
				$('#login_response').html('Access denied');
				return false;
			}
			else {
				$('#login_response').html('Thanks, redirecting you now...');
				window.location = 'http://www.putyourlightson.net/'+data;
			}
		}
	);
}

function sendCommentRequest(project) 
{
	$('#comment_response').html('');
	$('#comment_indicator').show();
	$.post('http://www.putyourlightson.net/comment/add/'+project, $('#comment_form').serialize(), 
		function(data) {
			$('#comment_indicator').hide();
			$('#download_response').show();
			if (data == "success") {
				$('#comment_response').html('Your comment was successfully submitted <br/>');
				$('submit').hide();
			}
			else {
				$('#comment_response').html('Please complete all of the fields above and try again');
			}
		}
	);
}

