
// ldlImgPlayer object
function ldlImgPlayer (name, images, img_id, div_id, div_w, div_h)
{
	this.name_ = name;

	this.images_ = images;
	this.idx_ = 0;
	this.player_on_ = 0;
	this.time_ = 1000;

	this.img_id_ = img_id;

	this.div_id_ = div_id;
	this.dw_ = div_w;
	this.dh_ = div_h;
}

ldlImgPlayer.prototype.draw_img = function (idx)
{
	var img = document.getElementById (this.img_id_);
	var img_div = document.getElementById (this.div_id_);

	// 'dw' and 'dh' must be of fixed size--either by making sure
	//  'img_div' has a fixed size or by setting 'dw' and 'dh'
	//  explicitly if ''img_div's size depends on 'img's size.
//	var dw = img_div.clientWidth;
//	var dh = img_div.clientHeight;
	
	var iw = this.images_[idx].w_;
	var ih = this.images_[idx].h_;

	img.src = this.images_[idx].title_;

	if (this.dw_ >= iw && this.dh_ >= ih) {
		img.width = iw;
		img.height = ih;
	} else if (this.dw_ >= iw) {
		img.height = this.dh_;
		img.width = iw * (this.dh_ / ih);
	} else if (this.dh_ >= ih) {
		img.width = this.dw_;
		img.height = ih * (this.dw_ / iw);
//	} else {
//		if (iw > ih) {
//	} else {
	}

//	this.idx_ = idx;

//	var title = document.getElementById ("img_title");
//	title.innerHTML = images[idx].title_;
}

ldlImgPlayer.prototype.next_img = function ()
{
	++this.idx_;
	if (this.idx_ >= this.images_.length) {
		this.idx_ = 0;
	}

	this.draw_img (this.idx_);
}

ldlImgPlayer.prototype.prev_img = function ()
{
	--this.idx_;
	if (this.idx_ < 0) {
		this.idx_ = this.images_.length - 1;
	}

	this.draw_img (this.idx_);
}

ldlImgPlayer.prototype.start_player = function ()
{
	var str = this.name_ + ".start_player()";
	this.timeout_ = setTimeout (str, this.time_);
	this.next_img ();
	this.player_on_ = 1;
}

ldlImgPlayer.prototype.stop_player = function ()
{
	clearTimeout (this.timeout_);
	this.player_on_ = 0;
}

ldlImgPlayer.prototype.toggle_player = function ()
{
	if (this.player_on_) {
		this.stop_player ();
	} else {
	  this.start_player ();
	}
}

