﻿function $obj(id) {
    return document.getElementById(id);
}

var PAGINA = 0;
var TPAGINA = 0;
var GALERIA = 0;
function pgAnterior() {
    if (PAGINA > 0) {
        PAGINA--;
        PageMethods.pgAnterior(PAGINA,  OnSucceeded, OnFailed);
    }
}

function pgProxima() {
    if (PAGINA < TPAGINA-1) {
        PAGINA++;
        PageMethods.pgProxima(PAGINA,  OnSucceeded, OnFailed);
    }
}

function mudaFoto(foto) {
    $obj('fotoPrincipal').src = '/images/galerias/' + GALERIA + '/' + foto + '.jpg?w=468&h=350';
}

function OnSucceeded(result, userContext, methodName) {
    if (methodName == "pgAnterior" || methodName == "pgProxima") {
        var LI = document.createElement("li");
        if (result.length > 0) {
            $obj('ulFotos').innerHTML = '';
        }
        for (cc = 0; cc < result.length; cc++) {
            LI.innerHTML = '<p><a href="#" onclick="javascript:mudaFoto(' + result[cc] + ');return false;">' + 
                '<img src="/images/galerias/' + GALERIA + '/' + result[cc] + '.jpg?w=64&amp;h=49&amp;c=2" alt="" width="64" height="49"></a></p>';
            $obj('ulFotos').appendChild(LI);
            LI = document.createElement("li");
        }
    }
}

function OnFailed(error, userContext, methodName) {
    if (methodName == "pgAnterior" || methodName == "pgProxima") {
        alert(error.get_message());
    }
}

if (typeof (Sys) !== "undefined") Sys.Application.notifyScriptLoaded();

function addEvent(obj, evType, fn) {
    if (obj.addEventListener) {
        obj.addEventListener(evType, fn, false);
        return true;
    } else if (obj.attachEvent) {
        var r = obj.attachEvent("on" + evType, fn);
        return r;
    } else {
        return false;
    }
}
//addEvent(window, 'load', INI);
//addEvent(window, 'load', CarregaINI);

window.onload = function() { INI(); CarregaINI();};

function CarregaINI() {
    PAGINA = -1;
    pgProxima();
}

//window.onload = function() { CarregaContatos(); };
