function getPageScroll(){

    var yScroll;
    
    if (self.pageYOffset) {
        yScroll = self.pageYOffset;
    }
    else 
        if (document.documentElement && document.documentElement.scrollTop) { // Explorer 6 Strict
            yScroll = document.documentElement.scrollTop;
        }
        else 
            if (document.body) {// all other Explorers
                yScroll = document.body.scrollTop;
            }
    
    arrayPageScroll = new Array('', yScroll)
    return arrayPageScroll;
}

function getPageSize(){

    var xScroll, yScroll;
    
    if (window.innerHeight && window.scrollMaxY) {
        xScroll = document.body.scrollWidth;
        yScroll = window.innerHeight + window.scrollMaxY;
    }
    else 
        if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
            xScroll = document.body.scrollWidth;
            yScroll = document.body.scrollHeight;
        }
        else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
            xScroll = document.body.offsetWidth;
            yScroll = document.body.offsetHeight;
        }
    
    var windowWidth, windowHeight;
    if (self.innerHeight) { // all except Explorer
        windowWidth = self.innerWidth;
        windowHeight = self.innerHeight;
    }
    else 
        if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
            windowWidth = document.documentElement.clientWidth;
            windowHeight = document.documentElement.clientHeight;
        }
        else 
            if (document.body) { // other Explorers
                windowWidth = document.body.clientWidth;
                windowHeight = document.body.clientHeight;
            }
    
    // for small pages with total height less then height of the viewport
    if (yScroll < windowHeight) {
        pageHeight = windowHeight;
    }
    else {
        pageHeight = yScroll;
    }
    
    // for small pages with total width less then width of the viewport
    if (xScroll < windowWidth) {
        pageWidth = windowWidth;
    }
    else {
        pageWidth = xScroll;
    }
    
    
    arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight)
    return arrayPageSize;
}



var giafatto = false;
var oldx
var oldy;
var xx = 280;
var yy = 160;
var myImage;



function mostra(testo,misura){
	//$$('select', 'object', 'embed').each(function(node){ node.style.visibility = 'hidden' });
	if(misura>0){
	 larg=misura;
	 }
	 else {
	 larg=400;
	 }
	$('player').style.visibility = 'hidden';
	 var objBody = $$('body')[0];

		//objBody.appendChild(Builder.node('div',{id:'overlay'}));
		
		 var arrayPageSize = getPageSize();
        $('overlay').setStyle({ width: arrayPageSize[0] + 'px', height: arrayPageSize[1] + 'px' });
		new Effect.Appear('overlay', { duration: 1.0, from: 0.0, to: 0.6 });

        
	
	//////////////////////////
    ob = document.getElementById('fo')
    os = $(ob);
    
    descr=document.getElementById(testo).innerHTML;
    
    cancImage = new Image();
    cancImage.src = urlimg + 'img/cancel.gif';
    
    
    
    var pulsante = document.createElement('img');
    pulsante.setAttribute('id', 'cancel');
    pulsante.setAttribute('onclick', 'chiudi()');
    pulsante.setAttribute('src', cancImage.src);
    pulsante.setAttribute('alt', 'Chiudi');
    pulsante.setAttribute('title', 'Chiudi');
    pulsante.setAttribute('style', 'float:right;cursor:pointer;margin-bottom:2px;z-index:20;');
    pulsante.style.cssText = 'float:right;cursor:pointer;marging-bottom:2px;z-index:20;';
    ob.appendChild(pulsante);
    
    
   
    var objOverlay = document.createElement('div');
   	objOverlay.innerHTML=descr;
    ob.appendChild(objOverlay);
    
    if (giafatto) {
        chiudi();
        return; 
    }
    arrayPageScroll = getPageScroll();
    page = getPageSize();
    pageX = page[0];
    pageY = page[1];//altezza pagina
    pageH = page[3];//alteza finestra browser
   
        //if(myImage.complete){//non funzia su ie6
        xx = larg;
        yy = 300;
        
        a = 2 * xx;
        b = 2 * yy + 60;
        oldy = pageY / 2;
        oldx = pageX / 2;
        
        ob.style.display = 'none';
        Nxx = oldx - xx
        
        
        var apertura = arrayPageScroll[1] + (pageH / 13);
        ob.style.top = apertura + 'px';
        ob.style.left = Math.round(Nxx) + 'px';
        ob.style.width = Math.round(a) + 'px';
        ob.style.height = 'auto' //Math.round(b) + 'px';
        //ob.style.maxheight =Math.round(b) + 'px';
        
        ob.innerHTML += '<br / class="clear" /><p id="par" onclick="chiudi();"><strong></strong></p>';
        
		
		
		
        new Effect.Appear('fo', { 
            duration: 0.5
        });
        //cancel = document.getElementById('cancel');
        //cancel.onclick = function(){chiudi();}
        
        giafatto = true;
        delete xx;
        delete yy;
        //}
    //fine onload
}//fine mostra

