
/*overstate*/
$(document).ready(function () {
    $(".menuoverstate").each(function (i) {

        preload_image = new Image();
        preload_image.src = this.src.replace(".jpg", "_o.jpg");

        $(this).hover(
            function () {
                if (this.src.indexOf("_o.jpg") == -1) {
                    this.src = this.src.replace(".jpg", "_o.jpg");
                }
            },
            function () {
                this.src = this.src.replace("_o.jpg", ".jpg");

            });
    });

    $(".menuoverstate2").each(function (i) {

        preload_image = new Image();
        preload_image.src = this.src.replace(".gif", "_o.gif");

        $(this).hover(
            function () {
                if (this.src.indexOf("_o.gif") == -1) {
                    this.src = this.src.replace(".gif", "_o.gif");
                }
            },
            function () {
                this.src = this.src.replace("_o.gif", ".gif");

            });
    });

    $(".menuoverstate3").each(function (i) {

        preload_image = new Image();
        preload_image.src = this.src.replace(".png", "_o.png");

        $(this).hover(
            function () {
                if (this.src.indexOf("_o.png") == -1) {
                    this.src = this.src.replace(".png", "_o.png");
                }
            },
            function () {
                this.src = this.src.replace("_o.png", ".png");

            });
    });




    /* slider */

    var $currentSlide = 0;

    $('#slider').cycle({
        fx: 'scrollHorz',
        timeout: 0,
        pager: '#people ul',
        pagerAnchorBuilder: function (idx, slide) {
            // return selector string for existing anchor 
            return '#people ul li:eq(' + idx + ') a';
        },
        onPagerEvent: function (idx, slide) {
            $currentSlide = idx;

            $('#about-talk div').css("display", "none");
            $('#about-talk div:eq(' + idx + ')').css("display", "block");

            $("#people ul li img").each(function (i) {
                if (idx != i) {
                    this.src = this.src.replace("_o.jpg", ".jpg");
                } else {
                    this.src = this.src.replace(".jpg", "_o.jpg");
                }
            });
        },
        onPrevNextEvent: function (isNext, idx, slide) {
            $currentSlide = idx;

            $('#about-talk div').css("display", "none");
            $('#about-talk div:eq(' + idx + ')').css("display", "block");

            $("#people ul li img").each(function (i) {
                if (idx != i) {
                    this.src = this.src.replace("_o.jpg", ".jpg");
                } else {
                    if (this.src.indexOf("_o.jpg") == -1) {
                        this.src = this.src.replace(".jpg", "_o.jpg");
                    }
                }
            });
        }
    });

    if ($('#people ul li img').first().attr('src')) {
        $('#people ul li img').first().attr('src', $('#people ul li img').first().attr('src').replace(".jpg", "_o.jpg"));
    }

    $('#about-talk div').css("display", "none");

    $('#about-talk div:first-child').css("display", "block");

    //Get The amount of pictures in the carousell
    var $index = $('#people ul li:last-child').index();
    $index += 1;

    //Set the width of the carousell
    var $size = ($index + 1) * 109;
    $size -= 12;
    $('#people ul').width($size);

    $("#people ul li img").each(function (i) {

        preload_image = new Image();
        preload_image.src = this.src.replace(".jpg", "_o.jpg");
      
    });

    /*

    //Limit positioning on the carousell
    var $limit = $size * -1;
    $limit += ($size / 2) + 97;

    $('.arrowright-people').click(function () {
    var $position1 = $('#people ul').position().left;
    if ($position1 <= $limit) {
    return false;
    } else {
    $('#people ul').animate({
    left: $position1 - 109
    });
    return false;
    }
    });

    $('.arrowleft-people').click(function () {
    var $position2 = $('#people ul').position().left;
    if ($position2 == 0) {
    return false;
    } else {
    $('#people ul').animate({
    left: $position2 + 109
    });
    return false;
    }
    });

    */

    $('.arrowright-people').click(function () {
        $('#slider').cycle("next");
    });

    $('.arrowleft-people').click(function () {
        $('#slider').cycle("prev");
    });

    /* slider2 */

    $('#slider2').cycle({
        fx: 'scrollHorz',
        prev: '.arrowleft',
        next: '.arrowright',
        timeout: 0,
        pager: '#work-thumbs ul',
        pagerAnchorBuilder: function (idx, slide) {
            // return selector string for existing anchor 
            return '#work-thumbs ul a:eq(' + idx + ')';
        }
    });

    /* brochure link */

    $('#brochure-link').click(function () {

    });

    $('#brochure-link').hover(
        function () {
            $('#brochure-info').css('display', 'block');
        },
        function () {
            $('#brochure-info').css('display', 'none');
        }
    );

    /* featued work */

    $('#latest a').hover(
        function () {
            $("span", this).css('display', 'none');
        },
        function () {
            $("span", this).css('display', 'block');
        }
    );

    /* work categories */

    $('#work-thumbs a').hover(
        function () {
            $("span", this).css('display', 'none');
        },
        function () {
            $("span", this).css('display', 'block');
        }
    );

});

