﻿/*! $Id: progressindicator.js 6700 2009-10-21 18:26:57Z bhillebrand $ */

/*						*/
/* @author hillebrand	*/
/*						*/
/*global $: false, Image: false */
"use strict";
function ProgressIndicator(container, hourglasSrc) {
	this.container = container;
	this.id = $(this.container).attr("id") + "ProgressIndicator";
	this.piStatus = true;

	this.Hourglas = new Image();

	//default img URL:					- here -
	this.Hourglas.src = hourglasSrc || "/assets/images/global/progressIndicator.gif";
	this.Hourglas.id = $(this.container).attr("id") + "ProgressIndicatorImg";
	this.Hourglas.className = "progressIndicator";
	this.Hourglas.alt = "loading";
	this.Hourglas.title = "loading";
	this.Hourglas.name = "loading";
	this.Hourglas.width = this.Hourglas.width; /* set html size */
	this.Hourglas.height = this.Hourglas.height;
	this.Hourglas.border = "0";

	this.posX = 0;
	this.posY = 0;

	if ((0 + this.Hourglas.width > 0) && (0 + this.Hourglas.height > 0)) {
		this.posX = Math.floor((0 + this.container.width())  / 2 - (this.Hourglas.width  / 2));
		this.posY = Math.floor((0 + this.container.height()) / 2 - (this.Hourglas.height / 2));
	}
	else {
		this.posX = Math.floor((0 + this.container.width())  / 2 - 33);
		this.posY = Math.floor((0 + this.container.height()) / 2 - 33);
		//alert('container dimension: ' + (0 + this.container.width()) + ' , ' + (0 + this.container.height()) );
		//alert('Hourglas position: ' + this.posX + ' , ' + this.posY);
	}

	$(this.container).eq(0).after('<div id="' + this.id + '" style="position:absolute;  left:' + this.posX + 'px; top:' + this.posY + 'px; width:' +
	this.Hourglas.width + 'px; height:' + this.Hourglas.height + 'px; background-color:inherit; "></div>');

	this.hourglasDiv = $("div#" + this.id, this.container.parent());
	this.hourglasDiv.eq(0).prepend(this.Hourglas);

	this.stop = function (fn) {
		var self = this;
		/* alert('in ' + this.id + ' Stop getPiStaus: ' + this.getPiStaus()); */
		/* this.hourglasDiv.fadeTo(410, 0, this.stopRamp(fn)); */
		this.hourglasDiv.fadeTo(410, 0,
			function () {
				/* alert(self.id + ' stopWorker: ' + self.setPiStaus(false)); */
				self.setPiStaus(false);
				if (typeof(fn) === "function") {
					if (fn) {
						fn();
					}
				}
			}
		);
	};

	this.start = function (fn) {
		// var self = this;
		//this.hourglasDiv.css("opacity", "1");
		/* alert(this.id + ' start: ' + this.setPiStaus(true)); */
		this.setPiStaus(true);
		this.hourglasDiv.fadeTo(1, 1,
			function () {
				/* alert('startWorker: ' + self.setPiStaus(true)); */
				if (typeof(fn) === "function") {
					fn();
				}
			}
		);
	};

	this.getPiStaus = function () {
		return this.piStatus;
	};
	/* alert(this.id + ' getPiStaus: ' + this.getPiStaus()); */

	this.setPiStaus = function (newStatus) {
		this.piStatus = newStatus ? true : false;
		return this.piStatus;
	};
}
/* END   $Id: progressindicator.js 6700 2009-10-21 18:26:57Z bhillebrand $ END   */
