// Global Variables
var currentBackgroundName;
var currentSWFName;
var currentLanguage="en";
var isImageHomeLoadedFirstTime=true;
var changeMenuAllowed=true;
var currentProgress;

var signDownX=830;
var signDownY=470;
var signUpX=20;
var signUpY=20;
var signX=signDownX, signY=signDownY;

// Size of work area, without zoom applied
var virtualWorkAreaWidth=1160; 
var virtualWorkAreaHeight=670; 

// Real workarea inside browser
var realWorkAreaTop;
var realWorkAreaLeft;
var realWorkAreaWidth;
var realWorkAreaHeight;

// Page functions
function pageLoaded()
{		
	initialize();	
	
	setBrowserDimensions(screen.availWidth, screen.availHeight);
	
	resizeObjectsOnBrowser();	
}

function imageHomeLoadedFirstTime()
{
	if (isImageHomeLoadedFirstTime)
	{
		setProgress(100); 
		
		document.getElementById("progressBar").style.display="";
		
		isImageHomeLoadedFirstTime=false;
		getBackgroundImageControl("home").style.display="";

		setBackground("home", "images/home.jpg");
			
		// Preload images
		preloadImages();	
		
		// Show Header and Footer
		document.getElementById("arcencielstudioHeader").style.display="";	
		document.getElementById("arcencielstudioFooter").style.display="";	
		
		applyFadeInEffectToImageControl("arcencielstudioHeader", 20);
		applyFadeInEffectToImageControl("arcencielstudioFooter", 20);		
		window.setTimeout("applyFadeInEffectToImageControl('arcencielstudioHome', 20);", 2000);
		window.setTimeout("applyFadeInEffectToImageControl('arcencielstudioHomeBackground', 20);", 2000);
		window.setTimeout("document.getElementById('arcencielstudioSign').style.display=''", 3000);			
		
		document.getElementById("progressBar").style.display="none";
		
		currentSWFName="home";
	}
}

function preloadImages()
{
	document.getElementById("imgWeddingDummy").src="images/wedding.jpg";	
	document.getElementById("imgFamilyDummy").src="images/family.jpg";
	document.getElementById("imgArquitectureDummy").src="images/arquitecture.jpg";
	document.getElementById("imgAdvertisingDummy").src="images/advertising.jpg";
	document.getElementById("imgEditionDummy").src="images/edition.jpg";
	document.getElementById("imgEditionSlideDummy").src="images/editionSlide.jpg";
	document.getElementById("imgModelDummy").src="images/model.jpg";
	document.getElementById("imgGallerySlideDummy").src="images/gallerySlide.jpg";
	document.getElementById("imgContactDummy").src="images/contact.jpg";
	document.getElementById("imgThanksDummy").src="images/thanks.jpg";
	document.getElementById("imgGalleriesDummy").src="images/misc/galleries.png";
}

