window.addEvent('domready',function(){
	$('artViperTellaFriend').addEvent('click',function(e){

	e 				= new Event(e).stop();
	var contWidth 	= 274;
	var contHeight 	= 264;
	var width 		= window.getScrollWidth();
	var height 		= window.getScrollHeight();

	var top =  /*window.getHeight().toInt() + */ window.getScrollTop().toInt();
	top+=50;


	if (document.documentElement && document.documentElement.clientWidth) {
		width=document.documentElement.clientWidth;
	}else if (document.body) {
		width=document.body.clientWidth;
	}

	if(document.getElementById('tellBox') != null){
			return false;
	}

	var width = (width-contWidth) / 2;
	height =(height-contHeight) / 2;

	var thisSite =  document.location.href;

	var tellaFriend = new Element('div',{
		'styles':	{
						'width':244,
						'height':234,
						'background-image':'url(images/box_bg.gif)',
						'background-repeat':'no-repeat',
						'padding':15,
						'visibility':'hidden',
						'position':'absolute',
						'left':width,
						'top':top
					},
		'id':		'tellBox'
	})

	var title = new Element('h1',{
		'html':'kleine Empfehlung',
		'id':'myTitle'
	})

	var yourName = new Element('input',{
	    'type':'text',
		'class':'inp',
		'id':'yourName',
		'value':'Bitte Ihren Namen eintragen!',
		'name':'yourName'
   })

	var myForm = new Element('form', {
		'action': '',
		'method': 'post',
		'id': 'myForm'
	})

	var userEmail = new Element('input', {
		'type':'text',
		'name':'userEmail',
		'id':'userEmail',
		'class':'inp',
		'value':'Ihre E-Mail-Adresse'
	})

	var receiveEmail = new Element('input', {
		'type':'text',
		'name':'receiveEmail',
		'id':'receiveEmail',
		'class':'inp',
		'value':'E-Mail Ihrer Freundin'
	})

	var message = new Element('textarea', {
		'id':'message',
		'name':'message',
		'class':'inp',
		'html':'Platz für eine kleine Nachricht'
	})

	var sendButton = new Element('input', {
		'type':'submit',
		'id':'sendoff',
		'value':'weiterleiten'

	})

	var page = new Element('input',{
		'type':'hidden',
		'name':'page',
		'id':'page',
		'value':thisSite
   })

	var answer = new Element('div', {
		'id':'answer',
		'styles': {
						'display':'block',
						'clear':'both'
				}
	})

	var closed = new Element('input',{
		'id':'close',
		'type':'button',
		'value':'schliessen'
	})


		e= new Event(e).stop();
		var eff = new Fx.Morph(tellaFriend,{ duration: 500, wait:true, transition:Fx.Transitions.linear });
		eff.start({
					opacity:[0,1]
		});


	tellaFriend.injectInside(document.body);
	title.injectInside(tellaFriend);
	myForm.injectInside(tellaFriend);
	yourName.injectInside(myForm);
	userEmail.injectInside(myForm);
	receiveEmail.injectInside(myForm);
	message.injectInside(myForm);
	sendButton.injectInside(myForm);
	closed.injectInside(myForm);
	answer.injectInside(myForm);
	page.injectInside(myForm);

	$$('.inp').addEvent('focus',function(){
		this.value='';
										})

	myForm.addEvent('submit',function(){
		$('answer').set('html','');
		new Request.HTML({ url:'tellafriend.php',data:this, method:'post', evalScripts:true, evalResponse:true,
					update:'answer'
		}).send();
		return false;
	})

	closed.addEvent('click',function(){
		var eff = new Fx.Morph(tellaFriend,{ duration: 500, wait:true, transition:Fx.Transitions.linear, onComplete:function(){
		tellaFriend.dispose() }});
		eff.start({
					opacity:[1,0]
		});
	  })

  })

})

