/*
	A simple class for displaying file information and progress
	Note: This is a demonstration only and not part of SWFUpload.
	Note: Some have had problems adapting this class in IE7. It may not be suitable for your application.
*/

// Constructor
// file is a SWFUpload file object
// Instantiating a new NationUploadProgress object with an existing file will reuse/update the existing DOM elements
function NationUploadProgress(file) {
	this.NationUploadProgressID = file.id;

	this.opacity = 100;
	this.height = 0;

	this.NationUploadProgressElement = $("#" + this.NationUploadProgressID);
	if (this.NationUploadProgressElement.length == 0) {
		this.NationUploadProgressElement = $("#nation_upload_template").clone();
		this.NationUploadProgressElement.attr("id", this.NationUploadProgressID);
		this.NationUploadProgressElement.appendTo(".nation_uploads");
		$("#" + this.NationUploadProgressID + " .nation_upload_item_filename").text(file.name);
	}

}
NationUploadProgress.prototype.setProgress = function (percentage) {
	$("#" + this.NationUploadProgressID + " .nation_upload_item_progress_bar").css("width", percentage + "%");
};
NationUploadProgress.prototype.setComplete = function () {
	/*this.NationUploadProgressElement.className = "progressContainer blue";
	this.NationUploadProgressElement.childNodes[3].className = "progressBarComplete";
	this.NationUploadProgressElement.childNodes[3].style.width = "";

	var oSelf = this;
	setTimeout(function () {
		oSelf.disappear();
	}, 10000);*/
};
NationUploadProgress.prototype.setError = function () {
	/*this.NationUploadProgressElement.className = "progressContainer red";
	this.NationUploadProgressElement.childNodes[3].className = "progressBarError";
	this.NationUploadProgressElement.childNodes[3].style.width = "";

	var oSelf = this;
	setTimeout(function () {
		oSelf.disappear();
	}, 5000);*/
};
NationUploadProgress.prototype.setCancelled = function () {
	/*this.NationUploadProgressElement.className = "progressContainer";
	this.NationUploadProgressElement.childNodes[3].className = "progressBarError";
	this.NationUploadProgressElement.childNodes[3].style.width = "";

	var oSelf = this;
	setTimeout(function () {
		oSelf.disappear();
	}, 2000);*/
};
NationUploadProgress.prototype.setStatus = function (status) {
	/*this.NationUploadProgressElement.childNodes[2].innerHTML = status;*/
};

// Show/Hide the cancel button
NationUploadProgress.prototype.toggleCancel = function (show, swfUploadInstance) {
	/*this.NationUploadProgressElement.childNodes[0].style.visibility = show ? "visible" : "hidden";
	if (swfUploadInstance) {
		var fileID = this.NationUploadProgressID;
		this.NationUploadProgressElement.childNodes[0].onclick = function () {
			swfUploadInstance.cancelUpload(fileID);
			return false;
		};
	}*/
};

// Fades out and clips away the NationUploadProgress box.
NationUploadProgress.prototype.disappear = function () {

	var reduceOpacityBy = 15;
	var reduceHeightBy = 4;
	var rate = 30;	// 15 fps

	if (this.opacity > 0) {
		this.opacity -= reduceOpacityBy;
		if (this.opacity < 0) {
			this.opacity = 0;
		}

		if (this.NationUploadProgressWrapper.filters) {
			try {
				this.NationUploadProgressWrapper.filters.item("DXImageTransform.Microsoft.Alpha").opacity = this.opacity;
			} catch (e) {
				// If it is not set initially, the browser will throw an error.  This will set it if it is not set yet.
				this.NationUploadProgressWrapper.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=" + this.opacity + ")";
			}
		} else {
			this.NationUploadProgressWrapper.style.opacity = this.opacity / 100;
		}
	}

	if (this.height > 0) {
		this.height -= reduceHeightBy;
		if (this.height < 0) {
			this.height = 0;
		}

		this.NationUploadProgressWrapper.style.height = this.height + "px";
	}

	if (this.height > 0 || this.opacity > 0) {
		var oSelf = this;
		setTimeout(function () {
			oSelf.disappear();
		}, rate);
	} else {
		this.NationUploadProgressWrapper.style.display = "none";
	}
};