/**
 * one45 Javascript functions using jquery
 * 
 */

 /**
  * Animates the background color of an element.
  * 
  * Fades from light-yellow to the original background color
  *
  * @param elem Element to highlight the background
  * @param time_delay (Optional) Duration to wait before removing the highlight
  * @param start_color (Optional) Color at the start of the animation
  * @param end_color (Optional)	Color at the end of the animation
  * 
  */
function timedHighlight(elem, time_delay, start_color, end_color)
{
	time_delay = (time_delay) ? time_delay : 2000;
	start_color = (start_color) ? start_color : '#FDFF64'; 
	end_color = (end_color) ? end_color : elem.css("background-color");
	
	elem.attr('style', 'background-color:' + start_color);
	elem.animate({backgroundColor: end_color}, time_delay, '', function(){elem.removeAttr('style')});
}

/**
 * return based implementation of break out of each() loop
 * use:
 *   return $['break'];
 */
jQuery['break'] = new Object();
jQuery.extend
({
	each: function(obj, fn, args)
	{
		if (obj.length == undefined)
		{
			for (var i in obj)
			{
				if (fn.apply(obj[i], args || [i, obj[i]] ) == jQuery['break'])
				{
					break;
				}
			}
		}
        else
        {
        	for (var i = 0; i < obj.length; i++)
        	{
        		if (fn.apply(obj[i], args || [i, obj[i]]) == jQuery['break'])
        		{
             		break;
             	}
             }
		}
		
		return obj;
     }
});

/**
 * Options for jQuery UI datepicker including french 
 * translation for all datepicker elements.
 *  
 * @return object
 */
function getDatePickerOptions()
{
	var french_options = {
		clearText: "Vide",
		clearStatus: "Effacez la date du jour",
		closeText: "Fin",
		closeStatus: "Fermez-vous sans changement",
		currentText: "Courant",
		currentStatus: "Montrez le mois courant",
		dateStatus: "Choisi DD, d M",
		dayStatus: "Commencez semaine avec DD",
		dayNames: ["Dimanche", "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi"],
		dayNamesMin: ["Di", "Lu", "Ma", "Me", "Je", "Ve", "Sa"],
		firstDay: 1,
		initStatus: "Choisissez une date",
		monthNames: ["Janvier", "Février", "Marche", "Avril", "Pouvez", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre"],
		monthNamesShort: ["Jan", "Fév", "Mar", "Avr", "Pou", "Jui", "Jui", "Aoû", "Sep", "Oct", "Nov", "Déc"],
		monthStatus: "Montrez un mois différent",
		nextText: "Après",
		nextStatus: "Montrez le mois prochain",
		prevText: "Préc",
		prevStatus: "Montrez le mois précédent",
		weekStatus: "",
		yearStatus: "Montrez une année différente"
	}
	
	var options =
	{
		changeYear: true,
		changeMonth: true,
		showAnim: 'fadeIn',
		duration: 'fast',
		showOn: 'button',
		buttonImageOnly: true,
		buttonImage: 'im/calendar.gif'
	}
	
	/**
	 * This depends on one45.js, which depends on a global var
	 * CURRENT_LOCALE which you get for free in htmlViews but have
	 * to add yourself in old pages.
	 */
	if (currentLocale() == 'fr_CA')
	{
		$.extend(options, french_options);
	}
	
	return options;
}