﻿var PaymentForMember =
{
	elContainer: null,
	detal: 0,
	elContainerSize: null,
	currentHeight: 0,
	top: 0,
	left: 0,
	isFirst: true,
	money: 3000,
	timeForPayment: 60,

	init: function() {
		var elContainer = utilObj.createEl("DIV");
		elContainer.className = "window";
		utilObj.addChildToBody(elContainer);
		this.elContainer = elContainer;

		var elDivHeader = utilObj.createEl("DIV");
		elDivHeader.className = "header";
		elContainer.appendChild(elDivHeader);
		var elClose = utilObj.createEl("SPAN");
		elClose.className = "btnClose";
		elClose.innerHTML = "X";
		utilObj.addEvent(elClose, "click", function(e) {
			PaymentForMember.hide();
		});
		elDivHeader.appendChild(elClose);
		elDivHeader.appendChild(utilObj.createElText("VietNamWays"));

		var elDivContent = utilObj.createEl("DIV");
		elDivContent.className = "content";
		elDivContent.innerHTML = "Bạn đã được thêm <span class='money'>\
			" + this.money + " VNĐ</span> vào tài khoản.<br />\
			<b>Lý do:</b> ở lại trang Web hơn <span class='time'>\
			" + this.timeForPayment + " phút</span>.";
		elContainer.appendChild(elDivContent);
		this.elContainerSize = utilObj.getElementSize(this.elContainer);

		if (utilObj.isIE && utilObj.appVersion < 7) {
			this.elContainer.style.position = "absolute";
			utilObj.addEvent(document, "scroll", function(e) {
				PaymentForMember.fitPostionWindow(e);
			});
		}
		else {
			this.elContainer.style.position = "fixed";
		}
		utilObj.addEvent(window, "resize", function(e) {
			PaymentForMember.fitPostionWindow(e);
		});
	},

	hide: function() {
		this.elContainer.style.top = "-2000px";
		this.elContainer.style.left = "-2000px";
		this.elContainer.style.display = "none";
	},

	createPostionWindow: function(e) {
		if (this.elContainerSize == null) return;
		var de = utilObj.getDocument();
		var deScroll = utilObj.getDocumentScroll();
		this.top = de.clientHeight;
		this.left = de.clientWidth - this.elContainerSize.width;
		if (utilObj.isIE && utilObj.appVersion < 7) {
			this.top += deScroll.scrollTop;
			this.left += deScroll.scrollLeft;
		}
	},

	fitPostionWindow: function(e) {
		if (this.isFirst) {
			this.isFirst = false;
			return;
		}
		if (this.elContainerSize == null) return;
		this.currentHeight = this.elContainerSize.height;
		this.createPostionWindow(e);
		this.elContainer.style.top = (this.top - this.currentHeight) + "px";
		this.elContainer.style.left = this.left + "px";
	},

	show: function(e) {
		if (this.elContainer == null) {
			this.init();
		}
		this.createPostionWindow(e);
		this.growWindow(e);
		window.setTimeout(function(ev) {
			PaymentForMember.hide();
		}, 5000);
	},

	growWindow: function(e) {

		this.detal += 0.01;
		if (this.currentHeight < this.elContainerSize.height) {
			if (this.currentHeight + this.detal >= this.elContainerSize.height) {
				this.currentHeight = this.elContainerSize.height;
			}
			else {
				this.currentHeight += Math.sin(this.detal);
			}
		}
		else {
			this.currentHeight = this.detal = 0;
			return;
		}
		this.createPostionWindow(e);
		this.elContainer.style.top = (this.top - this.currentHeight) + "px";
		this.elContainer.style.left = this.left + "px";
		window.setTimeout(function(ev) {
			PaymentForMember.growWindow(ev);
		}, 10);
	},

	cSharpCall: function(money, timeForPayment) {
		this.money = money;
		this.timeForPayment = timeForPayment;
		utilObj.addEvent(window, "load", function(e) {
			PaymentForMember.show(e);
		});
	}
};