var mooSimpleBox = new Class({
	options: {
		width: 		300,
		height: 	200,
		opacity:	'0',
		btnTitle:	"Ok",
		closeBtn:	null,
		signupBtn:	null,
		offBtn:	null,
		boxTitle:	"messageBox",
		boxClass:	'mainBox',
		id:			'myID',
		fadeSpeed:	500,
		box:		null,
		addContentID:null,
		addContent:  null,
		boxTxtColor: '#000',
		isVisible:	false,
		isDrag:		true
	},
		
	initialize: function(options){
		this.isVisible = false;
		if(options['isDrag']) this.isDrag = options['isDrag'];
		if(options['width']) this.width = options['width'];
		if(options['height']) this.height = options['height'];
		if(options['opacity']) this.opacity = '1.0';
		if(options['btnTitle']) this.btnTitle = options['btnTitle'];
		if(options['boxTitle']) this.boxTitle = options['boxTitle'];
		if(options['boxClass']) this.boxClass = options['boxClass'];
		if(options['boxTxtColor']) this.boxTxtColor = options['boxTxtColor'];
		if(options['fadeSpeed']) this.fadeSpeed = options['fadeSpeed'];
		if(options['id']) this.id = options['id'];
		if(options['closeBtn']) this.closeBtn = $(options['closeBtn']);
		if(options['signupBtn']) this.signupBtn = $(options['signupBtn']);
		if(options['offBtn']) this.offBtn = $(options['offBtn']);
		if(options['addContentID']) this.addContentID = options['addContentID'];
		
		if(options['addContentID']) {
			this.addContent = $(this.addContentID).innerHTML;
			$(this.addContentID).setStyle('visibility','hidden');
			$(this.addContentID).remove();
		}		
		
		this.createBox();	
	},
		
	createBox: function(){
		this.box = new Element('div');
		this.box.addClass(this.boxClass);
	},
	
	clickClose: function(){
		$(this.box).effect('opacity',{ wait:true, duration:this.fadeSpeed, transition:Fx.Transitions.linear }).chain(function(){
		}).start(this.opacity,0);
			this.isVisible = false;
			var isChecked = $('cbhide').checked;
			if (isChecked) {
				document.cookie = "tp_show_loaded=loaded; expires=Fri, 13 Jul 2050 05:28:21 UTC; path=/";
			
			}
		},
		
	clickOff: function(){
		$(this.box).effect('opacity',{ wait:true, duration:this.fadeSpeed, transition:Fx.Transitions.linear }).chain(function(){
		}).start(this.opacity,0);
			this.isVisible = false;
			document.cookie = "tp_show_loaded=loaded; expires=Fri, 13 Jul 2050 05:28:21 UTC; path=/";

		},
		
	clickSignup: function(){
		$(this.box).effect('opacity',{ wait:true, duration:this.fadeSpeed, transition:Fx.Transitions.linear }).chain(function(){
		}).start(this.opacity,0);
			this.isVisible = false;
			document.cookie = "tp_show_loaded=loaded; expires=Fri, 13 Jul 2050 05:28:21 UTC; path=/";
			var ea = $('eaname').value;
			
			var newWin = window.open("http://visitor.r20.constantcontact.com/d.jsp?llr=uwkvqtdab&m=1103387863764&p=oi&ea=" + ea, 'tmeml') ;
			if (!newWin || !newWin.top)
			{
				window.location.href = "http://visitor.r20.constantcontact.com/d.jsp?llr=uwkvqtdab&m=1103387863764&p=oi&ea=" + ea;
			}

			
			
			//window.location.href = "http://visitor.r20.constantcontact.com/d.jsp?llr=n7x6r7n6&m=1011349381005&p=oi&ea=" + ea;
			//window.open("http://visitor.r20.constantcontact.com/d.jsp?llr=n7x6r7n6&m=1011349381005&p=oi&ea=" + ea, 'tmeml');

		},
		
		fadeOut: function(){
			if(this.isVisible){
				$(this.box).effect('opacity',{ wait:true, duration:this.fadeSpeed, transition:Fx.Transitions.linear }).chain(function(){
			}).start(this.opacity,0);
			this.isVisible = false;
		}
			
	},
		
	fadeIn: function(){	
		if (document.documentElement && document.documentElement.clientWidth) {
			theWidth=document.documentElement.clientWidth;
		}else if (document.body) {
			theWidth=document.body.clientWidth;
		}
		if (window.innerHeight) {
			theHeight=window.innerHeight;
		}else if (document.documentElement && document.documentElement.clientHeight) {
			theHeight=document.documentElement.clientHeight;
		}else if (document.body) {
			theHeight=document.body.clientHeight;
		}
		var top = window.getScrollTop();
		var boxTop =  (theHeight - this.height) / 2 ;
        boxTop = (boxTop + top);
		var boxLeft = (theWidth - this.width) / 2;			
		this.box.setStyle('top',boxTop);
		this.box.setStyle('left',boxLeft);
		this.box.setStyle('position','absolute');
		this.box.setStyle('width',this.width);
		this.box.setStyle('height',this.height);
		this.box.setStyle('opacity',this.opacity);
		this.box.setStyle('cursor','move');
		this.box.setStyle('z-index','999990000');
		this.box.setAttribute('id', this.id);
		this.box.setStyle('visibility','hidden');
		this.box.injectInside(document.body);
		if(this.isVisible == false){
			this.box.effect('opacity',{ wait:true, duration: this.fadeSpeed, transition: Fx.Transitions.linear }).start(0,this.opacity);
			this.addHT();
			this.isVisible = true;
		}
	},
		
	addHT: function(){
	
		
		
		
		this.txtName = new Element('input', {
			type: 'text',
			name : "ea",
			id : 'eaname',
			size : "30",
			value : "", 
			styles: {
				'border': '1px solid #000000',
				'position':'absolute',
				'bottom':'45px',
				'left':'215px',
				'width':'125px',
				'height':'20px',
				'font-size':'12px',
				'font-family':'arial',
				'cursor':'pointer'
			}	
		})
		
		
		this.cbHide = new Element('input', {
			type : 'checkbox',
			name : 'cbhide',
			id : 'cbhide', 
			styles: {
				'border': '0px solid #000000',
				'position':'absolute',
				'bottom':'23px',
				'left':'298px',
				'width':'20px',
				'height':'12px',
				'font-size':'10px',
				'font-family':'arial',
				'cursor':'pointer'
			}	
		})
		
		this.cbLbl = new Element('label', {
			html : 'Hide permanently', 
			'for' : 'cbHide',
			styles: {
				'border': '0px solid #000000',
				'position':'absolute',
				'bottom':'26px',
				'left':'215px',
				'width':'90px',
				'height':'14px',
				'font-size':'11px',
				'font-family':'arial'
			}	
		})
		
		
		this.signupBtn = new Element('button', {
			styles: {
				'border': 'none',
				'background-image':'url(modules/mod_moopopup/moopopup/images/bg_button.gif)',
				'color':'#666',
				'position':'absolute',
				'bottom':'50px',
				'left':'350px',
				'width':'44px',
				'height':'19px',
				'font-size':'10px',
				'font-family':'arial',
				'cursor':'pointer'
			}	
		})
		
		
		this.closeBtn = new Element('button', {
			styles: {
				'border': 'none',
				'background-image':'url(modules/mod_moopopup/moopopup/images/bg_button.gif)',
				'color':'#666',
				'position':'absolute',
				'bottom':'25px',
				'left':'350px',
				'width':'44px',
				'height':'19px',
				'font-size':'10px',
				'font-family':'arial',
				'cursor':'pointer'
			}	
		})
		
		
		
		
		
		/*this.offBtn = new Element('button', {
			styles: {
				'border': 'none',
				'background-image':'url(modules/mod_moopopup/moopopup/images/bg_button.gif)',
				'color':'#666',
				'position':'absolute',
				'bottom':'3px',
				'right':'3px',
				'width':'44px',
				'height':'19px',
				'font-size':'10px',
				'font-family':'arial',
				'cursor':'pointer'
			}	
		})*/
		
	  var width = this.width.toInt() ;
		if(window.ie){
			var titleBar = new Element('div', {
				styles: {
					'width' : 				width,
					'height': 				'auto',
					'background-repeat':	'repeat-x',
					'background-position':	'right top',
					'line-height':			'20px',
					'padding':				'5px 5px 5px 5px',
					'position':				'absolute',
					'clear':				'both',
					'margin-bottom':		'10px',
					'top':					'0px',
					'left':					'0px',
					'color':				'#eee'
				}
		  })
		}else{
			var titleBar = new Element('div', {
				styles: {
					'width' : 				width,
					'height': 				'auto',
					'background-repeat':	'repeat-x',
					'background-position':	'right top',
					'line-height':			'auto',
					'padding':				'5px 5px 5px 5px',
					'position':				'absolute',
					'clear':				'both',
					'margin-bottom':		'10px',
					'top':					'0px',
					'left':					'0px',
					'color':				'#eee'
				}
			})
		}
		
		//$(titleBar).innerHTML = "&nbsp;"; //this.boxTitle;
		$(titleBar).innerHTML = this.boxTitle;
	
		var insideDiv = new Element('div',{
			styles: {
				'padding':'10px'
			}
		});
			
		insideDiv.setAttribute('id','myContent');
		this.box.innerHTML = '';
		
		insideDiv.injectInside(this.box);
	
		insideDiv.innerHTML = this.addContent;	
		
		this.closeBtn.innerHTML = "close";	
		$(this.closeBtn).addEvent('click',this.clickClose.bindWithEvent(this));			
		
		
		this.signupBtn.innerHTML = "signup";	
		$(this.signupBtn).addEvent('click',this.clickSignup.bindWithEvent(this));

		//this.offBtn.innerHTML = "off";	
		//$(this.offBtn).addEvent('click',this.clickOff.bindWithEvent(this));				
		
		titleBar.injectInside(this.box);
		
		this.cbLbl.innerHTML = "Don't show again";	
		
		
		this.txtName.injectInside(this.box);
		this.signupBtn.injectInside(this.box);
		
		this.cbHide.injectInside(this.box);
		this.cbLbl.injectInside(this.box);
		
		this.closeBtn.injectInside(this.box);
		
		//this.offBtn.injectInside(this.box);
			
		//if(this.isDrag == 'true'){
		//	this.box.makeDraggable();
		//}
		
		
	}
});

mooSimpleBox.implement(new Options, new Events);
