jQuery.employeeSearch = (function($){
	return function(settings) {
		if (document.title.match(/Logga in/)) { return; }
    	var config = {
			language: "sv"
    	};
    	if (settings) $.extend(config, settings);
    	function letVisitorContinue() {
			$('#continue-link').fadeIn();
    }
    
  var text = settings.text;
  var link = settings.link;
  var close = link.match(/en/)? 'close': 'stäng';
    
  var showEmployeeSearch = 'Faviken.showEmployeeSearch';
	var mayContinueRightAway = 'Faviken.mayContinueRightAway';
  var hasSeenSplashAlready = $.cookie(mayContinueRightAway);
	var visitingNow = $.cookie(showEmployeeSearch);
    
	// if has read before, show the continue-button right away.
	// else, wait 45 seconds.
	if (!visitingNow) {
		$.cookie(showEmployeeSearch, 'true', { path: '/', expires: .1 });

		if (config.language == "sv") {
			$('body').append( '<div id="EmployeeSearchScreen"><a href="' + link + 
			                  '"><div id="overlay" style="display: block; position: ' + 
			                  'absolute; top: 0pt; left: 0pt;"></a></div><div id="EmployeeSearch">' + 
			                  text + '<a id="close" href="#">X ' + close + '</a></div></div>');
		}
      	$('#close').click(function(evt) {
			    $('#EmployeeSearchScreen').fadeOut(1000, function() {
			      $(this).remove();
			    });
			    evt.stopPropagation();
			    evt.preventDefault();
		});

		if (hasSeenSplashAlready) {
    		letVisitorContinue();
		} 
		else {
        	$.cookie(mayContinueRightAway, 'true', { path: '/', expires: 999 });
        	setTimeout( function(){
      	  		letVisitorContinue();
      			}, 1000 * 12);
		}
  	}
  };
})(jQuery);
