/**
 * This file handles the display of the splash overlay
 */


// setup domain for cookies based on staging or live site
var currentDomain = window.location.href;
if (currentDomain.indexOf("eyemaginetech.enzo.eyemaginetech.com") == -1)
	cookieDomain =  'eyemaginetech.com';
else
	cookieDomain = 'eyemaginetech.enzo.eyemaginetech.com';
 


// set up dimensions of splash overlay
function setupSplashOverlayDimensions() {
	if ($(document).height() > $('#splash-container').height())
		$('#splash-container').height($(document).height() + 200);
	
	$('#splash-container').width($(document).width());
}

// closes splash overlay
function closeSplashOverlay() {
	$('#splash-container').fadeOut(700); 
}

// sets up splash overlay click handler
function setupSplashOverlayClick() {
	$('#splash-container #close-button,#splash-container').click(function() {
		closeSplashOverlay();
	});
}

//sets up splash button click handler
function setupSplashButtonClick() {
	$('#splash-button').click(function() {
		$('#splash-container').fadeIn(700);
	});
}


$(window).load(function() {
	if (jQuery.cookie('firstSiteVisit') !== 'false') {
		
		setupSplashOverlayDimensions()

		$('#splash-container').fadeIn(700);
		
		window.setTimeout(function() { 
			closeSplashOverlay();
		}, 4000);

		$('#splash-content').click(function(e) {
			e.stopPropagation();
		});
		
		setupSplashOverlayClick();
		setupSplashButtonClick();
		
		jQuery.cookie( 'firstSiteVisit', 'false', { domain: cookieDomain, path: '/', expires: 365 } );
	}
	else {
		
		setupSplashOverlayDimensions()

		$('#splash-content').click(function(e) {
			e.stopPropagation();
		});
			
		setupSplashOverlayClick();
		setupSplashButtonClick();
	}
});



