fullPath = '';
function getPage(btn, pageId) {
    if ($("#all #" + pageId).length < 1) {

        if ($(btn).find(".loading").length > 0) {
            $(btn).find(".loading").html("<img src=\"loading.gif\"/>");
        }
        else {
            $(btn).append("<span class=\"loading\"><img src=\"loading.gif\"/></span>");
        }

        var div = document.createElement("div");
        $(div).load(fullPath + pageId + ".htm", function () {

            $("#all").append("<div id=\"trans2\"></div><div id='" + pageId + "'>" + $(div).html() + "</div>");
            $(btn).find(".loading").html("");
           

            target = $(btn).attr('href');
            large = $(target).offset().left;
            $('html,body').animate({ scrollLeft: large }, 3400, 'easeInOutQuart');

            initFunc();

            return false;
        });
        return false;
    }
    else {
        target = $(btn).attr('href');
        large = $(target).offset().left;
        $('html,body').animate({ scrollLeft: large }, 3400, 'easeInOutQuart');
        return false;
    }
}
$(document).ready(function () {
    initFunc();
});
function initFunc() {

    $("#send").click(function () {
        valid = true;
        if ($("#nom").val() == "") {
            $("#nom").next(".erreurform").fadeIn().text("Please enter a name.");
            valid = false;
        }
        else {
            $("#nom").next(".erreurform").fadeOut();
        }
        if ($("#mail").val() == "") {
            $("#mail").next(".erreurform").fadeIn().text("Please enter an address.");
            valid = false;
        }
        else if (!$("#mail").val().match(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/i)) {
            $("#mail").next(".erreurform").fadeIn().text("Please enter a valid address.");
            valid = false;
        }
        else {
            $("#mail").next(".erreurform").fadeOut();
        }
        if ($("#txt").val() == "") {
            $("#txt").next(".erreurform").fadeIn().text("Please enter a message.");
            valid = false;
        }
        else {
            $("#txt").next(".erreurform").fadeOut();
        }
        return valid;
    });

    /* Scroll */
    $('a[href^=#]').click(function () {
        return getPage(this, $(this).attr('href').substr(1, 100));
    });



    /* Navigation nav */
    $('.menu li a').hover(function () {
        $(this).find('span').not('.fan1-on, .fan2-on, .fan3-on, .fan4-on').stop().animate({ "bottom": "-150px" }, { queue: false, duration: 850, easing: 'easeOutBounce' });

    }, function () {
        $(this).find('span').not('.fan1-on, .fan2-on, .fan3-on, .fan4-on').stop().animate({ "bottom": "40px" }, { queue: false, duration: 350 });
    });

    /* Fade hover gallery + cycle */
    $("img.b").hover(function () {
        $(this).stop().animate({ "opacity": "0" }, "slow");
    }, function () {
        $(this).stop().animate({ "opacity": "1" }, "slow");
    });


    $("#galery > div.test:not(:eq(0))").hide();

    $("#switch0").click(function () {
        var hidden = $("#galery > div.test:eq(0)");
        var visible = $("#galery > div.test:visible");
        visible.fadeOut(350, function () {
            hidden.fadeIn(350);
        });
    });
    $("#switch1").click(function () {
        var hidden = $("#galery > div.test:eq(1)");
        var visible = $("#galery > div.test:visible");
        visible.fadeOut(350, function () {
            hidden.fadeIn(350);
        });
    });
    $("#switch2").click(function () {
        var hidden = $("#galery > div.test:eq(2)");
        var visible = $("#galery > div.test:visible");
        visible.fadeOut(350, function () {
            hidden.fadeIn(350);
        });
    });
    $("#switch3").click(function () {
        var hidden = $("#galery > div.test:eq(3)");
        var visible = $("#galery > div.test:visible");
        visible.fadeOut(350, function () {
            hidden.fadeIn(350);
        });
    });



    $(".group .part").hover(function () {
        $(this).next('.shadow').children('span').fadeIn(550);
    }, function () {
        $(this).next('.shadow').children('span').delay(5500).fadeOut(550);
    });
    $("a[rel='example2']").colorbox({ transition: "fade", innerWidth: 700, innerHeight: 500 });
}

/* Still don't steal, bye buddy. */
