function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function triggerClose(){
parent.$.fancybox.close();
}

function autoClose(){
setTimeout("triggerClose()",20000);
}

$.ajax({
   type: "GET",
   url: "http://www.htmlprimer.com/prestitial/fetchprestitial.php",
	success: function(html) {
		var perstitial_code = html;
		//if(readCookie('prestitial') != 'prestitial' && perstitial_code.length > 20){
		if(perstitial_code.length > 20){
			$('#prestitial_wrap').html('<a id="prestitial" href="http://www.htmlprimer.com/prestitial/prestitial.php" style="display:none;"></a>');
	
			$(document).ready(function() {
				$('#prestitial').fancybox({
					'width'			: 782,
					'height'			: 386,
					'padding'			: 0,
					'margin'			: 10,
					'scrolling'			: 'no',
					'hideOnOverlayClick'		: true,
					'overlayOpacity'		: 0.4,
					'overlayColor'		: '#666',
					'titleShow'			: false,
					'showCloseButton'		: false,
					'centerOnScroll'		: true,
					'type'			: 'iframe'
				}).trigger('click');
			});
			
			autoClose();
	
			createCookie( 'prestitial', 'prestitial', '1' );
		}
	}
});
