

var loadGalleries = function() {
	var images = [
		['pieces/','1.jpg','2.jpg','3.jpg','4.jpg','5.jpg','6.jpg','7.jpg','8.jpg','9.jpg','10.jpg','12.jpg','13.jpg','14.jpg','15.jpg'],/* Pieces*/
		['rancho/','1.jpg','3.jpg','4.jpg','5.jpg','6.jpg','7.jpg','8.jpg','9.jpg','10.jpg','11.jpg','12.jpg','13.jpg'],/* Rancho*/
		['grant/','1---GCR.jpg','2---GCR.jpg','3A---GCR.jpg','3B---GCR.jpg','4---GCR.jpg','5---GCR.jpg','6---GCR.jpg','7---GCR.jpg']/* Grant*/
	]
	

	
	$(images).each(function(i,img) {
		var thisSection = $('.galleries.rightpanel #gallerysection:eq('+i+') .rightpane');
		var imgarr = images[i];
		
		$(thisSection).append('<ul></ul>');
		var thisUL = $(thisSection).find('ul');
		var currentDir = null;
		$(imgarr).each(function(idx) {
			if(idx==0) {
				currentDir = imgarr[idx];	
			}else{
				$(thisUL).append('<li><div class="thumb"><a class="single_image" href="images/gallery/'+currentDir+imgarr[idx]+'"><img src="images/gallery/'+currentDir+imgarr[idx]+'" /></a></div></li>');
				var thisImg = $(thisUL).find('li:last div a img');
				$(thisImg).imgscale({parent:'.thumb'});			
			}
		});
	});
	$(".single_image").fancybox();
	$(".single_image").fancybox({
		'transitionIn'	:	'fade',
		'transitionOut'	:	'fade',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	true,
		'modal'         :   false,
		'cyclic'        :   true
	});		
}

var isEmailValid = function(e) {
	var mpattern = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
	return mpattern.test(e);
};

$(document).ready(function() {
	if($('.galleries').length > 0) {						   
		loadGalleries();				
	}
	
	$('#emailme').keyup(function(e) {
		if (e.keyCode == '13') { //Enter Key KeyCode
			e.preventDefault();
			var email = $('#emailme').val();
			if(!isEmailValid(email)) {
				alert('Email address is invalid, please re-enter a valid email address.');
				return false;
			}
			
			$.post('poster.php',{'imail':email}, function(retval) {
				$('#emailme').remove(); 
				$('.contact.emailbox').css({'background-image': 'none' });
				$('.contact.emailbox').append('<h3 style="color:#fff; text-align:right">Thank You</h3>');
			});
		}
	});	
});				  
