var isIE    = !!(navigator.userAgent.toLowerCase().indexOf('msie') >= 0 && document.all);
var isOpera = !!(window.opera && document.getElementById);
var isMoz   = (!isIE && !isOpera);
var ini_top;
var zIndex = 50;
var $j = jQuery.noConflict();

function showme(id) {
    id = '#' + id;

    if ($j(id).css('position') != 'absolute') {
        $j(id).css('position', 'absolute');
        $j(id).css('left', 0);
        $j(id).css('top', $j('#fakeBody').get(0).offsetHeight + 2 + 'px');
        ini_top = $j('#fakeBody').get(0).offsetHeight + 2;
    }

    if (parseInt($j(id).css('height')) > 1){
        new_height = 1;
        new_top = ini_top;
    }else{
        $j(id).css('z-index', ++zIndex);
        new_height = $j(id + ' > .content').get(0).offsetHeight;
        if (!isMoz) new_height += 35;
        new_top = parseInt($j(id).css('top')) - new_height;
    }

    $j(id).animate(
        {height: new_height + 'px', top: new_top + 'px'},
        1000
    );

}

function down(id){
    id = '#' + id;
    $j(id).animate
    (
        {height: '0px', top: ini_top + 'px'},
        1000
    );
}
function restoreContact() {
	$j('#contact_div_dyamic').fadeOut("slow");
	$j('#contact_form').fadeIn(1500);
	//$j('#submit_button').attr("disabled", "false");
	//document.getElementById("submit_button").disabled = true;
}
$j(document).ready(function () {
    $j('.error').hide();
	$j('.input-txt').css({backgroundColor:"#000"});
	$j('.input-txt').focus(function(){
		$j(this).css({backgroundColor:"#ffff00", color:"#000"});
	});
	$j('.input-txt').blur(function(){
		$j(this).css({backgroundColor:"#000", color:"#ffff00"});
		$j("label#name_error").fadeOut("slow");
		$j("label#email_error").fadeOut("slow");
		$j("label#details_error").fadeOut("slow");
		$j("label#captcha_error").fadeOut("slow");
	});

	$j("input#submit_button").click(function() {
	    $j('.error').hide();
		var name = $j("input#name").val();
		if (name == "") {
			//$j("label#name_error").show();
			$j("label#name_error").fadeIn("slow");
			$j("input#name").focus();
			return false;
		}
		var email = $j("input#email").val();
		if (email == "") {
			$j("label#email_error").show();
			$j("input#email").focus();
			return false;
		} else {
			if( !IsEmail(email) ) {
				$j("label#email_error").show();
				$j("input#email").focus();
				return false;
			}
		}
		
		var details = $j("textarea#details").val();
		if (details == "") {
			$j("label#details_error").show();
			$j("textarea#details").focus();
			return false;
		}
		var captcha = $j("input#captcha").val();
		if (captcha == "") {
			$j("label#captcha_error").fadeIn("slow");
			$j("input#captcha").focus();
			return false;
		}

		var copy = $j('#copy').attr('checked')?1:0;
		//$j('#submit_button').attr("disabled", "true");
		var dataString = 'name='+ name + '&email=' + email + '&details=' + details + '&captcha=' + captcha + '&copy=' + copy;

		$j.ajax({
			type: "POST",
			url: "bin/process.php",
			dataType: "html",
			data: dataString,
			success: function(msg) {
				$j('#contact_form').fadeOut("slow");
				$j('#contact_div_dyamic').attr("class", "contact_div_dyamic");
				$j('#contact_div_dyamic').append("<div id='message'></div>");
				$j('#message').html(msg);
				$j('#message').hide();
				$j('#message').fadeIn(1500);
			}
		});
		return false;
	});

});

function IsEmail(email) {
	var regex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (regex.test(email)) return true; else return false;
}

/*
			success: function(msg) {
				alert(msg);
				$j('#contact_form').html("<div id='message'></div>");
				$j('#message').html("<h2>thank you!</h2>")
				.append("<p>your message has been forwarded to <strong>sayhello[at]aspiredmind.com</strong></p><p>we will be in touch soon.</p>")
				.hide()
				.fadeIn(1500, function() {
					$j('#message').append("<img id='checkmark' src='images/button_ok.png' />");
				});
			}

*/