var lastImage = 2;
var photo = new Array();
var nbPhotos = 10;
var languageAbrev;


function imgOver( image )
{
	// set l'image du menu pour le rollover (enabled)
	image.src = "../images/menu/" + image.name + "e.jpg";
}

function imgOut( image )
{
	// reset l'image du menu d'origine (disabled)
	image.src = "../images/menu/" + image.name + "d.jpg";
}

function tendanceOver( image )
{
	// set l'image du menu pour le rollover (enabled)
	image.src = "../images/" + image.name + "_e.jpg";
}

function tendanceOut( image )
{
	// reset l'image du menu d'origine (disabled)
	image.src = "../images/" + image.name + "_d.jpg";
}

function toEnglish( links )
{
	// permet de garder le lien actif pour transférer en anglais
	var oldUrl, newUrl
	
	oldUrl = document.location.toString();
	newUrl = oldUrl.replace( languageAbrev, "en" );
	links.href = newUrl;
}

function toFrench( links )
{
	// permet de garder le lien actif pour transférer en français
	var oldUrl, newUrl
	
	oldUrl = document.location.toString();	
	newUrl = oldUrl.replace( languageAbrev, "fr" );
	links.href = newUrl;
}

function init( langue )
{
	languageAbrev = langue
	
	// load les images de menu en cache
	var imageCacheEnabled = new Array();
	var menuItem = 9;
	
	for( var i = 0; i < menuItem; i++ )
	{
		imageCacheEnabled[i] = new Image();
		
		if( langue == 'en' && i < 6 )
		{
			imageCacheEnabled[i].src = "../images/menu/menu" + ( i + 1 ) + "_ene.jpg";
		}
		else
		{
			imageCacheEnabled[i].src = "../images/menu/menu" + ( i + 1 ) + "e.jpg";
		}
	}
	
	// images rotatives
	loadShow();
	
	if( document.location.toString().search( "inspiration.html" ) != -1 ) {
		loadCacheImages( "tendance" );
	}
}


function loadShow()
{
	for( var i = 0; i < nbPhotos; i++ )
	{
		photo[i] = new Image();
		photo[i].src = "../images/slideshow/photo" + ( i ) + ".jpg";
	}
	
	shuffle( photo );
	slideShow();
}	

function shuffle( array )
{
	var R, T, J

	for( J = array.length -1; J > 0; J-- )
	{
		R = randNum( J + 1 );
		T = array[J];
		array[J] = array[R];
		array[R] = T
	}

	return array
} 
		  
function randNum( num )
{
	return Math.floor( num * Math.random() )
} 

function slideShow()
{
	var speed = 4000;
	
	lastImage = lastImage == nbPhotos ? 0  : lastImage;

/*	if( lastImage == nbPhotos )
	{
		lastImage = 0;
	}*/

	document.photo.src = photo[lastImage].src;

	setTimeout( "slideShow()", speed );
	lastImage++;
}

function loadCacheImages( category ) {
	var imageCache = new Array();
	
	if( category == "tendance" ) {
		imageCache[0] = new Image();
		imageCache[0].src = "../images/UberLuxe_e.jpg";
		imageCache[1] = new Image();
		imageCache[1].src = "../images/NouvelleElegance_e.jpg";
		imageCache[2] = new Image();
		imageCache[2].src = "../images/LoftUrbain_e.jpg";
		imageCache[3] = new Image();
		imageCache[3].src = "../images/TechnoBranche_e.jpg";
		imageCache[4] = new Image();
		imageCache[4].src = "../images/FusionGlobale_e.jpg";
		imageCache[5] = new Image();
		imageCache[5].src = "../images/NeutresDelicats_e.jpg";
		
		/*for( var i = 0; i < imageCache.length; i++ )
		{
			alert(imageCache[i].src);
		}*/
	}
}
	
function openWindow( url, height, width, scrollbars, status, toolbar, menubar, location, resizeable, titlebar )
{
	var windowAttributes = height + ", ";
	windowAttributes = windowAttributes + width + ", ";
	windowAttributes = windowAttributes + scrollbars + ", ";
	windowAttributes = windowAttributes + status + ", ";
	windowAttributes = windowAttributes + toolbar + ", ";
	windowAttributes = windowAttributes + menubar + ", ";
	windowAttributes = windowAttributes + location + ", ";
	windowAttributes = windowAttributes + resizeable + ", ";
	windowAttributes = windowAttributes + titlebar; 
	
	window.open( url, null, windowAttributes );
}
