$(document).ready(function() {	
						   
	function hideDialog(){
		$('#xmp-mask').hide(1000);
		$('.window').hide();
		//$('#xmp-frame').attr('src', '');
	}
	
	function highlightWord(full, searchWord){
		var searchSpaces = ' ' + searchWord + ' ';
		var sLower = searchWord.toLowerCase();
		var sUpper = searchWord.toUpperCase();
		var sCamel = searchWord.substring(0,1).toUpperCase() + searchWord.substring(1, searchWord.length);
		full = full.replace(' ' + sLower + ' ', ' <span class=\"key-highlight\">' + sLower +'</span> ');
		full = full.replace(' ' + sUpper + ' ', ' <span class=\"key-highlight\">' + sUpper +'</span> ');
		full = full.replace(' ' + sCamel + ' ', ' <span class=\"key-highlight\">' + sCamel +'</span> ');

		return full;
	}
	
	function showDialog(inText){
		var id = '#xmp-dialog';
		//Get the screen height and width
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();
	
		//Set heigth and width to mask to fill up the whole screen
		$('#xmp-mask').css({'width':maskWidth,'height':maskHeight});
		
		//transition effect		
		$('#xmp-mask').fadeIn(1000);	
		$('#xmp-mask').fadeTo("slow",0.8);	

		//Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();
			  
		//Set the popup window to center
		$(id).css('top',  winH/2-$(id).height()/2);
		$(id).css('left', winW/2-$(id).width()/2);
		
		$('#xmp-dialog-content').html(inText);
		
		//transition effect
		$(id).fadeIn(2000);
	}
	
	//Register hiders
	$('#xmp-tools-modal').click(function() {		
		hideDialog();
	});	
	$('#xmp-mask').click(function() {		
		hideDialog();
	});
	
	$('#alert_banner').click(function(){
		hideDialog();							  
	});
	
	$('#xmp-mission').click(function(){
		showDialog();
	});
	
	showDialog();
});