var ad = {
	cssOuter: {
		position: 'fixed',
		zIndex: '97',
		left: '0px',
		top: '0px',
		width: '100%',
		height: '100%',
		backgroundColor: '#000000',
		opacity: '0.7',
		MozOpacity: '0.7',
		filter: 'alpha(opacity=70)',
		display: 'none'
	},
	
	cssFrame: {
		position: 'fixed',
		zIndex: '98',
		left: '50%',
		top: '50%',
		backgroundColor: '#FFFFFF',
		borderWidth: '10px',
		borderStyle: 'solid',
		overflow: 'hidden',
		display: 'none'
	},

	cssLink: {
		position: 'fixed',
		zIndex: '99',
		cursor: 'pointer',
		right: '50%',
		top: '50%',
		color: '#CCCCCC',
		fontFamily: 'Arial',
		fontSize: '11px',
		display: 'none'
	},

	timeout: null,
	viewed: false,
	
	css: function (el, styles)
	{
		for (key in styles) {
			try { el.style[key] = styles[key]; }
			catch (e) {}
		}
	},

	show: function ()
	{
		ad.css(ad.outer, {display: ''} );
		ad.css(ad.frame, {display: ''} );
		ad.css(ad.alink, {display: ''} );
	},
	
	hide: function ()
	{
		ad.css(ad.outer, {display: 'none'} );
		ad.css(ad.frame, {display: 'none'} );
		ad.css(ad.alink, {display: 'none'} );
		
	},
	
	setup: function (url, width, height, color)
	{
		if (window.XMLHttpRequest) /* IE7+, Opera 9, Mozilla, Safari */
		{
			window.onload = function ()
			{
				var xMargin = parseInt(- width / 2 - 10);
				var yMargin = parseInt(- height / 2 - 10);

				ad.outer = document.createElement('div');
				ad.css(ad.outer, ad.cssOuter);

				ad.frame = document.createElement('iframe');
				ad.css(ad.frame, ad.cssFrame);
				ad.css(ad.frame, { width: width + 'px', height: height + 'px', marginLeft: xMargin + 'px', marginTop: yMargin + 'px', borderColor: color } );
				
				ad.alink = document.createElement('a');
				ad.css(ad.alink, ad.cssLink);
				ad.css(ad.alink, { marginRight: xMargin + 'px', marginTop: (yMargin - 15) + 'px' } );

				ad.frame.src = url;
				
				ad.outer.onclick = ad.hide;
				ad.alink.onclick = ad.hide;

				ad.alink.appendChild(document.createTextNode('Fermer'));
				document.body.appendChild(ad.outer);
				document.body.appendChild(ad.frame);
				document.body.appendChild(ad.alink);
	
				document.body.onmouseover = function ()
				{
					if (ad.timeout)
					{
						clearTimeout(ad.timeout);
						ad.timeout = null;
					}
				}
				document.body.onmouseout = function ()
				{
					ad.timeout = setTimeout(function()
					{
						if (! ad.viewed)
						{
							var cookies = document.cookie.split(/;[\s]*/);
							for (var key in cookies) if (cookies[key] == 'adviewed=1') ad.viewed = true;
							
							if (! ad.viewed)
							{
								ad.show();
								ad.viewed = true;
								document.cookie = 'adviewed=1;path=/';
							}
						}
		
					}, 500);
				}
			}
		}
	}
};