function resizeObjectsOnBrowser()
{	
	calculateWorkAreaDimensions();
	
	applyZoomEffectToObject(document.getElementById("arcencielstudioHeader"));
	applyZoomEffectToObject(document.getElementById("arcencielstudioFooter"));	
	applyZoomEffectToHeaderFooter(document.getElementById("arcencielstudioHeader"));
	applyZoomEffectToHeaderFooter(document.getElementById("arcencielstudioFooter"));
	applyZoomEffectToHeaderFooter(document.getElementById("arcencielstudioHome"));
	applyZoomEffectToHeaderFooter(document.getElementById("arcencielstudioWedding"));
	applyZoomEffectToHeaderFooter(document.getElementById("arcencielstudioWedding2"));
	applyZoomEffectToHeaderFooter(document.getElementById("arcencielstudioWedding3"));
	applyZoomEffectToHeaderFooter(document.getElementById("arcencielstudioArquitecture"));
	applyZoomEffectToHeaderFooter(document.getElementById("arcencielstudioAdvertising"));
	applyZoomEffectToHeaderFooter(document.getElementById("arcencielstudioEdition"));
	applyZoomEffectToHeaderFooter(document.getElementById("arcencielstudioEditionSlide"));	
	applyZoomEffectToHeaderFooter(document.getElementById("arcencielstudioEdition2"));
	applyZoomEffectToHeaderFooter(document.getElementById("arcencielstudioFamily"));
	applyZoomEffectToHeaderFooter(document.getElementById("arcencielstudioModel"));
	applyZoomEffectToHeaderFooter(document.getElementById("arcencielstudioContact"));
	applyZoomEffectToHeaderFooter(document.getElementById("arcencielstudioContact2"));
	applyZoomEffectToHeaderFooter(document.getElementById("arcencielstudioThanks"));
	applyZoomEffectToHeaderFooter(document.getElementById("arcencielstudioThanks2"));
		
	applyZoomAndPositionToObject(document.getElementById("arcencielstudioSign"), signX, signY, 160, 60);
	
	applyZoomAndPositionToObject(document.getElementById("arcencielstudioHome"), 550, 150, 520, 425);
	applyZoomAndPositionToObject(document.getElementById("arcencielstudioHomeBackground"), 550, 150, 520, 425);

	applyZoomAndPositionToObject(document.getElementById("arcencielstudioWedding"), 550, 150, 520, 325);
	applyZoomAndPositionToObject(document.getElementById("arcencielstudioWeddingBackground"), 550, 150, 520, 325);
	applyZoomAndPositionToObject(document.getElementById("arcencielstudioWedding2"), 550, 485, 520, 40);
	applyZoomAndPositionToObject(document.getElementById("arcencielstudioWeddingBackground2"), 550, 485, 520, 40);
	applyZoomAndPositionToObject(document.getElementById("arcencielstudioWedding3"), 550, 540, 520, 40);
	applyZoomAndPositionToObject(document.getElementById("arcencielstudioWeddingBackground3"), 550, 540, 520, 40);
			
	applyZoomAndPositionToObject(document.getElementById("arcencielstudioFamily"), 550, 150, 520, 350);
	applyZoomAndPositionToObject(document.getElementById("arcencielstudioFamilyBackground"), 550, 150, 520, 350);
	
	applyZoomAndPositionToObject(document.getElementById("arcencielstudioArquitecture"), 550, 150, 520, 425);
	applyZoomAndPositionToObject(document.getElementById("arcencielstudioArquitectureBackground"), 550, 150, 520, 425);
	document.getElementById("arcencielstudioArquitectureScrollArea").style.height=convertVirtualYValueToRealYValue(310) + "px";
	
	applyZoomAndPositionToObject(document.getElementById("arcencielstudioAdvertising"), 550, 150, 520, 425);
	applyZoomAndPositionToObject(document.getElementById("arcencielstudioAdvertisingBackground"), 550, 150, 520, 425);
	document.getElementById("arcencielstudioAdvertisingScrollArea").style.height=convertVirtualYValueToRealYValue(310) + "px";
	
	applyZoomAndPositionToObject(document.getElementById("arcencielstudioEdition"), 550, 150, 520, 380);
	applyZoomAndPositionToObject(document.getElementById("arcencielstudioEditionBackground"), 550, 150, 520, 380);
	document.getElementById("arcencielstudioEditionScrollArea").style.height=convertVirtualYValueToRealYValue(240) + "px";
	applyZoomAndPositionToObject(document.getElementById("arcencielstudioEdition2"), 550, 540, 520, 40);
	applyZoomAndPositionToObject(document.getElementById("arcencielstudioEditionBackground2"), 550, 540, 520, 40);	
	
	applyZoomAndPositionToObject(document.getElementById("arcencielstudioModel"), 550, 150, 520, 425);
	applyZoomAndPositionToObject(document.getElementById("arcencielstudioModelBackground"), 550, 150, 520, 425);
	
	applyZoomAndPositionToObject(document.getElementById("arcencielstudioEditionSlide"), 0, 480, 1160, 40);	

	applyZoomAndPositionToObject(document.getElementById("arcencielstudioContact2"), 410, 150, 660, 50);
	applyZoomAndPositionToObject(document.getElementById("arcencielstudioContactBackground2"), 410, 150, 660, 50);	
	applyZoomAndPositionToObject(document.getElementById("arcencielstudioContact"), 410, 220, 660, 280);
	applyZoomAndPositionToObject(document.getElementById("arcencielstudioContactBackground"), 410, 220, 660, 280);	

	applyZoomAndPositionToObject(document.getElementById("arcencielstudioThanks"), 520, 210, 580, 200);
	applyZoomAndPositionToObject(document.getElementById("arcencielstudioThanksBackground"), 520, 210, 580, 200);
	applyZoomAndPositionToObject(document.getElementById("arcencielstudioThanks2"), 520, 430, 580, 80);
	applyZoomAndPositionToObject(document.getElementById("arcencielstudioThanksBackground2"), 520, 430, 580, 80);	

	applyZoomAndPositionToObject(document.getElementById("arcencielstudioGallerySlideFlashMovie"), 0, 92, 1160, 509);
	
	applyZoomAndPositionToObject(document.getElementById("arcencielstudioGallery"), 500, 120, 590, 460);
	
	applyZoomAndPositionToObject(document.getElementById("arcencielstudioBookMexicoFlashMovie"), 120, 180, 896, 384);
	applyZoomAndPositionToObject(document.getElementById("arcencielstudioBookWeddingFlashMovie"), 10, 175, 1141, 400);
			
	applyZoomEffectToObject(getBackgroundImageControl("home"));
	applyZoomEffectToObject(getBackgroundImageControl("wedding"));
	applyZoomEffectToObject(getBackgroundImageControl("family"));
	applyZoomEffectToObject(getBackgroundImageControl("arquitecture"));
	applyZoomEffectToObject(getBackgroundImageControl("advertising"));
	applyZoomEffectToObject(getBackgroundImageControl("edition"));
	applyZoomEffectToObject(getBackgroundImageControl("editionSlide"));
	applyZoomEffectToObject(getBackgroundImageControl("model"));
	applyZoomEffectToObject(getBackgroundImageControl("gallery"));
	applyZoomEffectToObject(getBackgroundImageControl("gallerySlide"));
	applyZoomEffectToObject(getBackgroundImageControl("contact"));	
	applyZoomEffectToObject(getBackgroundImageControl("thanks"));		
}

function setProgress(progress)
{
	if (progress < currentProgress) return;
	
	currentProgress=progress;

	document.getElementById("progressBarText").innerHTML="cargando... " + progress + "%";		
}

