var tweensInfos = new Array();
tweensInfos["TWEEN1"] = new Array(0,444,400,444,0,0,0,0,400,1,1);
tweensInfos["TWEEN2"] = new Array(304,0,304,238,415,0,415,0,400,1,1);
tweensInfos["TWEEN3"] = new Array(324,0,324,200,410,250,410,250,400,0,1);

tweensInfos["TWEEN4"] = new Array(0,445,400,445,0,0,0,0,400,1,1);
tweensInfos["TWEEN5"] = new Array(304,0,304,107,415,0,415,0,400,1,1);
tweensInfos["TWEEN6"] = new Array(324,0,324,400,410,120,410,120,400,0,1);

tweensInfos["TWEEN7"] = new Array(300,0,300,500,0,0,0,0,40,0,1);
tweensInfos["TWEEN8"] = new Array(0,441,392,441,720,0,328,0,400,1,1);
tweensInfos["TWEEN9"] = new Array(304,0,304,123,0,441,0,318,400,1,1);

tweensInfos["TWEEN10"] = new Array(300,0,300,500,0,0,0,0,400,0,1);
tweensInfos["TWEEN11"] = new Array(0,441,392,441,720,0,328,0,400,1,1);
tweensInfos["TWEEN12"] = new Array(304,0,304,108,0,442,0,332,400,1,1);

tweensInfos["TWEENLINK1"] = new Array(0,29,304,29,0,15,0,15,400,1,1);
tweensInfos["TWEENLINK2"] = new Array(0,29,304,29,0,15,0,15,400,1,1);
tweensInfos["TWEENLINK3"] = new Array(0,29,304,29,0,65,0,65,400,1,1);
tweensInfos["TWEENLINK4"] = new Array(0,29,304,29,0,65,0,65,400,1,1);

var theTimeout;

function stopAndDisplayService(id, mode, b) {
	clearTimeout(theTimeout);

	for(var i=1; i<13; i++) {
		if(document.getElementById("TWEEN"+i)) {
			var inf = tweensInfos["TWEEN"+i];
			$("#TWEEN"+i).stop();
			document.getElementById("TWEEN"+i).width = inf[0] + "px";
			document.getElementById("TWEEN"+i).style.width = inf[0] + "px";
			document.getElementById("TWEEN"+i).height = inf[1] + "px";
			document.getElementById("TWEEN"+i).style.height = inf[1] + "px";
			document.getElementById("TWEEN"+i).style.marginLeft = inf[4] + "px";
			document.getElementById("TWEEN"+i).style.marginTop = inf[5] + "px";
			document.getElementById("TWEEN"+i).style.opacity = 0;
		}
	}
	
	for(var j=1; j<5; j++) {
		var inf = tweensInfos["TWEENLINK"+j];
		$("#TWEENLINK"+j).stop();
		document.getElementById("TWEENLINK"+j).width = inf[0] + "px";
		document.getElementById("TWEENLINK"+j).style.width = inf[0] + "px";
		document.getElementById("TWEENLINK"+j).height = inf[1] + "px";
		document.getElementById("TWEENLINK"+j).style.height = inf[1] + "px";
		document.getElementById("TWEENLINK"+j).style.marginLeft = inf[4] + "px";
		document.getElementById("TWEENLINK"+j).style.marginTop = inf[5] + "px";
		$("#TWEENLINK"+j).hide(10);
	}
	
	displayService(id,mode,b);
}

