﻿jQuery(document).ready(function () {

    $.scrollTo('#about .bg', 0);

    $('.clouds').pan({ fps: 30, speed: .5, dir: 'left' });

    $(".slider").slideshow({
        width: 485,
        height: 147,
        transition: 'fade',
        slideshow: false,
        control: false
    });

    $(".slider-blue").slideshow({
        width: 875,
        height: 225,
        transition: 'fade',
        slideshow: false,
        control: false
    });

    $('#astronaut')
		  .sprite({ fps: 5, no_of_frames: 1 })
		  .spRandom({
		      top: 275,
		      left: 0,
		      right: 100,
		      bottom: 380,
		      speed: 5000,
		      pause: 500
		  });


    $(".tooltip").tipTip({ maxWidth: "400px", delay: "200" });
    $(".team").tipTip({ maxWidth: "600px", delay: "200" });
    $('a.services').click(function () { $.scrollTo('#space .nav', 1000); });
    $('a.our-work').click(function () { $.scrollTo('#soil-layers .nav', 800); });
    $('a.about').click(function () { $.scrollTo('#about', 1000); });

    //Content swapping
    $('.contentSwapLink').live('click', function () {
        var cid = $(this).attr("id");
        $(".discipline div").each(function () {
            $(this).fadeOut(250);
        });
        var cid2 = "#" + cid.replace("link", "swap");
        $(cid2).delay(300).fadeIn(250);
    });


    $('#footer a.contact').click(function () {
        //reset form
        $('#footer #contact #thankyou').hide();
        $('#footer #contact form').show();
        $('#contact #name').val("");
        $('#contact #email').val("");
        $('#contact #message').val("");
        $('#footer #contact').fadeIn(300);
    });
    $('#contact h3 a').click(function () {
        $('#footer #contact').fadeOut(300);
    });
});



// Contact form email

function contactValidate(name, email, comment) {
    var r = true;
    //firstname
    if (name == "") {
        $('#contact #name').addClass("invalid");
        r = false;
    } else {
    $('#contact #name').removeClass("invalid");
    }
    //email
    var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    if (reg.test(email) == false) {
        $('#contact #email').addClass("invalid");
        r = false;
    } else {
        $('#contact #email').removeClass("invalid");
    }
    //comments
    if (comment == "") {
        $('#contact #message').addClass("invalid");
        r = false;
    } else {
        $('#contact #message').removeClass("invalid");
    }

    return r;
}

//Send email
$('#sendemail').live('click', function () {
    //var url = location.pathname;
    var name = $('#contact #name').val();
    var email = $('#contact #email').val();
    var message = $('#contact #message').val();

    //name = name.replace(/['"]/g, '');
    //email = name.replace(/['"]/g, '');
    //message = name.replace(/['"]/g, '');
    if (contactValidate(name, email, message) != false) {
        var d = "{'name' : '" + name + "','email' : '" + email + "','message' : '" + message + "'}";
        $.ajax({
            type: "POST",
            url: "/email.asmx/SendEmail",
            data: d,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function () {
                //alert("send email success");
                $('#contact form').fadeOut(150);
                $('#thankyou').delay(160).fadeIn(300);
                $('#footer #contact').delay(3000).fadeOut(2000);
            }
        });
    }
});

(function () {
    var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
    po.src = 'https://apis.google.com/js/plusone.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();
