$(document).ready(function(){
	// Set up the cookies and interstitial:
	if( undefined == $.cookie('views') ){
		// Set the cookie:
		$.cookie('views', '0', { expires: 3, path: '/', domain: 'boatmangeller.com' });
	} else{
		if(parseInt($.cookie('views')) < 16){
			// Increment the cookie:
			$.cookie('views', (parseInt($.cookie('views')) + 1), { expires: 3, path: '/', domain: 'boatmangeller.com' });
		}
		
		if(parseInt($.cookie('views')) >= 16 && $.cookie('action') != 'nothanks'){
			$.cookie('views', 0, { expires: 3, path: '/', domain: 'boatmangeller.com' });
		}

		// Determine if we should show the interstitial:
		if(parseInt($.cookie('views')) === 2){
			// Show the interstitial:
			var interstitial = $('#interstitial').dialog({
				dialogClass: "module",
				draggable: false,
				height: '402',
				modal: true,
				resizable: false,
				width: '500',
				open: function() {
					try {
						pageTracker._trackEvent("Interstitial", "Show");
					} catch(err) {}

					$('.ui-dialog-overlay').click(function() {
						$(interstitial).dialog("close");
						$.cookie('views', 3, { expires: 3, path: '/', domain: 'boatmangeller.com' });
						$.cookie('action', 'clickbehind', { expires: 3, path: '/', domain: 'boatmangeller.com' });
						try {
							pageTracker._trackEvent("Interstitial", "Click Behind");
						} catch(err) {}
						return false;
					});
					$(".module .close_modal").click(function() {
						$(interstitial).dialog("close");
						$.cookie('views', 3, { expires: 30, path: '/', domain: 'boatmangeller.com' });
						$.cookie('action', 'nothanks', { expires: 30, path: '/', domain: 'boatmangeller.com' });
						try {
							pageTracker._trackEvent("Interstitial", "No Thanks");
						} catch(err) {}
						return false;
					});
					$(".module .dismiss_modal").click(function() {
						$(interstitial).dialog("close");
						$.cookie('views', 3, { expires: 3, path: '/', domain: 'boatmangeller.com' });
						$.cookie('action', 'maybelater', { expires: 3, path: '/', domain: 'boatmangeller.com' });
						try {
							pageTracker._trackEvent("Interstitial", "Maybe Later");
						} catch(err) {}
						return false;
					});
				}
				
			});
		}

		// Determine if we should show the interstitial:
		if($.cookie('first') != 'shown'){
		}
	}
});