function initialize()
{		
	getBackgroundImageControl("home").src="images/home.jpg";
	
	// Start progress
	window.setTimeout("setProgress(20);", 100);
	window.setTimeout("setProgress(30);", 600);
	window.setTimeout("setProgress(40);", 1200);
	window.setTimeout("setProgress(50);", 1500);
	window.setTimeout("setProgress(60);", 1800);
	window.setTimeout("setProgress(70);", 2400);
	window.setTimeout("setProgress(80);", 3000);
	window.setTimeout("setProgress(90);", 3500);
	
	// Set opacity to background controls
	setOpacityToObjectControl(getBackgroundImageControl("home"), 0);
	setOpacityToObjectControl(getBackgroundImageControl("wedding"), 0);
	setOpacityToObjectControl(getBackgroundImageControl("family"), 0);
	setOpacityToObjectControl(getBackgroundImageControl("arquitecture"), 0);
	setOpacityToObjectControl(getBackgroundImageControl("advertising"), 0);
	setOpacityToObjectControl(getBackgroundImageControl("edition"), 0);
	setOpacityToObjectControl(getBackgroundImageControl("editionSlide"), 0);
	setOpacityToObjectControl(getBackgroundImageControl("model"), 0);
	setOpacityToObjectControl(getBackgroundImageControl("gallery"), 0);
	setOpacityToObjectControl(getBackgroundImageControl("gallerySlide"), 0);
	setOpacityToObjectControl(getBackgroundImageControl("contact"), 0);
	setOpacityToObjectControl(getBackgroundImageControl("thanks"), 0);	
	
	// Opacity to controls
	setOpacityToObjectControl(document.getElementById("backgroundHome"), 50);		
	setOpacityToObjectControl(document.getElementById("backgroundWedding"), 50);
	setOpacityToObjectControl(document.getElementById("backgroundWedding2"), 50);
	setOpacityToObjectControl(document.getElementById("backgroundWedding3"), 50);
	setOpacityToObjectControl(document.getElementById("backgroundArquitecture"), 50);
	setOpacityToObjectControl(document.getElementById("backgroundAdvertising"), 50);
	setOpacityToObjectControl(document.getElementById("backgroundEdition"), 50);
	setOpacityToObjectControl(document.getElementById("backgroundEdition2"), 50);
	setOpacityToObjectControl(document.getElementById("backgroundFamily"), 50);	
	setOpacityToObjectControl(document.getElementById("backgroundModel"), 50);
	setOpacityToObjectControl(document.getElementById("backgroundContact"), 50);		
	setOpacityToObjectControl(document.getElementById("backgroundContact2"), 50);				
	setOpacityToObjectControl(document.getElementById("backgroundThanks"), 80);		
	setOpacityToObjectControl(document.getElementById("backgroundThanks2"), 80);
}

function changeBackgroundWithDelay(newBackgroundName, url, fadeInDelay, fadeOutDelay)
{
	var currentImageBackgroundControl, newImageBackgroundControl;
		
	changeMenuAllowed=false;
																										
	// Fade in new background
	newImageBackgroundControl = getBackgroundImageControl(newBackgroundName);
	if (newImageBackgroundControl != null)
	{
		applyZoomEffectToObject(newImageBackgroundControl);
		newImageBackgroundControl.src = url;
		
		window.setTimeout("applyFadeInEffectToImageControl('" + newImageBackgroundControl.id + "', 35);", fadeInDelay);	
	}
	else
	{
		alert("Error: background " + newBackgroundName + " not found.");
	}
	
	// Fade out current background
	currentImageBackgroundControl = getBackgroundImageControl(currentBackgroundName);
	if (currentImageBackgroundControl != null)
	{
		window.setTimeout("applyFadeOutEffectToImageControl('" + currentImageBackgroundControl.id + "', 40);", fadeOutDelay);		
	}
	
	currentBackgroundName = newBackgroundName;
		
	if (newImageBackgroundControl=="home" || currentBackgroundName == "home")
	{
		window.setTimeout("changeMenuAllowed=true;", (fadeInDelay*6));		
	}
	else
	{
		window.setTimeout("changeMenuAllowed=true;", (fadeInDelay*4));		
	}
}

function changeBackground(newBackgroundName, url)
{
	changeBackgroundWithDelay(newBackgroundName, url, 500, 0);
}

function setBackground(newBackgroundName, url)
{
	var currentImageBackgroundControl, newImageBackgroundControl;
																										
	// Fade in new background
	newImageBackgroundControl = getBackgroundImageControl(newBackgroundName);
	if (newImageBackgroundControl != null)
	{
		applyZoomEffectToObject(newImageBackgroundControl);
		newImageBackgroundControl.src = url;
		
		applyFadeInEffectToImageControl(newImageBackgroundControl.id, 15);
	}
	else
	{
		alert("Error: background " + newBackgroundName + " not found.");
	}
	
	currentBackgroundName = newBackgroundName;
}

function removeBackground()
{
	var currentImageBackgroundControl;
																										
	// Fade out current background
	currentImageBackgroundControl = getBackgroundImageControl(currentBackgroundName);
	if (currentImageBackgroundControl != null)
	{
		applyFadeOutEffectToImageControl(currentImageBackgroundControl, 40);		
	}
	
	currentBackgroundName = "";
}

