﻿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";
}

function addAtributes(rotatorID, i) {
    document.getElementById('btnRight'+i).onmouseover = function() { ChangeDirection('left', rotatorID); }
    document.getElementById('btnRight'+i).onmouseout = function() { FreezeRotator(rotatorID); }
    //document.getElementById('btnRight'+i).onmousedown = function() { SpeedUp('left', rotatorID); }
    //document.getElementById('btnRight'+i).onmouseup = function() { SlowDown('left', rotatorID); }
    document.getElementById('btnLeft'+i).onmouseover = function() { ChangeDirection('right', rotatorID); }
    document.getElementById('btnLeft'+i).onmouseout = function() { FreezeRotator(rotatorID); }
    //document.getElementById('btnLeft'+i).onmousedown = function() { SpeedUp('right', rotatorID); }
    //document.getElementById('btnLeft'+i).onmouseup = function() { SlowDown('right', 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 == "left") rotator.ScrollLeftNextFrame();
    else rotator.ScrollRightNextFrame();
}
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 == "left") rotator.ScrollLeftNextFrame();
    else rotator.ScrollRightNextFrame();
}

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);
}



