$(document).ready(function(){
	//
	// BBN
	//-------------------------------------------------------------------------------------\
	// Popup Interface v0.1
	//
	//=======================================================================================================\
	//
	// Master
	//
	function userInterface(){
		//
		var popup = this;
		//
		//---------------------------------------------------------------\
		//
		// APP ELEMENTS
		//
		//---------------------------------------------------------------\
		//
		// Elements
		//
		popup.overlay = $('#overlay');
		popup.allPopUps = $('.popup');
		//
		// Initialize
		//
		popup.initialize = function(){
			//			
			popup.overlay.click(function(){
				//
				popup.closePopup();
				// 	
			});	
			//
			popup.allPopUps.click(function(e){
				//
				e.stopPropagation();
				//
			});	
			//
			window.setInterval(function(){popup.centerPopup();}, 100);
			//
		}
		//
		//----------------------------------------\
		//
		// EVIRONMENT METHODS
		//
		//----------------------------------------\
		//
		popup.centerPopup = function(){
			//
			var name = $('#overlay').data('currentPopup');
			//
			if(typeof(name) != undefined){
				//
				var popupHeight = $('#overlay .popup.'+name).height();
				var windowHeight = $(window).height();
				var yPos = (windowHeight/2)-(popupHeight/2);
				//
				$('.popup.'+name).css('marginTop', yPos+'px');
				//
			}
			//
		};
		//
		//----------------------------------------\
		//
		popup.openPopup = function(name, callback, closecallback){
			//
			if(typeof(name) != undefined){
				//
				$('#overlay').data('currentPopup', name);
				$('#overlay').data('currentClosecallback', closecallback);
				//
			}
			//
			if($('#overlay .popup.'+name+' .screen.default').length > 0){
				//
				$('#overlay .popup.'+name+' .screen').hide();
				$('#overlay .popup.'+name+' .screen.default').show();
				//
			}
			//
			popup.centerPopup();
			//
			$('#overlay .popup.'+name).fadeIn(500);
			$('#overlay').fadeIn(500);
			$('#screenfloat').fadeIn(500);
			//
			if(typeof callback == 'function'){
				callback();
			}
			//
		}
		//
		//----------------------------------------\
		//
		popup.closePopup = function(name){
			//
			if(name == undefined){
				name = $('#overlay').data('currentPopup');
				callback = $('#overlay').data('currentClosecallback');
			}
			//
			$('#overlay .popup.'+name).fadeOut(500);
			$('#overlay').fadeOut(500);
			$('#screenfloat').fadeOut(500);
			//
			if(typeof callback == 'function'){
				callback();
			}
			//
		}
		//
		//----------------------------------------\
		//
		popup.centerPopup = function(){
			//
			var name = $('#overlay').data('currentPopup');
			//
			if(name != undefined){
				//
				var popupHeight = $('#overlay .popup.'+name).height();
				var windowHeight = $(window).height();
				var yPos = (windowHeight/2)-(popupHeight/2);
				//
				$('.popup.'+name).css('marginTop', yPos+'px');
				//
			}
			//
		}
		//
	}
	//
	// Instantiate
	popup = new userInterface();
	popup.initialize();
	//
});	