function calculateWorkAreaDimensions()
{
	var iBrowserWidth = getBrowserWidth();
	var iBrowserHeight = getBrowserHeight();
	var iObjectWidthRelationW, iObjectHeightRelationW;
	var iObjectWidthRelationH, iObjectHeightRelationH;
	
	// recalculate dimensions
	iObjectWidthRelationW = iBrowserWidth;
	iObjectHeightRelationW = Math.round(iObjectWidthRelationW * (virtualWorkAreaHeight/virtualWorkAreaWidth));
	iObjectHeightRelationH = iBrowserHeight;
	iObjectWidthRelationH = Math.round(iObjectHeightRelationH * (virtualWorkAreaWidth/virtualWorkAreaHeight));
	
	// Choose adecuated one
	if (iObjectWidthRelationW <= iBrowserWidth && iObjectHeightRelationW <= iBrowserHeight)
	{
		realWorkAreaWidth = iObjectWidthRelationW;
		realWorkAreaHeight = iObjectHeightRelationW;
		
		realWorkAreaTop = Math.round((iBrowserHeight-iObjectHeightRelationW)/2);
		realWorkAreaLeft = Math.round((iBrowserWidth-iObjectWidthRelationW)/2);		
	}
	else if (iObjectWidthRelationH <= iBrowserWidth && iObjectHeightRelationH <= iBrowserHeight)
	{
		realWorkAreaWidth = iObjectWidthRelationH;
		realWorkAreaHeight = iObjectHeightRelationH;
		
		realWorkAreaTop = Math.round((iBrowserHeight-iObjectHeightRelationH)/2);
		realWorkAreaLeft = Math.round((iBrowserWidth-iObjectWidthRelationH)/2);
	}
}

function convertVirtualXValueToRealXValue(value)
{
	return Math.round( ((value*realWorkAreaWidth)/virtualWorkAreaWidth));
}

function convertVirtualYValueToRealYValue(value)
{
	return Math.round( ((value*realWorkAreaHeight)/virtualWorkAreaHeight));
}

function applyZoomEffectToObject(object)
{
	if (realWorkAreaTop == null || realWorkAreaLeft == null || realWorkAreaWidth == null || realWorkAreaHeight == null) return;
	object.style.top = realWorkAreaTop + "px";
	object.style.left = realWorkAreaLeft + "px";
	object.style.width = realWorkAreaWidth + "px";
	object.style.height = realWorkAreaHeight + "px";		
}

function applyZoomEffectToHeaderFooter(object)
{
	items = object.getElementsByTagName("a"); 
	
	for(var index=0;index<items.length;index++)
	{
		items[index].style.fontSize = ((realWorkAreaWidth * items[index].getAttribute("virtualFontSize")) / virtualWorkAreaWidth) + "px";
	}	
	
	items = object.getElementsByTagName("li"); 
	
	for(var index=0;index<items.length;index++)
	{
		items[index].style.fontSize = ((realWorkAreaWidth * items[index].getAttribute("virtualFontSize")) / virtualWorkAreaWidth) + "px";
	}
	
	items = object.getElementsByTagName("input"); 
	
	for(var index=0;index<items.length;index++)
	{
		items[index].style.fontSize = ((realWorkAreaWidth * items[index].getAttribute("virtualFontSize")) / virtualWorkAreaWidth) + "px";
	}
	
	items = object.getElementsByTagName("textarea"); 
	
	for(var index=0;index<items.length;index++)
	{
		items[index].style.fontSize = ((realWorkAreaWidth * items[index].getAttribute("virtualFontSize")) / virtualWorkAreaWidth) + "px";
	}
	
	items = object.getElementsByTagName("select"); 
	
	for(var index=0;index<items.length;index++)
	{
		items[index].style.fontSize = ((realWorkAreaWidth * items[index].getAttribute("virtualFontSize")) / virtualWorkAreaWidth) + "px";
	}
	
}

function applyZoomAndPositionToObject(object, x, y, width, height)
{	
	object.style.top = (realWorkAreaTop + convertVirtualYValueToRealYValue(y)) + "px";
	object.style.left = (realWorkAreaLeft + convertVirtualXValueToRealXValue(x)) + "px";
	object.style.width = convertVirtualXValueToRealXValue(width) + "px";
	object.style.height = convertVirtualYValueToRealYValue(height) + "px";
}

