/* cfader */
TINY.cfader=function(){
  return{
    init:function(divs,fadetime,delay){
    	for(var i=0;i<divs.length;i++){
    		g(divs[i]).style.opacity=0;
    		g(divs[i]).style.position="absolute";
    		g(divs[i]).style.filter="alpha(opacity=0)";
    		g(divs[i]).style.visibility="hidden";
    	}
    	this.nAct=-1;
    	this.aDivs=divs;
    	this.nDur=fadetime;
    	this.nDelay=delay;
    	this.stoppie();
    	this.newfade();
    },
    newfade:function(){
    	if(this.nID1){clearInterval(this.nID1);}
    	this.nOldAct=this.nAct;
    	this.nAct++;
    	if(!this.aDivs[this.nAct]){this.nAct=0;}
    	if(this.nAct==this.nOldAct){return false;}
    	g(this.aDivs[this.nAct]).style.visibility="visible";
    	this.nInt=50;
    	this.nTime=0;
    	var p=this;
    	this.nID2=setInterval(function(){p.fade()},this.nInt);
    },
    fade:function(){
    	this.nTime += this.nInt;
    	var ieop=Math.round( this.easeInOut(this.nTime,0,1,this.nDur)*100);
    	var op=ieop/100;
    	g(this.aDivs[this.nAct]).style.opacity=op;
    	g(this.aDivs[this.nAct]).style.filter="alpha(opacity="+ieop+")";
    	if(this.nOldAct>-1){
    		g(this.aDivs[this.nOldAct]).style.opacity=1-op;
    		g(this.aDivs[this.nOldAct]).style.filter="alpha(opacity="+(100-ieop)+")";
    	}
    	if(this.nTime==this.nDur){
    		clearInterval(this.nID2);
    		if(this.nOldAct>-1){g(this.aDivs[this.nOldAct]).style.visibility="hidden";}
    		var p=this;
    		this.nID1=setInterval(function(){p.newfade()},this.nDelay);
    	}
    },
    easeInOut:function(t,b,c,d){
    	return c/2*(1-Math.cos(Math.PI*t/d))+b;
    },
    stoppie:function(){
      if(this.nID1){clearInterval(this.nID1);}
      if(this.nID2){clearInterval(this.nID2);}
    }
  }
}();

/* SCROLLER */
TINY.scroller=function(){
	return{
		init:function(a,c,b,s,d){
			a=T$(a); a.c=c; a.s=s; c=T$(c); b=T$(b); s=T$(s); a.n=d||0;
			b.style.display='block'; a.style.overflow='hidden';
			var h=a.offsetHeight, t=c.offsetHeight;
			if(t<h){
				b.style.display='none'
			}else{
				a.m=h-t; a.d=t/h; s.style.height=(h*(h/t))+'px'; s.style.top=b.style.top=0;
				s.onmousedown=function(event){TINY.scroller.st(event,a.id); return false};
				s.onselectstart=function(){return false}
			}
			a.l=b.offsetHeight-s.offsetHeight
		},
		st:function(e,f){
			var a=T$(f), s=T$(a.s); a.bcs=TINY.cursor.top(e); a.bct=parseInt(s.style.top);
			if(a.mv){this.sp(f)}
			a.mv=function(event){TINY.scroller.mv(event,f)};
			a.sp=function(){TINY.scroller.sp(f)};
			if(T$$$()){
				document.attachEvent('onmousemove',a.mv); document.attachEvent('onmouseup',a.sp)
			}else{
				document.addEventListener('mousemove',a.mv,1); document.addEventListener('mouseup',a.sp,1)
			}
			if(a.d){s.className+=' '+a.n}
		},
		mv:function(e,f){
			var a=T$(f), m=TINY.cursor.top(e)-a.bcs+a.bct, s=T$(a.s), c=T$(a.c);
			if(m>=0&&m<a.l){
				s.style.top=m+'px'; c.style.top=(m*-1*a.d)+'px'
			}else if(m<0){
				s.style.top=0; c.style.top=0
			}else if(m>a.l){
				s.style.top=a.l+'px'; c.style.top=a.m+'px'
			}
		},
		sp:function(f){
			var a=T$(f), s=T$(a.s); if(a.d){s.className=s.className.replace(' '+a.n,'')}
			if(T$$$()){
				document.detachEvent('onmousemove',a.mv); document.detachEvent('onmouseup',a.sp)
			}else{
				document.removeEventListener('mousemove',a.mv,1); document.removeEventListener('mouseup',a.sp,1)
			}
			a.mv=0;
		}
	}
}();

TINY.cursor=function(){
	return{
		top:function(e){
		  return T$$$()?window.event.clientY+document.documentElement.scrollTop+document.body.scrollTop:e.clientY+window.scrollY
		}
	}
}();

/* AJAX ==== funzioni ==== */
function ajaxShow(id,obj,stile){
  if(stile=="appear"){opacity(id,0,101,200);}
  if(stile=="highlight"){highLight(id);}
  execJSA(id,obj.responseText,false);
  if(stile=="blind"){ g(id).style.position=""; blindDown(id); }
}

function ajaxLoad(id,url,stile){
  if(stile=="appear"){changeOpac(0,id);}
  if(stile=="blind"){var ids=g(id).style; ids.overflow="hidden"; ids.display="block"; ids.height="0px";}
  //else{ g(id).innerHTML='<img src="'+_url+'css/ajax/ajax-loader.gif" alt="" />'; }
  var ajax = new XHConn();
  if(ajax){
    var fnCompleto = function(obj){ ajaxShow(id,obj,stile); }
    var fnErrore = function(){ return true; }
    //var fnErrore = function (obj) { alert("HTTP error: "+obj.status); }
    ajax.connect(url,"GET",false,fnCompleto,fnErrore);
    return false;
  }else{
    return true;
  }
}

function ajaxReplace(id,url,m,o){
  opacity(id,101,0,150);
  g(id).style.height="";
  setTimer("ajaxLoad('"+id+"','"+url+"','appear')",200);
  if(m){
    var e=g(m).getElementsByTagName('li');
    var l=e.length;
  	for(var i=0;i<l;i++){
      var n=e[i].getAttribute("id");
  		if(n==o){e[i].className='current';}
  		else{e[i].className=e[i].className.replace('current','');}
  	}
  }
  return false;
}

/* showimg */
function showimg(o){
  var img=g('gimg').getElementsByTagName('div');
  var ico=g('gico').getElementsByTagName('b');
  var l=ico.length;
	for(var i=0;i<l;i++){ img[i].className=img[i].className.replace('show','hide'); ico[i].className=ico[i].className.replace('switch off','switch');}
	g('img'+o).className='show';
	g('ico'+o).className='switch off';
	return false;
}


