var save_event_content;
window.addEvent('domready',function(){

	// iframe
	$$('a.registerIframe').each(function(item){
		item.addEvent('click',function(e){
			new Event(e).stop();
			try{
				this.blur();
			}catch(e){}
			//save_event_content = $('event-content').innerHTML;
			//$('event-content').innerHTML = '<div id="iframe-back"><a href="javascript:;" onclick="restoreIframe();">Back to text</a></div><iframe src="'+item.getProperty('href')+'" width="100%" height="470" frameborder="0" scrolling="auto"></iframe>';
			ui.popup.content = '<iframe src="'+item.getProperty('href')+'" width="100%" height="470" frameborder="0" scrolling="auto"></iframe>';
			ui.popupEl.setStyle('width', 850);
			ui.popupEl.setStyle('margin-left', '-425px');
			ui.showPopup();
		});
	});


	// menu
	if($('previous-editions-menu')){
		var prevEdAccord = new Fx.Slide($('previous-editions-menu').getElement('.accord-content'),{duration:300});
		prevEdAccord.hide();
		$('previous-editions-menu').getElement('.accord-toggle').addEvent('click',function(){
			prevEdAccord.toggle();
			$('previous-editions-menu').toggleClass('active');
		});
	}
	
	//keep me updated box
	if($('efkeepupdated-box')){
		kmu_def = window.easyFairs.ll.label_sitecontent__keep_me_updated_input_hint;
		kmu_field = $('efkeepupdated-box').getElement('input');
		kmu_field.addClass('hint');
		kmu_field.value = kmu_def;
		kmu_field.addEvent('focus',function(){
			if(this.value==kmu_def){
				this.removeClass('hint');
				this.value='';
			}
		});
		kmu_field.addEvent('blur',function(){
			if(this.value==''){
				this.addClass('hint');
				this.value = kmu_def;
			}
		});
		
		$('efkeepupdated-box').getElement('form').addEvent('submit',function(e){
			if(!formValidator.isEmail(kmu_field.value)){
				e.stop();
				with(ui.popup){
					title = window.easyFairs.ll.label_sitecontent__keep_me_updated_box_title;
					content = '<p>'+window.easyFairs.ll.label_fielderror_emailisnotvalid+'</p>';
					mayClose = true;
					loading = false;
				}
				ui.showPopup();
			}
		});
	}


	// magicMail
	var magicMailContainers = $$('.magicMailForm');
	if(magicMailContainers){
		magicMailContainers.each(function(item){
			var MagicMailObj = new MagicMail(item);
		});
	}
	
	
	// tellafriend
	if($('tellafriend')){
		
		var onAjaxCallBack = function(){
			new Tips(ui.popupContentEl.getElements('.mootooltip'),{className:'inPopupTips'});
		}
		
		$('tellafriend').addEvent('click',function(e){
			e.stop();
			with(ui.popup){
				title = window.easyFairs.ll.label_tellafriend__popup_title;
				content = '<div id="tellafriend_target"></div>';
				loading = true;
			}
			ui.showPopup();
			
			new Request.HTML({
				url:'index.php',
				method:'get',
				data:{
					L:window.easyFairs.lid,
					'type':40,
					id:$('tellafriend').getProperty('rel'),
					show_ll:window.easyFairs.show_ll,
					tx_ef_pitellafriend:{
						href:window.location.href
					}
				},
				update:$('tellafriend_target'),
				onComplete:function(r){ui.popup_hideLoad();onAjaxCallBack();ui.popup_ajaxize(onAjaxCallBack);}
			}).send();
			
		});
	}
	
	
	//show logoScroller
	if($('logoscroller-box')){
		var show_logoScroller_int;
		$('logoscroller-box').getElements('a').each(function(tableEl,i){
			if(i>0){
				tableEl.setStyles({
					'opacity':0,
					'visibility':'hidden'
				});
			}else{
				tableEl.setStyles({
					'opacity':1,
					'visibility':'visible'
				});
			}
		});
		function nextSlide(){
			var t = $$('#logoscroller-box a');
			for(var i = 0;i<t.length;i++){
				slide = t[i];
				if(slide.getStyle('opacity')==1){
					slide.fade(0);
					if(!t[i+1]){
						t[0].fade(1);
					}else{
						t[i+1].fade(1);
					}
				}
			}
		}
		show_logoScroller_int = nextSlide.periodical(2000);
		$('logoscroller-box').addEvent('mouseenter',function(){$clear(show_logoScroller_int);});
		$('logoscroller-box').addEvent('mouseleave',function(){show_logoScroller_int = nextSlide.periodical(2000);});
		
	}

});

function restoreIframe(){
	/*
	if(save_event_content==undefined || save_event_content==null || save_event_content==""){
		alert('Error when replacing iframe');
		return false;
	}
	*/
	document.getElementById('event-content').innerHTML = save_event_content;
	return false;
}

function pitellafriend_newCaptcha(){
	var img = $('pitellafriend_captcha');
	//get new image
	new Request({
		'url':window.easyFairs.pitellafriend.url,
		method:'get',
		data:{
			type:40,
			tx_ef_pitellafriend:{newCaptcha:1}
		},
		onComplete:function(r){img.getParent().set('html',r);}
	}).send();
}