$(document).ready(function(){

$('.newsletter input').click(function(){
		$(this).attr('value', '');
		$('.no-Email').hide('slow');
		
	});
$('.nav_item').mouseover(function(){
	$(this).children('.sub-nav').show();

	

}).mouseout(function(){
    $(this).children('.sub-nav').hide();
});

 $('.gallery-home-children').mouseover(function(){
	if($(this).children('.slider_lid').width() < 480 ){return false;}
	else{
	$(this).children('.slider_lid').animate({
			   width: '0px',
			}, 500, function() {});
}});
$('.gallery-home-children').mouseleave(function(){
$(this).children('.slider_lid').animate({
			   width: '480px',
			}, 500, function() {});
});

$('#newsletterForm').submit(function(){
if($(this).children('.email').val().length < 5){
if($(this).children('.no-Email').length == 1){return false;}
else{
$(this).append('<div class="no-Email">The Email you have entered seems to be wrong please try again</div>');
return false;
}
}

});



//GALLERY JS
var GalleryList = $('.Gallery-content ul');
var width = GalleryList.children().length * 770;
GalleryList.children().each(function(){
var img = $(this).children();
if(img.height() < 390) {
var padding = 390 - img.height();
padding = padding / 2;
 
}
});
GalleryList.width(width); 
var firstChild = GalleryList.children('li').first();
if(firstChild.width() < 770){$('.Caroseloverflow').css('width', firstChild.width());}
$('.prev').bind('click', function(){CustomCarosel('left');});
$('.next').bind('click', function(){CustomCarosel('right');});
});

function CustomCarosel(Direction){
var GalleryList = $('.Gallery-content ul');
var firstChild = GalleryList.children('li').first();
var lastChild = GalleryList.children('li').last();

if(Direction == 'left'){
var Clone = firstChild.clone(true);
var height = $(firstChild).children('img').height();
$(firstChild).children('img').css('height', height);
	$(firstChild).children('img').animate({
			   width: '0px',
			}, 1000, function() {
			$(GalleryList).append(Clone);
			
			firstChild.remove();
	});
}
else{
var height = $(lastChild).children('img').height();
var width = $(lastChild).children('img').width();
$(lastChild).children('img').css('width', '0px');
$(lastChild).children('img').css('height', height);
var Clone = lastChild.clone(true);
$(lastChild).css('width', '0px');
$(GalleryList).prepend(Clone);
$(Clone).children('img').animate({width: width,
			}, 1000, function() {
		
			lastChild.remove();});


}}


