(function(){
	/* Add events on object*/
	if (typeof 'addEvent' != 'function') {
		function addEvent(obj, evType, fn)
		{
			if (obj.addEventListener) {
				obj.addEventListener(evType, fn, true);
				return true;
			} else if (obj.attachEvent) {
				var r = obj.attachEvent("on"+evType, fn);
				return r;
			} else {
				return false;
			}
			return true;
		}
	}
	/** 
	  * Add window.onload event
	  * launch some functions according to the current page
	  */
	addEvent(window, 'load', function(){
		//startFlash();
		if(typeof sIFR == "function"){
			// This is the preferred "named argument" syntax
                      
			sIFR.replaceElement(named({sSelector:"#firstCol>h2", sFlashSrc:"/swf/eurostile.swf", sColor:"#6FAE03", sBgColor:"Null", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=left", sWmode:"transparent"}));
			var div = document.getElementById('content');
			if(div.className != "page5"){
				sIFR.replaceElement(named({sSelector:"#content h1", sFlashSrc:"/swf/eurostile.swf", sColor:"#6FAE03", sBgColor:"Null", nPaddingTop:6, nPaddingBottom:0, sFlashVars:"textalign=left", sWmode:"transparent"}));
			}else{
				sIFR.replaceElement(named({sSelector:"#content h1", sFlashSrc:"/swf/eurostile.swf", sColor:"#EC2685", sBgColor:"Null", nPaddingTop:6, nPaddingBottom:0, sFlashVars:"textalign=left", sWmode:"transparent"}));	
			}
		}
		return true;
	});
})();

// jQuery
$(document).ready(function(){
	// Scroll des ancres
	$('a[href*=#]')
    .not('a[href=#]')
    .bind('click', function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
			var $target = $(this.hash);
			$target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
			if ($target.length) {
				var targetOffset = $target.offset().top;
				$('html,body').animate({scrollTop: targetOffset}, "normal");
				return false;
			}
		}
     });
	
	// DATEPICKER (CALENDAR)
	var datePickerEvent = function(){
		var datePickers = $(".datepicker");
		if(datePickers.length > 0){
			datePickers.datepicker({
				showOn: 'button',
				buttonImage: '/img/common/calendar.gif',
				buttonImageOnly: true
			});
		}
	}
	datePickerEvent();
	
	// Module Messages
	var pMessages = function(){
		var addMessageForm = $('.messagesFrontend form[name=addMessage]');
		var addMessageCloturerInput = $('input#addMessageCloturerInput');
		if(addMessageForm.length > 0 && addMessageCloturerInput.length > 0){
			var i18nm_cloturerAlert = $('#i18nm_cloturerAlert').text();
			addMessageForm.submit(function(){
				if(confirm(i18nm_cloturerAlert)){
					addMessageCloturerInput.val(1);
				}
			});
			return false;
		}
	}
	pMessages();

	

	$('div.formation div.axeFormation').each(function(i){
		if(i == 0 && $(this).attr('class').toString().indexOf('noinitjs') == -1) {
			$(this).css({'background-image':'url(/img/2010/moins.gif)'});

		} else {
			$(this).parent()
					.removeClass('openBlock')
					.addClass('closeBlock');
			$(this).css({'background-image':'url(/img/2010/plus.gif)'});

		}
		$(this).css({'cursor':'pointer'});
		$(this).bind('click', function () {
			var el = $(this).parent().children('.formations');

			if(el.css("display") == "none"){
				el.slideDown(250);
				$(this).parent()
					.removeClass('closeBlock')
					.addClass('openBlock');
				$(this).css({'background-image':'url(/img/2010/moins.gif)'});
			} else {
				el.slideUp(250);
				$(this).parent()
					.removeClass('openBlock')
					.addClass('closeBlock');
				$(this).css({'background-image':'url(/img/2010/plus.gif)'});

			}
			//$(this).parent().children('.formations').toggle();
		});

	});

	$('div.inscrits div.inscrit div.titre').each(function(i){
		$(this).parent()
				.removeClass('openBlock')
				.addClass('closeBlock');
		$(this)
			.css({'background-image':'url(/img/2010/plus.gif)','cursor':'pointer'})
			.bind('click', function () {

				var el = $(this).parent().children('.information');

				if(el.css("display") == "none"){
					el.slideDown(250);
					$(this).parent()
						.removeClass('closeBlock')
						.addClass('openBlock');
					$(this).css({'background-image':'url(/img/2010/moins.gif)'});
				} else {
					el.slideUp(250);
					$(this).parent()
						.removeClass('openBlock')
						.addClass('closeBlock');
					$(this).css({'background-image':'url(/img/2010/plus.gif)'});

				}
		});

	});
	$('div.inscrits div.inscrit div.titre input[type="checkbox"]').bind('click', function (e) {
		e.stopPropagation();

	});
	$('.preinscription form .checkToHide').bind('click', function () {
		if($(this).is(':checked')) {
			$('.grpToHide')
				.attr("disabled", "disabled")
				.attr('checked', false);
		} else {
			$('.grpToHide').removeAttr("disabled");
		}
	});
	$('.preinscription form a.showDescription')
		.css({'display':'inline-block'})
		.bind('click', function () {
			var el = $(this).parent().parent().children('.descriptionLabel');
			if(el.css("display") == "none"){
				el.slideDown(250);
			} else {
				el.slideUp(250);

			}
			return false;
		});
});
