﻿/*
    This is the client script library for Mondorux to use its web services site-wide.
    It uses the behaviour.js, prototype.js and scriptaculous.js libraries and
    the web service proxy created by AJAX.NET.
*/

var avvisato = false;

// To get the next memo from the Memento web service
function GetNextMemo() {
    with (new Date()) {
		var now = toLocaleDateString() + " " + toLocaleTimeString();
	}
    Mondorux.Memento.GetNextHtmlMemo(
        now,
        function(result){
            $('nextmemo_space').innerHTML = result;
            new Effect.Appear('nextmemo_space');
            if($('nextmemo_space').down(1).innerHTML == "fra meno di un minuto"){
                if(!avvisato){
                    alert($('nextmemo_space').down(0).innerHTML);
                    avvisato = true;
                }
            } else { avvisato = false; }
        },
        function(result){
            new Effect.Fade('nextmemo_space');
        }
    );
}

// Behaviours
var mondorux_rules = {
    '#nextmemo_space': function(element){
        element.onmouseover = function() {
            new Effect.Highlight($('memos').down('li#' + $(element).down().readAttribute('id')));
        }
    },
    '#gethelp': function(element){
        element.onclick = function() {
            new Effect.toggle($('help'), 'blind');
        }
    },
    '#whysign': function(element){
        element.onclick = function() {
            new Effect.toggle($('becausesign'), 'blind');
        }
    },
    '#errore': function(element){
        element.onclick = function() {
            element.innerHTML = "";
        }
    },
    'div.has-popup': function(element){
        element.onmouseover = function() {
            $(element).down('.popup-label').style.display = "block";
        },
        element.onmouseout = function() {
            $(element).down('.popup-label').style.display = "none";
        }
    },
    '#lostpw': function(element){
        element.onmouseover = function() {
            new Effect.Highlight($('pw_recovery'));
            
        }
    }     
};
Behaviour.register(mondorux_rules);
Behaviour.addLoadEvent(
    function(){
        GetNextMemo();
        new PeriodicalExecuter(GetNextMemo, 10);        
    }
);

