
/*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");

            });

    }
        );
});

//product slideshow*/
$(document).ready(function() {
    $('.product').cycle({
    fx: 'fade',
        timeout: '7000',
        pager: '.product-nav',
        pagerAnchorBuilder: function(idx, slide) {
        return '<li><a></a></li>';
        }
    });
});

/*slideshow*/

$(document).ready(function() {
    $(".slideshow-nav a").click(function() {
        jQuery(".slideshow-nav a").each(function() {
            jQuery(this).removeClass("current");
        });

        jQuery(this).addClass("current");
    });

    var SCROLL_SPEED = 1250.0;
    var ANIMATE_INTERVAL = 4000.0;

    var index = 0;
    var items = $("#slideshow-wrapper li");
    var slideshow = $("#slideshow");
    var buttons = $(".slideshow-nav a");
    var pause = false;

    function showItems(start, end) {
        items.each(function(i) {
            $(this).removeClass("left-item");
            if (i == start)
                $(this).addClass("left-item");
            if (i >= start && i < end)
                $(this).show();
            else
                $(this).hide();
        });
    }

    // set initial state

    slideshow.scrollLeft(0);
    showItems(0, 6);

    slideshow.hover(function() {
        pause = true;
    },
        function() {
            pause = false;
        });

    function setOverstate(index) {
        buttons.removeClass("current");
        $(buttons[index]).addClass("current");
    }

    var scrollRight = function() {
        if (pause)
            return;
        slideshow.scrollLeft(0);
        if (index + 3 >= items.length) {
            index = 0;
            slideshow.scrollLeft(0);
            showItems(0, 6);
        }
        else {
            showItems(index, index + 6);
            index += 3;
            slideshow.animate({ scrollLeft: 920 }, SCROLL_SPEED,
            function() {
                showItems(index, index + 3);
                slideshow.scrollLeft(0);
            });
        }
        setOverstate(index / 3);
    };

    var animateInterval = setInterval(scrollRight, ANIMATE_INTERVAL);

    buttons.each(function(i) {
        $(this).click(function() {
            slideshow.stop().scrollLeft(0);
            clearInterval(animateInterval);
            showItems(i * 3, (i * 3) + 3);
            animateInterval = setInterval(scrollRight, ANIMATE_INTERVAL);
            index = i * 3;
        });
    });
});

$(document).ready(function() {    
    $(".slideshow-text").stop().fadeTo("fast", 0.7);
    $(".slideshow-text").hide();

    $(".slideshow a").hover(function() {
        $(this).find(".slideshow-text").slideToggle("fast");
    }, function() {
        $(this).find(".slideshow-text").slideToggle("fast");
    });
});


$(document).ready(function() {
    $(".subnav-wrapper").hide();

    $(".work").each(function() {
        var hovering = false;
        var subnavHovering = false;

        function checkState() {
            if (!hovering && !subnavHovering) {
                $(".subnav-wrapper").fadeOut("fast");
            }
        }

        $(".subnav-wrapper").hover(function() {
            subnavHovering = true;            
        },
        function() {
            subnavHovering = false;
            setTimeout(checkState, 1000);
        });

        $(this).hover(function() {
            $(".subnav-wrapper").fadeIn("fast");
            hovering = true;
        },
        function() {
            hovering = false;
            setTimeout(checkState, 1000);
        });
    });
});


