﻿var oPauseTime = 5000;
var allId = 2;
var oImgHeight = 0;
var oTitleHeight = 0;
var imgObj;
var titleObj;
var sid;
var ImgCount=3;
function ChangeFlashInfo(count) {
	if(count) ImgCount = count;
	
	if(sid) {clearInterval(sid);}
	allId = 2;
    
    oImgHeight = document.getElementById("divImgsScroll").offsetHeight;
    oTitleHeight = document.getElementById("divTitlesScroll").offsetHeight;

    imgObj = document.getElementById("divImgsScroll");
    imgObj.scrollTop = 0;
    titleObj = document.getElementById("divTitlesScroll");
    titleObj.scrollTop = 0;
	ChangeIndex(1);
		
    sid = setInterval("ChangeFlash()", oPauseTime);
    
    
}

function ChangeFlash() {
    if (allId > ImgCount || allId < 1)
        allId = 1;

    ChangeInfo(titleObj, oTitleHeight);
    ChangeIndex(allId);
    ChangeInfo(imgObj, oImgHeight);
    ++allId;
}

function ChangeInfo(obj, infoHeight) {
    var totalTop = obj.scrollHeight - infoHeight;
    var thisTop = 0;
    if (obj.scrollTop < totalTop) {
        thisTop = obj.scrollTop + infoHeight;
        while (obj.scrollTop < thisTop) {
            obj.scrollTop += 5;
        }
    }
    else if (obj.scrollTop == totalTop) {
        while (obj.scrollTop > 0) {
            obj.scrollTop -= 20;
        }
    }

    obj.scrollTop = thisTop;

}
function ChangeIndex(id) {
    for (var i = 1; i <= ImgCount; ++i) {
        document.getElementById("flashIndex" + i).className = "";
    }

    document.getElementById("flashIndex" + id).className = "flashChoose";
}

function ShowThisFlash(id) {
    clearInterval(sid);

    //Title
    ScrollToInfos(titleObj, id, oTitleHeight);

    //Image
    ScrollToInfos(imgObj, id, oImgHeight);

    //Index
    ChangeIndex(id);
    allId = id + 1;

    sid = setInterval("ChangeFlash()", oPauseTime);
}
function ScrollToInfos(obj, id, infoHeight) {
    var thisTop = obj.scrollTop;
    var targetTop = (id - 1) * infoHeight;

    if (thisTop > targetTop) {
        while (obj.scrollTop > targetTop) {
            obj.scrollTop -= 20;
        }
    }
    else {
        while (obj.scrollTop < targetTop) {
            obj.scrollTop += 20;
        }
    }

    obj.scrollTop = targetTop;
}