// JavaScript Document

var numImages = 0;
var currentImage = 1;
var imgWidth = 840;
var startX = -(imgWidth*2);
var slideSpeed = 1500;

function changeImage() {
	
	var first = jQuery('.banner_imgs .img_' + currentImage);
	var second = jQuery('.banner_imgs .img_' + (currentImage+1));
	var third = jQuery('.banner_imgs .img_' + (currentImage+2));
	
	third.animate({'left': '+=' + imgWidth + 'px'}, slideSpeed); 
	second.animate({'left': '+=' + imgWidth + 'px'}, slideSpeed); 
	first.animate({'left': '+=' + imgWidth + 'px'}, slideSpeed, function() {
																	jQuery('.banner_imgs').prepend( third );
																	third.attr('style', 'left: -840px');
																	third.attr('class', 'img_2');
																	second.attr('class', 'img_1');
																	first.attr('class', 'img_3');
															   }); 
	
}

function validateEmail(email) { 
	var re = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/ ;
	return email.match(re) 
}


function switchBlock() {
	email = jQuery('#txtEmail').attr('value');
	if (email != 'e-mail' && validateEmail(email)) {
		jQuery('#txtEmail').css('border', '1px solid #DEDEDE');
		jQuery('.form-block').animate({'left': '-=' + 130}, 300);
	} else {
		jQuery('#txtEmail').css('border', '1px solid #CC0000');
	}
}

function sendMail() {
	name = jQuery('#txtName').attr('value');
	surname = jQuery('#txtSurname').attr('value');
	if ((name != '' && name != 'nome') && (surname != '' && surname != 'cognome')) {
		jQuery('#txtName').css('border', '1px solid #DEDEDE');
		jQuery('#txtSurname').css('border', '1px solid #DEDEDE');
		document.frmNewsletter.submit();
	} else {
		jQuery('#txtName').css('border', '1px solid #CC0000');
		jQuery('#txtSurname').css('border', '1px solid #CC0000');
	}
}

jQuery(document).ready(function(){
	
	numImages = jQuery('.flash .banner_imgs li').size();
	window.setInterval("changeImage();", 3000);
	
	jQuery('#headline').delay(2500).fadeOut(800);
	
	jQuery('#blue_box').click(function() {
		if (jQuery(this).hasClass('closed')) {
			jQuery(this).animate({'left': -10}, 800);
			jQuery('p', this).animate({'margin-left': 32}, 800);
			jQuery(this).attr('class', 'opened');
		} else {
			jQuery(this).animate({'left': -190}, 800);
			jQuery('p', this).animate({'margin-left': 0}, 800);
			jQuery(this).attr('class', 'closed');
		}
	});
	
	var value1 = jQuery('#txtEmail').val();
	var value1_static = jQuery('#txtEmail').val();
	
	jQuery('#txtEmail').focus(function() {
		value1 = jQuery(this).val();
		if (value1 != value1_static) {
			jQuery(this).val(value1);
		} else {
			jQuery(this).val('');
		}
	});
	jQuery('#txtEmail').blur(function() {
		if(jQuery(this).val() == '') {
			jQuery(this).val(value1_static);
		}
	});
	
	var value2 = jQuery('#txtName').val();
	var value2_static = jQuery('#txtName').val();
	
	jQuery('#txtName').focus(function() {
		value2 = jQuery(this).val();
		if (value2 != value2_static) {
			jQuery(this).val(value2);
		} else {
			jQuery(this).val('');
		}
	});
	jQuery('#txtName').blur(function() {
		if(jQuery(this).val() == '') {
			jQuery(this).val(value2_static);
		}
	});
	
	var value3 = jQuery('#txtSurname').val();
	var value3_static = jQuery('#txtSurname').val();
	
	jQuery('#txtSurname').focus(function() {
		value3 = jQuery(this).val();
		if (value3 != value3_static) {
			jQuery(this).val(value3);
		} else {
			jQuery(this).val('');
		}
	});
	jQuery('#txtSurname').blur(function() {
		if(jQuery(this).val() == '') {
			jQuery(this).val(value3_static);
		}
	});

});

	

