﻿var BoxAnim = null;  //Global for ShowMoreDiv Interval
var clearNum = 0; // Global for cancelling BoxAnim interval
var StopAt = 0;

var SwitchArray = new Array();
var SwitchAnim = null;
var SwitchParentAnim = null;
var imgnum = 0;
var opac = 100;
var swap = 0;

function Animate(ElemId, ClickedId, intAmt, stopInt) {
    if (BoxAnim == null && !prm.get_isInAsyncPostBack()) {
        StopAt = parseInt(document.getElementById(ElemId).style.left) + stopInt;
        BoxAnim = setInterval("GoAnimate('" + ElemId + "', '" + ClickedId + "', '" + intAmt + "','" + StopAt + "');", 1);
    }
}

function GoAnimate(ElemId, ClickedId, intAmt, stopInt) {
    var Elem = document.getElementById(ElemId);
    if (Elem) {
        var CurrLeft = parseInt(Elem.style.left);
        if (intAmt > 0) {
            if (CurrLeft >= parseInt(stopInt)) {
                Elem.style.left = stopInt + "px";
                clearNum = 1;
            }
            else {
                Elem.style.left = (CurrLeft + parseInt(intAmt)) + "px";
            }
        }
        else {
            if (CurrLeft <= parseInt(stopInt)) {
                Elem.style.left = stopInt + "px";
                clearNum = 1;
            }
            else {
                Elem.style.left = (CurrLeft + parseInt(intAmt)) + "px";
            }
        }
    }
    else {
        clearNum = 1;
    }
    if (clearNum == 1) {
        clearInterval(BoxAnim);
        clearNum = 0;
        BoxAnim = null;
        DoAjaxNetPostBack(ClickedId, '');
    }
}

function GetArray(idPart) {
    var AllDivs = document.getElementsByTagName("div");
    var x = 0;
    var lookin = new RegExp(idPart);
    for (i = 0; i < AllDivs.length; i++) {
        var ElemId = AllDivs[i].id;
        if (lookin.test(ElemId) == true) {
            SwitchArray[x] = AllDivs[i].id;
            x++;
        }
    }
}

function SlideShowTime(img) {
    SwitchParentAnim = setInterval("SlideShow('" + img + "')", 7500);
}
function SlideShow(img) {
    SwitchAnim = setInterval("Anim('" + img + "')", 50);
}

function Anim(img) {
    var imgsrc = document.getElementById(img);
    if (swap == 0) {
        imgsrc.style.filter = "alpha(opacity=" + opac + ")";
        imgsrc.style.opacity = (opac / 100);
        imgsrc.style.MozOpacity = (opac / 100);
        imgsrc.style.KhtmlOpacity = (opac / 100);
        opac = opac - 5;
    }
    if (opac == 0) {
        if (imgnum == SwitchArray.length) {
            imgnum = 0;
        }
        imgsrc.innerHTML = document.getElementById(SwitchArray[imgnum]).innerHTML;
        imgnum++;
        BuildSwitchInt(imgnum);
        swap = 1;
    }
    if (swap == 1) {
        imgsrc.style.filter = "alpha(opacity=" + opac + ")";
        imgsrc.style.opacity = (opac / 100);
        imgsrc.style.MozOpacity = (opac / 100);
        imgsrc.style.KhtmlOpacity = (opac / 100);
        opac = opac + 5;
        if (opac == 100) {
            swap = 0;
            clearInterval(SwitchAnim);
        }
    }
}

function BuildSwitchInt(BlueInt) {
    document.getElementById("switcher_int").innerHTML = "";
    for (i = 1; i < SwitchArray.length; i++) {
        var NewDiv = document.createElement("div");
        if (i == BlueInt) {
            NewDiv.className = "switcher_db";
        }
        else {
            NewDiv.className = "switcher_lb";
            NewDiv.id = i + "_switcher_lb";
            NewDiv.onclick = function () { ClickFromInt(this.id); }
        }
        document.getElementById("switcher_int").appendChild(NewDiv);
    }
}

function ClickFromInt(elemID) {
    var BlueInt = parseInt(elemID);
    var imgsrc = document.getElementById("switcherContent");
    imgsrc.innerHTML = document.getElementById(SwitchArray[BlueInt - 1]).innerHTML;
    imgnum = BlueInt;
    clearInterval(SwitchAnim);
    swap = 0;
    opac = 100;
    imgsrc.style.filter = "alpha(opacity=" + opac + ")";
    imgsrc.style.opacity = (opac / 100);
    imgsrc.style.MozOpacity = (opac / 100);
    imgsrc.style.KhtmlOpacity = (opac / 100);
    BuildSwitchInt(BlueInt);
    clearInterval(SwitchParentAnim);
    SlideShowTime("switcherContent");
}
