// JavaScript Document
$(document).ready(function(){	
	// se popup foi fechado menos vezes do que pode ser apresentado e
	// se tempo de espera desde o ultimo fechamento já é maior que o tempo mínimo de espera previsto
	// então vai rodar a rotina do popup
	if((popupLayerClosedTimes < POPUPLAYERMAXCLOSE) && (popupLayerDowntime > POPUPLAYERMINWAIT)) {
	// Modal Layer
		$('body').each(function() {
			$(this).qtip({
				content: {
					 title: {
							text: '<span style="color:#EEEEEE">.</span>',
							button: '<span class="popuplayertext" style="color:#FF0000;">[X]</span>'
					 },
						text: '<div id="popuplayer" class="popuplayer"><img border="0" src="'+POPUPLAYERIMAGEPATH+'"></div>'
				},
				position: {
					 target: $(document.body), // Position it via the document body...
					 corner: 'right' // ...at the center of the viewport
				},
				show: {
					 ready: POPUPLAYERAUTOLOAD, // false means not show on ready automatically, true will show on ready itself... autoLoadLayer is a local variable loaded on php script
					 when: '', // Show it on click
					 solo: true // And hide all other tooltips
				},
				hide: false,
				style: {
					 width: { max: 1000, min:300 },
					 padding: '1px',
					 border: {
							width: 0,
							radius: 0,
							color: '#FFFFFF'
					 },
					 name: 'light'
				},
				api: {
					 beforeShow: function() {
							if(POPUPLAYERBLANKET) {
								// Fade in the modal "blanket" using the defined show speed
								$('#qtip-blanket').fadeIn(this.options.show.effect.length);
							}
					 },
					 beforeHide: function() {
						 // função para registro do exato instante do fechamento do popup
							setPopupLayerClosedTime();
							if(POPUPLAYERBLANKET) {
								// Fade out the modal "blanket" using the defined hide speed
								$('#qtip-blanket').fadeOut(this.options.hide.effect.length);
							}
					 }
				}
			})
		});
	}

	function setPopupLayerClosedTime() {
		$('<div id="qtip-blanket"><iframe src="./popups/popuplayer.closed.php"></div>')
			.css({
				 position: 'absolute',
				 top: $(document).scrollTop(), // Use document scrollTop so it's on-screen even if the window is scrolled
				 left: 0,
				 height: $(document).height(), // Span the full document height...
				 width: '100%', // ...and full width
	
				 opacity: 0.7, // Make it slightly transparent
				 backgroundColor: 'black',
				 zIndex: 5000  // Make sure the zIndex is below 6000 to keep it below tooltips!
			})
			.appendTo(document.body) // Append to the document body
			.hide();
	}
	 
	// Create the modal backdrop on document load so all modal tooltips can use it
	$('<div id="qtip-blanket">')
		.css({
			 position: 'absolute',
			 top: $(document).scrollTop(), // Use document scrollTop so it's on-screen even if the window is scrolled
			 left: 0,
			 height: $(document).height(), // Span the full document height...
			 width: '100%', // ...and full width

			 opacity: 0.7, // Make it slightly transparent
			 backgroundColor: 'black',
			 zIndex: 5000  // Make sure the zIndex is below 6000 to keep it below tooltips!
		})
		.appendTo(document.body) // Append to the document body
		.hide(); // Hide it initially
		
	if(POPUPLAYERAUTOLOAD && POPUPLAYERBLANKET) {
		$('#qtip-blanket').show(); //show blanket when autoloadlayermodal is true...
	}
});
	
	