$(document).ready(function ()
{
    var c = $("#scrollerWindow");
    var a = $("#topscrollingContent1");
    var j = $("#topscrollingContent2");
    var i = $("#topscrollingContent3");
    var d = 1600;
    function g()
    {
        c.stop().scrollTo($("#home"), d, {
            axis : "x", offset : {
                left : 0, top : 0
            }
        });
        a.stop().animate({
            backgroundPosition : "(0px 0px)"
        }, d);
        j.stop().animate({
            backgroundPosition : "(0px 0px)"
        }, d);
        i.stop().animate({
            backgroundPosition : "(0px 0px)"
        }, d);
        $("#nextArrow").removeClass("noScroll goto_home goto_web goto_photo goto_contact");
        $("#prevArrow").removeClass("noScroll goto_home goto_web goto_photo goto_contact");
        $("#nextArrow").addClass("goto_web");
        $("#prevArrow").addClass("noScroll");
        return false
    }
    function f()
    {
        c.stop().scrollTo($("#web"), d, {
            axis : "x", offset : {
                left : 0, top : 0
            }
        });
        a.stop().animate({
            backgroundPosition : "(-300px 0px)"
        }, d);
        j.stop().animate({
            backgroundPosition : "(-150px 0px)"
        }, d);
        i.stop().animate({
            backgroundPosition : "(-50px 0px)"
        }, d);
        $("#nextArrow").removeClass("noScroll goto_home goto_web goto_photo goto_contact");
        $("#prevArrow").removeClass("noScroll goto_home goto_web goto_photo goto_contact");
        $("#nextArrow").addClass("goto_photo");
        $("#prevArrow").addClass("goto_home");
        return false
    }
    function e()
    {
        c.stop().scrollTo($("#photo"), d, {
            axis : "x", offset : {
                left : 0, top : 0
            }
        });
        a.stop().animate({
            backgroundPosition : "(-600px 0px)"
        }, d);
        j.stop().animate({
            backgroundPosition : "(-300px 0px)"
        }, d);
        i.stop().animate({
            backgroundPosition : "(-100px 0px)"
        }, d);
        $("#nextArrow").removeClass("noScroll goto_home goto_web goto_photo goto_contact");
        $("#prevArrow").removeClass("noScroll goto_home goto_web goto_photo goto_contact");
        $("#nextArrow").addClass("goto_contact");
        $("#prevArrow").addClass("goto_web");
        return false
    }
    function b()
    {
        c.stop().scrollTo($("#contact"), d, {
            axis : "x", offset : {
                left : 0, top : 0
            }
        });
        a.stop().animate({
            backgroundPosition : "(-900px 0px)"
        }, d);
        j.stop().animate({
            backgroundPosition : "(-450px 0px)"
        }, d);
        i.stop().animate({
            backgroundPosition : "(-150px 0px)"
        }, d);
        $("#nextArrow").removeClass("noScroll goto_home goto_web goto_photo goto_contact");
        $("#prevArrow").removeClass("noScroll goto_home goto_web goto_photo goto_contact");
        $("#nextArrow").addClass("noScroll");
        $("#prevArrow").addClass("goto_photo");
        return false
    }
    $(".goto_home").live("click", g);
    $(".goto_web").live("click", f);
    $(".goto_photo").live("click", e);
    $(".goto_contact").live("click", b);
    $onForm = false;
    $("input,textarea").focus(function ()
    {
        $onForm = true;
    });
    $("input,textarea").blur(function ()
    {
        $onForm = false;
    });
    function h(k)
    {
        if (!$onForm)
        {
            switch (k.keyCode)
            {
                case 37:
                    if ($("#prevArrow").hasClass("goto_home")) {
                        g()
                    }
                    else
                    {
                        if ($("#prevArrow").hasClass("goto_web")) {
                            f()
                        }
                        else {
                            if ($("#prevArrow").hasClass("goto_photo")) {
                                e()
                            }
                        }
                    }
                    break;
                case 39:
                    if ($("#nextArrow").hasClass("goto_web")) {
                        f()
                    }
                    else
                    {
                        if ($("#nextArrow").hasClass("goto_photo")) {
                            e()
                        }
                        else {
                            if ($("#nextArrow").hasClass("goto_contact")) {
                                b()
                            }
                        }
                    }
                    break;
                default:
            }
        }
    }
    if ($.browser.mozilla) {
        $(document).keypress(h)
    }
    else {
        $(document).keydown(h)
    }
    $("#submit").click(function ()
    {
        var k = false;
        var m = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
        var l = $("#emailFrom").val();
        if (l == "") {
            $("#emailFrom").addClass("error");
            k = true
        }
        else
        {
            if (!m.test(l)) {
                $("#emailFrom").addClass("error");
                k = true
            }
            else {
                $("#emailFrom").removeClass("error")
            }
        }
        var o = $("#emailName").val();
        if (o == "") {
            $("#emailName").addClass("error");
            k = true
        }
        else {
            $("#emailName").removeClass("error")
        }
        var n = $("#emailMessage").val();
        if (n == "") {
            $("#emailMessage").addClass("error");
            k = true
        }
        else {
            $("#emailMessage").removeClass("error")
        }
        if (k == false)
        {
            $(this).hide();
            $("#Contact").fadeOut("fast", function ()
            {
                $("#Contact").before('<img src="../Images/loadingAnimation2.gif" alt="Loading" id="loadingImage" />')
            });
            $.post("sendemail.php", {
                emailFrom : l, emailName : o, emailMessage : n
            },
            function (p)
            {
                $("#loadingImage").fadeOut("fast", function ()
                {
                    $("#loadingImage").before("<p>Your message has been sent. Cheers!</p>")
                })
            })
        }
        return false;
    })
});

