var SA = {
	'created': 0,
	'opened': 0,
	'size': null,
	'docSize': null,
	'scroll': null,
	'isClosing': 0,
	'isOpening': 0,
	'onYes': null,
	'onNo': null,
	'onOk': null, 
	'ESCClose': 0,
	'open': function(_titulo, _txt, _callback, _type, _esc) {
		//type: 1->ok(alert)(X) / 2->yes/no(confirm)
		//format: 1->Warning(X) / 2->Ok
		if (this.opened == 0 && this.isOpening == 0) {
			if ($('SAWait').style.display != 'none' && $('SAWait').style.display != ''){
				SAWait.close();
			}

			mensure.load();//exec sempre na abertura do alert

			this.isOpening = 1;

			this.callback = _callback;
			this.ESCClose = _esc;

			this.docSize = {x:mensure.widthVisible(), y:mensure.heightVisible()};
			this.scroll = {x:mensure.posScrollX(), y:mensure.posScrollY()};
			var DS = {x:mensure.widthVisible(), y:mensure.heightTotal()};

			$('SATitulo').innerHTML = _titulo;
			$('SAText').innerHTML = _txt;

			$('blockbg').style.height = DS.y + 'px';
			if (!is_ie) {
				$('blockbg').style.width = (DS.x - 17) + 'px';
			} else {
				$('blockbg').style.width = DS.x + 'px';
			}

			if (_type == 1) $('SAAlert').style.display = "block";
			if (_type == 2) $('SAConfirm').style.display = "block";

			$('SA').style.display = "block";
			this.size = {x:$('SA').offsetWidth, y:$('SA').offsetHeight};

			var x = (this.docSize.x-this.size.x)/2+this.scroll.x;
			var y = (this.docSize.y-this.size.y)/2+this.scroll.y;

			if (is_ie6) hideSelect();
			
			$('SA').style.top = y + "px"; 
			$('SA').style.left = x + "px";
			$('blockbg').style.display = 'block';
			$('SA').alphaTo(0,100,'easeoutexpo',0.6,function(){
				SA.opened = 1;
				SA.isOpening = 0;
			});
		}
	},
	'close': function() {
		if (this.opened == 1 && this.isClosing == 0) {
			this.isClosing = 1;
			$('blockbg').style.display = 'none';
			$('SA').alphaTo(100,0,'easeoutexpo',0.6,function(){
				$('SA').style.display = 'none';

				//resetando as dimensões das imagens laterais
				$('SAAlert').style.display = "none";
				$('SAConfirm').style.display = "none";

				SA.opened = 0;
				SA.isClosing = 0;
			});
			if (is_ie6) showSelect();
		}
	},
	'refresh': function() {
		if (this.opened == 1 || this.isOpening == 1) {
			this.docSize = {x:mensure.widthVisible(), y:mensure.heightVisible()};
			this.scroll = {x:mensure.posScrollX(), y:mensure.posScrollY()};

			var DS = {x:mensure.widthVisible(), y:mensure.heightTotal()};
			
			$('blockbg').style.height = DS.y + 'px';
			if (!is_ie) {
				$('blockbg').style.width = (DS.x - 17) + 'px';
			} else {
				$('blockbg').style.width = DS.x + 'px';
			}

			var x = (this.docSize.x-this.size.x)/2+this.scroll.x;
			var y = (this.docSize.y-this.size.y)/2+this.scroll.y;
			
			$('SA').tweenTo(y,x,'easeoutexpo',0.35,null);
		}
	},
	'create': function() {
		if (this.created == 0) {
			new tween('SA');
			new alpha('SA');
			setAlpha('SA', 0);
			
			this.created = 1;
		}
	},
	'clickOk': function() {
		if (this.callback == null) this.close();
		else this.callback.onOk();
	},
	'clickYes': function() {
		this.callback.onYes();
	},
	'clickNo': function() {
		this.callback.onNo();
	}
};

var SAWait = {
	'size': null,
	'docSize': null,
	'scroll': null,
	'open': function() {
		mensure.load();//exec sempre na abertura do alert

		this.docSize = {x:mensure.widthVisible(), y:mensure.heightVisible()};
		this.scroll = {x:mensure.posScrollX(), y:mensure.posScrollY()};
		var DS = {x:mensure.widthVisible(), y:mensure.heightTotal()};

		$('blockbg').style.height = DS.y + 'px';
		if (!is_ie) {
			$('blockbg').style.width = (DS.x - 17) + 'px';
		} else {
			$('blockbg').style.width = DS.x + 'px';
		}

		$('SAWait').style.display = "block";
		this.size = {x:$('SAWait').offsetWidth, y:$('SAWait').offsetHeight};

		var x = (this.docSize.x-this.size.x)/2+this.scroll.x;
		var y = (this.docSize.y-this.size.y)/2+this.scroll.y;
		
		if (is_ie6) hideSelect();

		$('SAWait').style.top = y + "px"; 
		$('SAWait').style.left = x + "px";

		$('blockbg').style.display = 'block';
		setAlpha('SAWait', 0);
		$('SAWait').stopAlpha();
		$('SAWait').alphaTo(0,100,'easeoutexpo',0.6,function(){
			$('SAWait').stopAlpha();
		});
	},
	'close': function() {
		$('blockbg').style.display = 'none';

		$('SAWait').stopAlpha();
		$('SAWait').alphaTo(100,0,'easeoutexpo',0.6,function(){
			$('SAWait').style.display = 'none';
			$('SAWait').stopAlpha();
		});
		if (is_ie6) showSelect();
	},
	'refresh': function() {
		if ($('SAWait').style.display != 'none' && $('SAWait').style.display != ''){
			this.docSize = {x:mensure.widthVisible(), y:mensure.heightVisible()};
			this.scroll = {x:mensure.posScrollX(), y:mensure.posScrollY()};

			var DS = {x:mensure.widthVisible(), y:mensure.heightTotal()};
			
			$('blockbg').style.height = DS.y + 'px';
			if (!is_ie) {
				$('blockbg').style.width = (DS.x - 17) + 'px';
			} else {
				$('blockbg').style.width = DS.x + 'px';
			}

			var x = (this.docSize.x-this.size.x)/2+this.scroll.x;
			var y = (this.docSize.y-this.size.y)/2+this.scroll.y;
			
			$('SAWait').tweenTo(y,x,'easeoutexpo',0.35,null);
		}
	},
	'create': function() {
		new tween('SAWait');
		new alpha('SAWait');
		setAlpha('SAWait', 0);
	}
};