var ActiveMenu = "";
var idMenu = "";
function rollOn( id )
{
	if ( id == ActiveMenu ) return;
	
	// IE 6 Disabled
	if ( $.browser.msie && $.browser.version < 7 ) return;
	
	if ( id == idMenu ) {
		if ( $('#'+idMenu)[0].rollTimer ) clearTimeout($('#'+idMenu)[0].rollTimer);
		$('#'+idMenu)[0].rollTimer = null
		return;
	}
	else if ( idMenu != "" )
	{
		_rollOut( idMenu );
	}
	
	var node = $('#'+id);
	if ( $(node).attr("anim") != "0" ) return;
	
	var oImgL = $(node).find('img')[1]
	var oImgR = $(node).find('img')[0]
	var w = IMAGE_SIZE;//$(oImgL).width();
	var h = IMAGE_SIZE;//$(oImgL).height();
	var newH = 20/h * h;
	var newW = 20
	$(node).animate({
		scrollLeft: 0
	}, 350, function( ) {
		$(this).attr("anim","1");
	});
	$(oImgL).animate({
		width:	parseInt(newW),
		h:		parseInt(newH)
	}, 350);
	$(oImgR).animate({
		width:	parseInt(w),
		h:		parseInt( h)
	}, 350);
}
function rollOut( id )
{
	if ( id == ActiveMenu ) return;

	// IE 6 Disabled
	if ( $.browser.msie && $.browser.version < 7 ) return;
	
	var node = $('#'+id);
	//if ( $(node).attr("anim") != "1" ) return;
	if ( node[0].rollTimer )
		clearTimeout( node[0].rollTimer );
	node[0].rollTimer = setTimeout( "_rollOut('"+id+"')", 150 );
}

function _rollOut( id )
{
	var node = $('#'+id);
	$(node).attr("anim","2");
	
	var oImgL = $(node).find('img')[1]
	var oImgR = $(node).find('img')[0]
	var w = IMAGE_SIZE; //$(oImgR).width();
	var h = IMAGE_SIZE; //$(oImgR).height();
	var newH = 20/h * h;
	var newW = 20
	$(node).animate({
		scrollLeft: IMAGE_SIZE
	}, 350, function() {
		$(this).attr("anim","0");
	});
	$(oImgR).animate({
		width:	parseInt(newW),
		h:		parseInt(newH)
	}, 350);
	$(oImgL).animate({
		width:	parseInt(w),
		h:		parseInt( h)
	}, 350);
	idMenu = "";
}


$(document).ready( function() {
	initButtons();
});

var bAnim = false;

function initButtons() {

	$('div.MenuBtns').each( function( i ) {
		var index = i+1;
		var node = $(this); //$("#Menu"+index)
		$(node)[0].scrollLeft = IMAGE_SIZE; 		
		
		$(node).hover(
			function() {	
				rollOn(this.id);
				},
			function() {	
				rollOut(this.id);
			}
		);
		
		// For IE force onclick a
		$(node).click( function( )
		{
			try {
				var surl = $(this).find("a").attr('href');
				if ( surl )	document.location = surl;
			}
			catch( e ) {
			};
		});
		
		if ( $(node).attr("anim") == "1" ) return;
	
		var totalW = $(node).find(".Content").children("span").width();
		totalW+= 2*2+2;	// + padding left and right !
		
		totalW = 70;
		
		$(node).find(".Content").css('width', totalW+'px');
		
		var totalOverflow = totalW + 10 + IMAGE_SIZE		// + Small + Large
		if ( !$.browser.msie )	totalOverflow+=4
		$(node).width( totalOverflow );
		$($(this).next("div")[0]).find(".ContentFond").width( totalOverflow - 11*2 )
		
	});
}


// IE6 Ptch PNG
function IE6( o )
{
	if ( $.browser.msie && $.browser.version < 7 )
	{
		if ( $(o).attr('src').toLowerCase().indexOf( '.png' ) > 0 ) {
			var w = $(o).width();
			var h = $(o).height();
			var sStyles = ""; //jQuery.getStyles($(o)) +";width:"+w+"px;height:"+h+"px;display:inline;"
			var sStyles = "width:"+w+"px;height:"+h+"px;display:inline;"
			var span = document.createElement("SPAN")
			if (o.className!='')	span.className = o.className
			$(span).attr('style',sStyles+"filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'" + $(o).attr('src') + "\', sizingMethod='scale');\"" )
			$(span).insertAfter($(o))
			$(o).remove( );
		}
	}
}



jQuery.fn.center = function () {
    this.css("position","absolute");
    this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
    this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
    return this;
}




function PostContact( )
{
	var sUrl = "/contact-do.php"
	if ( $('#nom').val() == "" )	{	alert( "Vous devez saisir votre nom" );	return;	}
	if ( $('#prenom').val() == "" )	{	alert( "Vous devez saisir votre prénom" );	return;	}
	if ( $('#email').val() == "" && $('#tel').val() == "" )	{	
		alert( "Vous devez saisir un numéro de téléphone ou un email pour que nous puissions vous recontacter." );	
		return;	
	}
	
	var sDatas = "&nom=" + $('#nom').val()
	sDatas += "&prenom=" + $('#prenom').val()
	sDatas += "&email=" + $('#email').val()
	sDatas += "&tel=" + $('#tel').val()
	sDatas += "&societe=" + $('#societe').val()
	sDatas += "&objet=" + $('#objet').val()
	sDatas += "&texte=" + $('#texte').val()
	
	$.ajax({
		url: sUrl,
		cache: false,
		type: 'POST',
		data: sDatas,
		error: function(html){
			alert( "Une erreur c'est produite.\n" );
		},
		success: function(html){
			alert( "Votre demande a bien été transmise." );
		  }
	});	
	
}
