function isNumber(sText){
	var ValidChars = "0123456789";
	var IsNumber=true;
	var Char;
	for (i = 0; i < sText.length && IsNumber == true; i++) { 
		Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) {
			IsNumber = false;
		}
	}
	return IsNumber;
}

$(document).ready(function(){ 

	if (!($.browser.msie) || (($.browser.msie) && (parseInt($.browser.version) > 8))) {
		$(".box").corner();
		$(".clients #contentRight li").corner();
		$("#logos img").corner();
	}
	
	var ancre = document.location.href.split('#');
	if ((typeof(ancre[1]) != 'undefined') && (ancre[1].length > 0)) {
		if (isNumber(ancre[1])) {
			$("#UiAccordion").accordion({ autoHeight: false, collapsible: true, active : ancre[1] - 1 });
		}
		else {
			$("#UiAccordion").accordion({ autoHeight: false, collapsible: true });
			jQuery.facebox({ ajax: '/'+ancre[1]+'/' });
		}
	}
	else {
		$("#UiAccordion").accordion({ autoHeight: false, collapsible: true });
	}
	jQuery('.aUiAccordion').click(function() {
		//$(this).fadeOut();
		var ancre = this.href.split('#');
		jQuery('#UiAccordion').accordion("activate", ancre[1] - 1);
	});
	$("#contactform").validate();
	$("#phoneform").validate();
	$('a[rel*=facebox]').facebox();
	
	$(".clients #contentRight ul").shuffle();
	//$('.clients #contentRight li').each(function(index) {
		//randomnumber = Math.floor(Math.random()*76);
		//randomnumber = randomnumber + 100;
		//$(this).find("img").css({'max-width' : randomnumber +'px'});
	//});
	
	$("#UiAccordion h3 a").click(function(){ $.scrollTo("#UiAccordion", 200); });
	
	$('#rsociaux img').tipsy({title: 'alt', gravity: 's', fade: false});
	
	verticalAlignCenter();

});

$.validator.addMethod("phone", function(ph, element) {
	if (ph == null) {
		return false;
	}
	var stripped = ph.replace(/[\s()+-]|ext\.?/gi, "");
	return ((/\d{10,}/i).test(stripped));
}, "Veuillez entrer un numéro de téléphone valide.");

function verticalAlignCenter() {
	$(".clients #contentRight img").each(function() {
		var $elem = $(this);
		var elemHeight = $elem.height();
		if (elemHeight == 0)	// perhap's an element is no loaded
			return;
		var $container = $elem.parents("li:first");
		var marginTop = Math.floor(($container.height() - elemHeight) / 2);
		if (marginTop > 0)
			$elem.css("margin-top", marginTop);
	});
}