function chiudi(){
    giafatto = false;
	
	new Effect.Fade('overlay', { duration: 1.0, from: 0.6, to: 0.0 });
    new Effect.Fade('fo')
    ob = document.getElementById('fo');
    ob.innerHTML = "";
    $$('select', 'object', 'embed').each(function(node){ node.style.visibility = 'visible' });
    $('player').style.visibility = 'visible';
			
}

///////////////////////////		
var log_chiuso = true;
function apri_login(){
	//new Effect.toggle('logapp', 'slide', { delay: 0.3 });
	if(log_chiuso){
		new Effect.Move('wrapper_login', { x: 0, y: -92, mode: 'relative' })
		$('apri').style.display='none';
		$('apri2').style.display='block';
		log_chiuso=false;
		new Effect.Appear('logapp');
		
	}else {
	new Effect.Move('wrapper_login', { x: 0, y: 92, mode: 'relative' })
		$('apri').style.display='block';
		$('apri2').style.display='none';
		log_chiuso=true;
		new Effect.Fade('logapp');
	}
}

function apri_filtro(id){
	new Effect.toggle('filtro_opere', 'slide', { delay: 0.3 });	
}

function show_prm(id){
if (!document.getElementsByTagName) {

        return;
    }
   
    var prm = document.getElementsByTagName('div');
    for (var i = 0; i < prm.length; i++) {
		 var prmo = prm[i];
		//strclass=String(prmo.getAttribute('class'));
		strclass=String(prmo.className);
		strid=String(prmo.getAttribute('id'))
		
		 if(strid!=id && strclass=='prms'){
		 prmo.style.display='none';
		 }
		 
        else if (strid==id && strclass=='prms'){
        	new Effect.Appear(id);
        	}
		}
		
}
		
		
		
		
function apri_gallery(id_stampa){
$$('select', 'object', 'embed').each(function(node){ node.style.visibility = 'hidden' });
 new Ajax.Updater('gall', urlo + 'fuzajax/gallery', {
          onComplete: function(request){
            mostra('gall')
        },
         parameters: 'id_stampa='+id_stampa, 
        insertion: Insertion.insertContent,
        asynchronous: true
    });
    
} 


function multi_foto(){

new Ajax.Updater('multimedia', urlo + 'fuzajax/foto', {
		 onLoading: function(request){
           // new Effect.Fade('multimedia');
            $('multimedia2').style.display='none';
        	},
          onComplete: function(request){
          new Effect.Appear('multimedia2',{duration: 2.0});
          },
        insertion: Insertion.insertContent,
        asynchronous: true
    });

}


function multi_video(){

new Ajax.Updater('multimedia', urlo + 'fuzajax/video', {
		 onLoading: function(request){
          //  new Effect.Fade('multimedia');
          $('multimedia2').style.display='none';
        	},
          onComplete: function(request){
          new Effect.Appear('multimedia2',{duration: 2.0});
          },
        insertion: Insertion.insertContent,
        asynchronous: true
    });

}


