$(document).ready(function() {
	
	//Contact Captcha
	$('#windows').draggable({
		'stop': function() {
			check_placement();
		}
	});
	
	//Submit Buttons
	$('.contact-button').click(function() {
		submit_contact_form();
	});
	
});

function check_placement() {
	
	var trash = {
		'height': parseInt($('#trash').height().toString().replace('px','')),
		'width':  parseInt($('#trash').width().toString().replace('px','')),
		'top':    parseInt($('#trash').css('top').toString().replace('px','')),
		'left':   parseInt($('#trash').css('position','absolute').css('left').toString().replace('px',''))
	}
	var windows = {
		'height': parseInt($('#windows').height().toString().replace('px','')),
		'width':  parseInt($('#windows').width().toString().replace('px','')),
		'top':    parseInt($('#windows').css('top').toString().replace('px','')),
		'left':   parseInt($('#windows').css('left').toString().replace('px',''))
	}

	if(
	
		windows.top < trash.height && windows.top+windows.height > trash.top 
		&& windows.left+windows.width > trash.left && windows.left < trash.left+trash.width
		
	) {
	
		$('#windows').animate({top: trash.top, left: trash.left}, 500, function() {
			
			$(this).remove();
			$('#trash').attr('src','images/captcha/1265847112_Recylebin_full.png');
			document.forms[0].action = "contact.php";
			
		});
	
	}

}

var trash_full = new Image();
trash_full.src = 'images/captcha/1265847112_Recylebin_full.png';

function submit_contact_form() {
	var form = document.getElementById('contact-form');
	var rtn = true;
	if( form.name.value.trim() == "" ) {
		$(form.name).css('background-color','red');
		rtn = false;
	}
	else {
		$(form.name).css('background-color','#F3F3F3');
	}
	if( form.email.value.trim() == "" ) {
		$(form.email).css('background-color','red');
		rtn = false;
	}
	else {
		$(form.email).css('background-color','#F3F3F3');
	}
	if( form.message.value.trim() == "" ) {
		$(form.message).css('background-color','red');
		rtn = false;
	}
	else {
		$(form.message).css('background-color','#F3F3F3');
	}
	if( rtn )
	form.submit();
	return false;

}

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
