var legalpopup = (function() {
	
	var public = {};
	
	/*
		pseudo constructor method
	*/
	init = function() {
		window.addEvent('domready', function() {
		
			/*
				wrapper elem (non visible)
			*/
			legalpopup.wrapper = new Element('div', {id: 'legalpopup-wrapper'});	
			
			legalpopup.wrapper.set({
				styles : {
					width : $(document.body).getScrollSize().x,
					height : $(document.body).getScrollSize().y,
					position : 'absolute',
					'z-index' : '900'
				}
			});	
			
			legalpopup.wrapper.overlay = new Element('div', {'class': 'overlay'});
			
			/*
				set wrapper elem (non visible) eventHandlers
			*/
			legalpopup.wrapper.addEvent('mousewheel', function() {
				
				legalpopup.wrapper.box.set({
					styles : {	
						//top : ($(document.body).getScrollTop() + $(document.body).getSize().y/2),
					}
				});
			
			});
			
			
			/*
				overlay elem
			*/
			legalpopup.wrapper.overlay.set({
				styles : {
					width : $(document.body).getScrollSize().x,
					height : $(document.body).getScrollSize().y,
					'background-color' : '#000',
					'z-index' : '901',
					opacity : '0.7',
					overflow : 'hidden',
					cursor : 'pointer'
				}
			});
			$(legalpopup.wrapper.overlay).inject(legalpopup.wrapper, 'top');
			
			/*
				set overlay elem eventHandlers
			*/
			legalpopup.wrapper.overlay.addEvent('click', function() {
			
				legalpopup.destroy();
			});
			
			/*
				box elem
			*/
			legalpopup.wrapper.box = new Element('div', {'class': 'box'});
			
			legalpopup.wrapper.box.set({
				styles : {
					width : '533px',
					height : '533px',
					top : ($(document.body).getScrollTop() + $(document.body).getSize().y/2),
					'margin-top' : '-266px',
					left : '50%',
					'margin-left' : '-265px',
					position : 'fixed',
					'z-index' : '901'
				}
			});				
			
			$(legalpopup.wrapper.box).inject(legalpopup.wrapper, 'top');
			
			/*
				border elem
			*/
			legalpopup.wrapper.box.border = new Element('div', {'class': 'box'});
			
			legalpopup.wrapper.box.border.set({
				styles : {
					width : '533px',
					height : '533px',
					'background-color' : '#000',
					position : 'absolute',
					'z-index' : '902',
					opacity : '0.5'
				}
			});				
			
			$(legalpopup.wrapper.box.border).inject(legalpopup.wrapper.box, 'top');
			
			/*
				header elem
			*/
			legalpopup.wrapper.box.header = new Element('img', {'class': 'header', src: '/img/elements/legal_popup/header.jpg'});
			
			legalpopup.wrapper.box.header.set({
				styles : {
					position : 'absolute',
					'margin-left' : '8px',
					'margin-top' : '8px',
					'z-index' : '903'
				}
			});				
			
			$(legalpopup.wrapper.box.header).inject(legalpopup.wrapper.box, 'top');
			
			/*
				header button elem
			*/
			legalpopup.wrapper.box.button = new Element('div', {'class': 'button'});
			
			legalpopup.wrapper.box.button.set({
				styles : {
					position : 'absolute',
					width : '21px',
					height : '20px',
					'margin-left' : '474px',
					'margin-top' : '44px',
					'z-index' : '904',
					'cursor' : 'pointer',
					'background-image' : 'url(/img/elements/legal_popup/btn_header.jpg)'
				}
			});				
			
			$(legalpopup.wrapper.box.button).inject(legalpopup.wrapper.box, 'top');			
			
			/*
				set header button elem eventHandlers
			*/
			legalpopup.wrapper.box.button.addEvent('click', function() {
			
				legalpopup.destroy();
			});
			
			legalpopup.wrapper.box.button.addEvent('mouseenter', function() {
				
				legalpopup.wrapper.box.button.set({
					styles : {
						'background-image' : 'url(/img/elements/legal_popup/btn_header_hover.jpg)'
					}
				
				});
			});
			
			legalpopup.wrapper.box.button.addEvent('mouseleave', function() {
				
				legalpopup.wrapper.box.button.set({
					styles : {
						'background-image' : 'url(/img/elements/legal_popup/btn_header.jpg)'
					}				
				});
			});
			
			/*
				copy elem
			*/
			legalpopup.wrapper.box.copy = new Element('div', {'class': 'copy'});
			
			legalpopup.wrapper.box.copy.set({
				styles : {
					position : 'absolute',
					'margin-left' : '8px',
					'margin-top' : '97px',
					'width' : '516px',
					'height' : '426px',
					'z-index' : '903',
					'background-color' : '#fff'
				}
			});				
			
			$(legalpopup.wrapper.box.copy).inject(legalpopup.wrapper.box, 'bottom');
			
			/*
				copy p elem
			*/
			legalpopup.wrapper.box.copy.text = new Element('p', {'class': 'text'});
			
			legalpopup.wrapper.box.copy.text.set({
				styles : {
					position : 'absolute',
					'margin-left' : '32px',
					'margin-top' : '32px',
					width : '451px',					
					'z-index' : '904',
					color : '#000',
					'font-family' : 'Arial',
					'font-size' : '12px',
					'text-align' : 'justify',
					'line-height' : '19px'
				}
			});				
			
			$(legalpopup.wrapper.box.copy.text).set("html", "Biocodex offers general information relating to various medical conditions and their treatment. Such information is provided for informational purposes only and is not meant to be a substitute for advice provided by a doctor or other qualified health care professional.<br /><br />Prescription medicines for use by healthcare professionals are regulated by government agencies in each of the countries in which they are available, such as the Food and Drug Administration in the United States (U.S.A) or AFSSAPS in France. These regulations often restrict the use of these medicines and the prescribing information that can be disclosed to the public so that you should always consult with a doctor or other health care professional for medical advice or information about diagnosis and treatment.<br /><br />You may also need to visit other healthcare Web sites to find out more about prescription products.");
			$(legalpopup.wrapper.box.copy.text).inject(legalpopup.wrapper.box.copy, 'bottom');

			/*
				footer elem
			*/
			legalpopup.wrapper.box.footer = new Element('div', {'class': 'footer'});
			
			legalpopup.wrapper.box.footer.set({
				styles : {
					position : 'absolute',
					width : '516px',
					height : '76px',
					'margin-left' : '8px',
					'margin-top' : '447px',
					'z-index' : '903',
					'cursor' : 'pointer',
					'background-image' : 'url(/img/elements/legal_popup/btn_footer.jpg)'
				}
			});				
			
			$(legalpopup.wrapper.box.footer).inject(legalpopup.wrapper.box, 'bottom');			
			
			/*
				set footer elem eventHandlers
			*/
			legalpopup.wrapper.box.footer.addEvent('click', function() {
				
				/*
					set global styles
				*/				
				$(document.body).set({
					styles : {
						'overflow-x' : 'visible'				
					}			
				});
				legalpopup.destroy();
				

			});
			
			legalpopup.wrapper.box.footer.addEvent('mouseenter', function() {
				
				legalpopup.wrapper.box.footer.set({
					styles : {
						'background-image' : 'url(/img/elements/legal_popup/btn_footer_hover.jpg)'
					}
				
				});
			});
			
			legalpopup.wrapper.box.footer.addEvent('mouseleave', function() {
				
				legalpopup.wrapper.box.footer.set({
					styles : {
						'background-image' : 'url(/img/elements/legal_popup/btn_footer.jpg)'
					}				
				});
			});
			
			/*
				set global eventHandlers
			*/
			window.addEvent('resize', function(){
				legalpopup.wrapper.overlay.set({
					styles : {
						width : $(document.body).getScrollSize().x,
						height : $(document.body).getScrollSize().y
					}
				});
							
				legalpopup.wrapper.box.set({
					styles : {
						top : ($(document.body).getScrollTop() + $(document.body).getSize().y/2)
					}
				});	
			});
		
		});
	}
	
	/*
		show the popup
	*/
	public.show = function() {
		// set custom dom properties
		$(document.body).set({
			styles : {
				'overflow-x' : 'hidden'				
			}			
		});
		// inject the elem into the dom
		$(legalpopup.wrapper).inject(document.body, 'top');
	}	
	
	/*
		destroy the popup
	*/
	public.destroy = function() {
		// remove the element from the dom
		$(legalpopup.wrapper).destroy();
	}
	
	// call the pseudo constructor
	init();
	
	return public;
	
})();
