//var mainPath = 't3/fileadmin/templates/';
var mainPath = 'fileadmin/templates/';
var cal = {
	init: function(options)
	{
		var that = this;
		if(options) this.c = $(options.container);
		if(!this.c) return;
		this.els = this.c.getElements('.eventsCal');
		this.shown = null;
		this.nextMonth = this.c.getElement('.columNext a');
		this.prevMonth = this.c.getElement('.columPrevious a');
		$$(this.nextMonth, this.prevMonth).addEvent('click', function(e){
			if(e) e.stop();
			that.changeCal(this.href);
		});
		this.els.each(function(el, ind)
		{
			var tip = el.getElement('.eventsCalTip');

			//alert(tip);
			if(tip){
				tip.addEvents(
				{
					'mouseleave': function(e)
					{
						this.timer = this.hide.delay(1000, this);
					},
					'mouseenter': function(e)
					{
						if(this.timer) $clear(this.timer);
					}
				});
				var trigger = el.getElement('.day').addEvents(
				{
					'click': function(e)
					{
						if(e) e.stop();
						this.tip.toggle();
						if(that.shown && that.shown != this.tip) that.shown.hide();
						that.shown = this.tip;
					}
				});
				trigger.tip = tip;
			}
		});
	},
	changeCal : function(link)
	{
		var href = link+'&type=100';
		var that = this;
		var req = new Request({
			method: 'get', 
			url: href, 
			onSuccess: function(response){
				that.c.set('html', response);
				that.init();
			} 
		});
		req.send();
		this.c.getFirst().empty().addClass('loading');
	}
}
window.addEvent('domready', function()
{
	cal.init({'container':'calendar-container'});
	if(searchInput = $('searchFieldId')){
		searchInput.addEvents(
		{
			'focus':function()
			{
				if(this.value == 'Chercher...') this.value='';
			},
			'blur': function()
			{
				if(this.value == '') this.value='Chercher...';
			}
		});
	}
	var toggles = $$('.left-block-nav');
	var Elms = $$('.multiple');
	if(toggles.length > 0)
	{
		toggles.each(function(el, index)
		{
			if(Elms[index])
			{
				var act = null;
				var menus = el.getElements('a');
				var tabs = Elms[index].getElements('.actus-list').hide();
				menus.each(function(menu,ind)
				{
					if(menu.hasClass('active')){
						act = ind;
					}
					menu.addEvent('click', function(e)
					{
						if(e) e.stop();
						if(act != ind)
						{
							tabs[act].hide();
							menus[act].removeClass('active');
							act = ind;
							tabs[act].show();
							menu.addClass('active');
						}
					});
				});
				if($chk(act)) tabs[act].show();
			}
		});
	}
	
	/*var animC;
	if(animC = $('animAccueil'))
	{
		var lien = animC.getElement('a');
		if(lien){
			var lienHref = lien.get('href');
			lien.destroy()
			var animHeader = new Swiff(mainPath+'flash/header.swf', {id:'animHeaderSwf', width:'650', height: '230',params:{ 'wmode':'transparent', 'SWRemote':'' }, vars:{contentUrl:lienHref}});
			animC.adopt(animHeader);
		}
	}*/
	
	var actus = {
		init: function()
		{
			var actusC = $$('.actus-list');
			var $this = this;
			actusC.each(function(el,ind)
			{
				var actus = el;
				var lien = el.getElement('.actus-loader a');
				var infos = {}; 
				if(lien) {
					lien = lien.get('href');
					el.addClass('loading');
					$this.getList(lien, actus, infos, ind);
				}
			}, this);
		}
		,getList : function(link, target, infos, ind)
		{
			var that = this;
			var req = new Request({
				method: 'get',
				url: link, 
				onSuccess: function(response){
					target.removeClass('loading');
					target.set('html', response);
				} 
			});
			req.send();
			target.empty().addClass('loading');
		}

	};
	actus.init();
	
	/*
	if ($$('a.share')) {
		$$('a.share').each(function(a){
			//containers
			var storyList = a.getParent();
			var shareHover = storyList.getElements('div.share-hover')[0];
			shareHover.set('opacity',0);
			//show/hide
			a.addEvent('mouseenter',function() {
					shareHover.setStyle('display','block').fade('in');
			});
			shareHover.addEvent('mouseleave',function(){
				shareHover.fade('out');
			});
			storyList.addEvent('mouseleave',function() {
				shareHover.fade('out');
			});
		});
	}
	*/
	
	/* SUCKERFISH MENU */
	if(Browser.Engine.trident && Browser.Engine.version < 5)
	{
		//Suckerfish Alternative for IE, using MOOTOOLS.
		$$('#menu li').each(function(el, index)
		{
			el.addEvents(
			{
				'mouseenter':function(e)
				{
					this.addClass('over');
				},
				'mouseleave':function(e)
				{
					this.removeClass('over');
				}
			});
		});
	}
	
});
