var foodlist = new Array(24);
for (i = 0; i < foodlist.length; i++) { foodlist[i] = new Array(3); }
foodlist[0][0] = "spaguetti"; foodlist[0][1] = "880"; foodlist[0][2] = "45";
foodlist[1][0] = "tom_jala"; foodlist[1][1] = "907"; foodlist[1][2] = "46";
foodlist[2][0] = "molho_cru"; foodlist[2][1] = "518"; foodlist[2][2] = "26";
foodlist[3][0] = "oister"; foodlist[3][1] = "984"; foodlist[3][2] = "47";
foodlist[4][0] = "sopa_de_agua"; foodlist[4][1] = "920"; foodlist[4][2] = "47";
foodlist[5][0] = "poached_cod"; foodlist[5][1] = "920"; foodlist[5][2] = "47"
foodlist[6][0] = "arroz_de_marisco"; foodlist[6][1] = "920"; foodlist[6][2] = "47"
foodlist[7][0] = "Mussels"; foodlist[7][1] = "1274"; foodlist[7][2] = "68";
foodlist[8][0] = "soup"; foodlist[8][1] = "922"; foodlist[8][2] = "47";
foodlist[9][0] = "sopas"; foodlist[9][1] = "919"; foodlist[9][2] = "47";
foodlist[10][0] = "broth"; foodlist[10][1] = "968"; foodlist[10][2] = "65";
foodlist[11][0] = "petiscos"; foodlist[11][1] = "920"; foodlist[11][2] = "47";
foodlist[12][0] = "morcela"; foodlist[12][1] = "920"; foodlist[12][2] = "47";;
foodlist[13][0] = "crab"; foodlist[13][1] = "1117"; foodlist[13][2] = "57";
foodlist[14][0] = "caldo_verde"; foodlist[14][1] = "920"; foodlist[14][2] = "47";
foodlist[15][0] = "bolos_bacalhau_rolling"; foodlist[15][1] = "920"; foodlist[15][2] = "47";
foodlist[16][0] = "flower_toss"; foodlist[16][1] = "938"; foodlist[16][2] = "48";
foodlist[17][0] = "fig_yogurt_honey"; foodlist[17][1] = "948"; foodlist[17][2] = "48";
foodlist[18][0] = "figs"; foodlist[18][1] = "920"; foodlist[18][2] = "47";
foodlist[19][0] = "sonhos"; foodlist[19][1] = "920"; foodlist[19][2] = "47";
foodlist[20][0] = "cookies"; foodlist[20][1] = "891"; foodlist[20][2] = "45";
foodlist[21][0] = "cupcakes_orange_choco"; foodlist[21][1] = "919"; foodlist[21][2] = "47";
foodlist[22][0] = "cupcakes_pbj"; foodlist[22][1] = "1011"; foodlist[22][2] = "51";
foodlist[23][0] = "pears"; foodlist[23][1] = "660"; foodlist[23][2] = "33";

