// so we know when things are loaded.
window.isLoaded = false;

// mainly for the portfolio rollovers, but needed for all rollovers ( so we can use one script )
window.iSelectedRollover = "";

GTEXT = null;

// function called when page is loaded.
function init()
{	
	isLoaded = true;
	checkMargins();
}

// array of rollover information
window.gROLLOVERS = new Array()

/** addRollover */
/* this function adds items to an array, which holds information about doing javascript rollovers.
 * This is the function for most rollovers on the site ( except for the portfolio )
 *
 * param sRollName	String	the name of the image element on the page. this is also the index of the array.
 * param sLayerName	String	the name that the image element sits on.
 * param sImageOffSrc	String	the src of the image in its default state.
 * param sImageOnSrc	String	the src of the image in its rollover state.
 */
function addRollover( sRollName, sLayerName, sImageOffSrc, sImageOnSrc )
{
	// make an array to hold our information
	gROLLOVERS[sRollName] = new Array();

	gROLLOVERS[sRollName]["imageElement"]

	// image object for the rollover state.
	gROLLOVERS[sRollName]["imageObject"] = new Image();
	gROLLOVERS[sRollName]["imageObject"].src = sImageOnSrc;

	// src for the normal state.
	gROLLOVERS[sRollName]["imageInitial"] = sImageOffSrc;

	// get a reference to the image.
	if (document.layers)
	{
		gROLLOVERS[sRollName]["imageElement"] = document.layers[sLayerName].document.images[ sRollName ];
	}
	else
	{
		gROLLOVERS[sRollName]["imageElement"] = document.images[ sRollName ];
	}
}

/** addRollover */
/* this function adds items to an array, which holds information about doing javascript rollovers. and
 * for navigation that is selectable (the Portfolio)
 *
 * param sRollName	String	the name of the image element on the page. this is also the index of the array.
 * param sLayerName	String	the name that the image element sits on.
 * param sImageOffSrc	String	the src of the image in its default state.
 * param sImageOnSrc	String	the src of the image in its rollover state.
 * param sImageSelSrc	String	the src of the image in its selected state.
 */
function addRollOverSelectable( sRollName, sLayerName, sImageOffSrc, sImageOnSrc, sImageSelSrc )
{
	addRollover( sRollName, sLayerName, sImageOffSrc, sImageOnSrc );
	gROLLOVERS[sRollName]["imageSelected"] = new Image();
	gROLLOVERS[sRollName]["imageSelected"].src = sImageSelSrc;
}

/** rollOn */
/* sets the image source of a particular image on the page to the over state.
 *
 * param sRollName	String	an index of the global rollover array.
 */
function rollOn( sRollName )
{
	// checks to make sure the array item exists and that the particular item isn't already selected.
	if ( typeof gROLLOVERS[sRollName] != "undefined" && sRollName != "portfolio_" + iSelectedRollover )
	{
		gROLLOVERS[sRollName]["imageElement"].src = gROLLOVERS[sRollName]["imageObject"].src;
	}
}

/** rollOff */
/* sets the image source of a particular image on the page to the normal state.
 *
 * param sRollName	String	an index of the global rollover array.
 */
function rollOff( sRollName )
{
	// checks to make sure the array item exists and that the particular item isn't already selected.
	if ( typeof gROLLOVERS[sRollName] != "undefined" && sRollName != "portfolio_" + iSelectedRollover )
	{
		gROLLOVERS[sRollName]["imageElement"].src = gROLLOVERS[sRollName]["imageInitial"];
	}
}

/** rollSelected */
/* sets the image source of a particular image on the page to the on (selected) state.
 * this is called from the load image function below
 *
 * param sRollName	String	an index of the global rollover array.
 */
function rollSelected( sRollName )
{
	// checks to make sure the array item exists.
	if ( typeof gROLLOVERS[sRollName] != "undefined" )
	{
		gROLLOVERS[sRollName]["imageElement"].src = gROLLOVERS[sRollName]["imageSelected"].src;
	}
}

/** loadImage */
/* loads an image of the portfolio
 *
 * param iIndex number of the item in the portfolio.
 */
function loadImage( iIndex )
{
	if (gPORTFOLIO_IMG != null)
	{
		var iOld = iSelectedRollover;

		// checks if the up or down button was clicked.
		if ( iIndex == "up" || iIndex == "dn" )
		{
			var iNextImage = -1;
			if (iIndex == "up")
			{
				iNextImage = 1;
			}
			
			// if we are at the end or beginning, we
			// wrap the number around to start or
			// finish.
			iSelectedRollover += iNextImage;
			if ( iSelectedRollover < 1 )
			{
				iIndex = gImageTotal;
			} 
			else if ( iSelectedRollover > gImageTotal )
			{
				iIndex = 1;
			}
			else
			{
				iIndex = iSelectedRollover;
			}				
		}

		iSelectedRollover = iIndex;

		// rolls off old item and selects the new item
		rollOff("portfolio_" + iOld);
		rollSelected("portfolio_" + iSelectedRollover);

		if ( iIndex < 10 )
		{
			iIndex = "0" + iIndex;
		}

		// changes the portfolio image
		gPORTFOLIO_IMG.src = gPATH + gCLIENT_NAME + iIndex + ".jpg";
		
		
		if (GTEXT!=null) 
		{
			iDiv = iSelectedRollover -1
			GSHOWTitle.innerHTML = ShowTitles["portfolio_" + iDiv];
			GSHOWNameDate.innerHTML = ShowArtists["portfolio_" + iDiv] + "<br><span class='showDate'>" + ShowDates["portfolio_" + iDiv] + "</span>";
		}

		
	}
}


function checkMargins(){
	var w = 864
	var h = 460;
	if (is_nav4less || is_ie5less )
	{
		w = 10
		h = 10
	} 
	
	if( typeof window.innerWidth == "number" )
	{
		w = window.innerWidth
		h = window.innerHeight
	}	
	else if( document.documentElement && document.documentElement.clientWidth )
	{
		w = document.documentElement.clientWidth;
		h = document.documentElement.clientHeight;
	}
	else if (document.body && document.body.clientWidth)
	{
		w = document.body.clientWidth;
		h = document.body.clientWidth;
	}
	if( w <= 864 && !wSet)
	{
		G_BG.style.marginLeft = "0px";
		G_BG.style.left = "20px";
		wSet = true
	}
	else if ( w > 864 && wSet)
	{
		wSet = false
		G_BG.style.marginLeft = "-424px";
		G_BG.style.left = "50%";
	}
	
	if ( h <= 460 && !hSet)
	{
		G_BG.style.marginTop = "0px";
		G_BG.style.top = "0px";
		hSet = true
	}
	else if (h > 460 && hSet)
	{
		hSet = false
		G_BG.style.marginTop = "-217px";
		G_BG.style.top = "50%";
 	}
}


    // convert all characters to lowercase to simplify testing
    var agt=navigator.userAgent.toLowerCase();

    // *** BROWSER VERSION ***
    // Note: On IE5, these return 4, so use is_ie5up to detect IE5.
    var is_major = parseInt(navigator.appVersion);
    var is_minor = parseFloat(navigator.appVersion);
    var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
                && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
                && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
    var is_nav4less = (is_nav && (is_major <= 5));    
    var is_mac    = (agt.indexOf("mac")!=-1);
    var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
    var is_ie5less    = (is_ie && (is_major <= 5) );

