jQuery.noConflict();

/**
 * Méthodes globales applicatives
 */
var Application = {
	/*
	 * Nombre de colonnes pour la zone Widgets
	 */
	cols: 3,
	screens: 4,
	acceptImage: '/datas/styles/medsport/icons/smalls/accept.png',
	deniedImage: '/datas/styles/medsport/icons/smalls/cancel.png',
	ajaxLoaderImage: '/datas/styles/medsport/icons/smalls/ajax-loader.gif',
	ajaxLoaderImageInline: '/datas/styles/medsport/icons/smalls/ajax-loader-xs.gif',
	start: function() {
		
	},
	/*
	 * Méthode permettant d'afficher un ajax loader dans une zone id spécifiée
	 */	
	setAjaxLoader: function(id, style){
		if (undefined == style) {
			jQuery("#" + id).html('<img src="' + Application.ajaxLoaderImage + '" />');			
		}
		else if ('xs' == style) {
			jQuery("#" + id).html('<img src="' + Application.ajaxLoaderImageInline + '" />');
		}

	},
	/*
	 * Méthode permettant d'afficher un ajax loader dans une zone id spécifiée et centrée
	 */	
	setAjaxLoaderCenter: function(id, style){
		if (undefined == style) {
			jQuery("#" + id).html('<img src="' + Application.ajaxLoaderImage + '" class="center" />');			
		}
		else if ('xs' == style) {
			jQuery("#" + id).html('<img src="' + Application.ajaxLoaderImageInline + '" class="center" />');
		}

	},
	/*
	 * Méthode permettant d'afficher un ajax loader dans une zone id spécifiée
	 */	
	setAcceptStatus: function(id){
		jQuery("#" + id).html('<img src="' + Application.acceptImage + '" />');
	},
	/*
	 * Méthode permettant d'afficher un ajax loader dans une zone id spécifiée
	 */	
	setDeniedStatus: function(id){
		jQuery("#" + id).html('<img src="' + Application.deniedImage + '" />');
	},
	/*
	 * twinlight
	 */
	twinLight: function(screen, id) {
		
	},
	/*
	 * Méthode permettant de mettre à jour un champ
	 */
	registerData: function(entity, keys, fields, values) {
		
	}
}

var show_connect_form = function(what) {
	if (what) {
		jQuery('#a-connect').css('display', 'none');
		//jQuery('#flogin-content').css('display', 'block');
		jQuery('#flogin').css('display', 'block');
	}
	else {
		jQuery('#a-connect').css('display', 'block');
		//jQuery('#flogin-content').css('display', 'none');
		jQuery('#flogin').css('display', 'none');
	}
	return false;
}

jQuery(document).ready(function() {
	jQuery(".is_calendar").datepicker({
		monthNames: ['Janvier','Février','Mars','Avril','Mai','Juin','Juillet','Août','Septembre','Octobre','Novembre','Décembre'],
		dateFormat: 'dd/mm/yy',
		closeText: 'Fermer',
		clearText: 'Effacer',
		currentText: 'Aujourd\'hui',
		nextText: 'Suivant',
		prevText: 'Précédent'
	});
	
	//Init les Tag Suggests
	TagSuggest.mini_nb_chars = 3;
	TagSuggest.ini();
	
	/*
	 * Affichage des messages
	 */
	 jQuery('#system-messages').fadeIn({duration: 1000}).bind('click', function(){
	 	jQuery(this).slideToggle({duration: 2000});
	 });
	 	
	jQuery('#a-connect').click(function() {
		return show_connect_form(true);
	});
	
	jQuery('#a-connect-close').click(function() {
		return show_connect_form(false);
	});
	
	//jQuery('#content').css('height', jQuery('#subcontainer').css('height'));
	var str = new String(document.location);
	if (!str.match('note_index\.php') && !str.match('home\.php') && !str.match('user_form\.php')) {
		var _height = document.getElementById('subcontainer').clientHeight;
		jQuery('#content').css('height', _height+'px');
	}
	
	if (str.match('note_form\.php')) {
		jQuery('#content').css('height', 'auto');
	}
	
	/*
	 * Papillons
	 */
	/*if (jQuery.browser.mozilla || jQuery.browser.opera || jQuery.browser.safari) {
		// Création du div
		jQuery("#header").append('<div id="fly-butterfly"></div>');
		
		// Placement du div
		var fly_butterfly_top = jQuery.cookie('fly_butterfly_top') == null ? 5 : jQuery.cookie('fly_butterfly_top');
		var fly_butterfly_left = jQuery.cookie('fly_butterfly_left') == null ? '80%' : jQuery.cookie('fly_butterfly_left');
		jQuery("#fly-butterfly").css('top', fly_butterfly_top);
		jQuery("#fly-butterfly").css('left', fly_butterfly_left);
	}
	
	/*jQuery('#fly-butterfly').Draggable({
			zIndex: 	9999,
			ghosting:	false,
			opacity: 	0.9,
			containment : 'parent',
			onStop: function() {
				// On mémorise la position
				jQuery.cookie('fly_butterfly_top', jQuery("#fly-butterfly").css('top'));
				jQuery.cookie('fly_butterfly_left', jQuery("#fly-butterfly").css('left'));
			}
	});		*/

	if (jQuery(document).tooltip) {
		jQuery('.comite a').tooltip({
			showURL: false
		});
	}
});