function showSWFWithDelay(name, delayFadeIn)
{
	currentSWFName=name;
	
	switch(currentSWFName)
	{
		case "home":
			window.setTimeout("applyFadeInEffectToImageControl('arcencielstudioHome', 20);", delayFadeIn);
			window.setTimeout("applyFadeInEffectToImageControl('arcencielstudioHomeBackground', 20);", delayFadeIn);
		break;
		
		case "wedding":
			window.setTimeout("applyFadeInEffectToImageControl('arcencielstudioWedding', 20);", delayFadeIn);
			window.setTimeout("applyFadeInEffectToImageControl('arcencielstudioWeddingBackground', 20);", delayFadeIn);
			window.setTimeout("applyFadeInEffectToImageControl('arcencielstudioWedding2', 20);", delayFadeIn);
			window.setTimeout("applyFadeInEffectToImageControl('arcencielstudioWeddingBackground2', 20);", delayFadeIn);
			window.setTimeout("applyFadeInEffectToImageControl('arcencielstudioWedding3', 20);", delayFadeIn);
			window.setTimeout("applyFadeInEffectToImageControl('arcencielstudioWeddingBackground3', 20);", delayFadeIn);
		break;
				
		case "family":
			window.setTimeout("applyFadeInEffectToImageControl('arcencielstudioFamily', 20);", delayFadeIn);
			window.setTimeout("applyFadeInEffectToImageControl('arcencielstudioFamilyBackground', 20);", delayFadeIn);
		break;
		
		case "arquitecture":
			window.setTimeout("applyFadeInEffectToImageControl('arcencielstudioArquitecture', 20);", delayFadeIn);
			window.setTimeout("applyFadeInEffectToImageControl('arcencielstudioArquitectureBackground', 20);", delayFadeIn);
		break;
		
		case "advertising":
			window.setTimeout("applyFadeInEffectToImageControl('arcencielstudioAdvertising', 20);", delayFadeIn);
			window.setTimeout("applyFadeInEffectToImageControl('arcencielstudioAdvertisingBackground', 20);", delayFadeIn);
		break;
		
		case "edition":
			window.setTimeout("applyFadeInEffectToImageControl('arcencielstudioEdition', 20);", delayFadeIn);
			window.setTimeout("applyFadeInEffectToImageControl('arcencielstudioEditionBackground', 20);", delayFadeIn);
			window.setTimeout("applyFadeInEffectToImageControl('arcencielstudioEdition2', 20);", delayFadeIn);
			window.setTimeout("applyFadeInEffectToImageControl('arcencielstudioEditionBackground2', 20);", delayFadeIn);
		break;
		
		case "editionSlide":
			window.setTimeout("applyFadeInEffectToImageControl('arcencielstudioEditionSlide', 20);", delayFadeIn);
		break;
		
		case "bookMexico":		
			window.setTimeout("applyFadeInEffectToImageControl('arcencielstudioBookMexicoFlashMovie', 20);", delayFadeIn);
		break;
		
		case "bookWedding":		
			window.setTimeout("applyFadeInEffectToImageControl('arcencielstudioBookWeddingFlashMovie', 20);", delayFadeIn);
			window.setTimeout("applyZoomAndPositionToObject(document.getElementById('arcencielstudioBookWeddingFlashMovie'), 10, 175, 1140, 400);", 2000);			
		break;
		
		case "model":
			window.setTimeout("applyFadeInEffectToImageControl('arcencielstudioModel', 20);", delayFadeIn);
			window.setTimeout("applyFadeInEffectToImageControl('arcencielstudioModelBackground', 20);", delayFadeIn);
		break;
		
		case "contact":
			window.setTimeout("applyFadeInEffectToImageControl('arcencielstudioContact', 20);", delayFadeIn);
			window.setTimeout("applyFadeInEffectToImageControl('arcencielstudioContactBackground', 20);", delayFadeIn);
			window.setTimeout("applyFadeInEffectToImageControl('arcencielstudioContact2', 20);", delayFadeIn);
			window.setTimeout("applyFadeInEffectToImageControl('arcencielstudioContactBackground2', 20);", delayFadeIn);
		break;
		
		case "thanks":
			window.setTimeout("applyFadeInEffectToImageControl('arcencielstudioThanks', 20);", delayFadeIn);
			window.setTimeout("applyFadeInEffectToImageControl('arcencielstudioThanksBackground', 20);", delayFadeIn);
			window.setTimeout("applyFadeInEffectToImageControl('arcencielstudioThanks2', 20);", delayFadeIn);
			window.setTimeout("applyFadeInEffectToImageControl('arcencielstudioThanksBackground2', 20);", delayFadeIn);
		break;
		
		case "gallery":
			window.setTimeout("applyFadeInEffectToImageControl('arcencielstudioGallery', 20);", delayFadeIn);
		break;
	}
}

function showSWF(name)
{
	showSWFWithDelay(name, 0);
}

function showGallerySlideSWF(galleryName)
{
	getDivForSWF("gallerySlide").style.display="";
	//startGallerySlideSWF("dummy");
	currentSWFName="gallerySlide";	
	window.setTimeout("startGallerySlideSWF('" + galleryName + "')", 3000);		
}

