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 startAd(){
	Modal.show('625', '320')
}

$(document).ready(function() {

	




	Modal = {
		
		overlayID : 'overlay',
		overlayFadeDuration : 450,
		content : '<div id="mod_wrap"><div id="mod_content">\
		<div id="mod_close"><img src = "/images/pop-close.gif" alt ="close" /></div>\
		<div id="popup">\
		<a href="holiday2011/index.html" ><img style = "margin:20px;" src ="/images/holiday_popup.jpg" alt="Hats off to the holidays" /></a>\
		</div></div>',
		contentID : '',
		contentCenter : 0,
		closeID : '',
		overlay : '',
		modalFunction : '',
		docHeight : $(document).height(),
		winHeight : $(window).height(),
		winScrollTop : 0,
		overlayHeight : 0,
		winCenter : 0,
		mod_content_w : 10,
		mod_content_h : 10,
		top_offset : 40,
		
		
		
		
		
	
		addModal : function (){ //if modal doesn't exist in the dom, add it
			
			if($('#' + Modal.overlayID).length == 0){ // look for the ID of whatever you've named your overlay
				$('body').prepend(Modal.overlay); // if it doesn't exist already, add it to the dom
				
			}
			
		
			$('body').prepend(Modal.content);
			
		
			
			
			// set the defaults to animate from on our modal content
			
			// set the height of our overlay to the docuement height
			$('#' + Modal.overlayID).height(Modal.overlayHeight);
			
			
			$('#mod_content').height(Modal.mod_content_h);
			$('#mod_content').width(Modal.mod_content_w);
			$('#mod_wrap').width(Modal.mod_content_w);
			
			$('#' + Modal.overlayID).fadeIn(Modal.overlayFadeDuration, function(){ // fade in the overlay 
				
			
				$('#mod_wrap').show(); //show the modal content by ID and run any functions
			
				
				//center the modal 
				Modal.winCenter=(Modal.winHeight / 2) + Modal.winScrollTop;
				//Modal.contentCenter = $('#mod_wrap').height() / 2 ) -  Modal.top_offset ;
				Modal.contentCenter = (Modal.mod_content_h / 2 ) + Modal.top_offset ;
				
				//offset our content depending on scrollTop
				var contentTop = Modal.winCenter - Modal.contentCenter;
				
				$('#mod_wrap').css('marginLeft', '-' + (Modal.mod_content_w/2) + 'px'); // IF there is a top margin, get rid of it
				$('#mod_wrap').css('top', contentTop);
				
				$('#mod_wrap').css('marginTop', '0px'); // IF there is a top margin, get rid of it
				
				// run any function that was passed
				eval(Modal.modalFunction); 
				
			
			})
			
			//hide the shadowbox and reset the defaults
			$('#' + Modal.overlayID + ', #mod_close').click(function(e){
				e.preventDefault();
				Modal.hide();
			});
			
		},
		
		show : function(w, h, func){
			
			// reset defaults	
			
			Modal.docHeight=$(document).height();
			Modal.winHeight=$(window).height();
			Modal.winScrollTop=$(document).scrollTop();
			Modal.mod_content_w = w;
			
			Modal.mod_content_h = h;
			Modal.setOverlayHeight();
			Modal.overlay = '<div id="' + Modal.overlayID + '"></div>';
			Modal.modalFunction = func;	
			
			Modal.addModal();
			
			
		},
		
		hide : function()
		{
			
			$('#mod_wrap').remove(); //remove the modal content 
			$('#' + Modal.overlayID).fadeOut(Modal.overlayFadeDuration) // fade out the overlay
			

		
		},
		
		
		
		
		setOverlayHeight : function()
		{
		
			(Modal.docHeight < Modal.winHeight) ? Modal.overlayHeight = Modal.winHeight : Modal.overlayHeight = Modal.docHeight ;
			
		}
		
	};
	
	
	
	if(!readCookie('aps_ad')){
		createCookie('aps_ad', 'aps_ad', 0);
		//setTimeout('startAd()', 1000)
		// UNCOMMENT TO USE USE COOKIE TO SHOW AD. HOLIDAY SCRIPT IS IN INDEX FILE UNTIL AFTER THE HOLIDAYS.
		
	}
	
	//setTimeout('startAd()', 1000);  // Use this to turn on modal pop up ads.

	
	
	
	
});