var thinglist = new Array(23);
for (i = 0; i < thinglist.length; i++) { thinglist[i] = new Array(3); }
thinglist[0][0] = "diesel_layout"; thinglist[0][1] = "1150"; thinglist[0][2] = "78";
thinglist[1][0] = "vestal"; thinglist[1][1] = "1019"; thinglist[1][2] = "52";
thinglist[2][0] = "bulgari"; thinglist[2][1] = "962"; thinglist[2][2] = "49";
thinglist[3][0] = "ferragamo"; thinglist[3][1] = "1062"; thinglist[3][2] = "54";
thinglist[4][0] = "fendi_01"; thinglist[4][1] = "1150"; thinglist[4][2] = "118";
thinglist[5][0] = "fendi_02"; thinglist[5][1] = "1100"; thinglist[5][2] = "57";
thinglist[6][0] = "purse_V1"; thinglist[6][1] = "1208"; thinglist[6][2] = "61";
thinglist[7][0] = "SergioRossi"; thinglist[7][1] = "1035"; thinglist[7][2] = "53";
thinglist[8][0] = "Red_shoes"; thinglist[8][1] = "1303"; thinglist[8][2] = "66";
thinglist[9][0] = "Guerlin_01"; thinglist[9][1] = "958"; thinglist[9][2] = "49";
thinglist[10][0] = "Guerlin_02"; thinglist[10][1] = "844"; thinglist[10][2] = "43";
thinglist[11][0] = "magnifique"; thinglist[11][1] = "983"; thinglist[11][2] = "50";
thinglist[12][0] = "Louis_Vuitton"; thinglist[12][1] = "1078"; thinglist[12][2] = "55";
thinglist[13][0] = "bobbi_brown"; thinglist[13][1] = "943"; thinglist[13][2] = "48";
thinglist[14][0] = "Maybeline"; thinglist[14][1] = "1074"; thinglist[14][2] = "54";
thinglist[15][0] = "Chanel"; thinglist[15][1] = "1245"; thinglist[15][2] = "63";
thinglist[16][0] = "estelauder"; thinglist[16][1] = "1214"; thinglist[16][2] = "62";
thinglist[17][0] = "explosion_powder_diptych"; thinglist[17][1] = "1056"; thinglist[17][2] = "54";
thinglist[18][0] = "izod"; thinglist[18][1] = "1063"; thinglist[18][2] = "54";
thinglist[19][0] = "gs_shiseido"; thinglist[19][1] = "941"; thinglist[19][2] = "48";
thinglist[20][0] = "rings"; thinglist[20][1] = "1132"; thinglist[20][2] = "57";
thinglist[21][0] = "winc_ab"; thinglist[21][1] = "954"; thinglist[21][2] = "48";
thinglist[22][0] = "rings_on_white"; thinglist[22][1] = "993"; thinglist[22][2] = "50";

var liquidslist = new Array(20);
for (i = 0; i < liquidslist.length; i++) { liquidslist[i] = new Array(3); }
liquidslist[0][0] = "tom_jala"; liquidslist[0][1] = "907"; liquidslist[0][2] = "46";
liquidslist[1][0] = "cognac"; liquidslist[1][1] = "912"; liquidslist[1][2] = "46";
liquidslist[2][0] = "wine_pour"; liquidslist[2][1] = "1086"; liquidslist[2][2] = "55";
liquidslist[3][0] = "Icetea-lemon"; liquidslist[3][1] = "1232"; liquidslist[3][2] = "62";
liquidslist[4][0] = "smirn"; liquidslist[4][1] = "834"; liquidslist[4][2] = "42";
liquidslist[5][0] = "redwine"; liquidslist[5][1] = "895"; liquidslist[5][2] = "45";
liquidslist[6][0] = "scotch"; liquidslist[6][1] = "902"; liquidslist[6][2] = "46";
liquidslist[7][0] = "h2O"; liquidslist[7][1] = "788"; liquidslist[7][2] = "40";
liquidslist[8][0] = "trufle_mart"; liquidslist[8][1] = "834"; liquidslist[8][2] = "42";
liquidslist[9][0] = "wwine"; liquidslist[9][1] = "748"; liquidslist[9][2] = "38";
liquidslist[10][0] = "poma"; liquidslist[10][1] = "1044"; liquidslist[10][2] = "53";
liquidslist[11][0] = "glenl"; liquidslist[11][1] = "920"; liquidslist[11][2] = "47";
liquidslist[12][0] = "shiseido"; liquidslist[12][1] = "1041"; liquidslist[12][2] = "53";
liquidslist[13][0] = "Laborotory"; liquidslist[13][1] = "1111"; liquidslist[13][2] = "56";
liquidslist[14][0] = "paint_drops"; liquidslist[14][1] = "1006"; liquidslist[14][2] = "51";
liquidslist[15][0] = "praire"; liquidslist[15][1] = "1036"; liquidslist[15][2] = "53";
liquidslist[16][0] = "CK"; liquidslist[16][1] = "848"; liquidslist[16][2] = "43";
liquidslist[17][0] = "diesel_watch"; liquidslist[17][1] = "635"; liquidslist[17][2] = "32";
liquidslist[18][0] = "time"; liquidslist[18][1] = "1049"; liquidslist[18][2] = "53";
liquidslist[19][0] = "inks_03"; liquidslist[19][1] = "1100"; liquidslist[19][2] = "56";