function hideAllSWF()
{
	switch(currentSWFName)
	{
		case "home":
			applyFadeOutEffectToImageControl("arcencielstudioHome", 20);
			applyFadeOutEffectToImageControl("arcencielstudioHomeBackground", 20);
		break;
		
		case "wedding":
			applyFadeOutEffectToImageControl("arcencielstudioWedding", 20);
			applyFadeOutEffectToImageControl("arcencielstudioWeddingBackground", 20);
			applyFadeOutEffectToImageControl("arcencielstudioWedding2", 20);
			applyFadeOutEffectToImageControl("arcencielstudioWeddingBackground2", 20);
			applyFadeOutEffectToImageControl("arcencielstudioWedding3", 20);
			applyFadeOutEffectToImageControl("arcencielstudioWeddingBackground3", 20);
		break;
		
		case "family":
			applyFadeOutEffectToImageControl("arcencielstudioFamily", 20);
			applyFadeOutEffectToImageControl("arcencielstudioFamilyBackground", 20);
		break;
		
		case "arquitecture":
			applyFadeOutEffectToImageControl("arcencielstudioArquitecture", 20);
			applyFadeOutEffectToImageControl("arcencielstudioArquitectureBackground", 20);
		break;
		
		case "advertising":
			applyFadeOutEffectToImageControl("arcencielstudioAdvertising", 20);
			applyFadeOutEffectToImageControl("arcencielstudioAdvertisingBackground", 20);
		break;
		
		case "edition":
			applyFadeOutEffectToImageControl("arcencielstudioEdition", 20);
			applyFadeOutEffectToImageControl("arcencielstudioEditionBackground", 20);
			applyFadeOutEffectToImageControl("arcencielstudioEdition2", 20);
			applyFadeOutEffectToImageControl("arcencielstudioEditionBackground2", 20);
		break;
		
		case "editionSlide":
			applyFadeOutEffectToImageControl("arcencielstudioEditionSlide", 20);			
		break;
		
		case "model":
			applyFadeOutEffectToImageControl("arcencielstudioModel", 20);
			applyFadeOutEffectToImageControl("arcencielstudioModelBackground", 20);
		break;
		
		case "contact":
			applyFadeOutEffectToImageControl("arcencielstudioContact", 20);
			applyFadeOutEffectToImageControl("arcencielstudioContactBackground", 20);
			applyFadeOutEffectToImageControl("arcencielstudioContact2", 20);
			applyFadeOutEffectToImageControl("arcencielstudioContactBackground2", 20);
		break;
		
		case "thanks":
			applyFadeOutEffectToImageControl("arcencielstudioThanks", 20);
			applyFadeOutEffectToImageControl("arcencielstudioThanksBackground", 20);
			applyFadeOutEffectToImageControl("arcencielstudioThanks2", 20);
			applyFadeOutEffectToImageControl("arcencielstudioThanksBackground2", 20);
		break;
		
		case "bookMexico":
			applyFadeOutEffectToImageControl("arcencielstudioBookMexicoFlashMovie", 20);
		break;
		
		case "bookWedding":
			applyFadeOutEffectToImageControl("arcencielstudioBookWeddingFlashMovie", 20);
		break;
		
		case "gallery":
			applyFadeOutEffectToImageControl("arcencielstudioGallery", 20);
		break;
		
		case "gallerySlide":
			//applyFadeOutEffectToImageControl(getDivForSWF("gallerySlide").id, 40);
			startGallerySlideSWF("dummy");			
			//window.setTimeout("getDivForSWF('gallerySlide').style.display='none';", 500);
			getDivForSWF("gallerySlide").style.display="none";
		break;
	}

	currentSWFName="";
}

function getDivForSWF(name)
{
	switch(name)
	{
		case "arquitecture":
			return document.getElementById("arcencielstudioArquitectureFlashMovie");
		break;

		case "advertising":
			return document.getElementById("arcencielstudioAdvertisingFlashMovie");
		break;
		
		case "edition":
			return document.getElementById("arcencielstudioEditionFlashMovie");
		break;
		
		case "contact":
			return document.getElementById("arcencielstudioContactFlashMovie");
		break;
		
		case "gallerySlide":
			return document.getElementById("arcencielstudioGallerySlideFlashMovie");
		break;
		
		case "bookMexico":
			return document.getElementById("arcencielstudioBookMexicoFlashMovie");
		break;
		
		case "bookWedding":
			return document.getElementById("arcencielstudioBookWeddingFlashMovie");
		break;
		
		case "thanks":
			return document.getElementById("arcencielstudioThanksFlashMovie");
		break;
		
		default:
			return null;		
	}
}

function getCurrentBackgroundImageControl()
{
	var imgBackground = getBackgroundImageControl(currentBackgroundName);
	
	if (imgBackground == null)
	{
		return document.getElementById("imgHomeBackground");
	}
	else
	{
		return imgBackground;
	}
}

function getBackgroundImageControl(name)
{
	switch(name)
	{
		case "home":
			return document.getElementById("imgHomeBackground");
		break;
	
		case "wedding":
			return document.getElementById("imgWeddingBackground");
		break;
		
		case "family":
			return document.getElementById("imgFamilyBackground");
		break;

		case "arquitecture":
			return document.getElementById("imgArquitectureBackground");
		break;

		case "advertising":
			return document.getElementById("imgAdvertisingBackground");
		break;

		case "edition":
			return document.getElementById("imgEditionBackground");
		break;
		
		case "editionSlide":
			return document.getElementById("imgEditionSlideBackground");
		break;

		case "model":
			return document.getElementById("imgModelBackground");
		break;

		case "gallery":
			return document.getElementById("imgGalleryBackground");
		break;
		
		case "gallerySlide":
			return document.getElementById("imgGallerySlideBackground");
		break;
		
		case "contact":
			return document.getElementById("imgContactBackground");
		break;
		
		case "thanks":
			return document.getElementById("imgThanksBackground");
		break;
		
		default:
			return null;		
	}
}

