var	models = new Array();
var	modelText = new Array();
var	modelDirectory = "http://www.ursart.com/mb/";
var	modelImgDirectory="images/mayaModels/"
var animatedGifs = new Array();

function writeModelTable(){

	addModel("alphabetTimes", "NURBS Alphabet, font: Times;", false);
	addModel("ant", "Ant, rigged", false);
	addModel("apple", "Apple", false);
	addModel("basicSmiley", "Basic Smiley, Bump-mapped face", false);
	addModel("brokenEgg", "Broken Egg", false);
	addModel("buildingFacadeSet", "Building facades, stairway and sidewalk", false);
	addModel("chocolateKiss", "Chocolate Kiss", false);
	addModel("chromeBalanceBalls", "Newton's Cradle - Chrome \(textured as smileys\)", false);
	addModel("clownDollHead", "Clown Doll Head", false);
	addModel("crayon", "Crayon (label texture says \"crayola\")", false);
	addModel("desklamp", "Desklamp, rigged, with lighting", false);
	addModel("fertilization", "Fertilization model; Animated (not realistic, proportionally)", true);
	addModel("frenchDoor", "French Door", false);
	addModel("glueBottle", "Glue Bottle", false);
	addModel("hammer", "Hammer", false);
	addModel("inkBottleAndQuill", "Ink Bottle and Quill", false);
	addModel("jewels", "Jewels", false);
	addModel("junebug", "June Bug; Rigged", false);
	addModel("matchbook", "Matchbook and matches", false);
	addModel("milkBottles", "Milk Bottles; one is a single layer of geometry, the other doubled", false);
	addModel("mushroom", "Mushroom and grass", false);
	addModel("pie", "Pie");
	addModel("planetsRotating", "Planets; Simple animated Rotation", true);
	addModel("playboyBunnyLogo", "Playboy bunny logo", false);
	addModel("radishSmiley", "Radish Smiley", false);
	addModel("rollerskate", "Rollerskate", false);
	addModel("roundedCube", "Rounded cube; Why? Just an incredibly useful starting shape that isn't native to Maya", false);
	addModel("rubberDucky", "Rubber ducky", false);
	addModel("sexSymbols", "Sex Symbols", false);
	addModel("simpleBoat", "Simple Boat", false);
	addModel("spikeyBall", "Spikey Ball", false);
	addModel("umbrella", "Umbrella", false);
	addModel("waterlily", "Waterlily", false);
	addModel("yoyo", "Yo-yo", false);
	
	allModels = "";

	modelTable = "<table border='0' cellspacing='0' cellpadding='2'>";
	
	for (i=0; i<7; i++){
		modelTable += "<tr valign='top'>";
		for (j=i*5; j<i*5+5; j++){
			imgExtension = ".jpg";
			for (k = 0; k<animatedGifs.length; k++){
				if (animatedGifs[k] == models[j]){
					imgExtension = ".gif";
				}
			}
			
			modelTable += "<td class='mayaModelCell'>";
		
			if (models[j]){
				
				modelTable += "<a href='#' onmouseover='wireframeOn(\"";
				modelTable += models[j] + "\")' onmouseout='wireframeOff(\"" + models[j] + "\")'>";
				modelTable += "<img class='mayaModelImg' id ='" + models[j] + "Img' src='" + modelImgDirectory + models[j] + imgExtension +"'></a>";
				modelTable += "<br><br>";
				modelTable += modelText[j] + "<br>";
				modelTable += "</td>";
			}
		}
		
		modelTable += "</tr><tr>";
	
		for (l=i*5; l<i*5+5; l++){
			if (models[l]){
				modelTable += "<td><a onclick='trackDownload(\""+ models[l]+"\");' href='" + modelDirectory + models[l] + ".mb' onmouseover='wireframeOn(\""+ models[l] + "\")' onmouseout='wireframeOff(\"" + models[l] + "\")'>";
				modelTable += "<span class='wireframeLink'>" +  models[l] + ".mb</span></a><br/><br/>";
				modelTable += "</td>";
			}
		}	 
		modelTable += "</tr>";
	}
	modelTable += "</table><br>";
	allModels += modelTable;
	document.getElementById("mayaModelIndex").innerHTML = allModels;
}

function addModel(_modelName, _title, _animated){
	if (!_animated){
		models.push(_modelName);
		modelText.push(_title);
	}else{
 		animatedGifs.push(_modelName);
	}
}

//rolloverFunctions
function wireframeOn(modelName) {
	document.getElementById(modelName+"Img").src = modelImgDirectory + modelName + "_w.jpg";
}
	
function wireframeOff(modelName) {
	if (modelName == "fertilization" || modelName == "planetsRotating"){
		extension = ".gif";
	} else {
		extension = ".jpg";
	}
	document.getElementById(modelName+"Img").src = modelImgDirectory + modelName + extension;
}

function trackDownload(_modelName){
	//alert("do you want to download this model?")
   _gaq.push(['_trackEvent', 'maya model', 'download', _modelName]);
}
	
//load rollover Images
if (document.images) {
	for (i=0; i++; i<models.length){
		models[i] = new Image();
		models[i].src = url(modelImgDirectory + models[i] + "_w.jpg");	
	}
}
