﻿var colors = ['#00fffc', '#ff00de', '#ff0000', '#b400ff', '#30ff00', '#fffc00', '#00ccff'];
var i;
var prevC;
var errorVisible = false;
function GetColor() {
    var x = parseInt(Math.random() * 7);
    while (prevC == x) {
        x = parseInt(Math.random() * 7);
    }
    prevC = x;
    return x;
}
function SetColor() {
    var color = colors[GetColor()];
    $('#logo').animate({ backgroundColor: color }, 1500);
}


function HideAll() {
    $('#message').animate({ marginTop: '-36px' }, function() {
        $('#message').text('');
        $('#emailInput').fadeOut(function() {
            $('#email').val('');
            $('#text').fadeIn();
            errorVisible = false;
            $('#email').css('color', 'Black')
        });
    });
}






$(document).ready(function(){
    var color = colors[GetColor()];
    $('#logo').css({ backgroundColor: color });
    i = setInterval('SetColor()', 3000);
    $('#logo').click(function() {
        if ($('#text:visible').length) {
            $('#text').fadeOut('normal', function() {
                $('#emailInput').fadeIn();
                //$('#email').select().focus();
            });
        }
        else {
            $('#emailInput').fadeOut('normal', function() {
                $('#text').fadeIn();
            });
        }
    });
$("#email").defaultvalue("Enter your email and hit ENTER");

						   
						   
						   
						   
						   
						   
// Ajax form						   
$("#ajax-contact-form").submit(function(){
	var str = $(this).serialize();
	
	   $.ajax({
	   type: "POST",
	   url: "contact.php",
	   data: str,
	   success: function(msg){
		
				$("#message").ajaxComplete(function(event, request, settings){
				
					if(msg == 'OK') // Message Sent? Show the 'Thank You' message and hide the form
						{
							$('#email').css('color','Gray').blur();
							$('#message').text("Successfully sent, Thank You!").css('color', 'Green').animate({ marginTop: '10px' }, function() {
								$('#message').animate({ marginTop: '2px' });
								errorVisible = true;
							});
							setTimeout('HideAll()', 4000);
						}
						else
						{
							result = msg;
							$('#message').text(result).css('color', 'Red').animate({ marginTop: '10px' }, function() {
								$('#message').animate({ marginTop: '2px' });
								errorVisible = true;
							});
						}
		
				//$(this).html(result);
		
			});
	
		}
	
	 });
	
	return false;
	
	});

});