/////////////////
function rassegna_video(){
new Ajax.Updater('rassegna', urlo + 'fuzajax/rasvideo', {
		 onLoading: function(request){
          //  new Effect.Fade('multimedia');
          $('rassegna2').style.display='none';
        	},
          onComplete: function(request){
          new Effect.Appear('rasssegna2',{duration: 2.0});
          },
        insertion: Insertion.insertContent,
        asynchronous: true
    });

}

function rassegna_audio(){
new Ajax.Updater('rassegna', urlo + 'fuzajax/rasaudio', {
		 onLoading: function(request){
          //  new Effect.Fade('multimedia');
          $('rassegna2').style.display='none';
        	},
          onComplete: function(request){
          new Effect.Appear('rassegna2',{duration: 2.0});
          },
        insertion: Insertion.insertContent,
        asynchronous: true
    });

}

function rassegna_stampa(){
new Ajax.Updater('rassegna', urlo + 'fuzajax/raspdf', {
		 onLoading: function(request){
          //  new Effect.Fade('multimedia');
          $('rassegna2').style.display='none';
        	},
          onComplete: function(request){
          new Effect.Appear('rassegna2',{duration: 2.0});
          },
        insertion: Insertion.insertContent,
        asynchronous: true
    });

}


////////////////////


var id;
var ids;
function accord(divo){
    if ((id != divo) && (id) && document.getElementById(id).style.display != 'none') {
        new Effect.toggle(id, 'blind');
    }
    new Effect.toggle(divo, 'blind');
    id = divo;
}

function disaccordo(divo){
    if ((ids != divo) && document.getElementById(ids) && document.getElementById(ids).style.display != 'none') {
        new Effect.toggle(ids, 'blind');
    }
    new Effect.toggle(divo, 'blind');
    ids = divo;
}


function change_img(obj,img){
//$(obj).src=urlimg+'img/'+img';change_img('cc1','cartelle_stampa_btn_over.gif')
}



function toggleDisp() {
    for (var i=0;i<arguments.length;i++){
        var d = $(arguments[i]);
        if (d.style.display == 'none')
            d.style.display = 'block';
        else
            d.style.display = 'none';
    }
}
/*-----------------------------------------------------------
    Toggles tabs - Closes any open tabs, and then opens current tab
    Input:     1.The number of the current tab
                    2.The number of tabs
                    3.(optional)The number of the tab to leave open
                    4.(optional)Pass in true or false whether or not to animate the open/close of the tabs
    Output: none 
    ---------------------------------------------------------*/
function toggleTab(num,numelems,opennum,animate) {
    if ($('tabContent'+num).style.display == 'none'){
        for (var i=1;i<=numelems;i++){
            if ((opennum == null) || (opennum != i)){
                var temph = 'tabHeader'+i;
                var h = $(temph);
                if (!h){
                    var h = $('tabHeaderActive');
                    h.id = temph;
                }
                var tempc = 'tabContent'+i;
                var c = $(tempc);
                if(c.style.display != 'none'){
                    if (animate || typeof animate == 'undefined')
                        Effect.toggle(tempc,'blind',{duration:0.5, queue:{scope:'menus', limit: 3}});
                    else
                        toggleDisp(tempc);
                }
            }
        }
        var h = $('tabHeader'+num);
        if (h)
            h.id = 'tabHeaderActive';
        h.blur();
        var c = $('tabContent'+num);
        c.style.marginTop = '2px';
        if (animate || typeof animate == 'undefined'){
            Effect.toggle('tabContent'+num,'blind',{duration:0.5, queue:{scope:'menus', position:'end', limit: 3}});
        }else{
            toggleDisp('tabContent'+num);
        }
    }
}

