function count_down() {
	
	var launchDate = new Date(2012, 5, 6, 0, 0, 0); 
	//year, month-1, day, hour, min, sec - exemple: 2011,0,1,0,0,0 for 1st January 2011 0 hours 0 minutes 0 seconds
	
	$('#count-down').countdown({until: launchDate, 
	layout: 
		'<div class="image{d100}"></div><div class="image{d10}"></div><div class="image{d1}"></div>' + 
        '<div class="space"></div>' + 
        '<div class="image{h10}"></div><div class="image{h1}"></div>' + 
        '<div class="space"></div>' + 
        '<div class="image{m10}"></div><div class="image{m1}"></div>' + 
        '<div class="space"></div>' + 
        '<div class="image{s10}"></div><div class="image{s1}"></div>' +
		'<div class="label label-1 label-d{d100}{d10}{d1}">{dl}</div>' +
		'<div class="label label-2 label-h{h10}{h1}">{hl}</div>' +
		'<div class="label label-3 label-m{m10}{m1}">{ml}</div>' +
		'<div class="label label-4 label-s{s10}{s1}">{sl}</div>'});
}

var pageXold = 0;
var fadedIn = 0;

$(window).unload(function() {
	$(this).children('.tool-tip').hide();
	$(this).children('.tool-tip-right').hide();
});

function tool_tips() {
	$('.show-tool-tip').each(function(){
		$(this).append('<div class="tool-tip">' + $(this).attr('title') + '</div><div class="tool-tip-right"></div>');
	});
	$('.show-tool-tip').mouseover(function(e) {
		pageXold = e.pageX;
		$(this).attr('title','');
		$(this).children('img').attr('alt', '');
		$(this).children('.tool-tip').css('top', e.pageY - $(this).offset().top + $(this).position().top + 25 );
		$(this).children('.tool-tip').css('left', e.pageX - $(this).offset().left + $(this).position().left - 5);
		$(this).children('.tool-tip-right').css('top', e.pageY - $(this).offset().top + $(this).position().top + 25 );
		$(this).children('.tool-tip-right').css('left', e.pageX - $(this).offset().left + $(this).position().left - 5 + $(this).children('.tool-tip').width() + 15);
		$(this).children('.tool-tip').fadeIn('300', function(){
			fadedIn = 1;
			if (! $.support.opacity) {
				this.style.removeAttribute('filter');
			}
		});
		$(this).children('.tool-tip-right').fadeIn('300');
	}).mousemove(function(e) {
		if (((e.pageX - pageXold) > 0) && (fadedIn)) {
			$(this).children('.tool-tip-right').css({display: 'none'});
		}
		pageXold = e.pageX;
		$(this).children('.tool-tip').css('top', e.pageY - $(this).offset().top + $(this).position().top + 25 );
		$(this).children('.tool-tip-right').css('top', e.pageY - $(this).offset().top + $(this).position().top + 25 );
		$(this).children('.tool-tip-right').css('left', e.pageX - $(this).offset().left + $(this).position().left - 5 + $(this).children('.tool-tip').width() + 15);
		$(this).children('.tool-tip').css('left', e.pageX - $(this).offset().left + $(this).position().left - 5);
		if (fadedIn) {
			$(this).children('.tool-tip-right').css({display: 'block'});
		}
	}).mouseout(function() {
		$(this).attr('title', $(this).children('.tool-tip').html());
		$(this).children('.tool-tip').stop(true, true).hide();
		$(this).children('.tool-tip-right').stop(true, true).hide();
		fadedIn = 0;
	}).click(function() {
		$(this).attr('title', $(this).children('.tool-tip').html());
		$(this).children('.tool-tip').stop(true, true).hide();
		$(this).children('.tool-tip-right').stop(true, true).hide();
		fadedIn = 0;
	});
}

var timer = 0;
var time_change_color = 0;

function change_color_input() {
	time_change_color++;
	switch (time_change_color) {
		case 1: $('#email').css({color: '#d00000'}); break;
		case 2: $('#email').css({color: '#b00'}); break;
		case 3: $('#email').css({color: '#a00'}); break;
		case 4: $('#email').css({color: '#900'}); break;
		case 5: $('#email').css({color: '#800'}); break;
		case 6: $('#email').css({color: '#700'}); break;
		case 7: $('#email').css({color: '#660505'}); break;
		case 8: $('#email').css({color: '#550505'}); break;
		case 9: $('#email').css({color: '#411'}); break;
		case 10: $('#email').css({color: '#311'}); break;
		case 11: $('#email').css({color: '#211'}); break;
		case 12: $('#email').css({color: '#111'}); clearInterval(timer); time_change_color = 0; break;
	}
}

function contact() {

	function isValidMail(mail) {
		var pattern = new RegExp(/^[a-zA-Z0-9_\.\-]+\@([a-zA-Z0-9\-]+\.)+[a-zA-Z0-9]{2,4}$/i);
		return pattern.test(mail);
	}	
		
	var s1 = $('#email').attr('value');
	var s2 = 'Enter your e-mail.';
	var s3 = 'Your e-mail is not valid.';
	var s4 = 'Enter another one?';
	
	$('#email').val(s1);
	
	$('#email').focus(function() {
		var email = $('#email').val();
		if ((email == s1) || (email == s2) || (email == s3) || (email == s4)) {
			$('#email').val('');
		}
	});
	
	$('#email').blur(function() {
		if ($('#email').val() == '') {
			$('#email').val(s2);
		}
	});

	function submit() {
		
		clearInterval(timer); 
		time_change_color = 0;
		$('p.submit input').blur();
		$('#email').css({color: '#111'});
		var email = $('#email').val();
		if ((email == '') || (email == s1) || (email == s2) || (email == s4)) {
			$('#email').val(s2);
		} else if (isValidMail(email)) {
			$('#ajax-loader').css({display: 'block'});
			$.ajax({
				url: 'send-mail.php',
				type: 'post',
				data: 'email=' + email,
				success: function(msg){
					$('#ajax-loader').css({display: 'none'});
					if ((msg.indexOf('OK') != -1) && (msg.indexOf('echo') == -1)) {					
						$('#info-box-ok ').fadeIn(function() {
							if (! $.support.opacity) {
								this.style.removeAttribute('filter');
							}
						});
						setTimeout(function() {
							$('#info-box-ok ').fadeOut();
							$('#email').val(s4);
						}, 8000);
					} else {
						$('#info-box-ko').fadeIn(function() {
							if (! $.support.opacity) {
								this.style.removeAttribute('filter');
							}
						});
						setTimeout(function() {
							$('#info-box-ko').fadeOut();
						}, 8000);
					}
				},
				error: function() {
					$('#ajax-loader').css({display: 'none'});
					$('#info-box-ko').fadeIn(function() {
						if (! $.support.opacity) {
							this.style.removeAttribute('filter');
						}
					});
					setTimeout(function() {
						$('#info-box-ko').fadeOut();
					}, 8000);
				}
			});
		} else {
			$('#email').val(s3);
			$('#email').css({color: '#e00'});
			timer = setInterval('change_color_input()', 250);
		}
	}
	
	$('#register-form').submit(function() {
		submit();
		return false;
	});
}
