$( function() {
	$(".gallery-images li img").css({opacity:.65});
	$(".gallery-images ul li a").lightBox();		
	$(".gallery-images li").bind("mouseover", imageAnimate);
	
	$('#btnsubmit button').click(function(){
		submitUpdateInfo();
		return false;
	});
});

imageAnimate = function(e){
	$('.gallery-active-image').remove();

	var increase = 10;
	var el = $(this);
	var w = el.width();
	var h = el.height();
	var c = el.clone(true).unbind('mouseover').addClass('gallery-active-image');
	var o = el.offset();

	c
	.css({position:'absolute',cursor:'pointer',zIndex:500,width:w,height:h,left:o.left,top:o.top})
	.bind('mouseout',function(){
		$(this).stop().remove();
	});

	$('body').append(c);
	c.find('img').css({position:'absolute'}).animate({opacity:1,left:-1*(increase/2),top:-1*(increase/2),width:w+increase,height:h+increase},250);
}

submitUpdateInfo = function(){
	
	var parts = $('#textarea1').val().split(/\s/);
	var firstname = parts[0] || '';
	var lastname = parts[1] || '';
	var email = $('#textarea2').val();
	var error = false;
	
	$('#textarea1,#textarea2').removeClass('error');
	
	if(!email.match(/^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/i)){
		$('#textarea2').addClass('error');
		error = true;
	}
	if(firstname == '' || lastname == ''){
		$('#textarea1').addClass('error');
		error = true;
	}
	
	if(error) return;

	var params = 'contact-submit=updates_only&first-name='+firstname+'&last-name='+lastname+'&email='+email;
	
	$.ajax({
		type	: "POST",
		url		: "/contact-us/index.php",
		dataType: 'text',
		async	: false,
		data	: params,
		success: function(content){
			if(content == 'SUCCESS'){
				var html = $('#share_info>form').html();
				$('#share_info>form').html('<span class="thanks">Thank you for your interest in Alexan Carlyle.</span>');	
				setTimeout(function(){
					$('#share_info>form').html(html);
				},5000);
			}
		}
	});			
}

