$(function () {	
	$('a.confContrubitorLink').fancyZoom();
	
	$('a.confContrubitorLink').hover(function () {
		$(this).children('img').animate({'opacity' : 0.7});
	}, function () {
		$(this).children('img').animate({'opacity' : 1});
	});
	
	//LOG IN FORM
	$('a.invite').click(function (e) {
		e.preventDefault();
		
		var confDetails = $(this).parent().parent().prev().children('.confEntryDetails'),
			city = confDetails.children('h1').text(),
			date = confDetails.children('h3.no_margin').text(),
			time = confDetails.children('h3:last').text(),
			confAddress = $(this).parent().parent().prev().children('.confEntryAddress'),
			address = confAddress.children("p:first").html(),
			entryid = $(this).parent().parent().next('.hiddenInfo').text(),
			id = $(this).attr('href'),
			maskHeight = $(document).height(),
			maskWidth = $(window).width(),
			winH = $(window).height(),
			winW = $(window).width();
			
		$('#inviteEntryID').val(entryid);

		$('#inviteConferenceInfo').html(city + "<br />" + date + "<br />" + time + "<br /><br />" + address + "<br /><br />");		
		
		$('#mask').css({'width': maskWidth, 'height': maskHeight});		
		$('#mask').fadeIn(1000).fadeTo("slow", 0.5);	
		
		$(id).css('top',  winH / 2 - $(id).height() / 2);
		$(id).css('left', winW / 2 - $(id).width() / 2);
		$(id).fadeIn(2000); 
	});
	
	$('a.invitationImageSelect').click(function (e) {
		e.preventDefault();
		
		var img = $(this).next('img'),
			imgSrc = img.attr("src");
		
		$('a.invitationImageSelect').fadeTo('fast', 1);
		$(this).fadeTo('fast', 0.5);
		
		$("#inviteImage").html("<img src='" + imgSrc + "' width='350' height='197' alt='Invite image' />");
		$("#inviteImageSrc").val(imgSrc);
	});
	
	$('.window .close').click(function (e) {
		e.preventDefault();
		$('#mask').fadeOut(600);
		$('.window').fadeOut(300);
	});
			
	$('#mask').click(function () {
		$(this).fadeOut(600);
		$('.window').fadeOut(300);
	});		
	
	//INVITE FORM

	$('#friendName').keyup(function () {
		var name = $(this).val();
		$('#inviteLiveName').text(name);
	});
	
	$('#inviteMessage').keyup(function () {
		var message = $(this).val();
		$('#inviteLiveMessage').text(message);
	});
	
	$('#inviteForm').validate({
		rules: {
			friendName: {
				required: true,
				minlength: 2
			},
			friendEmail: {
				required: true,
				minlength: 5
			},
			yourName: {
				required: true,
				minlength: 2
			}
		},
		messages: {
			friendName: {
				required: "Please enter your friends full name",
				minlength: "Please enter more than 2 letters"
			},
			friendEmail: {
				required: "Please enter an email address",
				minlength: "Please enter more than 5 characters",
				email: "Please enter a valid email address"
			},
			yourName: {
				required: "Please enter your full name",
				minlength: "Please enter more than 2 characters"
			}
		},
		submitHandler: function () {
			$('#inviteForm').ajaxSubmit({
				url: 'http://everythingconference.org/scripts/inviteProcess.php',
				success: function (responseText, statusText, xhr) {
					$('inviteImageSrc').val("");
                    $('#result').html("<h3 class='warningColour'>" + responseText + "</h3>").fadeOut(4000);
				}
			});
        }
    });	
});

function showRequest(formData, jqForm, options) { 
	var queryString = $.param(formData);
	console.log('Submitting: ' + queryString);
	return true;
}
