﻿
var slides = $(".slide").length;
var currentSlide = -1;
var eq = 0;
var play = true;

function SlideRight() {
    play = false;
    $(".slide:eq(" + currentSlide + ")").stop().animate({ "left": -800 }, { duration: 500, easing: "easeOutSine" });
    currentSlide = eq;
    $(".slide:eq(" + currentSlide + ")").css({ "left": 800 }).stop().animate({ "left": 0 }, { duration: 500, easing: "easeOutSine" });
}
function SlideLeft() {
    play = false;
    $(".slide:eq(" + currentSlide + ")").stop().animate({ "left": 800 }, { duration: 500, easing: "easeOutSine" });
    currentSlide = eq;
    $(".slide:eq(" + currentSlide + ")").css({ "left": -800 }).stop().animate({ "left": 0 }, { duration: 500, easing: "easeOutSine" });
}

function AutoSlide() { 
    
        if (play) { $('#right').click(); play = true; setTimeout("AutoSlide(); ", 4000); }
     
}

$().ready(function() {

    $("#right").click(function() {
        if ((currentSlide + 2) > slides) { eq = 0; } else { eq = (currentSlide + 1); }
        $(".beanBox:eq(" + eq + ")").trigger("mouseenter").click();
    });
    $("#left").click(function() {
        eq = currentSlide - 1;
        if ((eq) < 0) { eq = slides - 1; }
        $(".beanBox:eq(" + eq + ")").trigger("mouseenter").click();
    });

    function Beans() {
        $(".shadow").fadeTo(0, 0);
        $(".beanBox").unbind("mouseenter").unbind("mouseleave").filter(":not(.active)").bind("mouseenter", function() {
            $(this).addClass("hover").find(".bean").stop().animate({ "top": 10 }, { duration: 500, easing: "easeOutBounce" });
            $(this).find(".shadow").stop().animate({ opacity: 0.85 }, 300);
        }).bind("mouseleave", function() {
            $(this).removeClass("hover").find(".bean").stop().animate({ "top": 25 }, { duration: 500, easing: "easeOutBounce" });
            $(this).find(".shadow").stop().animate({ opacity: 0 }, 500);
        }).trigger("mouseleave");

        $(".beanBox").unbind("click").click(function() {
            $(this).addClass("active").siblings(".beanBox").removeClass("active");
            eq = $(".beanBox").index($(this));
            if ((eq > currentSlide && !(currentSlide == (slides - 1) && eq == 0))) { SlideRight(); }
            else { SlideLeft(); }
            Beans();
        });
    } Beans();

    if (section.length > 0) {
        if (section.toLowerCase() == "community")
            $("#Build-A-Community").trigger("mouseenter").click();
        else if (section.toLowerCase() == "advertise")
            $("#Advertise-On-PartnerUp").trigger("mouseenter").click();
        else if (section.toLowerCase() == "survey")
            $("#Survey-Our-Community").trigger("mouseenter").click();
        else if (section.toLowerCase() == "small-business")
            $("#Visit-PartnerUp").trigger("mouseenter").click();
    }
    else {

        $(".beanBox:eq(0)").trigger("mouseenter").click();

        play = true;

        setTimeout("AutoSlide(); ", 3000);
    }

});