function foodInit() {
	loadClear();
	setImageWidth(foodlist[0][1]);
	document.getElementById('mainimage').src = "food/" + foodlist[0][0] + ".jpg";
	foodSlideInit();
	mouseInit();
}

function thingInit() {
	loadClear();
	setImageWidth(thinglist[0][1]);
	document.getElementById('mainimage').src = "things/" + thinglist[0][0] + ".jpg";
	thingSlideInit();
	mouseInit();
}

function liquidsInit() {
	loadClear();
	setImageWidth(liquidslist[0][1]);
	document.getElementById('mainimage').src = "liquids/" + liquidslist[0][0] + ".jpg";
	liquidsSlideInit();
	mouseInit();
}

function prevFood () {
	arrowsOff(); 
	document.getElementById('mainimage').src = "images/clear.gif";
	var t = parseInt(document.displayedImg.imgNumber.value);
	t = (t > 0) ? (t - 1) : (foodlist.length - 1);
	document.displayedImg.imgNumber.value = t;
	setImageWidth(foodlist[t][1]);
	document.getElementById('mainimage').src = "food/" + foodlist[t][0] + ".jpg";
}

function nextFood () {
	arrowsOff(); 
	document.getElementById('mainimage').src = "images/clear.gif";
	var t = parseInt(document.displayedImg.imgNumber.value);
	t = (t < (foodlist.length - 1)) ? (t + 1) : 0;
	document.displayedImg.imgNumber.value = t;
	setImageWidth(foodlist[t][1]);
	document.getElementById('mainimage').src = "food/" + foodlist[t][0] + ".jpg";
}

function prevThing () {
	arrowsOff(); 
	document.getElementById('mainimage').src = "images/clear.gif";
	var t = parseInt(document.displayedImg.imgNumber.value);
	t = (t > 0) ? (t - 1) : (thinglist.length - 1);
	document.displayedImg.imgNumber.value = t;
	setImageWidth(thinglist[t][1]);
	document.getElementById('mainimage').src = "things/" + thinglist[t][0] + ".jpg";
}

function nextThing () {
	arrowsOff(); 
	document.getElementById('mainimage').src = "images/clear.gif";
	var t = parseInt(document.displayedImg.imgNumber.value);
	t = (t < (thinglist.length - 1)) ? (t + 1) : 0;
	document.displayedImg.imgNumber.value = t;
	setImageWidth(thinglist[t][1]);
	document.getElementById('mainimage').src = "things/" + thinglist[t][0] + ".jpg";
}

function prevLiquids () {
	arrowsOff(); 
	document.getElementById('mainimage').src = "images/clear.gif";
	var t = parseInt(document.displayedImg.imgNumber.value);
	t = (t > 0) ? (t - 1) : (liquidslist.length - 1);
	document.displayedImg.imgNumber.value = t;
	setImageWidth(liquidslist[t][1]);
	document.getElementById('mainimage').src = "liquids/" + liquidslist[t][0] + ".jpg";
}

function nextLiquids () {
	arrowsOff(); 
	document.getElementById('mainimage').src = "images/clear.gif";
	var t = parseInt(document.displayedImg.imgNumber.value);
	t = (t < (liquidslist.length - 1)) ? (t + 1) : 0;
	document.displayedImg.imgNumber.value = t;
	setImageWidth(liquidslist[t][1]);
	document.getElementById('mainimage').src = "liquids/" + liquidslist[t][0] + ".jpg";
}

var swidth = 0;

function foodSlideInit () {
	for (var n = 0; n < foodlist.length; n++) { swidth = swidth + parseInt(foodlist[n][2]) + 6; }
	document.getElementById('slider').style.width = swidth + "px";
	var tname;
	for (var n = 0; n < foodlist.length; n++) { 
		tname = "t" + n;
		document.getElementById(tname).style.width = foodlist[n][2] + "px";
		document.getElementById(tname).src = "foodthumbs/" + foodlist[n][0] + "_tn.jpg";
		document.getElementById(tname).onmouseover = borderOn;
		document.getElementById(tname).onmouseout = borderOff;
	}
}

