/** AGGIUNTA LUX - SetCookie - usato x ricordare l'ultimo menu scelto (solo x utente loggato) **/
function SetCookie (name,value,expires,path,domain,secure) {
  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}

/*
	PHOTOREC - JavaScript per animazioni e interattivita'� menu
*/
	
	var myrules = {
		// effetto hover menu
		'.sidebar ul li' : function(element){
			if(!$(element).hasClassName('selected')) {
				element.onmouseover = function(){
					Element.addClassName(element,'selected');
				}
				element.onmouseout = function(){
					Element.removeClassName(element,'selected');
				}
			}
		},
		'.sidebar ul li ul li' : function(element){
			element.onmouseover = function(){}
			element.onmouseout = function(){}
		},

/* commentato in attesa della grafica completa

		'#area_riservata .main .block' : function(element){
			element.onmouseover = function(){
				Element.addClassName(element,'hover');
			}
			element.onmouseout = function(){
				Element.removeClassName(element,'hover');
			}
		},
*/		
		// apertura/chiusura menu principale
		'#toggle-menu-site' : function(element){
			element.onclick = function(){
				new Effect.BlindDown($('menu-site'),{duration: 0.8,delay: 1});
				new Effect.BlindUp($('menu-admin'),{duration: 0.8});
				new Effect.Fade(this);
				Effect.Appear('toggle-menu-admin', {delay: 1});
				//-- LUX -- x ricordare scelta utente
				SetCookie ("last_menu", "menu-site", null, "/");
			}
		},
		// apertura/chiusura menu area riservata
		'#toggle-menu-admin' : function(element){
			element.onclick = function(){
				new Effect.BlindDown($('menu-admin'),{duration: 0.8,delay: 1});
				new Effect.BlindUp($('menu-site'),{duration: 0.8});
				new Effect.Fade(this);
				Effect.Appear('toggle-menu-site', {delay: 1});
				//-- LUX -- x ricordare scelta utente
				SetCookie ("last_menu", "menu-admin", null, "/");
			}
		}
	};


/** AGGIUNTA LUX - funzioni x la visualizzazione dello spinner ad ogni richiesta ajax **/

/*
//riferimento all'oggetto Control.Modal (che visualizza il loading)
var my_loading = new Control.Modal(false, {
	contents:            function(){  
        					return "<div id='loading'></div>";  
    					 },
	fade:                true,
	fadeDuration:        0.50,
	overlayCloseOnClick: false
});
*/

var ID_AJAX_BUTTON = "";

Ajax.Responders.register({
  onCreate: function() {
    //my_loading.open();
    if( ID_AJAX_BUTTON && $( ID_AJAX_BUTTON ) ){
    	try{ $( ID_AJAX_BUTTON ).disable(); }catch(e){}
	    $( ID_AJAX_BUTTON ).addClassName("btn_loading");	    
    }
  },
  onComplete: function() {
    //my_loading.close();
    if( ID_AJAX_BUTTON && $( ID_AJAX_BUTTON )){
	    try{ $(ID_AJAX_BUTTON).enable(); }catch(e){}
	    $(ID_AJAX_BUTTON).removeClassName("btn_loading");
	    ID_AJAX_BUTTON = "";
    }
  },
  onException: function() {
    //my_loading.close();
    if( ID_AJAX_BUTTON && $( ID_AJAX_BUTTON )){
	    try{ $(ID_AJAX_BUTTON).enable(); }catch(e){}
	    $(ID_AJAX_BUTTON).removeClassName("btn_loading");
	    ID_AJAX_BUTTON = "";
    }
  }
});

//--------------------------------------------------------

function goInternal(cod_tipo_oggetto, cod_oggetto){			
	
	var arr = location.pathname.split("/");
	var old_cod_oggetto = arr.pop();
	var old_cod_tipo_oggetto = arr.pop();	

	new Ajax.Updater("content", "/oggetti/view-ajax/"+ cod_tipo_oggetto +"/"+ cod_oggetto, {		
		onSuccess: function(transport){
			
		},
		onComplete: function(){
			//-- se esiste un bottone back gli imposto l'href all'attuale documenti
			if( $("back") ){
				$("back").href = "javascript:goInternal("+old_cod_tipo_oggetto+", "+old_cod_oggetto+")";
			}
			//-- inizializzo l'oggetto (che di default viene creato all'onLoad)
			myLightWindow = new lightwindow();
			
			//-- LUX -- non visualizzo il tag gallery
			myLightWindow.options.hideGalleryTab = true
		}
	});
}

//-----------------------------------------------------------
/* AGGIUNTA SIMO: per impostazione del Referer in tabella utenti Rikorda*/

function GetCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);

    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

if( GetCookie("PROVENIENZA") == null && document.referrer!=""  ){

        var today = new Date();
        var expire = new Date();
        expire.setTime(today.getTime() + 3600000*24*60);

        SetCookie('PROVENIENZA', document.referrer, expire, '/', '', '');
}