// Flash
// Handle all the FSCommand messages in a Flash movie.
function arcencielstudio_DoEvent(command, args) {
	var arcencielstudioObj = isInternetExplorer ? document.all.arcencielstudio : document.arcencielstudio;

	if (command == "showSWF")
	{
		hideAllSWF();
		
		switch (args)
		{
			case "bookMexico":
				showSWF("bookMexico");
			break;
			
			case "bookWedding":
				showSWF("bookWedding");
			break;
		}		
	}
	else if (command == "removeBackground")
	{
		removeBackground();
	}
	else if (command == "changeBackgroundAndShowSWF_long" || command == "changeBackgroundAndShowSWF_short")
	{	
		var delayFadeIn, delayFadeOut;
		
		hideAllSWF();

		if (command.indexOf("long") != -1)
		{
			delayFadeIn=1000;
			delayFadeOut=1000;			
			delayFadeInSWF=3900;
		}		
		else if (command.indexOf("short") != -1)
		{
			delayFadeIn=1000;
			delayFadeOut=1000;			
			delayFadeInSWF=2000;
		}
		else
		{
			delayFadeIn=0;
			delayFadeOut=0;
			delayFadeInSWF=0;
		}
		
		switch (args)
		{
			case "home":
				showSWFWithDelay("home", delayFadeInSWF);				
				changeBackgroundWithDelay("home", "images/home.jpg", delayFadeIn, delayFadeOut);
			break;
			
			case "wedding":
				showSWFWithDelay("wedding", delayFadeInSWF);
				changeBackgroundWithDelay("wedding", "images/wedding.jpg", delayFadeIn, delayFadeOut);
			break;
			
			case "family":		
				showSWFWithDelay("family", delayFadeInSWF);	
				changeBackgroundWithDelay("family", "images/family.jpg", delayFadeIn, delayFadeOut);
			break;
			
			case "arquitecture":			
				showSWFWithDelay("arquitecture", delayFadeInSWF);	
				changeBackgroundWithDelay("arquitecture", "images/arquitecture.jpg", delayFadeIn, delayFadeOut);
			break;
			
			case "advertising":			
				showSWFWithDelay("advertising", delayFadeInSWF);	
				changeBackgroundWithDelay("advertising", "images/advertising.jpg", delayFadeIn, delayFadeOut);
			break;
			
			case "edition":			
				showSWFWithDelay("edition", delayFadeInSWF);	
				changeBackgroundWithDelay("edition", "images/edition.jpg", delayFadeIn, delayFadeOut);
			break;
			
			case "editionSlide":
				showSWFWithDelay("editionSlide", delayFadeInSWF);			
				changeBackgroundWithDelay("editionSlide", "images/editionSlide.jpg", delayFadeIn, delayFadeOut);
			break;
			
			case "model":	
				showSWFWithDelay("model", delayFadeInSWF);		
				changeBackgroundWithDelay("model", "images/model.jpg", delayFadeIn, delayFadeOut);
			break;
			
			case "gallery":			
				changeBackgroundWithDelay("gallery", "images/gallery.jpg", delayFadeIn, delayFadeOut);
				showSWFWithDelay("gallery", delayFadeInSWF);
			break;
			
			case "gallerySlide":			
				changeBackgroundWithDelay("gallerySlide", "images/gallerySlide.jpg", delayFadeIn, delayFadeOut);
			break;
			
			case "contact":	
				showSWFWithDelay("contact", delayFadeInSWF);		
				changeBackgroundWithDelay("contact", "images/contact.jpg", delayFadeIn, delayFadeOut);
			break;
			
			case "thanks":
				showSWFWithDelay("thanks", delayFadeInSWF);			
				changeBackgroundWithDelay("thanks", "images/thanks.jpg", delayFadeIn, delayFadeOut);
			break;			
		}		
	}
	else if (command == "changeBackgroundAndShowGallerySlideSWF")
	{
		changeBackground("gallerySlide", "images/gallerySlide.jpg");
		showGallerySlideSWF(args);
	}	
}

function arcencielstudioGallerySlide_DoFSCommand(command, args) {
	var arcencielstudioGallerySlide = isInternetExplorer ? document.all.arcencielstudioGallerySlide : document.arcencielstudioGallerySlide;

	if (command == "gotoGallerySWF")
	{		
		hideAllSWF();

		changeBackground('gallery');
	}
}

function arcencielstudioThanks_DoFSCommand(command, args) {
	var arcencielstudioThanks = isInternetExplorer ? document.all.arcencielstudioThanks : document.arcencielstudioThanks;

	if (command == "changeBackgroundAndShowGallerySlideSWF")
	{
		hideAllSWF();
		
		changeBackground("gallerySlide", "images/gallerySlide.jpg");
		showGallerySlideSWF(args);
	}
}

function changeLanguageSWF(name, langId)
{
	currentLanguage=langId;
	var flashMovie=getFlashMovieObject(name);
	
	if (flashMovie != null)
	{
		flashMovie.changeLanguage(langId);		
	}
}

function startGallerySlideSWF(galleryName)
{
	var flashMovie=getFlashMovieObject("gallerySlide");
	
	if (flashMovie != null)
	{
		flashMovie.startGallerySlide(galleryName);		
	}
}

function fadeToHideSWF(name)
{
    var flashMovie=getFlashMovieObject(name);
    flashMovie.fadeToHide();
}

function getFlashMovieObject(name)
{
	var movieName;
	
	switch (name)
	{
		case "arcencielstudio":
			movieName = "arcencielstudio";
		break;
		
		case "arquitecture":
			movieName = "arcencielstudioArquitecture";
		break;
		
		case "edition":
			movieName = "arcencielstudioEdition";
		break;
		
		case "advertising":
			movieName = "arcencielstudioAdvertising";
		break;
		
		case "contact":
			movieName = "arcencielstudioContact";
		break;
		
		case "gallerySlide":
			movieName = "arcencielstudioGallerySlide";
		break;
		
		default:
			return null;
	}
	
    if (window.document[movieName])
	{
        return window.document[movieName];
    }

    if (navigator.appName.indexOf("Microsoft Internet")==-1)
	{
        if (document.embeds && document.embeds[movieName])
		{
        	return document.embeds[movieName];
		}
    }
    else
	{
        return document.getElementById(movieName);
    }
}

