$(document).ready(function() {
	
	jQuery(".blocCoursBourse").hide();
	
	function saveOrder(id) {
		var res = id;
		var box = $(".actionHP #" + id).sortable('toArray');

		if ($.browser.msie)
			$.cookie(id, box, { expires: 7 });
		else
			$.cookie(id, box, { expires: 7, path: window.location.pathname });
	}
	
	function restoreOrder(id) {
		var cookie = $.cookie(id);

		if (!cookie)
			return;
			
		$.each(cookie.split(','), function () {
			$('#'+this).appendTo('#' + id);
		});
	}
	
	$(".actionHP #left, #right").sortable({
		placeholder: 'sortGhost',
		forcePlaceholderSize: true,
		connectWith: '.connectSortables',
		update: function(event, ui) { saveOrder('left');saveOrder('right'); }
	});

	restoreOrder('left');
	restoreOrder('right');
	
	AssignTooltip('.values a.Paris img', '#coursParis');
	AssignTooltip('.values a.NewYork img', '#coursNewYork');
	AssignTooltip('.values a.Brent img', '#coursBrent');
	
	/* 	Assign un tooltip a l'element target.
		Le contenu de tooltip sera preleve dans 'contenu' (sans doute une div cachee ?).
	*/
	function AssignTooltip(target, contenu) {
		$(target).qtip({
			show: 'mouseover',
			hide: 'mouseout',
			corner: 'bottomLeft',
			position: {
						corner: {
							tooltip: 'topMiddle', // Modif from 'topRight' 09/11/2009 
							target: 'bottomMiddle' // Modif from 'bottomLeft' 09/11/2009 
						}
			},
			content: $(contenu).html(),
			style: {
						width: $(contenu).width(),
						height: $(contenu).height()-3+'px',
						padding: 0,
						// Ajout 09/11/2009 
						border: {
							 width: 1,
							 radius: 1,
							 color: '#28639E'
						},
						// Fin ajout 09/11/2009 
						background: 0
			}
		});
	}
	
});
