fade_time = 5000;
function init_fader() {
	imagini = $('pic_changer').getElementsByTagName("img");
	lis = $('pic_changer').getElementsByTagName('li');
	
	var numar_poze = imagini.length;
	for ( i=0;i<lis.length;i++ ) {
		lis[i].onclick = function() { new_id = this.id.split("_") ; show_pic(new_id[2]-1); return false; }
	}
	show_pic(0);
}
function show_pic(numar,prev) {
	clearTimeouts();
	imagini = $('pic_changer').getElementsByTagName("img");
	var numar_poze = imagini.length;	
	prev = prev + 1;
	if ( !isNaN(prev)) {
		nrul = numar+1;
		$('top_pic_'+prev).style.dispay="none";
		fadeIn('top_pic_'+nrul,0,3);
	}
	else {
		lis = $('pic_changer').getElementsByTagName('li');
		for ( i=0;i<lis.length;i++ ) {
			lis[i].className = "";
		}
	}
	next = numar + 1 ;
	np = next;
	if ( next >= numar_poze ) { next = 0 ; np = numar+1;}
	$('pic_change_'+np).className= "numar_poza";
	if ( prev > 0 ) $('pic_change_'+prev).className= ""; 
	if ( prev == 0 ) $('pic_change_'+numar_poze).className= ""; 
	imagini = $('pic_changer').getElementsByTagName("img");
	for ( i=0;i<imagini.length;i++ ) {
		imagini[i].style.display = "none";
	}
	numarul=numar+1;
	fadeIn('top_pic_'+numarul,0,3);
	setTimeout('show_pic('+next+','+numar+')',fade_time);
}
timers = new Array();
oldSetTimeout = window.setTimeout;
window.setTimeout = function(code, interval) {
	timers.push(oldSetTimeout(code, interval));
}
function resetTimeouts() {
	timers = new Array();
}
function clearTimeouts() {
	for (var i= 0;i < timers.length; i++) {
		clearTimeout(timers[i]);
	}
	resetTimeouts();
}

function setOpacity(id, opac) {
  if(opac<0){opac=0;} if(opac>100){opac=100;}
  var c = opac/100;
  var docu = document.getElementById(id);
//  alert(id);
  if(typeof(docu.style.filter)=='string'){docu.style.filter='alpha(opacity:'+opac+')';}
  if(typeof(docu.style.KHTMLOpacity)=='string'){docu.style.KHTMLOpacity=c;}
  if(typeof(docu.style.MozOpacity)=='string'){docu.style.MozOpacity=c;}
  if(typeof(docu.style.opacity)=='string'){docu.style.opacity=c;}
}
function fadeIn(id, opac, step) {
    document.getElementById(id).style.display="block";
    setOpacity(id, opac);    
    if (opac<100) {
        setTimeout("fadeIn('"+id+"',"+(opac+step)+","+step+")", 30);
    }
}
function fadeOut(id, opac, step) {
    setOpacity(id, opac);    
    if (opac>0) {
        setTimeout("fadeOut('"+id+"',"+(opac-step)+","+step+")", 30);
    } else {
        document.getElementById(id).style.display="none";
    }
}