function thingSlideInit () {
	for (var n = 0; n < thinglist.length; n++) { swidth = swidth + parseInt(thinglist[n][2]) + 6; }
	document.getElementById('slider').style.width = swidth + "px";
	var tname;
	for (var n = 0; n < thinglist.length; n++) { 
		tname = "t" + n;
		document.getElementById(tname).style.width = thinglist[n][2] + "px";
		document.getElementById(tname).src = "thingthumbs/" + thinglist[n][0] + "_tn.jpg";
		document.getElementById(tname).onmouseover = borderOn;
		document.getElementById(tname).onmouseout = borderOff;
	}
}

function liquidsSlideInit () {
	for (var n = 0; n < liquidslist.length; n++) { swidth = swidth + parseInt(liquidslist[n][2]) + 6; }
	document.getElementById('slider').style.width = swidth + "px";
	var tname;
	for (var n = 0; n < liquidslist.length; n++) { 
		tname = "t" + n;
		document.getElementById(tname).style.width = liquidslist[n][2] + "px";
		document.getElementById(tname).src = "liquidsthumbs/" + liquidslist[n][0] + "_tn.jpg";
		document.getElementById(tname).onmouseover = borderOn;
		document.getElementById(tname).onmouseout = borderOff;
	}
}

function foodThumb(t) {
	document.getElementById('mainimage').src = "images/clear.gif";
	document.displayedImg.imgNumber.value = t;
	setImageWidth(foodlist[t][1]);
	document.getElementById('mainimage').src = "food/" + foodlist[t][0] + ".jpg";
}

function thingThumb(t) {
	document.getElementById('mainimage').src = "images/clear.gif";
	document.displayedImg.imgNumber.value = t;
	setImageWidth(thinglist[t][1]);
	document.getElementById('mainimage').src = "things/" + thinglist[t][0] + ".jpg";
}

function liquidsThumb(t) {
	document.getElementById('mainimage').src = "images/clear.gif";
	document.displayedImg.imgNumber.value = t;
	setImageWidth(liquidslist[t][1]);
	document.getElementById('mainimage').src = "liquids/" + liquidslist[t][0] + ".jpg";
}

function borderOn() {
	this.style.border = "2px solid #BBB";
	this.style.margin = "0 1px 0 1px";
}

function borderOff() {
	this.style.border = "0";
	this.style.margin = "2px 3px 0 3px";
}

var int;

function goLeft() {
	int = setInterval("thumbLeft()", 20);
}

function stopLeft() {
	clearInterval(int);
}

function goRight() { 
	int = setInterval("thumbRight()", 20);
}

function stopRight() {
	clearInterval(int);
}

function thumbLeft() {
	var t = getLeft();
	if (t < 0) { 
		t = t + 8;
		document.getElementById('slider').style.left = t + "px";
	}
}

function thumbRight() { 
	var t = getLeft();
	if (t > (1011 - swidth)) { 
		t = t - 8;
		document.getElementById('slider').style.left = t + "px"; 
	}
}

function getLeft() {
	var s;
	if(document.defaultView && document.defaultView.getComputedStyle) {
		var slide = document.getElementById('slider');
		var sstyle = document.defaultView.getComputedStyle(slide, "");
		s = parseInt(sstyle.getPropertyValue("left"));
	} else {
		s = document.getElementById('slider').offsetLeft;
	}
	return s;
}

function loadClear() { 
	if (document.images) { 
		var clr = new Image(1,1); 
		clr.src = "images/clear.gif"; 
	}
}

function setImageWidth(wdt) {
	var w = parseInt(wdt);
	document.getElementById('imageshell').style.width = w + "px";
	document.getElementById('mainimage').style.width = w + "px";
}

function mouseInit () {
	document.getElementById('smarrowleft').onmouseover = goLeft;
	document.getElementById('smarrowleft').onmouseout = stopLeft;
	document.getElementById('smarrowright').onmouseover = goRight;
	document.getElementById('smarrowright').onmouseout = stopRight;
	document.body.onmousemove = arrowsOn;
	document.body.onmouseout = arrowsOff;
	document.onmousemove = (function() { 
		var onmousestop = function() { 
			arrowsOff(); 
		}, thread;
		return function() { 
			clearTimeout(thread); 
			thread = setTimeout(onmousestop, 1500); 
		};
	}) ();
}

