﻿/************************
Usman Bashir
http://creative-fuzon.com/

default.asp.js : Code Behind for default.asp
http://creative-fuzon.com/

Version: 1.2.0.1

Start Date & Time: 19/08/2008 - 12:08:00 AM
Last Build Date & Time: 13/11/2008 - 01:16:00 AM
************************/

$(document).ready(function() {
    $("#logo").click(function(e) {
        e.preventDefault();
        hideAll();
        $("#home").show("slow");
    });

    $("#home-link").click(function(e) {
        e.preventDefault();
        hideAll();
        $("#home").show("slow");
    });

    $("#about-link").click(function(e) {
        e.preventDefault();
        hideAll();
        $("#about").show("slow");
    });

    $("#resume-link").click(function(e) {
        e.preventDefault();
        hideAll();
        $("#resume").show("slow");
    });

    $("#portfolio-highlights-link").click(function(e) {
        e.preventDefault();
        hideAll();
        $("#portfolio-highlights").show("slow");
    });

    $("#twitter-link").click(function(e) {
        e.preventDefault();
        hideAll();
        $("#twitter").show("slow");
    });

    $("#contact-link").click(function(e) {
        e.preventDefault();
        hideAll();
        $("#contact").show("slow");
    });

    function hideAll() {
        $("#home").hide("fast");
        $("#about").hide("fast");
        $("#resume").hide("fast");
        $("#portfolio-highlights").hide("fast");
        $("#twitter").hide("fast");
        $("#contact").hide("fast");
    }

    $("#skills a").click(function(e) {
        e.preventDefault();
        $("#skills div").slideUp({ duration: 800, easing: "easeInExpo" });
        $("#" + $(this).attr("rel")).slideDown({ duration: 600, easing: "easeOutExpo" });
    });

    $("#twitter_div").twitter();

    var sSubmitForm = "#contact-form fieldset ";

    $(sSubmitForm + "input, " + sSubmitForm + "textarea").each(function() {
        $(this).val($(this).attr("title"));
    });

    $(sSubmitForm + "input, " + sSubmitForm + "textarea").focus(function() {
        if ($(this).val() == $(this).attr("title")) {
            $(this).val("");
        }
    });

    $(sSubmitForm + "input, " + sSubmitForm + "textarea").blur(function() {
        if ($(this).val() == "") {
            $(this).val($(this).attr("title"));
        }
    });

    $("#contact-form").submit(function() {
        var bValid = false;
        var bName, bEmail, bMessage = false;
        var sMessage = "";

        if ($("#text-name").val() == "" || $("#text-name").val() == $("#text-name").attr("title")) { sMessage += "Please type your full name.\n"; bName = false; } else { bName = true; }

        if ($("#text-email").val() == "" || $("#text-email").val() == $("#text-email").attr("title")) {
            sMessage += "Please type your email address.\n";
            bEmail = false;
        } else {
            var rMask = new RegExp("[a-zA-Z0-9_]+@+[a-zA-Z0-9_]+[\.]+[a-zA-Z]");
            var rResult = rMask.test($("#text-email").val());
            if (rResult == false) {
                sMessage += "Please type a valid email address.\n";
                bEmail = false;
            } else {
                bEmail = true;
            }
        }

        if ($("#text-comment").val() == "" || $("#text-comment").val() == $("#text-comment").attr("title")) { sMessage += "Please type your message.\n"; bMessage = false; } else { bMessage = true; }

        if (bName && bEmail && bMessage) { bValid = true; } else { bValid = false; }
        if (bValid == true) { submitContact(); return false; } else { alert(sMessage); return false; }
    });

});

function submitContact() {
	$("#contact-form").hide("fast");
	$("#form-working").show("fast");
		
	$.post("contact.php", 
		{txtName: $("#text-name").val(), txtEmail: $("#text-email").val(), txtComment: $("#text-comment").val()},
		function(data) {
			$("#form-working").hide("fast");
			$("#form-result").show("fast").html(data);
			$("#form-result a").click(function(e) {
				e.preventDefault();
				$("#form-result").hide("fast");
				$("#contact-form").show("slow");
			});
		}
	);
	return false;
}