var main = {
	_cfg : null,
	
	start : function (cfg){
		_cfg = cfg;
		main.init();
		main.initListener();
	},
	
	init : function(){
		$('#modalScreen').css('opacity', _cfg.opacity);
		$('#modalScreen').css('display', 'none');
		if($.browser.msie){
			/*$('#modalScreen').css('height', document.documentElement.clientHeight);*/
			$('#modalScreen').css('height', 850);
		}
		
	},
	
	initListener : function(){
		$("a[@rel='close']").bind('click', main.hideBox);
		$('#modalScreen').bind('click', main.hideBox);
		$("#btnvalid").bind('click',main.checkForm);
		$("a[@rel='close2']").bind('click', main.hideBox2);
		$("#btnclose").bind('click',main.hideBox2);
	},
	
	showBox : function(e){
		/*if($.browser.msie){
			$('#modalScreen').css('height', document.documentElement.clientHeight);
		}*/
		$('#modalScreen').fadeIn(_cfg.time);
		$('#newsletterContainer').fadeIn(_cfg.time);
	},
	
	showBox2 : function(e){
		$('#newsletterContainer2').fadeIn(_cfg.time);
	},
	
	hideBox : function(){
		$('#modalScreen').fadeOut(_cfg.time);
		$('#newsletterContainer').fadeOut(_cfg.time);
		$('#newsletterContainer2').fadeOut(_cfg.time);
	},
	
	hideBox2 : function(){
		$('#modalScreen').fadeOut(_cfg.time);
		$('#newsletterContainer2').fadeOut(_cfg.time);
	},
	
	checkForm : function(e){
		e.preventDefault();
		var test = new Array();
		$("#frmNews input.mandatory").each(function(){
			test.push(form.checkTextField($( this )));
		});
		if($.inArray(false,test) == -1){
			var mailTest = form.checkMail($('#emailtxt'));
			if(mailTest){
				$.ajax({
					url : $("#frmNews").attr('action'),
					type: 'POST',
					data : $("#frmNews").serialize(),
					success : main.back			
				});
			}
		}
	},
	
	back : function(data){
		$('#newsletterContainer').fadeOut(100,main.showBox2);
		
		
	}
};

$(document).ready(function() {
	var option = {
		time : 200,
		opacity : 0.4
	};
	main.start(option);
});