function openBook(name)
{
	arcencielstudio_DoEvent("showSWF", name);
	/*
	switch (name)
	{
		case "bookWedding":
			//window.parent.open('books/wedding/bookWedding.htm','_blank','width=900,height=500,scrollbars=yes,top=' + Math.round((screen.availHeight-500)/2) + ',left=' + Math.round((screen.availWidth-900)/2) + ',toolbar=no,location=no,directories=no,menubar=no,resizable=no,status=yes');			
			//window.open('books/wedding/bookWedding.htm',null,'width=900,height=500,scrollbars=yes,top=' + Math.round((screen.availHeight-500)/2) + ',left=' + Math.round((screen.availWidth-900)/2) + ',toolbar=no,location=no,directories=no,menubar=no,resizable=no,status=yes');			
		break;
		
		default:
		break;
	}*/
	
	
}

function changeBackground(name)
{
	var isAnimationSignRequired=true;
	
	if (!changeMenuAllowed) return;
	
	if (currentBackgroundName == name)
	{
		return ;
	}
	else if (currentBackgroundName == "home" || name == "home")
	{		
		arcencielstudio_DoEvent('changeBackgroundAndShowSWF_long', name);
	}
	else
	{	
		isAnimationSignRequired=false;
		
		arcencielstudio_DoEvent('changeBackgroundAndShowSWF_short', name);
	}
	
	if (isAnimationSignRequired)
	{	
		if (name != "home")
		{
			window.setTimeout("animateSign(true);", 2000);
		}
		else
		{
			window.setTimeout("animateSign(false);", 2000);
		}
	}
}

function animateSign(up)
{
	if (up)
	{
		animationXToSign(signX, signUpX, 10, true, "animationYToSign(signY, signUpY, 20, false, '');");
	}
	else
	{
		animationYToSign(signY, signDownY, 10, true, "animationXToSign(signX, signDownX, 20, false, '');");
	}
}

function animationYToSign(yStart, yEnd, step, animateAgain, command)
{
	var object = document.getElementById('arcencielstudioSign');
		
	if (yStart > yEnd) // Left
	{
		if (signY <= yEnd) 
		{
			if (animateAgain) { window.setTimeout(command, 1); }
			return ;
		}
		
		signY -= step;
	}	
	else if (yStart <= yEnd) // Right
	{
		if (signY > yEnd) 
		{
			if (animateAgain) { window.setTimeout(command, 1); }
			return ;
		}

		signY += step;
	}
	else
	{
		if (animateAgain) { window.setTimeout(command, 1); }
		return ;
	}
	
	applyZoomAndPositionToObject(document.getElementById("arcencielstudioSign"), signX, signY, 160, 60);
	
	window.setTimeout("animationYToSign("+yStart+","+yEnd+","+ step + "," + animateAgain + ",\"" + command + "\");", 1);
}

function animationXToSign(xStart, xEnd, step, animateAgain, command)
{
	var object = document.getElementById('arcencielstudioSign');
		
	if (xStart > xEnd) // Left
	{
		if (signX <= xEnd) 
		{
			if (animateAgain) { window.setTimeout(command, 1); }
			return ;
		}
		
		signX -= step;
	}	
	else if (xStart < xEnd) // Right
	{
		if (signX >= xEnd) 
		{
			if (animateAgain) { window.setTimeout(command, 1); }
			return ;
		}

		signX += step;
	}
	else
	{
		if (animateAgain) { window.setTimeout(command, 1); }
		return ;
	}
	
	applyZoomAndPositionToObject(document.getElementById("arcencielstudioSign"), signX, signY, 160, 60);
	
	window.setTimeout("animationXToSign(" + xStart + "," + xEnd + "," + step + "," + animateAgain + ",\"" + command + "\");", 1);
}

function sendMail()
{
	if (document.getElementById("txtName").value == "" || document.getElementById("txtMail").value == "" || document.getElementById("txtPhone").value == "" || document.getElementById("txtService").value == "" || document.getElementById("txtCommentaries").value == "")
	{
		document.getElementById("errorDataMail").style.display="";
		return;
	}
	else
	{
			// Enviar MAIL
			var httpRequest = getObjectHttpRequest();

			urlMail = "http://www.arcencielstudio.com/sendMail.php?";			
			urlMail += "nombre=" + document.getElementById("txtName").value + "&";	
			urlMail += "mail=" + document.getElementById("txtMail").value + "&";	
			urlMail += "asunto=ArcencielStudio - " + document.getElementById("txtService").value + "&";
			urlMail += "mensaje=";
			urlMail += document.getElementById("txtCommentaries").value + "<br>";
			urlMail += "Tel.: " + document.getElementById("txtPhone").value + "<br>";
			urlMail += "Mail: " + document.getElementById("txtMail").value+ "<br>";
			urlMail += "Como sabe de nosotros?: " + document.getElementById("slcHowKnowAboutUs").options[document.getElementById("slcHowKnowAboutUs").selectedIndex].text;
			//alert(urlMail);

			httpRequest.open("POST", urlMail);
			httpRequest.send();
				
			changeBackground('thanks');
	}
}

function getObjectHttpRequest() {
    var xmlhttp;

    // code for IE7+, Firefox, Chrome, Opera, Safari
    if (window.XMLHttpRequest) {
        xmlhttp = new XMLHttpRequest();
    }
    else // code for IE6, IE5
    {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }

    return xmlhttp;
}
