﻿var hedef;
var kayanNes, kayanNesDik, imgSagOk, imgSolOk;

//var hedefBelirle = 168; Uzun Gen
//var hedefBelirle = 157; //Dar Gen
var _pxAdim = 3;
var _msAra = 5;

var sonlandirmaArtigi = 11;

var calismaKilidi = 0;


function KaydirmaOklari()
{
    kayanNes = document.getElementById("dvKayan");
//    imgSolOk = document.getElementById("imgSolOk");
//    imgSagOk = document.getElementById("imgSagOk");
//    imgSolOk.style.display = "none";
//    imgSagOk.style.display = ((kayanNes.scrollWidth-kayanNes.offsetWidth) > sonlandirmaArtigi)?"":"none";
//    
//    if(imgSagOk.style.display == "none")
//    {
//        document.getElementById("imgSagOkPasif").style.display = document.getElementById("imgSolOkPasif").style.display = "none";
//    }
}

function Kaydir(yon)
{
    if(calismaKilidi == 0)
    {
        calismaKilidi = 1;
        kayanNes = document.getElementById("dvKayan");        
        hedef = kayanNes.scrollLeft + yon*hedefBelirle;

        if(hedef > (kayanNes.scrollWidth-kayanNes.offsetWidth) || hedef < 0)
        {
            calismaKilidi = 0;
            kayanNes.scrollLeft = 232;
            
            return;
        }
        if(hedef == 0)
        {
             calismaKilidi = 0;
            kayanNes.scrollLeft = 870;
        }
            
        if(yon==1)
            HedefeKayIleri();
        else 
            HedefeKayGeri();
    }
}

function HedefeKayIleri()
{
    if(calismaKilidi && ((kayanNes.scrollLeft+=_pxAdim) < hedef)) setTimeout("HedefeKayIleri()", _msAra);
    else
    {
        calismaKilidi = 0;
        artikKayma = kayanNes.scrollLeft % hedefBelirle;
        //alert("kayanNes.scrollLeft % _pxAdim ("+kayanNes.scrollLeft+" % "+hedefBelirle+") = artikKayma (" + artikKayma + ")");
        kayanNes.scrollLeft -= artikKayma;
        
//        imgSolOk.style.display = (kayanNes.scrollLeft == 0)?"none":"";
//        imgSagOk.style.display = (kayanNes.scrollLeft == (kayanNes.scrollWidth-kayanNes.offsetWidth-sonlandirmaArtigi))?"none":"";        
       // alert(kayanNes.scrollLeft + " " + (kayanNes.scrollWidth-kayanNes.offsetWidth));
    }
}

function HedefeKayGeri()
{
    if(calismaKilidi && ((kayanNes.scrollLeft -= _pxAdim) > hedef))setTimeout("HedefeKayGeri()", _msAra);
    else
    {
        calismaKilidi = 0;
        artikKayma = hedefBelirle - (kayanNes.scrollLeft % hedefBelirle);
        //alert("kayanNes.scrollLeft % _pxAdim ("+kayanNes.scrollLeft+" % "+hedefBelirle+") = artikKayma (" + artikKayma + ")");
        if(artikKayma != hedefBelirle)
        kayanNes.scrollLeft += artikKayma;
        
//        imgSolOk.style.display = (kayanNes.scrollLeft == 0)?"none":"";
//        imgSagOk.style.display = (kayanNes.scrollLeft == (kayanNes.scrollWidth-kayanNes.offsetWidth-sonlandirmaArtigi))?"none":"";
        //alert(kayanNes.scrollLeft + " " + (kayanNes.scrollWidth-kayanNes.offsetWidth));
    }
}



