var onload = function() {
	
	$('.customscroll').each(function() {
		CSBfleXcroll(this.id);
	});
	
	$('.vscrollerbarend').each(function() {
		var top = parseInt($(this).css('top'), 10) + 9 + 'px';
		$(this).css('top', top);
		
	});
	
	var ajaxLoading = false;
	
	$('a.ajax').click(function(e) {
		var newHref = root + 'ajax/' + $(this).attr('href').substring(root.length);
		
		$.ajax({
			contentType: "application/x-www-form-urlencoded;charset=ISO-8859-1"
		});
		
		if(ajaxLoading == false){
			ajaxLoading = true;
			// affiche l'upload frame
			
			$('#cadre_loading').css('display', 'block');
			$(this).parent().parent().addClass('active').siblings().removeClass('active');
			
			$('#ajax_content').load(newHref, null, function (responseText, textStatus, XMLHttpRequest) {
				$(this).html(responseText);
				
				//$("a.colorbox").colorbox({transition:"elastic", contentCurrent:"{current} / {total}", bgOpacity: 0.5});
				//reload le JS
				$('.customscroll').each(function() {
					CSBfleXcroll(this.id);
				});
				
				$('.vscrollerbarend').each(function() {
					var top = parseInt($(this).css('top'), 10) + 9 + 'px';
					$(this).css('top', top);
				});
				
				//alert('uhh');
				// cache l'upload frame
				$('#cadre_loading').css('display', 'none');
				ajaxLoading = false;
			});
		}
		
		return false;
	});
	

	
	$('div.bulle_right_bottom').click(function(e) {
		var bulleContent = $(this).prev('.bulle_content');
		if(bulleContent.css('display') == 'none') {
			$(this).css('background-image', 'url('+root+'img/arrow_up.png)');
		} 
		else {
			$(this).css('background-image', 'url('+root+'img/arrow_down.png)');
		}
		bulleContent.toggle('blind', {direction: 'vertical'});
	});

	//$("a.colorbox").colorbox({transition:"elastic", contentCurrent:"{current} / {total}", bgOpacity: 0.5});
	//$("a.colorboxvideo").colorbox({transition:"elastic", contentCurrent:"", bgOpacity: 0.5});
}

$(onload);
