﻿
var currentPage = 1;
var isStop = false;
var isRunning = false;
var playerImagesCount = 3;
var showPage = 2;
var currentPageObj;
var showPageObj;
var playerTime = 10000;

$(function() {
    setInterval("Player()", playerTime);
});

function Player() {
    if (isStop || isRunning) return;

    NextImage();    
}

function PerviousImage() {
    if (isRunning) return;
    isRunning = true;
    
    if (currentPage == 1)
        showPage = playerImagesCount;
    else showPage = currentPage - 1;

    currentPageObj = $("#img_" + currentPage);
    showPageObj = $("#img_" + showPage);

    if (showPage < currentPage) {

        showPageObj.css("margin-left", "-908px");

        showPageObj.show();
        showPageObj.animate({ "margin-left": "0px" }, "slow", MoveComplete);
    }
    else {

        showPageObj.css("margin-left", "-1816px");
        showPageObj.show();
        currentPageObj.animate({ "margin-left": "908px" }, "slow", MoveComplete);
    }
}

function NextImage() {
    if (isRunning) return;
    isRunning = true;
    
    if (currentPage == playerImagesCount)
        showPage = 1;
    else showPage = currentPage + 1;

    currentPageObj = $("#img_" + currentPage);
    showPageObj = $("#img_" + showPage);

    if (showPage > currentPage) {
        
        showPageObj.css("margin-left", "0px");

        showPageObj.show();
        currentPageObj.animate({ "margin-left": "-908px" }, "slow", MoveComplete);
    }
    else {
        showPageObj.css("float", "right");
        showPageObj.css("float", "right");

        showPageObj.show();
        $("#img_div").animate({ "margin-left": "-908px" }, "slow", MoveComplete);
    }
}

function MoveComplete() {
    currentPageObj.hide();
    $("#img_div").css("margin-left", "0px");
    showPageObj.css("float", "left");
    currentPageObj.css("float", "left");
    showPageObj.css("margin-right", "0px");
    currentPageObj.css("margin-right", "0px");
    showPageObj.css("margin-left", "0px");
    currentPageObj.css("margin-left", "0px");
    currentPage = showPage;

    isRunning = false;
}

function PauseOrResume(obj) {
    if (isStop) {
        isStop = false;
    }
    else {
        isStop = true;
    }
}

