var player;


//конструктор класса Player
function Player(){
    this.step = 3;
    this.delay = 30;
    //this.jump = navigator.appName=='Netscape'? 100 : 100;
    this.jump;
    this.interval;
    this.container = document.getElementById('scontainer');
    this.content = document.getElementById('scontent');
    this.contentWidth = document.getElementById("fpscontenttable").offsetWidth;
    this.row = document.getElementById('machineryRow');
    this.play = function(){
        this.stop();
        setNormalSpeed();
        this.interval = setInterval(moveForward, this.delay);
    };
    this.stop = function(){
        clearInterval(this.interval);
    };
    this.fastForward = function(){
        this.stop();
        setFastSpeed();
        this.interval = setInterval(moveForward, this.delay);
    };
    this.rewind = function(){
        this.stop();
        setFastSpeed();
        this.interval = setInterval(moveBackward, this.delay);
    };
}

function moveForward(){   
    var jump = 0;
    if(parseInt(player.content.style.left) <= (player.contentWidth - parseInt(player.container.style.width)) * -1){
		cloneForward();
        jump = player.jump;
	}
    player.content.style.left = parseInt(player.content.style.left) - (player.step - jump)  + "px";
}

function moveBackward(){ 
    var jump = 0;
    if(parseInt(player.content.style.left) >= 0){
			cloneBackward();
            jump = player.jump;
    }
    player.content.style.left = parseInt(player.content.style.left) + (player.step - jump)  + "px";
}

function setFastSpeed(){
    player.step = 5;  
}

function setNormalSpeed(){
    player.step = 1;
}

function cloneForward(){
	firstNode = player.row.childNodes[0];
	player.jump = firstNode.offsetWidth;
	cloneNode=firstNode;//.cloneNode(true);
    player.row.removeChild(firstNode);
    player.row.appendChild(cloneNode);
}

function cloneBackward(){
	firstNode = player.row.childNodes[0];
	lastNode = player.row.childNodes[player.row.childNodes.length - 1];
	player.jump = lastNode.offsetWidth;
	cloneNode = lastNode;//.cloneNode(true);
	player.row.removeChild(lastNode); 
	player.row.insertBefore(cloneNode, firstNode);
    
}