function displayService(id, mode, j) {
	var modeInvert = "on";
	
	if(mode=="on") {
		document.getElementById("smService_financement").className = "element_sousmenu_lateral";
		document.getElementById("smService_recherche_appartement").className = "element_sousmenu_lateral";
		document.getElementById("smService_negociation_revente").className = "element_sousmenu_lateral";
		document.getElementById("smService_travaux_suivi").className = "element_sousmenu_lateral";
		document.getElementById("smService_"+id).className = "element_sousmenu_lateral_hover";
		modeInvert = "off";
	}
	
	var tabPart = Array("financement","recherche_appartement","negociation_revente","travaux_suivi");
	var part = Math.ceil(j/3);
	var actualPart = tabPart[part-1];
	var partFirst = (part*3-2);
	var partLast = part*3;
	var nextPart;
	var nextPartToDisplay;
	if(part == 4) {
		nextPart = tabPart[0];
		nextPartToDisplay = 1;
	}
	else {
		nextPart = tabPart[part];
		nextPartToDisplay = partLast+1;
	}
	var inf = tweensInfos["TWEEN"+j];
	var infLink = tweensInfos["TWEENLINK"+part];
	var width = inf[2];
	var height = inf[3];
	var opacity = inf[10];
	var marginLeft = inf[6];
	var marginTop = inf[7];
	var widthLink = infLink[2];
	var heightLink = infLink[3];
	var marginLeftLink = infLink[6];
	var marginTopLink = infLink[7];
	
	if(mode == "off") {
		width = inf[0];
		height = inf[1];
		opacity = inf[9];
		marginLeft = inf[4];
		vmarginTop = inf[5];
		
		widthLink = infLink[0];
		heightLink = infLink[1];
		marginLeftLink = infLink[4];
		marginTopLink = infLink[5];
	}
	
	$("#TWEEN"+j).animate({
		width: width + "px",
		height: height + "px",
		opacity: opacity,
		marginLeft: marginLeft + "px",
		marginTop: marginTop + "px"
	}, inf[8],function() {
		if(j==partFirst) {
			inf = tweensInfos["TWEENLINK"+part];
			$("#TWEENLINK"+part).animate({ 
			width: widthLink + "px",
			height: heightLink + "px",
			marginLeft: marginLeftLink + "px",
			marginTop: marginTopLink + "px"
			}, inf[8]);
			if(mode == "off") {
				$("#TWEENLINK"+part).hide(1000);
			}
		}

		if(j==partLast && mode == "on") {
			theTimeout = setTimeout(function(){displayService(id,modeInvert,partFirst)},20000);
		}
		else if(j==partLast && mode == "off") {
			displayService(nextPart,"on",nextPartToDisplay);
		}
		else {
			displayService(id,mode,j+1);
		}
	});
}

function ajaxLoader() {
}

ajaxLoader.prototype.submitForm = function(formId,lang) {
	this.callAjax("submitForm",lang,formId);
}

ajaxLoader.prototype.callAjax = function(mode,lang,param1) { 
	var httpObject = getXMLHTTP();
	
	if(httpObject)
	{
		switch(mode) {
			case "submitForm":
				switch(param1) {
					case "paris_contact_form":
						var paris_contact_nom = document.paris_contact_form.paris_contact_nom.value;
						var paris_contact_prenom = document.paris_contact_form.paris_contact_prenom.value;
						var paris_contact_email = document.paris_contact_form.paris_contact_email.value;
						var paris_contact_adresse = document.paris_contact_form.paris_contact_adresse.value;
						var paris_contact_cp = document.paris_contact_form.paris_contact_cp.value;
						var paris_contact_ville = document.paris_contact_form.paris_contact_ville.value;
						var paris_contact_message = document.paris_contact_form.paris_contact_message.value;
						var chaine = paris_contact_nom + "|PARAM|" + paris_contact_prenom + "|PARAM|" + paris_contact_email + "|PARAM|" + paris_contact_adresse + "|PARAM|" + paris_contact_cp + "|PARAM|" + paris_contact_ville + "|PARAM|" + paris_contact_message;
						chaine = encodeURIComponent(chaine);
						httpObject.open("POST","include/ajaxModules/" + mode + ".php?idForm=" + param1 + "&lang=" + lang + "&chaine=" + chaine, true);
						break;
				}	
				break;
		}
	}

	httpObject.onreadystatechange = function()
	{
		if (httpObject.readyState==4 && httpObject.responseText)
		{	
			parent.theAjaxLoader.generateJson(httpObject, mode);		
		}
	};
	
	httpObject.send(null);
}

ajaxLoader.prototype.generateJson = function(httpObject, mode) { 
	var toDisplay = "";
	var JSON = eval('(' + httpObject.responseText + ')'); 

	switch(mode) {
		case "submitForm":
			if(JSON.isOK == "yes") {
				switch(JSON.idForm) {
					case "paris_contact_form":
						document.paris_contact_form.paris_contact_nom.value = "";
						document.paris_contact_form.paris_contact_prenom.value = "";
						document.paris_contact_form.paris_contact_email.value = "";
						document.paris_contact_form.paris_contact_ville.value = "";
						document.paris_contact_form.paris_contact_cp.value = "";
						document.paris_contact_form.paris_contact_message.value = "";
						document.paris_contact_form.paris_contact_adresse.value = "";
						break;
				}
			}

			Shadowbox.open({
				content:    JSON.msg,
				player:     'html',
				width:      330,
				height:		JSON.height
			});
			break;
	}
}
