
function imageCount(){
	var imageCount = $('input[name=images]:checked').size();
	$('#imageCount').text(imageCount);
}

function requestImages(){
    var images = $('input[name=images]').serialize(),
		images = images.replace(/&/g, ","),
		images = images.replace(/images=/g, ""),
		images = images.replace(/-/g, "_"),
		name = $('#name').val(),
		email = $('#email').val(),
		telephone = $('#telephone').val(),
		gallery = $('#gallery').val(),
		username = $('#username').val();
		
		if($('#message').val() != ''){
			message = $('#message').val();
		}else{
			message = 'Nothing';
		}

	if (images != ""){
		$('.loading').fadeIn();
		$.ajax({
			type: "POST",
			url: '/contact.php?cmd=imagerequest&images='+images+'&name='+name+'&username='+username+'&email='+email+'&telephone='+telephone+'&gallery='+gallery+'&message='+message,
			success: function(){
				$('.loading').fadeOut();
				$('.drag .section').slideUp('fast', function(){
					$(this).html('<h3 class="title">Request complete!</h3><p>Thank you '+name+', Your request has been sent and a confirmation email is on its way to you at '+email+'</p>');
					$(this).slideDown('fast');
				});
			}
		});
	}else{
		alert('Please select your images first');
	}
}


function dragBox(){
	var topPadding = 5,
		offset = $(".drag").offset(),
		dragBox = $('.drag').outerHeight();
	
	if (top > offset.top) {
		$(".drag").stop().animate({
				marginTop: top - offset.top + topPadding
			}, { duration: 400, easing: 'easeInOutSine'});
	}
	
	$(window).scroll(function() {
	var top = $(window).scrollTop(),
		margin = parseInt($(".drag").css("margin-top"),10);
			
		if (top > offset.top) {
		$(".drag").stop().animate({
				marginTop: top - offset.top + topPadding
			}, { duration: 400, easing: 'swing'});
		} else if (top < offset.top) {
			$(".drag").stop().animate({
				marginTop: 0
			}, { duration: 400, easing: 'swing'});
		}
	});
}

$(function(){
	$('input[type=text], input[type=password]').addClass('text');
});
