/**
 * Epoch Graphics Portfolio
 ***************************/

// Globals
var prevNav = null;
var curNum  = null;
var curRow = null;

// Dynamic Image Loading
var images = new Array(2);
images[0] = new Array(10);
images[1] = new Array(10);

// print
var printmax = 8;

images[0][0] = "printlvwa.jpg";
images[0][1] = "printyards.jpg";
images[0][2] = "printjuice.jpg";
images[0][3] = "printallthrottle.jpg";
images[0][4] = "printxilinx.jpg";
images[0][5] = "printrc.jpg";
images[0][6] = "printweeks.jpg";
images[0][7] = "printmonster.jpg";

images[0][8] = "printyards.jpg";
images[0][9] = "printyards.jpg";


// web
var webmax = 8;

images[1][0] = "webwhiteknight.jpg";
images[1][1] = "webmarples.jpg";
images[1][2] = "webbafg.jpg";
images[1][3] = "webtarrar.jpg";
images[1][4] = "webfeestofunds.jpg";
images[1][5] = "webducheney.jpg";
images[1][6] = "websavings.jpg";
images[1][7] = "websc.jpg";

images[1][8] = "printyards.jpg";
images[1][9] = "printyards.jpg";


///
/// Utility Functions
///

// Returns the size of 
// the current row
function rowMax(which)
{
	if (which == null)
	{
		var row = curRow;
	}
	else
	{
		var row = which;
	}
	
	switch (row)
	{
		// Print
		case 0:
			max = printmax;
			break;
		// Web
		case 1:
			max = webmax;
			break;
		default:
			max = 10;
			break;
	}
	return max;
}

///
/// Navigation Functions
///

function navFwd(el)
{
	if (el != null && el.style.visibility == "hidden")
	{
		if (curRow == 1)
		{
			show(rowMax(0), 0);
		}
		else
		{
			show(rowMax(1), 1);
		}
		
		return;
	}
	
	var next = curNum + 1;
	var row = curRow;
	if (next > rowMax())
	{
		next = 1;
		row = (curRow == 1) ? 0 : 1;
	}
	show(next, row);
	
	return;
}

function navBack(el)
{
	if (el != null && el.style.visibility == "hidden")
	{
		if (curRow == 1)
		{
			show(1, 0);
		}
		else
		{
			show(1, 1);
		}		
		
		return;
	}
	
	var prev = curNum - 1;
	var row = curRow;
	if (prev < 1)
	{
		prev = rowMax( (curRow == 1) ? 0 : 1 );
		row = (curRow == 1) ? 0 : 1;
	}
	show(prev, row);
}

///
/// Disclaimer Functions
///

function disclaimerCheck(n, which)
{
	var disclaimerMap = new Array(2);
	disclaimerMap[0] = new Array(2);
	disclaimerMap[0][0] = 1;
	disclaimerMap[0][1] = 6;
	disclaimerMap[1] = new Array(2);
	disclaimerMap[1][0] = 1;
	disclaimerMap[1][1] = 2;
	
	for (i=0;i<disclaimerMap[which].length;i++)
	{
		if (disclaimerMap[which][i] == n)
		{
			return true;
		}
	}
	return false;
}

function disclaimerOff()
{
	d = document.getElementById('foliodisclaim');
	d.style.visibility = "hidden";
}

function disclaimerOn()
{
	d = document.getElementById('foliodisclaim');
	d.style.visibility = "visible";
}

///
/// Display Functions
///


function navon(el) 
{
	if (el != prevNav)
	{
		el.style.color = "#999";
	}
	
}

function navoff(el) 
{
	if (el != prevNav)
	{
		el.style.color = "#fff";
	}
}

function sectionOn(which)
{
	prnt = document.getElementById('printfolionavtitle');
	web   = document.getElementById('webfolionavtitle');
	
	printback = document.getElementById('navback');
	printfwd  = document.getElementById('navfwd');
	
	webback = document.getElementById('nnavback');
	webfwd  = document.getElementById('nnavfwd');
	
	prnt.style.color = "#fff";
	web.style.color = "#fff";
		
	printback.style.visibility = "hidden";
	printfwd.style.visibility = "hidden";
	webback.style.visibility = "hidden";
	webfwd.style.visibility = "hidden";
	
	switch (which)
	{
		case 0:
			prnt.style.color = "#f90";
			printback.style.visibility = "visible";
			printfwd.style.visibility = "visible";
			break;
		case 1:
			web.style.color = "#f90";
			webback.style.visibility = "visible";
			webfwd.style.visibility = "visible";			
			break;
	}
	
	if (curRow != which && curRow != null)
	{
		hideRow(curRow);
	}
}

function loadImage(which, n)
{
	if (!document.images) { return false };
	
	if (which == 0)
	{
		var name = "print" + n;
	}
	else
	{
		var name = "web" + n;
	}

	document.images[name].src = "i/folio/" + images[which][n-1];	
}

function hideRow(which)
{
	if (which == 0)
	{
		var id = "print";
		var nid = "n";
	}
	else
	{
		var id = "web";
		var nid = "nn";
	}	

	for (j=1;j<=rowMax(which);j++)
	{
		var obj = document.getElementById(id + j);
		if (obj != null)
		{
			// Hide Image, caption and blurb
			obj.style.visibility = "hidden";
			obj.style.display = "none";

			// Turn the number white
			var num = document.getElementById(nid + j);
			num.firstChild.style.color = "#fff";
		}
	}
}

function show(n, which, star)
{		
	var pre = '';
	if (which == 0)
	{
		var id = "print";
	}
	else
	{
		var id = "web";
		var pre = "n";
	}
	
	// Hide all objects in row
	hideRow(which);

	// Download the image
	loadImage(which, n);

	// Turn on proper navigation
	sectionOn(which);

	// Hide Disclaimer
	disclaimerOff();

	// Check for disclaimer
	if( star == true)
	{
		disclaimerOn();
	}
	else if( star != false && disclaimerCheck(n, which))
	{
		disclaimerOn();
	}
	
	// Show the selected object
	var obj = document.getElementById(id + n);
	obj.style.visibility = "visible";
	obj.style.display = "block";	
	
	// Highlight the proper navigation
	var number = document.getElementById(pre + 'n' + n);	
	number.firstChild.style.color = "#f90";
	
	prevNav = number.firstChild;
	curNum  = n;
	curRow = which;
	
	return;
}

///
/// Main onLoad Routine
///

function go()
{
 	show(1, 0);
 
	var nextprev = document.getElementById('folionextprev');
	nextprev.style.visibility = "visible";
	
	var pt = document.getElementById('printfolionavtitle');
	var pl = document.getElementById('printfolionav');
	var wt = document.getElementById('webfolionavtitle');
	var wl = document.getElementById('webfolionav');
	
	pt.style.visibility = "visible";
	pt.style.display = "block";
	
	pl.style.visibility = "visible";
	pl.style.display = "block";

	wt.style.visibility = "visible";
	wt.style.display = "block";

	wl.style.visibility = "visible";
	wl.style.display = "block";
	
}