$(document).ready(function() {

function popOpen(popID, popWidth) {

if ($('#' + popID).length > 0) {
	
		//Fade in the Popup and add close button
		$('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).prepend('<a href="#" class="close-btn"></a>');
		 //Define margin for center alignment (vertical horizontal) – we add 80px to the height/width to accomodate for the padding and border width defined in the css
		var popMargTop = ($('#' + popID).height() + 80) / 2;
		var popMargLeft = ($('#' + popID).width() + 10) / 2;
		
		//Apply Margin to Popup
		$('#' + popID).css({ 
			'margin-top' : -popMargTop,
			'margin-left' : -popMargLeft
		});

		//Fade in Background
		$('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
		$('#fade').css({'filter' : 'alpha(opacity=100)'}).fadeIn(0); //Fade in the fade layer 
			
	
}
	

};
	var onealert = $.cookie('seeMeOnce');
		if (onealert != 'viewed') {
			popOpen('welcome', '243'); //Run popOpen function once on load
			$("#mainbody-wrapper").hide();
			// —— THIS IS THE LINE TO ADD
	};
	
	//Close Popups and Fade Layer
	$('a.close-btn').live('click', function() { //When clicking on the close or fade layer…
	$.cookie('seeMeOnce', 'viewed'); 
	$("#mainbody-wrapper").fadeIn();
	$('#fade , .popup_block').fadeOut(function() {
	$('#fade, a.close-btn').remove(); //fade them both out
	});
	return false;
	
	

});
	var fade_out = function() {
  		$('#fade , .popup_block').fadeOut().empty();
		$("#mainbody-wrapper").fadeIn();
		$.cookie('seeMeOnce', 'viewed');
	}
	setTimeout(fade_out, 8000);

//fade the close-btn
	$(document).ready(function() {
	$('.close-btn').append('<span class="hover"></span>').each(function () {
	  var $span = $('> span.hover', this).css('opacity', 0);
	  $(this).hover(function () {
	    $span.stop().fadeTo(500, 1);
	  }, function () {
	    $span.stop().fadeTo(500, 0);
	  });
	});
	});

});
