﻿$(document).ready(function () {
    // menu items
    $('#menu li').fadeTo(0, 0.25);
    $('#on').fadeTo(0, 1);
    $('#menu li').hover(
        
            function () {
                $(this).stop().animate({ opacity: 1 });
            },
            function () {
                if ($(this).attr('id') != 'on') {
                $(this).stop().animate({ opacity: 0.25 });
                };
            }
        
    );

    // video show
    $('#video').click(
            function () {
                $('#video_contain').fadeTo("slow", 0.8, function () {
                    $('#video_player').fadeIn("slow");
                });
            }
    );

    // close video
    $('#video_contain').click(function () {
        $('#video_contain').fadeToggle();
    });

    // esc
    $('*').keydown(function (event) {
        if (event.keyCode == '27') {
            $('#video_contain').fadeOut();
        }
    });

    // testimonials
    $('#testimonials div').easySlider({
        auto: true,
        continuous: true,
        speed: 1000,
        pause: 10000,
        controlsShow: false
    });

    // randomise message
    $(function () {

        jQuery.jQueryRandom = 0;
        jQuery.extend(jQuery.expr[":"],
        {
            random: function (a, i, m, r) {
                if (i == 0) {
                    jQuery.jQueryRandom = Math.floor(Math.random() * r.length);
                };
                return i == jQuery.jQueryRandom;
            }
        });

        var i, iStart, iCount, j, iTimer;
        var iRandomStart = $("#message li:random").text();

        // Settings
        iCount = $('#message li').length - 1;
        iTimer = 1700;


        i = 0;
        $('#message li').each(function () {
            if (iRandomStart == $(this).text()) {
                iStart = i;
                j = i;
            }
            i++;
        });

        i = 0;
        $('#message > li').each(function () {
            if (i == iStart) { $(this).show(); } else { $(this).hide(); }
            i++;
        });

        setInterval(function () {
            i = 0;
            $('#message > li').each(function () {
                if (j > iCount) { j = 0; };
                if (i == j) {
                    $(this).animate({ top: '+=100', opacity: 'toggle' }, iTimer, function () {
                        j++;
                        $(this).animate({ top: '-=100' }, 100);
                    });
                };
                if (i == j + 1) {
                    $(this).fadeIn(iTimer);
                };
                if (j + 1 > iCount) {
                    if (i == 0) { $(this).fadeIn(iTimer); };
                };
                i++
            });
        }, iTimer * 3);

    });
});
