﻿/*

CODE BY ismailperim
ismail@perim.net

*/

function Slider(_nesneAdi, _sliderID, _kutuUzunluk, _kutuYukseklik, _sure) {
    this.KutuUzunluk = _kutuUzunluk;
    this.KutuYukseklik = _kutuYukseklik;
    this.KutuSayi = 0;
    this.SliderID = _sliderID;
    this.Say = 0;
    this.Interval = 0;
    this.IntervalOto = 0;
    this.NesneAdi = _nesneAdi;
    this.Simdiki = 0;
    this.NeKadar = 0;
    this.Sure = _sure;
    this.Islem = false;
    this.Tekrar = false;


    this.Yukle = function () {

        document.getElementById(this.SliderID).style.width = this.KutuUzunluk.toString() + "px";
        document.getElementById(this.SliderID).style.height = this.KutuYukseklik.toString() + "px";
        document.getElementById(this.SliderID).style.overflow = "hidden";

        var icKutular = document.getElementById(this.SliderID).getElementsByTagName("DIV");
        this.KutuSayi = icKutular.length;

        var tablo = document.createElement("TABLE");
        tablo.cellPadding = 0;
        tablo.cellSpacing = 0;
        tablo.style.width = (this.KutuSayi * this.KutuUzunluk).toString() + "px";
        tablo.style.height = (this.KutuYukseklik).toString() + "px";

        var tbody = document.createElement("TBODY");
        var satir = document.createElement("TR");

        var sutun;
        for (i = 0; i < this.KutuSayi; i++) {
            sutun = document.createElement("TD");
            sutun.style.textAlign = "center";
            sutun.style.verticalAlign = "top";
            sutun.style.width = this.KutuUzunluk.toString() + "px";
            sutun.innerHTML = icKutular[i].innerHTML;
            icKutular[i].style.display = "none";
            satir.appendChild(sutun);
        }

        tbody.appendChild(satir);
        tablo.appendChild(tbody);
        document.getElementById(this.SliderID).appendChild(tablo);

        document.getElementById(this.SliderID).scrollLeft = 0;
    }

    this.Kaydir = function (gel) {
        if (!this.Islem) {
            if (gel > this.Simdiki) {
                this.NeKadar = (gel - this.Simdiki) * this.KutuUzunluk;
                this.Interval = setInterval(this.NesneAdi + ".KaydirSaga(" + gel + ")", 1);
                this.Simdiki = gel;
            }
            else {
                this.NeKadar = (this.Simdiki - gel) * this.KutuUzunluk;
                this.Interval = setInterval(this.NesneAdi + ".KaydirSola(" + gel + ")", 1);
                this.Simdiki = gel;

            }
        }
    }

    this.KaydirSaga = function (gel) {

        if (this.Say < this.NeKadar) {
            this.Islem = true;
            this.Say += 3;
            document.getElementById(this.SliderID).scrollLeft += 3;
        }
        else {
            this.Say = 0;
            this.NeKadar = 0;
            clearInterval(this.Interval);
            this.Islem = false;
            if (this.Tekrar) {
                this.Tekrar = false;
                this.Oto();
            }
        }
    }

    this.KaydirSola = function (gel) {

        if (this.Say < this.NeKadar) {
            this.Islem = true;
            this.Say += 6;
            document.getElementById(this.SliderID).scrollLeft -= 6;
        }
        else {
            this.Say = 0;
            this.NeKadar = 0;
            clearInterval(this.Interval);
            this.Islem = false;
            if (this.Tekrar) {
                this.Tekrar = false;
                this.Oto();
            }
        }
    }

    this.Oto = function () {

        this.IntervalOto = setInterval(this.NesneAdi + ".OtoKaynak()", eval(this.Sure));


    }

    this.OtoKaynak = function () {


        if (this.Simdiki < this.KutuSayi - 1) {

            this.Kaydir(eval(this.Simdiki) + 1);

        }
        else {
            this.Kaydir(0);
        }

    }

    this.Sonraki = function () {
        if (!this.Islem) {
            this.Tekrar = true;
            this.Kaydir(eval(this.Simdiki) + 1);
            clearInterval(this.IntervalOto);
        }
    }

    this.Onceki = function () {
        if (!this.Islem) {
            this.Tekrar = true;
            this.Kaydir(eval(this.Simdiki) - 1);
            clearInterval(this.IntervalOto);
        }
    }


}

function Enter(field, event) {
    var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
    if (keyCode == 13) {

        __doPostBack('ctl00$hypAra', '');

        return false;
    }
    else
        return true;
}
