function menuInit()
{
	//alert (window.scrollbars.visible)
	// preload XML
	var isIE/*@cc_on=1@*/;
	var req = new Ajax.Request("./projects.xml", { method: "GET", asynchronous: false });
	myXml = req.transport.responseXML;
	
	new Ajax.Updater('top', './top.html',{ method: 'get' });
	drawMenu(myXml)
	new Ajax.Updater('page', './accueil.html',{ method: 'get' });
	new Ajax.Updater('footer', './footer.html',{ method: 'get' });
}

function drawMenu()
{
	var isIE/*@cc_on=1@*/;

	var oMenu = document.getElementById('menu')
	var oProjects  = myXml.getElementsByTagName('project');
	var oTable = document.createElement("table");
	oMenu.appendChild(oTable)

	var oTbody = document.createElement("tbody");
	for (var i=0;i< oProjects.length;i++){
		var oName = oProjects[i].getAttribute("name");
		var oCustomer =oProjects[i].getAttribute("customer");
		var oIcon =oProjects[i].getAttribute("icon");
		
		var oTr =document.createElement("tr");
		oTr.className="menuitem";
		oTr.setAttribute("title", oName);
		if(isIE){
			oTr.onclick = function() {drawProject(this)};
		}
		else
		{
			oTr.setAttribute("onclick", "drawProject(this)");					
		}
		
		var oTd1 =document.createElement("td")
		var newImg = document.createElement("img");
		newImg.setAttribute("src", oIcon);
		newImg.setAttribute("alt", "");
		
		var oTd2 =document.createElement("td")
		oTd2.innerHTML ="+"+oName+"<br/>"+oCustomer
		
		oTable.appendChild(oTbody)
		oTbody.appendChild(oTr)
		oTr.appendChild(oTd1)
		oTd1.appendChild(newImg)
		oTr.appendChild(oTd2)
		
	}
}

function drawProject(id)
{
	var isIE/*@cc_on=1@*/;
	var id= (id.getAttribute('title'))
	
	var oPage = document.getElementById('page')
	ClearDiv (oPage)
	var oDiv = document.createElement("div");
	var oTitle = document.createElement("div");
	oTitle.className="title";
	oTitle.innerHTML = id
	
	oPage.appendChild(oDiv)
	oDiv.appendChild(oTitle)
	
	var oProj = getElementsByAttribute(myXml,'project','name',id)	
	
	var xComment = oProj[0].getElementsByTagName('comment')[0]
	var oComment = document.createElement("div");
	oComment.className="comment";
	oComment.innerHTML = xComment.firstChild.nodeValue
	oDiv.appendChild(oComment)

	var oMedia = document.createElement("div");
	oMedia.className="media";
	oMedia.setAttribute("id","media");	
	oDiv.appendChild(oMedia);

	var oFile = oProj[0].getElementsByTagName('file')[0]
	var oUrl = oFile.getAttribute("url");
	
	drawFile( oUrl );
	
	var oUl = document.createElement("ul");
	oUl.className="thumbs";
	oDiv.appendChild(oUl);
	
	var oChilds = oProj[0].childNodes
	for (var i=0;i< oChilds.length;i++)
	{
		if ( oChilds[i].nodeType !=3)
		{
			if (oChilds[i].tagName == "file")
			{				
				var oLi = document.createElement("li");
				oLi.className="thumb";
				oUl.appendChild(oLi);
				var oUrl = oChilds[i].getAttribute("url");

				//------------SET THUMBS
				/*
				var oImg = document.createElement("img");
				if(isIE){
					alert (oUrl)
					oImg.onclick = function(){drawFile("./"+oUrl)};
				}
				else
				{
					oImg.setAttribute("onclick", "drawFile('"+oUrl+"')");					
				}
				oImg.setAttribute("alt", "");
				oLi.appendChild(oImg);
				*/
				if(getExt(oUrl) =='flv')
				{
					oLi.innerHTML = '<img src=\"./img/video.png\" alt=\"\" onclick=\"drawFile(&quot;'+oUrl+'&quot;)\">'
					//oImg.setAttribute("src", './img/video.png');
				}
				else if(getExt(oUrl) =='jpg')
				{
					oLi.innerHTML = '<img src=\"'+oUrl+'\" alt=\"\" onclick=\"drawFile(&quot;'+oUrl+'&quot;)\">'
					//oImg.setAttribute("src", oUrl);
				}
			}			
		}
	}
}

function drawFile(iUrl)
{
	//alert(iUrl)
	var oMedia = document.getElementById('media')
	ClearDiv(oMedia)
	if(getExt(iUrl) =='flv')
	{
		oMedia.innerHTML ='<object height="384" width="512" data="./libs/player_flv_maxi.swf" type="application/x-shockwave-flash"><param value="./libs/player_flv_maxi.swf" name="movie"/><param value="true" name="allowFullScreen"/><param value="flv=../'+iUrl+'&amp;width=512&amp;height=384&amp;showstop=1&amp;showvolume=1&amp;showtime=1&amp;startimage=&amp;showfullscreen=1&amp;bgcolor1=ffffff&amp;bgcolor2=ffffff&amp;playercolor=a6a6a6&amp;playeralpha=20&amp;loadingcolor=53bedd&amp;buttonovercolor=53bedd&amp;sliderovercolor=ffffff&amp;slidercolor1=ffffff&amp;slidercolor2=ffffff&amp;autoload=1&amp;autoplay=1&amp;videobgcolor=ffffff" name="FlashVars"/></object>'	
	}
	else if(getExt(iUrl) =='jpg')
	{
		var oImg = document.createElement("img");
		oImg.setAttribute("src", iUrl);
		oImg.setAttribute("alt", "");
		oMedia.appendChild(oImg);
	}
	else
	{
		alert('missing file');
	}	
}

function getElementsByAttribute(oElm, strTagName, strAttributeName, strAttributeValue){
    var arrElements = (strTagName == "*" && document.all)? document.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    var oAttributeValue = (typeof strAttributeValue != "undefined")? new RegExp("(^|\\s)" + strAttributeValue + "(\\s|$)") : null;
    var oCurrent;
    var oAttribute;
    for(var i=0; i<arrElements.length; i++){
        oCurrent = arrElements[i];
        oAttribute = oCurrent.getAttribute(strAttributeName);
        if(typeof oAttribute == "string" && oAttribute.length > 0){
            if(typeof strAttributeValue == "undefined" || (oAttributeValue && oAttributeValue.test(oAttribute))){
                arrReturnElements.push(oCurrent);
            }
        }
    }
    return arrReturnElements;
}

function LoadHtml(oDiv,oAdress)
{
	//-----Load an url in the gallery's <DIV>
	
	new Ajax.Updater('gallery', oAdress,{ method: 'get' });
		
}

function ClearDiv(oDiv)
{
	if ( oDiv.hasChildNodes() )
	{
		while ( oDiv.childNodes.length >= 1 )
		{
			oDiv.removeChild( oDiv.firstChild );       
		} 
	}
}

function getExt(oUrl){
	var oExt = oUrl.split(".").pop()
	return oExt
}
