﻿// JScript File

var req   = null;

var count =  0; //количество возможных кликов вправо
var moves =  1; //количество кликов вправо

var arrOfFoto = null;
var left = null;
var right = null;

var div_center = null;

window.onload = function()
{
    div_center = document.getElementById("div_center");
    left = document.getElementById("div_left");
    right = document.getElementById("div_right");
    
    send2();
}
function send2()
{
    req = getRequest2();
    req.onreadystatechange = stateChange_send2;
    req.open("POST", "afishyload.aspx", true);
    req.setRequestHeader("Content-Type", "text/html");
    req.send("");
}
function getRequest2()
{
    var xreq = null;
    if(window.XMLHttpRequest)
    {
        xreq = new XMLHttpRequest;
    }
    else if(typeof ActiveXObject != "undefined")
    {
        xreq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    return xreq;
}
function stateChange_send2()
{
    if(req.readyState == 4)
    {   
        count = req.responseText.split("*count*")[1] - 2;
        if(count > 1) right.style.visibility = "visible";
        parseResponce(req.responseText.split("*send*")[1]);
    }
}
function fotoleft()
{
    if(moves > 1) formTable(--moves);
    if(moves == 1) left.style.visibility = "hidden";
    right.style.visibility = "visible";
}
function fotoright()
{
    if(moves < count) formTable(++moves);
    if(moves == count) right.style.visibility = "hidden";
    left.style.visibility = "visible";
}
function parseResponce(str)
{
    if(str != null)
    {
        arrOfFoto = str.split("***");
        formTable(1);
    }
}
function formTable(p)
{
    var fotos = "";
    for(var i = p; i < 3 + p && i < arrOfFoto.length; i++) fotos += arrOfFoto[i];
    div_center.innerHTML = fotos;
}

