﻿
imageCount = strintCounter;

var width = 300;
function getElementsByClassName(needle) {
    var my_array = document.getElementsByTagName("a");
    var retvalue = new Array();
    var i;
    var j;

    for (i=0,j=0;i<my_array.length;i++) {
        var c = " " + my_array[i].className + " ";
        if (c.indexOf(" " + needle + " ") != -1) retvalue[j++] = my_array[i];
    }
    return retvalue;
}
var classname = 'one';
function toggle()
{
    var divs = getElementsByClassName("currentPage")
    for(i=0; i <divs.length;i++)
    {
        if(divs[i].className == 'currentPage')
        {

            divs[i].className = 'undefined';

        }

    }
//alert(classname);
}
function startSlideShow()
{
    if (imageCount > 0)
    {
        updateImage();
    }
    timerID = setTimeout("runThread();", 4000);
}

function stopSlideShow()
{
    clearTimeout(timerID);
}

function updateImage()
{
    if (imageCount > 0)
    {
        document.getElementById('ImgComments').innerHTML  = imageComments[counter].toString() ;
        document.getElementById('ImageFile').src = images[counter].toString();
    }
    document.getElementById('ImageFile').alt = imageName[counter].toString();
    document.getElementById('ImageFile').title = imageName[counter].toString();


    var currentPage = Math.ceil((counter + 1)/PageSize);
    if(page!=currentPage)ChangePaggng(currentPage,PageSize);

    var strPage="Page" + currentPage;
    document.getElementById(strPage).className='currentPage';

    PreviewImage(document.getElementById('Page' + counter));
}

function runThread()
{
    showNext();
    timerID = setTimeout("runThread();", 3000);
}

function showNext()
{
    counter++;
    if (counter >= imageCount) counter = 0;
    if (imageCount > 0)
    {
        updateImage();
    }
}

function showCurrent(intIndex){
    counter=intIndex;
    if (counter >= imageCount) counter = 0;
    if (imageCount > 0)
    {
        updateImage();
    }
}

function showPrevious()
{
    counter--;
    if (counter < 0) counter = imageCount - 1;
    if (imageCount > 0)
    {
        updateImage();
    }
}

function toggleSlideShow()
{
    slideShow = !slideShow;
    if (!slideShow){
        document.getElementById("ctl00_ContentPlaceHolder1_Ctrl_photo_album1_imgPlay").src=  '/App_Themes/' + LangSettingsKey + '/images/play.gif';
        document.getElementById("ctl00_ContentPlaceHolder1_Ctrl_photo_album1_imgPlay").title = getwordKeyPlay;
        stopSlideShow();
    }
    else {
        document.getElementById("ctl00_ContentPlaceHolder1_Ctrl_photo_album1_imgPlay").src=  '/App_Themes/' + LangSettingsKey + '/images/pause.gif';
        document.getElementById("ctl00_ContentPlaceHolder1_Ctrl_photo_album1_imgPlay").title = getwordKeyPause;
        startSlideShow();
    }
}
function ChangePaggng(intPage,intPageSize){
    var strPage="Page" + (page==0?1:page);
    document.getElementById(strPage).className = document.getElementById(strPage).oldClassName;

    page=intPage;
    PageSize=intPageSize;
    var tnailstart = parseInt(intPage -1 )* (intPageSize);
    if (tnailstart < 0)tnailstart = 0;
    var tnailend = intPageSize + tnailstart;
    if(tnailend >= imageCount)	tnailend = imageCount;
    var str="";
    for(intIndex = tnailstart; intIndex <= tnailend -1 ; intIndex++){
        str=str + "<a id='Page" + intIndex + "' alt='" + imageName[intIndex].toString() + "' title='" + imageName[intIndex].toString() + "' onclick='changeImageIndex(" + intIndex + "); ' >" + intIndex + "</a>";
    }
    document.getElementById("thumb").innerHTML=str;
    showCurrent(tnailstart);
}

function PreviewImage(obj){
    toggle();
    var arrImage=document.getElementById("thumb").getElementsByTagName("img");
    for (i=0; i <= arrImage.length -1; i++){
        ResetImage(arrImage[i]);
    }
    if (imageCount > 0)
    {
        obj.className="currentPage";

    }
}

function ResetImage(obj){
    obj.className=obj.oldClassName;
}
function changeImageIndex(id){
    toggle();
    showCurrent(id);
    var strPage="Page" + (id==0?1:id);
    obj=document.getElementById(strPage);
    PreviewImage(obj);
}

var scrollingTimerID = 0;