function arrowsOn() {
	document.getElementById('arrowleft').style.visibility = "visible";
	document.getElementById('arrowright').style.visibility = "visible";
}

function arrowsOff() {
	document.getElementById('arrowleft').style.visibility = "hidden";
	document.getElementById('arrowright').style.visibility = "hidden";
}

var bgcolor, flipped;
var state = new Array(54);

function squaresInit() {
	loadClear();
	if (document.images) {
		var images = new Array(108);
		for (var n = 0; n < 108; n++) { images[n] = new Image(115, 115); }
		var p = 0;
		for (var m = 1; m < 7; m++) {
			for (n = 1; n < 10; n++) {
				images[p].src = "front/gold_0" + m + "0" + n + ".jpg";
				p++;
			}
		}
		for (m = 1; m < 7; m++) {
			for (n = 1; n < 10; n++) {
				images[p].src = "front/black_0" + m + "0" + n + ".jpg";
				p++;
			}
		}
	}
	document.getElementById('imageshell').style.width = "1035px";
	var tname;
	for (var m = 1; m < 7; m++) {
		for (n = 1; n < 10; n++) {
			tname = "i0" + m + "0" + n;
			document.getElementById(tname).src = "front/gold_0" + m + "0" + n + ".jpg";
		}
	}
	flipped = 0;
	for (var n = 0; n < 54; n++) { state[n] = 0; }
}

function flip(pos) {
	var imgsrc;
	if (flipped == 0) {
		bgcolor = 0;
		setTimeout("autoFlip()", 2000);
	} else if (flipped == 54) {
		bgcolor = 1;
		setTimeout("autoFlip()", 2000);
	}
	if ((bgcolor == 0) && (state[pos] == 0)) {
		imgsrc = "black_";
		state[pos] = 1;	
		flipped++;
		doFlip(pos, imgsrc);
	} else if ((bgcolor == 1) && (state[pos] == 1)) {
		imgsrc = "gold_";
		state[pos] = 0;
		flipped--;
		doFlip(pos, imgsrc);
	}
}

function autoFlip() {
	if ((flipped > 0) && (flipped < 54)) {
		var n = Math.floor(Math.random() * 54);
		while (state[n] != bgcolor) { n = Math.floor(Math.random() * 54); }
		flip(n);
		setTimeout("autoFlip()", 50);
	}
}

