var onload = function() {
	/*
	$.clientCoords = function(){
		if(jQuery.browser.msie){
			return {
				w:document.documentElement.offsetWidth,
				h:document.documentElement.offsetHeight
			}
		}
		else
			return {w:window.innerWidth, h:window.innerHeight}
	}

	var screenDimensions = $.clientCoords();

	if(screenDimensions.w > 1680) {
		$('body').css('background-image', 'url('+root+'img/bg/bg1920.jpg)');
	}
	else if(screenDimensions.w > 1440) {
		$('body').css('background-image', 'url('+root+'img/bg/bg1680.jpg)');
	}
	else if(screenDimensions.w > 1280) {
		$('body').css('background-image', 'url('+root+'img/bg/bg1440.jpg)');
	}
	else if(screenDimensions.w > 1024) {
		$('body').css('background-image', 'url('+root+'img/bg/bg1280.jpg)');
	}
	else if(screenDimensions.w > 800) {
		//$('body').css('background-image', 'url('+root+'img/bg/bg1024.jpg)');
	}
	else {
		//$('body').css('background-image', 'url('+root+'img/bg/bg800.jpg)');
	}
	*/
	$('.customscroll').each(function() {
		CSBfleXcroll(this.id);
	});
	
	$('.vscrollerbarend').each(function() {
		var top = parseInt($(this).css('top'), 10) + 9 + 'px';
		$(this).css('top', top);
		
	});
	/*
	$(window).bind('resize', function() {
		var screenDimensions = $.clientCoords();
	
		if(screenDimensions.w > 1680) {
			$('body').css('background-image', 'url('+root+'img/bg/bg1920.jpg)');
		}
		else if(screenDimensions.w > 1440) {
			$('body').css('background-image', 'url('+root+'img/bg/bg1680.jpg)');
		}
		else if(screenDimensions.w > 1280) {
			$('body').css('background-image', 'url('+root+'img/bg/bg1440.jpg)');
		}
		else if(screenDimensions.w > 1024) {
			$('body').css('background-image', 'url('+root+'img/bg/bg1280.jpg)');
		}
		else if(screenDimensions.w > 800) {
			//$('body').css('background-image', 'url('+root+'img/bg/bg1024.jpg)');
		}
		else {
			//$('body').css('background-image', 'url('+root+'img/bg/bg800.jpg)');
		}
	});
	*/
	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;
	});
	
	$('#live_scoring_container').cycle({ 
		fx:         'fade', 
		timeout:     6000,
		speed: 1000
	});
	
	
	$('#main_slideshow').cycle({ 
		fx:         'scrollHorz', 
		timeout:     12000,
		speed: 1000
	});
	
	$('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);
