
var Popup = {
	
	popupMinWidth	: 240,
	popupMaxWidth	: 960,
	currentWidth	: 320,

	confirm : function(Question, Action) {
		Popup.setTitle('Question');
		Popup.setContent('<div class="LoadingContent">Loading content...</div>');
		Popup.show(500);
		xajax_renderConfirmQuestion(Question, Action);		
	},
	
	error : function(Message) {
		Popup.infoBox(Message, 'Error');
	},
	
	infoBox : function(Message, Type) {
		Popup.setContent('<div class="LoadingContent">Loading content...</div>');
		Popup.show(500);
		xajax_renderInfoBox(Message, Type);		
	},

	getWindowWidth : function() {
	  var myWidth = 0, myHeight = 0;
	  if( typeof( window.innerWidth ) == 'number' ) {
	    //Non-IE
	    myWidth = window.innerWidth;
	  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	    //IE 6+ in 'standards compliant mode'
	    myWidth = document.documentElement.clientWidth;
	  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	    //IE 4 compatible
	    myWidth = document.body.clientWidth;
	  }
	  return myWidth;
	},

	getWindowHeight : function() {
	  var myWidth = 0, myHeight = 0;
	  if( typeof( window.innerWidth ) == 'number' ) {
	    //Non-IE
	    myHeight = window.innerHeight;
	  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	    //IE 6+ in 'standards compliant mode'
	    myHeight = document.documentElement.clientHeight;
	  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	    //IE 4 compatible
	    myHeight = document.body.clientHeight;
	  }
	  return myHeight;
	},

	hide : function() {
		$('FancyPopup').style.display	= 'none';
		$('FancyPopupLoader').style.display	= 'none';
		$('FancyPopupDimmer').style.display	= 'none';
	},

	hideDimmer : function() {
		$('FancyPopupDimmer').style.display	= 'none';
		$('FancyPopupLoader').style.display	= 'none';
	},
	
	cleanPopup : function() {
		xajax_xCreatePopup()
	},
	
	setContent : function(Content) {
		if( $('FancyPopupContent') ) {
			$('FancyPopupContent').innerHTML = Content;
		}
	},
	
	setTitle : function(Title) {
		
		if( $('FancyPopupHeader') ) {
			$('FancyPopupHeader').innerHTML = Title;
		}
	},

	show : function(Width) {
	
		if ( Width < this.popupMinWidth ) {
			Width	= this.popupMinWidth;
		}
		
		if ( Width > this.popupMaxWidth ) {
			Width = this.popupMaxWidth;
		}
		
		var currentYOffset	= document.viewport.getScrollOffsets();
		var screenWidth		= this.getWindowWidth();
		var screenHeight	= this.getWindowHeight();
		
		$('FancyPopupContent').style.width	= Width+'px';
		$('FancyPopup').style.width			= Width+'px';
		
		var popupWidth					= $('FancyPopup').getWidth();
		var popupHeight					= $('FancyPopup').getHeight();
		
		$('FancyPopup').style.margin	= '0';
		$('FancyPopup').style.left		= ((screenWidth/2)-(popupWidth/2))+'px';
		if( typeof( window.innerWidth ) == 'number' ) {
			$('FancyPopup').style.top			= '64px';
		} else {
			window.scroll(0,0);
			$('FancyPopup').style.top			= '64px';
		}
		
		$('FancyPopup').style.position		= 'fixed';
		$('FancyPopupDimmer').style.display	= 'block';
		$('FancyPopup').style.display		= 'block';
		
		// new Draggable('FancyPopup', { handle: 'fancy-popup-header', starteffect: '', endeffect: '' });
		this.currentWidth	= Width;	
	},
	
	showDimmer : function() {
		$('FancyPopupDimmer').style.display	= 'block';
	},
	
	showLoader : function() {
		$('FancyPopupLoader').style.display	= 'block';
		$('FancyPopupDimmer').style.display	= 'block';
	},
	
	hideLoader : function() {
		$('FancyPopupLoader').style.display	= 'none';
		$('FancyPopupDimmer').style.display	= 'none';
	}
}