// $Id: fade.js 1409 2007-06-05 07:09:02Z taras $

var buffer_big_image = new Object;
var step = 20;
var timeo = 10;

function Fader( imageId , opa)
{

	if(!opa){
		opa = 100;
	}
	this.image = ge( imageId );
	this.oldImage = '';
	this.opacity = opa;
	this.setOpacity( this.image, this.opacity );
	this.image.style.visibility = 'visible';
	this.active = true;
	var self = this;
	this.fadeIn( self );
	return false;
}

Fader.prototype.changeImage = function( fader, newImage ) {

	if ( ( fader.oldImage != newImage.img.src ) && ( ! fader.active ) ) {
		if(ge( 'but_prev' ) && ge( 'but_next' )) {	
			ge( 'but_prev' ).disabled = true;
			ge( 'but_next' ).disabled = true;
			replaceClass( ge( 'but_prev_f' ), 'fsubnav', 'fsubnav fsubnav_n' );
			replaceClass( ge( 'but_next_f' ), 'fsubnav', 'fsubnav fsubnav_n' );
		}

		fader.oldImage = newImage.img.src;
		fader.caption = newImage.caption;
	 	fader.opacity = 100;
		fader.active = true;
	 	fader.fadeOut( fader );
	}
}


Fader.prototype.fadeIn = function(fader) {

	if ( fader.opacity <= 100) {
		fader.setOpacity( fader.image, fader.opacity );
		fader.opacity += step;
		window.setTimeout( function(){fader.fadeIn(fader)}, timeo );
	} else {
		if(ge( 'but_prev' ) && ge( 'but_next' )) {
			ge( 'but_prev' ).disabled=false;
			ge( 'but_next' ).disabled=false;
			replaceClass( ge( 'but_prev_f' ), 'fsubnav fsubnav_n', 'fsubnav' );
			replaceClass( ge( 'but_next_f' ), 'fsubnav fsubnav_n', 'fsubnav' );
		}
		fader.active = false;
		update_image_caption(fader);
	}
}


Fader.prototype.fadeOut = function(fader) {
	if ( fader.opacity >= 0 ) {
		fader.setOpacity( fader.image, fader.opacity );
		fader.opacity -= step;
		window.setTimeout( function(){fader.fadeOut(fader)}, timeo );
	} else {
		fader.image.src = fader.oldImage;
		window.setTimeout( function(){fader.fadeIn(fader)}, timeo );
	}
}



Fader.prototype.setOpacity = function( obj, opacity ) {
	opacity = (opacity == 100)?99.999:opacity;
  opacity = (opacity <= 0)?0.001:opacity;
  // IE/Win
  obj.style.filter = "alpha(opacity:"+opacity+")";
  // Safari<1.2, Konqueror
  obj.style.KHTMLOpacity = opacity/100;
  // Older Mozilla and Firefox
  obj.style.MozOpacity = opacity/100;
  // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj.style.opacity = opacity/100;
}

function update_image_caption (fader){

}