
window.addEvent('domready', function() 
{
	
	/*
	if( Cookie.read('startsession') == 1 )
	{
		initJsSession();
		Cookie.dispose('startsession');
	}
	*/
	// Initialisation des accordéons
	/*
	if( $$('toggler') )
	{
		initAccordion();
	}
	*/
	
	var settings = {
		debugBox: 1,
		slideSearchOptions: 0
	}
	
	
	if( $('extensionInfo') )
	{
		var slideExtensionInfoElements = new Fx.Slide('extensionInfoElements');
	
		$('extensionInfo').addEvent('click', function(e){
			e.stop();
			slideExtensionInfoElements.toggle();
		});
		
		slideExtensionInfoElements.hide();
	}
	
	if( $('searchOptions') )
	{
		var slideSearchOptionsElements = new Fx.Slide('searchOptionsElements');
		var cookieSlideSearchOptions = new Hash.Cookie('cookieSlideSearchOptions');
		
		var state = cookieSlideSearchOptions.get('slideSearchOptions') != 0 && cookieSlideSearchOptions.get('slideSearchOptions') != null;
		
		if(state) 
		{
			settings['slideSearchOptions'] = 0;		
			slideSearchOptionsElements.hide();
		} 
		else 
		{
			settings['slideSearchOptions'] = 1;	
			slideSearchOptionsElements.show();		
		}
		
		$('searchOptions').addEvent('click', function(e){
			e.stop();
			slideSearchOptionsElements.toggle();
			
			if (settings['slideSearchOptions'] == 0) settings['slideSearchOptions'] = 0;		
			else settings['slideSearchOptions'] = 1;	
		});
		
		slideSearchOptionsElements.addEvent('complete', function() 
		{
			cookieSlideSearchOptions.extend(settings);
		});
	}
	
	if( $$('delete_thumb') )
	{
		//alert('ok');	
	}
	
	
	if( $('slideshow') )
	{
		var elements_tab = Array();
		var timer = 0;
		var increment = 5000;
		var slide_show_index = 0;
		
		$$('span.slide_show_toggle').each(function(element,index) 
		{
			elements_tab[index] = element;
		});
		
		function autoClick( element )
		{
			if(element) element.fireEvent( 'click');
			//slide_show_index = slide_show_index+1;
		}
		
		function displayElement()
		{
			autoClick( $('slide_show_toggle_'+slide_show_index) );
		}
		
		function displaySlideShow()
		{
			clearInterval(timer);
			
			slide_show_index = slide_show_index >= 5 ? 0 : slide_show_index;
			displayElement( slide_show_index );
			
			timer = setInterval(function(){displaySlideShow(slide_show_index);}, increment);
		}
		
		var slideshow = $('slideshow');
		
		slideshow.addEvent('mouseover', function(e){
			clearInterval(timer);
		});
		
		slideshow.addEvent('mouseout', function(e){
			timer = setInterval(function(){displaySlideShow(slide_show_index);}, increment);
		});
		
		$$('span.slide_show_toggle').each(function(element,index) 
		{
			element.addEvent('click', function(e){
				//e.stop();
				//$$('div.more_box').set( 'style', 'display:none' );
				$$('div.more_box').fade('out');
				$$('div.more_box').set( 'style', 'display:none' );
				$('more_box_'+index).set( 'style', 'display:block;float:left;position:relative;margin-top:100px;' );
				$('more_box_'+index).fade('in');
			
				var filename = $('slide_show_bkg_'+index).get('class'); 
				$('slide_show_background').set('style', 'background:url(\'medias/images/slideshow/'+filename+'.jpg\') no-repeat;');
				
				$$('span.slide_show_toggle').set('class', 'slide_show_toggle');
				$('slide_show_toggle_'+index).set('class', 'slide_show_toggle current');
				//element.fireEvent( 'click', Array, 25000);
				slide_show_index = index+1;
			});
			
		});
		
		if($('more_box_0'))
		{
			$$('div.more_box').set( 'style', 'display:none' );
			$('more_box_0').set( 'style', 'display:block;float:left;position:relative;margin-top:100px;' );
			$$('div.more_box').fade('out');
		}
		//$('more_box_0').fade('in');
		
		//$('slide_show_toggle_0').fireEvent( 'click');
		
		
		$$('div.more_box').each(function(element,index) 
		{
			var content = new Fx.Slide( element.getElement('div.more_content_'+index) );
						
			element.getElement('span.more_'+index).addEvent('click', function(e){
				e.stop();
				content.toggle();
			});
			
			content.hide();
		});
		
		
		displaySlideShow( slide_show_index );
		
	}
	
	if( $$('span.tooltip') )
	{
		$$('span.tooltip').each(function(element,index) 
		{
			var tooltip_content = element.getElement('.tooltip_content');
			tooltip_content.set('style', 'display:none');
			
			var tooltip_trigger = element.getElement('.tooltip_trigger');
			
			var title = tooltip_trigger.getElements('img').get('alt');
			var content = tooltip_content.innerHTML;
			
			element.store('tip:title', unescape(title)); 
			element.store('tip:text', unescape(content)); 
		});
		
		var tooltip = new Tips('.tooltip',{ 
			fixed: false, 
			hideDelay: 50,
			showDelay: 50
		});
		
		tooltip.addEvents({
			'show': function(tip) {
				tip.fade('in');
			},
			'hide': function(tip) {
				tip.fade('out');
			}
		});
	}
	
	
	if( $('content_tabs') )
	{
		$('tab_intro').addEvent('click', showTab.bind($('content_intro')));
		$('tab_info').addEvent('click', showTab.bind($('content_info')));
		
		$('content_intro').fade(1);
		$('content_info').fade(0);
		$('content_info').set('class', 'content_hidden');
	}
	
	if( $('comments_tabs') )
	{
		$('tab_write_comment').addEvent('click', showTab.bind($('content_write_comment')));
		$('tab_display_comments').addEvent('click', showTab.bind($('content_display_comments')));
		
		$('content_write_comment').fade(1);
		$('content_display_comments').fade(0);
		$('content_display_comments').set('class', 'content_hidden');
	}
	
	// Initialisation des éditeurs WYSIWYG
	if( $('intro') )
	{
		wysiwyg_intro 	= new wysiwyg({ textarea: $('intro'), tools1: 1, tools2: 1 });
		$('submit').addEvent('click',function(){ if(wysiwyg_intro.open) wysiwyg_intro.toTextarea(); });
		
		iframeBox = $("iframe_intro");
		textareaBox = $("intro");
		handleCorner = $("resize_intro");
		textDiv = $("wysiwyg_intro");
		new dragObject(handleCorner, textDiv, textareaBox, iframeBox, null, new Position(iframeBox.offsetWidth-6, iframeBox.offsetHeight), new Position(iframeBox.offsetWidth-6, 1000), null, CornerMove, null, false);

	}
	if( $('text') )
	{
		wysiwyg_text 	= new wysiwyg({ textarea: $('text'), tools1: 1, tools2: 1 });
		$('submit').addEvent('click',function(){ if(wysiwyg_text.open) wysiwyg_text.toTextarea(); });
		
		iframeBox = $("iframe_text");
		textareaBox = $("text");
		handleCorner = $("resize_text");
		textDiv = $("wysiwyg_text");
		new dragObject(handleCorner, textDiv, textareaBox, iframeBox, null, new Position(iframeBox.offsetWidth-6, iframeBox.offsetHeight), new Position(iframeBox.offsetWidth-6, 1000), null, CornerMove, null, false);
	}
	
	if( $('mp_text') )
	{
		wysiwyg_mp_text 	= new wysiwyg({ textarea: $('mp_text'), tools1: 1, tools2: 0 });
		$('submit').addEvent('click',function(){ if(wysiwyg_mp_text.open) wysiwyg_mp_text.toTextarea(); });
		
		iframeBox = $("iframe_mp_text");
		textareaBox = $("mp_text");
		handleCorner = $("resize_mp_text");
		textDiv = $("wysiwyg_mp_text");
		new dragObject(handleCorner, textDiv, textareaBox, iframeBox, null, new Position(iframeBox.offsetWidth-6, iframeBox.offsetHeight), new Position(iframeBox.offsetWidth-6, 1000), null, CornerMove, null, false);
	}
	if( $('front_text') )
	{
		wysiwyg_front_text 	= new wysiwyg({ textarea: $('front_text'), tools1: 1, tools2: 0 });
		$('submit').addEvent('click',function(){ if(wysiwyg_front_text.open) wysiwyg_front_text.toTextarea(); });
		
		iframeBox = $("iframe_front_text");
		textareaBox = $("front_text");
		handleCorner = $("resize_front_text");
		textDiv = $("wysiwyg_front_text");
		new dragObject(handleCorner, textDiv, textareaBox, iframeBox, null, new Position(iframeBox.offsetWidth-6, iframeBox.offsetHeight), new Position(iframeBox.offsetWidth-6, 1000), null, CornerMove, null, false);
	}
	
	
	if( $('created') )
	{
		new DatePicker('#created', { timePicker: true, format: 'Y-m-d H:i', inputOutputFormat: 'Y-m-d H:i', toggleElements: '.created_toggler' });
	}
	if( $('modified') )
	{
		new DatePicker('#modified', { timePicker: true, format: 'Y-m-d H:i', inputOutputFormat: 'Y-m-d H:i', toggleElements: '.modified_toggler' });
	}
	
	 //call multiBox
	if( $$('mb') )
	{
		var initMultiBox = new multiBox({
			mbClass: '.mb',//class you need to add links that you want to trigger multiBox with (remember and update CSS files)
			container: $(document.body),//where to inject multiBox
			descClassName: 'multiBoxDesc',//the class name of the description divs
			path: './Files/',//path to mp3 and flv players
			useOverlay: true,//use a semi-transparent background. default: false;
			maxSize: {w:1000, h:800},//max dimensions (width,height) - set to null to disable resizing
			addDownload: true,//do you want the files to be downloadable?
			pathToDownloadScript: './Scripts/ForceDownload.asp',//if above is true, specify path to download script (classicASP and ASP.NET versions included)
			addRollover: true,//add rollover fade to each multibox link
			addOverlayIcon: true,//adds overlay icons to images within multibox links
			addChain: true,//cycle through all images fading them out then in
			recalcTop: true,//subtract the height of controls panel from top position
			addTips: true//adds MooTools built in 'Tips' class to each element (see: http://mootools.net/docs/Plugins/Tips)
		}); 
	}
	
	if( $$('img') )
	{
		var initMultiBox = new multiBox({
			mbClass: '.img',//class you need to add links that you want to trigger multiBox with (remember and update CSS files)
			container: $(document.body),//where to inject multiBox
			descClassName: 'multiBoxDesc',//the class name of the description divs
			path: './Files/',//path to mp3 and flv players
			useOverlay: true,//use a semi-transparent background. default: false;
			maxSize: {w:600, h:500},//max dimensions (width,height) - set to null to disable resizing
			addDownload: true,//do you want the files to be downloadable?
			pathToDownloadScript: './Scripts/ForceDownload.asp',//if above is true, specify path to download script (classicASP and ASP.NET versions included)
			addRollover: true,//add rollover fade to each multibox link
			addOverlayIcon: true,//adds overlay icons to images within multibox links
			addChain: true,//cycle through all images fading them out then in
			recalcTop: true,//subtract the height of controls panel from top position
			addTips: true//adds MooTools built in 'Tips' class to each element (see: http://mootools.net/docs/Plugins/Tips)
		}); 
	}
	
	if( $$('anim') )
	{
		var initMultiBox = new multiBox({
			mbClass: '.anim',//class you need to add links that you want to trigger multiBox with (remember and update CSS files)
			container: $(document.body),//where to inject multiBox
			descClassName: 'multiBoxDesc',//the class name of the description divs
			path: './Files/',//path to mp3 and flv players
			useOverlay: true,//use a semi-transparent background. default: false;
			maxSize: {w:600, h:400},//max dimensions (width,height) - set to null to disable resizing
			addDownload: true,//do you want the files to be downloadable?
			pathToDownloadScript: './Scripts/ForceDownload.asp',//if above is true, specify path to download script (classicASP and ASP.NET versions included)
			addRollover: true,//add rollover fade to each multibox link
			addOverlayIcon: true,//adds overlay icons to images within multibox links
			addChain: true,//cycle through all images fading them out then in
			recalcTop: true,//subtract the height of controls panel from top position
			addTips: true//adds MooTools built in 'Tips' class to each element (see: http://mootools.net/docs/Plugins/Tips)
		}); 
	}
	
	if( $$('video') )
	{
		var initMultiBox = new multiBox({
			mbClass: '.video',//class you need to add links that you want to trigger multiBox with (remember and update CSS files)
			container: $(document.body),//where to inject multiBox
			descClassName: 'multiBoxDesc',//the class name of the description divs
			path: './Files/',//path to mp3 and flv players
			useOverlay: true,//use a semi-transparent background. default: false;
			maxSize: {w:600, h:400},//max dimensions (width,height) - set to null to disable resizing
			addDownload: true,//do you want the files to be downloadable?
			pathToDownloadScript: './Scripts/ForceDownload.asp',//if above is true, specify path to download script (classicASP and ASP.NET versions included)
			addRollover: true,//add rollover fade to each multibox link
			addOverlayIcon: true,//adds overlay icons to images within multibox links
			addChain: true,//cycle through all images fading them out then in
			recalcTop: true,//subtract the height of controls panel from top position
			addTips: true//adds MooTools built in 'Tips' class to each element (see: http://mootools.net/docs/Plugins/Tips)
		}); 
	}
	
	updateCategoryLinkType();
	displayPasswordUpdate();
	displayAvatarUpdate();
	
	if( $('debug') )
	{
		var slideDebugBox = new Fx.Slide('debugBox');
		var cookieDebugBox = new Hash.Cookie('cookieDebugBox');
		
		var state = cookieDebugBox.get('debugBox') != 1 && cookieDebugBox.get('debugBox') != null;
		
		if(state) 
		{
			settings['debugBox'] = 0;		
			slideDebugBox.hide();
		} 
		else 
		{
			settings['debugBox'] = 1;	
			slideDebugBox.show();		
		}
		
		$('debugBar').addEvent('click', function(e)
		{
			e.stop();
			slideDebugBox.toggle();
					
			if (settings['debugBox'] == "1") settings['debugBox'] = 0;		
			else settings['debugBox'] = 1;	
		});
		
		slideDebugBox.addEvent('complete', function() 
		{
			cookieDebugBox.extend(settings);
		});
	}
	

	
});


