var txNbtipafriendPi1 = {
	// init the onclick-event for the tip-a-friend-link
	sendOptions: null,
	delayID: 0,
	tiplink: function()
	{
		$('tx-nbtipafriend-pi1-tiplink').addEvent('click',function(e){
			e = new Event(e);
			e.stop();
			// Show Loader
			NB.Effect.loader(true);
			// Show Blank-Form
			txNbtipafriendPi1.blankForm();
			
		});		
	},
	// init the send-form in blank-mode
	blankForm: function()
	{
		txNbtipafriendPi1.init();
		objRequest = new Request.HTML(txNbtipafriendPi1.sendOptions).get();
		// Fade in lightbox-style
		NB.Effect.fadeIn('genericLightbox');		
		txNbtipafriendPi1.init();
	},
	// init the form-events
	init: function()
	{
		NB.Effect.initImages();
		txNbtipafriendPi1.sendOptions = {
				url: init_txNbtipafriendPi1.formUrl,
				async: false,
				update: $('genericLightboxContent')
		};
		if(sendBtn = $('tx-nbtipafriend-pi1-send'))
		{
			sendBtn.addEvent('click',function(e){
				e = new Event(e);
				e.stop();
				txNbtipafriendPi1.sendForm();
			});
		}
		if(closeBtn = $$('.tx-nbtipafriend-pi1-close'))
		{
			closeBtn.addEvent('click',function(){
				NB.Effect.loader(false);	
				NB.Effect.fadeOutComplete = null;
				NB.Effect.fadeOut('genericLightbox');
			});						
		};		
		if(helpBtn = $$('.tx-nbtipafriend-pi1-help'))
		{
			helpBtn.addEvent('mouseover',function(){
				txNbtipafriendPi1.helpText(true);
			});		
			helpBtn.addEvent('mouseout',function(){
				txNbtipafriendPi1.helpText(false);
			});					
		};				
	},
	sendForm: function()
	{
		NB.Effect.loaderIgnore = true;
		NB.Effect.smallLoader(true,$('tx-nbtipafriend-pi1-send-wrap'));
		
		// we need this only for ie6 random gif bug (no animation)
		
		if (txNbtipafriendPi1.delayID) {
			$clear(txNbtipafriendPi1.delayID);
		}
		
		txNbtipafriendPi1.delayID = txNbtipafriendPi1.sendFormReal.delay(200);

		
	},
	sendFormReal: function()
	{
		objRequest = new Request.HTML(txNbtipafriendPi1.sendOptions).post($('tx-nbtipafriend-pi1-form'));
		
		txNbtipafriendPi1.init();
		NB.Effect.loaderIgnore = false;
		if($$('.tx-nbtipafriend-pi1-response')[0])
		{
			window.setTimeout(function(){
				NB.Effect.fadeOut('genericLightbox');
				NB.Effect.loader(false);
			}, 1500);
		}
	},
	helpText: function(showHelp)
	{
		if(helpObj = $('tx-nbtipafriend-pi1-help-content')){}else{return false;}
		
		if(showHelp)
		{
			helpObj.setStyle('display','block');
		}else{
			helpObj.setStyle('display','none');
		}
	}
};

window.addEvent('domready',function(){
	if($('tx-nbtipafriend-pi1-tiplink'))
	{
		txNbtipafriendPi1.tiplink();
	}
	if($('loader'))
	{
		$('loader').addEvent('click',function(objEvent){
			if (!NB.Effect.loaderIgnore) {
				objEvent.stop();
				NB.Effect.fadeOutComplete = null;
				NB.Effect.fadeOut('genericLightbox');
			}
				
		});				
	}
});
