var args = arguments[0];
var WTools = require('WidgetTools');

var animation = require('alloy/animation');

//WTools.setTiProps(args, $.bgView);

initUI();

function initUI(){

	var children;

	if (args.children) {
		
		children = args.children|| [];
		
		if(OS_IOS){
			$.container.add(children);
		}
		
		if(OS_ANDROID){
			for(var i = 0, j = children.length; i < j; i++){
				$.container.add(children[i]);
			}
		}
		
	}
	
	if(args.closeButton){
		$.closeBtn.visible = true;
		$.closeBtn.getView().addEventListener('click', function(e){
			cancelPopup(e);
		});
	}else{
		$.closeBtn.visible = false;
	}
	
}

$.show = function(){
	fadeIn();
};

$.hide = function(){
	fadeOut();
};

function cancelPopup(e){	

	if(e.source !== $.bgView && e.source !== $.closeBtn.getView()) return;
	
	fadeOut();
}

function fadeIn() {
	$.bgView.open();
//	$.bgView.opacity = 0;
	$.bgView.visible = true;
	animation.fadeIn($.bgView, 300, function(e) {
//		$.bgView.opacity = 1;
	});

};

function fadeOut() {

	animation.fadeOut($.bgView, 300, function(e) {
		$.bgView.visible = false;
			$.bgView.close();
	});

};

//WTools.cleanArgs(args);
@@ -419,16 +419,58 @@
 %09%09%0A%09%7D%0A%09%0A
+%09var closeBtnView = $.closeBtn.getView();%0A
 %09if(args
@@ -482,34 +482,32 @@
 eButton)%7B%0A%09%09
-$.
 closeBtn
 .visible = t
@@ -486,32 +486,36 @@
 ton)%7B%0A%09%09closeBtn
+View
 .visible = true;
@@ -517,26 +517,24 @@
 true;%0A%09%09
-$.
 closeBtn
 .getView
@@ -525,26 +525,20 @@
 closeBtn
-.get
 View
-()
 .addEven
@@ -604,26 +604,24 @@
 else%7B%0A%09%09
-$.
 closeBtn
 .visible
@@ -612,16 +612,20 @@
 closeBtn
+View
 .visible
@@ -1157,8 +1157,9 @@
 s(args);
+%0A

correct set visibility of close button