﻿function navigation(total, maximo, rotatorID, i) {

    var totalInt = parseInt(total);
    var maximoInt = parseInt(maximo);

    if (totalInt < (maximoInt + 1)) {
        closeNavigation(i);
    } else {
        addAtributes(rotatorID, i);
    }
}

function closeNavigation(i) {
    //document.getElementById("btnRight" + i).style.display = "none";
    //document.getElementById("btnLeft" + i).style.display = "none";
    var bl = document.getElementById("btnRight" + i);
    bl.className += " disabled";
    bl.onclick = function(){
	    return false;
    }
    var br = document.getElementById("btnLeft" + i);
    br.className += " disabled";
    br.onclick = function(){
	    return false;
    }
}

function addAtributes(rotatorID, i) {
    document.getElementById('btnRight' + i).onmouseover = function () { ChangeDirection('up', rotatorID); }
    document.getElementById('btnRight' + i).onmouseout = function () { FreezeRotator(rotatorID); }
    document.getElementById('btnRight' + i).onmousedown = function () { SpeedUp('up', rotatorID); }
    document.getElementById('btnRight' + i).onmouseup = function () { SlowDown('up', rotatorID); }
    document.getElementById('btnLeft' + i).onmouseover = function () { ChangeDirection('down', rotatorID); }
    document.getElementById('btnLeft' + i).onmouseout = function () { FreezeRotator(rotatorID); }
    document.getElementById('btnLeft' + i).onmousedown = function () { SpeedUp('down', rotatorID); }
    document.getElementById('btnLeft' + i).onmouseup = function () { SlowDown('down', rotatorID); }
}

var canStart = true;

function ChangeDirection(dir, rotatorID) {
    if (!canStart) return;
    else canStart = false;

    var rotator = window[rotatorID];
    rotator.ScrollDirection = dir;
    rotator.StartRotator();
    for (i = 5; i > 0; i--)
        if (dir == "up") rotator.ScrollUpNextFrame();
    else rotator.ScrollDownNextFrame();
}
function FreezeRotator(rotatorID) {
    var rotator = window[rotatorID];
    rotator.Freeze();
    rotator.StopRotator();
    canStart = false;
    window.setTimeout(function() { canStart = true; }, 100);
}

function SpeedUp(dir, rotatorID) {
    var rotator = window[rotatorID];
    rotator.Freeze();
    rotator.StopRotator();
    rotator.StartRotator();
        if (dir == "up") rotator.ScrollUpNextFrame();
    else rotator.ScrollDownNextFrame();
}

function SlowDown(dir, rotatorID) {
    var rotator = window[rotatorID];
    rotator.Freeze();
    rotator.StopRotator();
    canStart = true;
    window.setTimeout(function() { ChangeDirection(dir, rotatorID); }, 100);
}

function showCallbackImage(srcElement, lixo, idx, rotatorID, managerID) {

    var rotator = window[rotatorID];

    for (i = 0; i < rotator.NumberOfFrames; i++) {
        if (i == idx) {
            document.getElementById('imgRotator' + i.toString()).className = 'selected';
        } else {
            document.getElementById('imgRotator' + i.toString()).className = '';
        }
    } window[managerID].AjaxRequest(srcElement + ' ' + idx);
}

// JS to AS target
function getFlashMovie(movieName) {
    var isIE = navigator.appName.indexOf("Microsoft") != -1;
    return (isIE) ? window.document.getElementById(movieName) : document[movieName];
}

//JS to AS data submit
function playVideo(player, clip, idx, rotatorID) {
    var rotator = window[rotatorID];
    for (i = 0; i < rotator.NumberOfFrames; i++) {
        if (i == idx) {
            document.getElementById('imgRotator' + i.toString()).className = 'selected';
        }
        else {
            document.getElementById('imgRotator' + i.toString()).className = '';
        }
    }
    getFlashMovie(player).asPlayVideo(idx + 1);
}



