function openPopup(project){
			currentProject = project;
			document.getElementById('project_'+project).style.display='block';document.getElementById('fade').style.display='block';
			
			
			// preload images only
			var postimages = new Array();
			
			for(var i=0;i<projects[currentProject].media.length;i++){
				
				if(projects[currentProject].media[i].type == "img"){
						postimages[i] = new Image();
					  postimages[i].src = projects[currentProject].media[i].src;
				}
			}
		}
		
		function closePopup(){
			// change media back to first media
			changeMedia(0);
			document.getElementById('project_'+currentProject).style.display='none';document.getElementById('fade').style.display='none';
		}
		
		function removeAllChildNodes(node){
			while ((node).hasChildNodes())
			{
		  	(node).removeChild((node).firstChild);
			}
		}
		
		
		function changeMedia(media){
			
			var content = document.getElementById('project_content_'+currentProject);
			
			var type = projects[currentProject].media[media].type;
			
			switch(type){
						
				case "img":
					
					// create image from project name
					var img = document.createElement('img');
						
						img.setAttribute("alt", "image of the project");
						var src = projects[currentProject].media[media].src;
						img.setAttribute("src", src);
						
					var div = document.createElement("div");
						div.setAttribute("id","project_"+currentProject+"_media");
						div.setAttribute("class","popup_middle_media");
						div.appendChild(img);
					
					
					// create caption div
					var caption = document.createElement("div");
					
						caption.setAttribute("class","popup_middle_caption");
						
						caption.appendChild(document.createTextNode(projects[currentProject].media[media].description));
						
						// clear current content
						removeAllChildNodes(content);
						
						// add image to content
						content.appendChild(div);
						
						// add caption
						content.appendChild(caption);
						
					break;
				
				case "swf":
					
						// create a div for swf, add to content
						var div = document.createElement("div");
						div.setAttribute("id","project_"+currentProject+"_media");
						div.setAttribute("class","popup_middle_media");
							
					
					// create caption div
					var caption = document.createElement("div");
					caption.setAttribute("class","popup_middle_caption");
					caption.appendChild(document.createTextNode(projects[currentProject].media[media].description));
					
					// clear current content
					removeAllChildNodes(content);
					content.appendChild(div);
							
					// add swf to div
					var flashvars = {};
					var params = {};
					var attributes = {};
					swfobject.embedSWF(projects[currentProject].media[media].src, "project_"+currentProject+"_media", "640", "360", "9.0.0", "expressInstall.swf", flashvars, params, attributes);
					
					// add caption 
					content.appendChild(caption);
					break;
				
				case "mov":
					
					// create a div for swf, add to content
					var div = document.createElement("div");
					div.setAttribute("id","project_"+currentProject+"_media");
					div.setAttribute("class","popup_middle_media");
							
					
					// create caption div
					var caption = document.createElement("div");
					caption.setAttribute("class","popup_middle_caption");
					caption.appendChild(document.createTextNode(projects[currentProject].media[media].description));
					
					
					// generate unique info to avoid caching
					var date = new Date();
					var unistring = date.getTime();
					
					
					// clear current content and add new
					removeAllChildNodes(content);
					content.appendChild(div);
					
					// add swf to div
					var flashvars = {file:projects[currentProject].media[media].src+"?"+unistring};
					var params = {};
					var attributes = {allowfullscreen:"true"};
					swfobject.embedSWF("MediaPlayer.swf?"+unistring, "project_"+currentProject+"_media", "640", "360", "9.0.0", "expressInstall.swf", flashvars, params, attributes);
					
					// add caption 
					content.appendChild(caption);
						
					break;
					
				case "l3d":
					// create a div for swf, add to content
					var div = document.createElement("div");
					div.setAttribute("id","project_"+currentProject+"_media");
					div.setAttribute("class","popup_middle_media");
							
					
					// create caption div
					var caption = document.createElement("div");
					caption.setAttribute("class","popup_middle_caption");
					caption.appendChild(document.createTextNode(projects[currentProject].media[media].description));
				
					
					// add l3d to content
		      		
		      		/* Can't create dynamically with createElement in IE, forced to use innerHTML */
		      		
		      		var lusterVarString = "";
	      			for(var i = 0; i < projects[currentProject].media[media].lusterVars.length; i++){
	      				lusterVarString = lusterVarString + projects[currentProject].media[media].lusterVars[i][0]+"=\'"+projects[currentProject].media[media].lusterVars[i][1]+"\'&";
	      			}
	      			lusterVarString = lusterVarString.substring(0,lusterVarString.length - 1);
		      		
		      		var innerHTML = "<object id=\"app\" classid=\"CLSID:FD51C62E-3543-4B7B-865B-1A7E53FAC698\" width=\"640\" height=\"360\">\n";
		                innerHTML += "<param name=\"src\" value=\"l3ds/Preloader.l3d\" />\n";
		                innerHTML += "<param name=\"xml\" value=\"false\" />\n";
				    	innerHTML += "<param name=\"LusterVars\" value=\""+lusterVarString+"\"/>\n";
		                innerHTML += "<embed name=\"app\" type=\"application/x-luster\" width=\"640\" height=\"360\" src=\"l3ds/Preloader.l3d\" lustervars=\""+lusterVarString+"\" xml=\"false\" />\n";
		      			innerHTML += "</object>\n";
		      		
		      		div.innerHTML = innerHTML;
		      		
			      	// clear current content
					removeAllChildNodes(content);
					
					content.appendChild(div);
						
					// add caption 
					content.appendChild(caption);
					
					break;
			}
		}