﻿$(document).ready(function () {
//    $("#dPhotoFrame").mouseenter(function () {
//        $(".caption").stop(true,true);
//        $(".caption").slideDown('fast');
//        entered = true;
//    });
//    $("#dPhotoFrame").mouseleave(function () {
//        $(".caption").stop(true, true);
//        $(".caption").slideUp('fast');
//        entered = false;
//    });
    var interval = setInterval(Cycle, 4000);
    OnReadyFunctions();
});

function Cycle() {
    var p1 = "#dPhoto1";
    var p2 = "#dPhoto2";
    var z1 = $(p1).css("z-index");
    var z2 = $(p2).css("z-index");
    var HomePhotosPath = "http://www.holycross.ac.uk/posted/web/images/" + whichpage + "/";
    var Front;
    var Back;
    if (z1 > z2) {
        Front = $(p1); Back = $(p2);
    } else {
        Front = $(p2); Back = $(p1);
    }
    $(".caption").slideUp("fast");
    Front.fadeOut("slow", function () {
        var bgimg = GetImg(Back);
        var Section = "";
        switch (bgimg.substr(0, 1)) {
            case "U":
                Section = "University Centre";
                break;
            case "S":
                Section = "Sixth Form";
                break;
            case "C":
                Section = "Holy Cross College";
                break;
        }
        $("#dCategory").html(Section);
        bgimg = bgimg.replace(/_/gi, " ");
        $("#dText").html(bgimg.substring(2, bgimg.length - 4));
        if (entered) {
            $(".caption").slideDown("fast");
        }
        Back.css("z-index", 25);
        Front.css("z-index", 20);
        for (var x = 0; x <= imgs.length; x++) {
            if ($(Back).css("background-image").indexOf(imgs[x]) > -1) {
                if (Number(x) + 1 == imgs.length) {
                    $(Front).css("background-image", "url(" + HomePhotosPath + imgs[0] + ")");
                } else {
                    $(Front).css("background-image", "url(" + HomePhotosPath + imgs[Number(x) + 1] + ")");
                }
                break;
            }
        }
        Front.css("display", "block");
    });
}
function GetImg(id) {
    var imgpath = id.css("background-image");
    imgpath = imgpath.substr(imgpath.lastIndexOf("/") + 1);
    imgpath = imgpath.replace('")', '');
    return imgpath;
}

