function off(){
	var con = confirm('are you sure?');
	if (con)
	{
		document.getElementById('cover').style.width = window.innerWidth + 'px';
		document.getElementById('cover').style.height = window.innerHeight + 'px';
		fade();
	}
}

function reveal(){
	x = 10;
	document.getElementById('cover').style.opacity = 0.0;
	document.getElementById('cover').style.height ='0px';
	document.getElementById('cover').style.width = '0px';
	alert('I missed you too...\n:)');
}

var x = 10;
function fade(){
	document.getElementById('cover').style.opacity = 0 + '.' + x ;
	x++;
	if (x <= 99)
	{
		var t = setTimeout('fade()',50);
	}else{
		document.getElementById('cover').style.opacity = 1 ;
	var back = new Element('div',{
		'text':'go back',
		'styles':{
			'margin-top':$('cover').getSize().y/2,
			'cursor':'default',
			'font-size':'12pt',
			'color':'#fff'	
		},
		'events':{
			'click':function(e){
				reveal();
				this.dispose();
			}		
		}	
	}).inject($('cover'));	}

}


var passwordCheck = new Class({
	initialize:function(){
		this.build();
	},

	build:function(){
		var that = this;
		this.dark = new Element('div',{
			'styles':{
				'width':window.getSize().x,
				'height':window.getSize().y,
				'position':'absolute',
				'top':0,
				'left':0,
				'background-color':'#000080',
				'opacity':'0.8'
			}
		});

		this.container = new Element('div',{
			'styles':{
				'width':'300px',
				'height':'150px',
				'position':'absolute',
				'top':(window.getSize().y/2) - 75,
				'left':(window.getSize().x/2) - 150,
				'border':'3px solid #8a2be2',
				'background-color':'#8470ff'
			}
		});

		this.txtLabel = new Element('label',{
			'for':'pas',
			'text':'enter password',
			'styles':{
				'display':'block',
				'text-align':'center',
				'font':'17pt arial',
				'color':'#fff'
			}
		}).inject(this.container);

		this.pasInput = new Element('input',{
			'type':'password',
			'id':'pas',
			'maxlength':'8',
			'styles':{
				'display':'block',
				'margin':'5px auto',
				'width':'50px'
			}
		}).inject(this.container);

		this.msg = new Element('div',{
			'styles':{
				'height':'20px',
				'font':'11pt arial',
				'color':'#fff',
				'text-align':'center'
			}
		}).inject(this.container);

		this.okBtn = new Element('input',{
			'type':'button',
			'value':'download',
			'styles':{
				'margin-right':'5px',
				'width':'80px'
			},
			'events':{
				'click':function(){
					that.chackPas();
				}
			}
		}).inject(this.container); 

		this.cancelBtn = new Element('input',{
			'type':'button',
			'value':'cancel',
			'styles':{
				'margin-left':'5px',
				'width':'80px'
			},
			'events':{
				'click':function(){
					that.cancelAction();
				}
			}
		}).inject(this.container); 
	},

	askForPas:function(DBody){
		this.dark.inject(DBody);
		this.container.inject(DBody);
	},

	cancelAction:function(){
		this.msg.innerHTML = '';
		this.dark.dispose();
		this.container.dispose();
	},

	chackPas:function(){
		var that = this;
		if (this.pasInput.value == '')
		{
			this.msg.innerHTML = 'please enter a password';
		}else if (this.pasInput.value.match(/\D/))
		{
			this.msg.innerHTML = 'password is incorrect';
		}else{
			var req = new Request.HTML({
				method: 'post', 
				url: 'password.php', 
				data:{'pass':this.pasInput.value},
				update: that.msg,
				onComlete:function(){
					if (that.msg.innerHTML != 'password is incorrect')
					{
						that.cancelAction();
					}
				}
			}).send();
		}
	}
});

window.addEvent('domready',function(){
	var askForPassword = new passwordCheck();

	$('cvLink').addEvent('click',function(){
		askForPassword.askForPas(document.body);
	});
});