function doFlip(pos, imgsrc) {
	switch(pos) {
		case 0: document.getElementById('i0101').src = "front/" + imgsrc + "0101.jpg"; break;
		case 1: document.getElementById('i0102').src = "front/" + imgsrc + "0102.jpg"; break;
		case 2: document.getElementById('i0103').src = "front/" + imgsrc + "0103.jpg"; break;
		case 3: document.getElementById('i0104').src = "front/" + imgsrc + "0104.jpg"; break;
		case 4: document.getElementById('i0105').src = "front/" + imgsrc + "0105.jpg"; break;
		case 5: document.getElementById('i0106').src = "front/" + imgsrc + "0106.jpg"; break;
		case 6: document.getElementById('i0107').src = "front/" + imgsrc + "0107.jpg"; break;
		case 7: document.getElementById('i0108').src = "front/" + imgsrc + "0108.jpg"; break;
		case 8: document.getElementById('i0109').src = "front/" + imgsrc + "0109.jpg"; break;
		case 9: document.getElementById('i0201').src = "front/" + imgsrc + "0201.jpg"; break;
		case 10: document.getElementById('i0202').src = "front/" + imgsrc + "0202.jpg"; break;
		case 11: document.getElementById('i0203').src = "front/" + imgsrc + "0203.jpg"; break;
		case 12: document.getElementById('i0204').src = "front/" + imgsrc + "0204.jpg"; break;
		case 13: document.getElementById('i0205').src = "front/" + imgsrc + "0205.jpg"; break;
		case 14: document.getElementById('i0206').src = "front/" + imgsrc + "0206.jpg"; break;
		case 15: document.getElementById('i0207').src = "front/" + imgsrc + "0207.jpg"; break;
		case 16: document.getElementById('i0208').src = "front/" + imgsrc + "0208.jpg"; break;
		case 17: document.getElementById('i0209').src = "front/" + imgsrc + "0209.jpg"; break;
		case 18: document.getElementById('i0301').src = "front/" + imgsrc + "0301.jpg"; break;
		case 19: document.getElementById('i0302').src = "front/" + imgsrc + "0302.jpg"; break;
		case 20: document.getElementById('i0303').src = "front/" + imgsrc + "0303.jpg"; break;
		case 21: document.getElementById('i0304').src = "front/" + imgsrc + "0304.jpg"; break;
		case 22: document.getElementById('i0305').src = "front/" + imgsrc + "0305.jpg"; break;
		case 23: document.getElementById('i0306').src = "front/" + imgsrc + "0306.jpg"; break;
		case 24: document.getElementById('i0307').src = "front/" + imgsrc + "0307.jpg"; break;
		case 25: document.getElementById('i0308').src = "front/" + imgsrc + "0308.jpg"; break;
		case 26: document.getElementById('i0309').src = "front/" + imgsrc + "0309.jpg"; break;
		case 27: document.getElementById('i0401').src = "front/" + imgsrc + "0401.jpg"; break;
		case 28: document.getElementById('i0402').src = "front/" + imgsrc + "0402.jpg"; break;
		case 29: document.getElementById('i0403').src = "front/" + imgsrc + "0403.jpg"; break;
		case 30: document.getElementById('i0404').src = "front/" + imgsrc + "0404.jpg"; break;
		case 31: document.getElementById('i0405').src = "front/" + imgsrc + "0405.jpg"; break;
		case 32: document.getElementById('i0406').src = "front/" + imgsrc + "0406.jpg"; break;
		case 33: document.getElementById('i0407').src = "front/" + imgsrc + "0407.jpg"; break;
		case 34: document.getElementById('i0408').src = "front/" + imgsrc + "0408.jpg"; break;
		case 35: document.getElementById('i0409').src = "front/" + imgsrc + "0409.jpg"; break;
		case 36: document.getElementById('i0501').src = "front/" + imgsrc + "0501.jpg"; break;
		case 37: document.getElementById('i0502').src = "front/" + imgsrc + "0502.jpg"; break;
		case 38: document.getElementById('i0503').src = "front/" + imgsrc + "0503.jpg"; break;
		case 39: document.getElementById('i0504').src = "front/" + imgsrc + "0504.jpg"; break;
		case 40: document.getElementById('i0505').src = "front/" + imgsrc + "0505.jpg"; break;
		case 41: document.getElementById('i0506').src = "front/" + imgsrc + "0506.jpg"; break;
		case 42: document.getElementById('i0507').src = "front/" + imgsrc + "0507.jpg"; break;
		case 43: document.getElementById('i0508').src = "front/" + imgsrc + "0508.jpg"; break;
		case 44: document.getElementById('i0509').src = "front/" + imgsrc + "0509.jpg"; break;
		case 45: document.getElementById('i0601').src = "front/" + imgsrc + "0601.jpg"; break;
		case 46: document.getElementById('i0602').src = "front/" + imgsrc + "0602.jpg"; break;
		case 47: document.getElementById('i0603').src = "front/" + imgsrc + "0603.jpg"; break;
		case 48: document.getElementById('i0604').src = "front/" + imgsrc + "0604.jpg"; break;
		case 49: document.getElementById('i0605').src = "front/" + imgsrc + "0605.jpg"; break;
		case 50: document.getElementById('i0606').src = "front/" + imgsrc + "0606.jpg"; break;
		case 51: document.getElementById('i0607').src = "front/" + imgsrc + "0607.jpg"; break;
		case 52: document.getElementById('i0608').src = "front/" + imgsrc + "0608.jpg"; break;
		case 53: document.getElementById('i0609').src = "front/" + imgsrc + "0609.jpg"; break;
	}
	return true;
}