function KaydirmaOklariDik()
{
    kayanNes = document.getElementById("dvKayanDik");
//    imgSolOk = document.getElementById("imgSolOk");
//    imgSagOk = document.getElementById("imgSagOk");
//    imgSolOk.style.display = "none";
//    imgSagOk.style.display = ((kayanNes.scrollWidth-kayanNes.offsetWidth) > sonlandirmaArtigi)?"":"none";
//    
//    if(imgSagOk.style.display == "none")
//    {
//        document.getElementById("imgSagOkPasif").style.display = document.getElementById("imgSolOkPasif").style.display = "none";
//    }
}


//YUKARI KAYDIR
function KaydirmaOklariDik()
{
    kayanNesDik = document.getElementById("dvKayanDik");
//    imgSolOk = document.getElementById("imgSolOk");
//    imgSagOk = document.getElementById("imgSagOk");
//    imgSolOk.style.display = "none";
//    imgSagOk.style.display = ((kayanNesDik.scrollHeight-kayanNesDik.offsetWidth) > sonlandirmaArtigi)?"":"none";
//    
//    if(imgSagOk.style.display == "none")
//    {
//        document.getElementById("imgSagOkPasif").style.display = document.getElementById("imgSolOkPasif").style.display = "none";
//    }
}

function KaydirDik(yonDik)
{
    if(calismaKilidi == 0)
    {
        calismaKilidi = 1;
        kayanNesDik = document.getElementById("dvKayanDik");        
        hedef = kayanNesDik.scrollTop + yonDik*hedefBelirleDik;

        if(hedef > (kayanNesDik.scrollHeight-kayanNesDik.offsetWidth) || hedef < 0)
        {
            calismaKilidi = 0;
            kayanNesDik.scrollTop = 232;
            
            return;
        }
        if(hedef == 0)
        {
             calismaKilidi = 0;
            kayanNesDik.scrollTop = 870;
        }
            
        if(yonDik==1)
            HedefeKayIleriDik();
        else 
            HedefeKayGeriDik();
    }
}

function HedefeKayIleriDik()
{
    if(calismaKilidi && ((kayanNesDik.scrollTop+=_pxAdim) < hedef)) setTimeout("HedefeKayIleriDik()", _msAra);
    else
    {
        calismaKilidi = 0;
        artikKayma = kayanNesDik.scrollTop % hedefBelirleDik;
        //alert("kayanNesDik.scrollTop % _pxAdim ("+kayanNesDik.scrollTop+" % "+hedefBelirleDik+") = artikKayma (" + artikKayma + ")");
        kayanNesDik.scrollTop -= artikKayma;
        
//        imgSolOk.style.display = (kayanNesDik.scrollTop == 0)?"none":"";
//        imgSagOk.style.display = (kayanNesDik.scrollTop == (kayanNesDik.scrollHeight-kayanNesDik.offsetWidth-sonlandirmaArtigi))?"none":"";        
       // alert(kayanNesDik.scrollTop + " " + (kayanNesDik.scrollHeight-kayanNesDik.offsetWidth));
    }
}

function HedefeKayGeriDik()
{
    if(calismaKilidi && ((kayanNesDik.scrollTop -= _pxAdim) > hedef))setTimeout("HedefeKayGeriDik()", _msAra);
    else
    {
        calismaKilidi = 0;
        artikKayma = hedefBelirleDik - (kayanNesDik.scrollTop % hedefBelirleDik);
        //alert("kayanNesDik.scrollTop % _pxAdim ("+kayanNesDik.scrollTop+" % "+hedefBelirleDik+") = artikKayma (" + artikKayma + ")");
        if(artikKayma != hedefBelirleDik)
        kayanNesDik.scrollTop += artikKayma;
        
//        imgSolOk.style.display = (kayanNesDik.scrollTop == 0)?"none":"";
//        imgSagOk.style.display = (kayanNesDik.scrollTop == (kayanNesDik.scrollHeight-kayanNesDik.offsetWidth-sonlandirmaArtigi))?"none":"";
        //alert(kayanNesDik.scrollTop + " " + (kayanNesDik.scrollHeight-kayanNesDik.offsetWidth));
    }
}

