var fireOn = Browser.Engine.trident ? 'load' : 'domready';
var currentActive = null;

window.addEvent(fireOn, function(){
	
	$$('a.noclick').addEvent('click', function(ev){
		ev.stop();
		return false;
	});
	
	if($('track_list')){
		var trackFx = new Fx.Slide('track_list', {
			duration: 1000,
			transition: Fx.Transitions.Pow.easeOut
		});
		trackFx.hide();
		
		$('track_event').addEvent('click', function(el){
			el.stop();
			trackFx.toggle();
		});
	}
	
	if($('na_list')){
		var naFx = new Fx.Slide('na_list', {
			duration: 1000,
			transition: Fx.Transitions.Pow.easeOut
		});
		naFx.hide();
		
		$('na_event').addEvent('click', function(el){
			el.stop();
			naFx.toggle();
		});
	}
	
	// Dropdown with multi levels..
	if($$('ul.fancy_drop')){
		
		$$('ul.fancy_drop li').each(function(el){
			
			var subMenu = el.getElement('ul');
			if(subMenu){
				var subMenuFx = new Fx.Slide(subMenu, {duration: 1000,transition: Fx.Transitions.Pow.easeOut});
				subMenuFx.hide();
				el.getElement('a').addEvent('click', function(el){
					el.stop();
					subMenuFx.toggle();
				});
			}
		});

	}
	
	if($$('ul.courses')){	
		
		$$('ul.courses li.entry a').addEvent('click', function(e){
			
			var e = new Event(e).target;
			var EL = $$('.hide-'+e.get('rel'));
			
			if(currentActive && currentActive.className == EL.className && EL.getStyle('display') == 'block'){
				EL.setStyle('display', 'none');
				currentActive = null;
			}else{
				if(currentActive){
					currentActive.setStyle('display', 'none');
				}
				EL.setStyle('display','block');
				currentActive = EL;
			}
			
		});
	}
	
	var content = $$('#main, #footer, #side');
	if (content){
		content.each(function(c){
			var links = c.getElementsByTagName('a');
			var link, href;
			for(i=0; i<links.length; i++)
			{
				link = links[i];
				href = link.getAttribute('href');
				
				if(href && href.substring(0,4) == 'http' && !href.match(/joinricsineurope\.eu/))
					link.setAttribute('target', '_blank');
			}
		});
	}
		
	/* FLIR*/
	if (!(Browser.Engine.name == 'trident' && Browser.Engine.version == 4)){
		FLIR.init( { path: '/javascript/front/facelift-1.2/' , classnameIgnore: 'noFlir'} );

		FLIR.replace( 'div.item h3' ,  new FLIRStyle({ cFont:'lane',   mode: 'wrap' }) );
		FLIR.replace( 'div.plainblock h2' ,  new FLIRStyle({ cFont:'lane',   mode: 'wrap' }) );
		FLIR.replace( 'div.text h3' ,  new FLIRStyle({ cFont:'lane',   mode: 'wrap' }) );
		FLIR.replace( 'div.contact h3' ,  new FLIRStyle({ cFont:'lane',   mode: 'wrap' }) );
		FLIR.replace( 'div.homecolumns h2' ,  new FLIRStyle({ cFont:'lane',   mode: 'wrap' }) );	
		//FLIR.replace( '#main #tickertape span' ,  new FLIRStyle({ cFont:'lane',   mode: 'wrap' }) );	
	}

	/* EXTERNAL LINKS */
	var content = $('main');
	var domainRe = new RegExp(document.location.host.replace(/\./ig, '\.'));
		
	if (content){
		var links = content.getElementsByTagName('a');
		var link, href;
		for(i=0; i<links.length; i++)
		{
			link = links[i];
			href = link.getAttribute('href');
			
			if(href && href.substring(0,4) == 'http' && !href.match(domainRe))
				link.setAttribute('target', '_blank');
		}
	}
	
	/* Initialize Mooquee and define width */
	if($('tickertape')){
		obj = new mooquee($('tickertape'));
		obj.setDirection('left');
	
		var totalWidth = 0;
		$$('#tickertape span').each(function(item){
			totalWidth += item.getSize().x + 200;
		});
		$('mooquee-text').setStyle('width', totalWidth);
	}
	

});
