var GlobalHeight = 379;

$(document).ready(function() {
    $(".slideInfo").each(function() {
        var ThisInfoIndex = $(".slideInfo").index(this);
        $(this).attr({ "curr": (ThisInfoIndex) }).css({ zIndex: (ThisInfoIndex + 100) });
    });
    SlideFnc();
    $("#slideContact a, #slideContact").mouseover(function() {
        $("#slideContact").addClass("slideContacthov");
    });
    $("#slideContact a").mouseout(function() {
        $("#slideContact").removeClass("slideContacthov");
    });
});


function SlideFnc() {
    $(".box").bind("click", function() {
        var IndexedBox = $(".box").index(this);
        ////
        if ($(".slideInfo:visible").size() == 0) {
            var ZIndexed = 150;
        } else {
            var ZIndexed = parseInt($(".slideInfo:visible").css("zIndex")) + 1;
        }
        ////
        ////OpenFrame(IndexedBox, "Open");
        OpenFrame(IndexedBox, "Open", ZIndexed, this.id);
        $(this).animate({ opacity: 1.0 });
        $(this).siblings(".box").animate({ opacity: 0.5 });
        return false;
    });

    ////function OpenFrame(OpenThis, Pos) {
    function OpenFrame(OpenThis, Pos, ZIndexed, IDentify) {
        $("#slidePrev, #slideNext").attr({ ref: OpenThis });
        ////
        $(".slideInfo").eq(OpenThis).css({ "zIndex": ZIndexed });
        var slideButtonsZindex = parseInt(ZIndexed) + 1;
        $("#slide_buttons").css({ "zIndex": slideButtonsZindex });
        ////
        if (Pos == "Prev") {
            $(".slideInfo[curr!=" + OpenThis + "]").fadeOut("slow", function() {
                $(".action_buttons").removeClass("ACTIVE");
            })
            $(".slideInfo").eq(OpenThis).show();
        } else if (Pos == "Open") {
        $(".slideInfo").eq(OpenThis).fadeIn("slow", function() {
            $(".slideInfo[curr!=" + OpenThis + "]").hide();
            $(".action_buttons").removeClass("ACTIVE");
            $("#slide_buttons").fadeIn("slow");            
        });
        } else {
            $(".slideInfo").eq(OpenThis).fadeIn("slow", function() {
                $(".slideInfo[curr!=" + OpenThis + "]").hide();
                $(".action_buttons").removeClass("ACTIVE");
            });
        }
        //// $("#slideContact a").attr({ href: "http://www.mihomes.com/Hindsight_vid?utm_medium=Widget&utm_campaign=Fastest&utm_source=" + $(".slideInfo").eq(OpenThis).attr("ref") });
        $("#mainContact a").attr({ href: $("#"+IDentify+" a").attr("href")});
    }

    $("#slideClose").bind("click", function() {
        $("#slide_buttons").fadeOut("slow", function() {
            $(".slideInfo").fadeOut("slow");
        });
    });

    function closeActive() {
    }

    $("#slideNext").bind("click", function() {
        if ($(this).hasClass("ACTIVE") == false) {
            var ThisRef0 = $(this).attr("ref");
            if (ThisRef0 == ($(".slideInfo").size() - 1)) {
                var ThisRef = -1;
                var Pos = "Prev";
            } else {
                var ThisRef = ThisRef0;
                var Pos = "Next";
            }
            OpenFrame((parseInt(ThisRef) + 1), Pos);
            $(this).addClass("ACTIVE");
            return false;
        }
    });
    $("#slidePrev").bind("click", function() {
        if ($(this).hasClass("ACTIVE") == false) {
            var ThisRef0 = $(this).attr("ref");
            if (ThisRef0 == 0) {
                var ThisRef = $(".slideInfo").size();
                var Pos = "Next";
            } else {
                var ThisRef = ThisRef0;
                var Pos = "Prev";
            }
            OpenFrame((parseInt(ThisRef) - 1), Pos);
            $(this).addClass("ACTIVE");
            return false;
        }
    });
}

