var modalPopup = new function() {
	var _this = this;
	_this.init = function (){
		appendPopup();
		centerPopup();
		disableLinks();
	}

	function centerPopup(){
		var popup = document.getElementById('popup');
		popup.style.left = (document.body.clientWidth - popup.clientWidth)/2 + 'px';
	}
	
	function appendPopup(){
	
		// let's grab request url and redirect the user to an equivalent page on Gust.
		var gust_pages = {	'about-us': 'about', 'angel-capital': 'recentpress', 'angel-investor': 'browse', 'contact':'contact', 
							'deal-flow':'platform','deal-flow-crm':'platform','deal-room':'investors','entrepreneur':'industrystandard',
							'management':'team','start-up-business-plan':'entrepreneurs','start-up-capital':'platform','start-up-financing':'platform',
							'start-up-funding':'entrepreneurs','start-up-money':'r/search/investors', 'venture-valuation':'knowledge'	},
		url = 'https://www.gust.com',
		login_url = 'https://www.gust.com/r/users/sign_in',
		path = window.location.pathname,
		name = path.split('/');
		name.reverse();
		// If the users requested a page that is not available on the new Gust then send them to its homepage		
		if(name[1] in gust_pages){
			url = url + '/' + gust_pages[ name[1] ]
		} else{
			url += path;
		}
		var overlay = $('<div class="hide" id="modal_bg"></div>'),
			popup = $('<div class="hide" id="popup"></div>'),
			content = '<h2>Angelsoft is now Gust!</h2>';
				content += '<p>Whether you\'re an entrepreneur or investor, Gust offers you an enhanced way to connect and collaborate. Go to <a href="'+url+'">Gust.com</a> and <a href="'+login_url+'">sign in </a>with your old Angelsoft log in.</p>';
				content += '<p>While <a href="'+url+'">Gust.com</a> is currently available only in English, over the next few weeks we\'ll be adding the complete site experience in French, Spanish, Portuguese, and Chinese. Stay tuned!</p>';
				content += '<p class="btn btn_primary rounded"><a href="'+url+'">Go to Gust.com</a></p>';
				content += '<p class="btn btn_secondary rounded"><a href="'+login_url+'">Log In</a></p>';				
		$(popup).append(content);
		$('body').append(overlay);
		$('body').append(popup);
	}
	
	function disableLinks(){
		$('a').not('#popup a').click(function(ev){
			ev.preventDefault();
		})
	}	
}
$(document).ready(function(){
	modalPopup.init();
})

