﻿$(document).ready(function () {

    /*STARTUP*/

    $(function () {

        $('.stone').css('opacity', 0);
        
        $('#s1').delay(initDelay * 1.5).fadeTo(fadeDelay, 0.7);
        $('#s2').delay(initDelay * 2.0).fadeTo(fadeDelay, 0.7);
        $('#s3').delay(initDelay * 2.5).fadeTo(fadeDelay, 0.7);

    });

    //Tile clickers
    $('#CounsellingButton').click(function () {
        window.location.href = "services.aspx?s=counselling";
    });
    $('#HynotherapyButton').click(function () {
        window.location.href = "services.aspx?s=hypnotherapy";
    });
    $('#ReikiButton').click(function () {
        window.location.href = "services.aspx?s=reiki";
    });
    $('#MeditationButton').click(function () {
        window.location.href = "services.aspx?s=meditation";
    });
    $('#SpiritualCounsellingButton').click(function () {
        window.location.href = "services.aspx?s=spiritual_counselling";
    });

    /*STONES*/

    $('.stone').click(function () {

        if ($(this).queue("fx").length > 0) {
            return;
        }
        else {
            $(this).stoneMenu();
        }

    });

    $('.stone').mouseenter(function () {
        if ($(this).queue("fx").length > 0) {
            return;
        }
        else {

            $(this).stoneMenu();
        }

    });

    jQuery.fn.stoneMenu = function () {

        /*GET DATA*/

        var stID = $(this).attr("id");    /*Which menu DIV?*/
        var menuShellClass;
        var stNum;
        var stoneOffset;    /*Where to move each stone?*/
        var menuOffset;

        stID = '#m' + stID.substr(1, 1)
        stNum = parseInt(stID.substr(2, 1));
        menuShellClass = ".menuShell" + stNum;

        switch (stNum) {
            case 1:
                stoneOffset = 80;
                menuOffset = 60;
                break;
            case 2:
                stoneOffset = 60;
                menuOffset = 100;
                break;
            case 3:
                stoneOffset = 75;
                menuOffset = 70;
                break;
        }

        $('.stone,.menu').stop(false, true);

        /*SHOW*/

        /*Activate and animate stone up*/
        $(this).animate({ top: -stoneOffset, opacity: 1 }, slideDelay).delay(menuShowDelay);

        /*Show relevant menu*/
        $(stID).show();
        $(stID).animate({ top: 90 + menuOffset, height: 300 }, slideDelay);
        $(menuShellClass).delay(slideDelay).fadeIn('slow');

        /*HIDE*/

        /*Animate stone down and deactivate*/
        $(this).animate({ top: 0, opacity: 0.7 }, slideDelay);

        /*Hide menu*/
        $(menuShellClass).delay(menuShowDelay).fadeOut('fast');
        $(stID).delay(menuShowDelay).animate({ top: 90, height: 0 }, slideDelay);
        $(stID).hide(slideDelay);

    }

});
