var ua = navigator.userAgent.toLowerCase();
var Version = parseInt(navigator.appVersion);
var isIE = ((ua.indexOf("msie") != -1) && (ua.indexOf("opera") == -1) && (ua.indexOf("webtv") == -1))? true:false;
var isIE5 = (isIE && (Version == 4) && (ua.indexOf("msie 5.0")!=-1));
var isMac = (navigator.appVersion.indexOf("Mac") != -1);

function preload()
{
	imgload=new Array();
	for(var j=0; j<preload.arguments.length; j++)
	{
		imgload[j]=new Image();
		imgload[j].src=preload.arguments[j];
	}
}

function largeur_fenetre()
{
	if (window.innerWidth) return window.innerWidth;
	else if (document.body && document.body.offsetWidth) return document.body.offsetWidth;
	else return 0;
}

function createThumbnail(parent, file)
{
	if (isIE && isMac) {return true;}
	else
	{
		// Init
		var screenSize = largeur_fenetre();
		var centerContainer = document.getElementById("mainContent");
		var centerContainerHeight = parseInt(centerContainer.offsetHeight)+30;
		var centerContainerLeft = parseInt(centerContainer.parentNode.offsetLeft);
		var margeLeftBloc = 186;
		
		var diff = 0;
		
		// Préchargement
		var newimg = document.createElement('img');
		newimg.id = "thumbnail";
		newimg.src = "../images/loading.gif";
		if (isIE)
		{
			newimg.style.width="35px";
			newimg.style.height="35px";
		}
		newimg.alt = "Loading...";
		newimg.className="noBorder";
		newimg.style.position = "absolute";
		newimg.style.left = "-9000px";
		
		var topValue = parseInt(parent.offsetTop)+110;
		newimg.style.top = topValue+"px";
		
		document.body.appendChild(newimg);
		var leftPos = parseInt(parent.offsetLeft)+centerContainerLeft+margeLeftBloc+parseInt(parent.offsetWidth);
		var rightPos = parseInt(parent.offsetLeft)+centerContainerLeft+margeLeftBloc-parseInt(newimg.offsetWidth);
		
		newimg.style.left = (screenSize-leftPos<parseInt(newimg.offsetWidth))?(rightPos+"px"):(leftPos+"px");
					
		// Affichage de l'image réelle
		var rImg=document.createElement('img');
		rImg.src = file;
		rImg.style.position = "absolute";
		rImg.style.left = "-9000px";
		rImg.style.top = "0px";
		document.body.appendChild(rImg);
		
		if (!rImg.complete)
		{
			rImg.onload = function() 
			{ 
				newimg.style.left = "-9000px";
				newimg.src = rImg.src;
				newimg.style.width = rImg.offsetWidth;
				newimg.style.height = rImg.offsetHeight;
				newimg.className="thumb";
				
				rightPos = parseInt(parent.offsetLeft)+centerContainerLeft+margeLeftBloc-parseInt(newimg.offsetWidth);
				
				newimg.style.left = (screenSize-leftPos<parseInt(newimg.offsetWidth))?(rightPos+"px"):(leftPos+"px");
				
				diff = parseInt(parent.offsetTop)+110+parseInt(rImg.offsetHeight);
				topValue = parseInt(parent.offsetTop)+110-((diff>centerContainerHeight)?(diff-centerContainerHeight):0);
				
				newimg.style.top = topValue+"px";
				rImg.parentNode.removeChild(rImg);
			}
		}
		else
		{
			newimg.style.left = "-9000px";
			newimg.src = rImg.src;
			newimg.style.width = rImg.offsetWidth;
			newimg.style.height = rImg.offsetHeight;
			newimg.className="thumb";
			
			rightPos = parseInt(parent.offsetLeft)+centerContainerLeft+margeLeftBloc-parseInt(newimg.offsetWidth);
			newimg.style.left = (screenSize-leftPos<parseInt(newimg.offsetWidth))?(rightPos+"px"):(leftPos+"px");
			
			diff = parseInt(parent.offsetTop)+110+parseInt(rImg.offsetHeight);
			topValue = parseInt(parent.offsetTop)+110-((diff>centerContainerHeight)?(diff-centerContainerHeight):0);
			
			newimg.style.top = topValue+"px";
			rImg.parentNode.removeChild(rImg);
		}
	}
}

function destroyThumbnail()
{
	if (isIE && isMac) {return true;}
	else
	{
		var thumb = (document.getElementById)?document.getElementById("thumbnail"):document.all.thumbnail;
		thumb.parentNode.removeChild(thumb);
	}
}

function minHeightMac(id,value)
{
	if (isMac && isIE)
	{
		var elem = document.getElementById(id);
		if (elem.offsetHeight<value) elem.style.height = value+"px";
	}
}

function fixIE5()
{
	if (isIE5 && !isMac)
	{
		if (parseInt(document.all.secondColumn.offsetTop)>89) 
		{
			document.all.secondColumn.style.marginTop = "0px";
			document.all.firstColumn.style.marginTop = "-1px";
		}
	}
		
	if (isIE && !isMac)
	{
		var imgArray = document.getElementsByName('camera');
		
		for (var i=0; i<imgArray.length; i++)
		{
			imgArray[i].style.top="0px";
			imgArray[i].style.left="0px";
		}
	}
}

//Avant l'affichage de la page
preload("../images/loading.gif","../images/icon2.jpg","../images/menus/bighbuttonh1.gif","../images/menus/bighbuttonh2.gif","../images/menus/bighbuttonh3.gif","../images/menus/bighbuttonh4.gif", "../images/menus/smallhbuttonh.gif", "../images/right_arrow_hover.gif", "../images/left_arrow_hover.gif");
if (isIE5 && !isMac) preload("../images/menus/vButton-hover.gif","../images/menus/vButton-hover-up.gif","../images/menus/vButton-hover-down.gif");
else preload("../images/menus/vButton-hover.png","../images/menus/vButton-hover-up.png","../images/menus/vButton-hover-down.png");