/* ------------- SETUP ------------- */
var imagesURLroot = 'portfolio/images/';
var frontsURLroot = 'portfolio/fronts/';
var imagePath = '';

/* ------------- PUBLIC ------------- */


/* -- for photography.php -- */
function showMoreThumbs(obj,butnMo) {
	// alert ($(obj));


	// if ($(obj).style.height=="auto") { grow = false; } else { grow = true; }

	if ($(obj).style.height != thumbOriginalCSSHeight +"px") { grow = false; } else { grow = true; }

	// close other thumb sets
	tObArray = $$('.thumbs ul');
	for (i=0; i<tObArray.length; i++) {
		if (tObArray[i].style.height != thumbOriginalCSSHeight +"px") { // nb. same comparison as above
			tObArray[i].style.height = thumbOriginalCSSHeight +"px";
			bObj = $$('.thumbs sup a'); // all hide buttons
			bObj = bObj[i]; // gallery count picks one
			bObj.innerHTML = oldButnTitle; // rename
		}
	}

	if (grow) {
		$(obj).style.webkitTransition = "all 0.3s ease-in-out"; // woo!
		$(obj).style.mozTransition = "all 0.3s ease-in-out"; // WOO!
		$(obj).style.oTransition = "all 0.3s ease-in-out"; // WOOHOO!
	
		$(obj).style.height=$(obj).origHeight + "px";		
		oldButnTitle = $(butnMo).innerHTML;
		$(butnMo).innerHTML = "less<img src='./css/uparrow.png' width='5px' height='10px' />";
	}
}
/* -- end for photography.php -- */ 






/* -- these are the nav functions for the image.php pages --*/

function DEAD_n() { //next
	curIG = imgs[curHash].split('_');
	curIG = curIG[0];
	nexIG = imgs[curHash+1].split('_');
	nexIG = nexIG[0];

	if ((curHash+1<=imgs.length-1) && (nexIG == curIG)) { // if one higher is within the range and with this gallery
		curHash++;
		document.location.href = "./photo.php#" + curHash;
		loadImagetoFitFromId(curHash);
	} else {
		i();
	}
}

function DEAD_p() { //previous
	curIG = imgs[curHash].split('_');
	curIG = curIG[0];
	preIG = imgs[curHash-1].split('_');
	preIG = preIG[0];
	
	if ((curHash-1>=0) && (curIG == preIG)) {
		curHash--;
		document.location.href = "./photo.php#" + curHash;
		loadImagetoFitFromId(curHash);	
	} else {
		i();
	}
}

function DEAD_i() { //index (retaining position)
 	document.location.href = "./photography.php#" + curHash;
}

function DEAD_mbNext () { // main image click behaviour -- next unless last image, then return to menu
	if (curHash+1<=imgs.length-1) {
		n();
	} else {
		i();
	}
}
/* -- end nav functions for photo.php -- */

/* -- load image functions -- */

// used on photo.php page
function DEAD_loadImagetoFitFromId(imgId) {
	var vpHeight = document.viewport.getHeight();
	var vpWidth = document.viewport.getWidth() +120; // this is a hack as there is a bigger mistake. i am currently calculating the images sizes to compare wrongly. due to 'fit within' scaling in PS, i don't know which side i'm scaling against.

//	var vpHeight = 10000; var vpWidth = 100000; // just checking big res

    var curImgType=2; // start at 2 prevents thumbs being displayed
    var itHeight = 0;
    
    var loop = true;
    while ( loop == true ) { // yes this is a retarded use of while. woteva
    	if (imageTypes[curImgType] != undefined) { // prevent overrun with massive screens
    		itDims = imageTypes[curImgType].split('|');
	        itWidth = itDims[1];
	        itHeight = itDims[2];
        
		    if ((vpHeight >= itHeight) && (vpWidth >= itWidth)) {
	        	curImgType++;
	        } else {
	        	loop = false; // break
	        	curImgType--;
	        }
	    } else {
			loop = false; // break
		}
	}
	
	imgPathElements = imgs[imgId].split("|");
		
	displayNow(
		imagesURLroot
		+encodeURIComponent(imgPathElements[0])
		+"/"
		+getRelPathFromImageTypeId(curImgType)
		+"/"
		+imgPathElements[1]);
}

// used on the front page. to get full window size images.
function DEAD_loadImageFullFrameFromRelURL(picRelUrl) {
	picProps = picRelUrl.split('#');
	picProps = picProps[1];
	
	// there are bugs in this code - with viewport arount 550x400px some 3:2 images are wrong.
	var vpHeight = document.viewport.getHeight();
	var vpWidth = document.viewport.getWidth();
	
	// alert("h " +vpHeight +"  w " +vpWidth);
	
	var i = imageTypes.length-1;
	
	var itPwh = imageTypes[i].split('|');
	var itHeight = itPwh[2];
	var itWidth = itHeight * picProps;

	
	while ((itWidth >= vpWidth) && (itHeight >= vpHeight)) {
		// alert ("looping: itWidth" +itWidth +" vpHeight" +vpWidth +" itHeight" +itHeight +" vpHeight" +vpHeight);
		i--;
		var itPwh = imageTypes[i].split('|');
		var itHeight = itPwh[2];
		var itWidth = itHeight * picProps;
	}
	i++;

	imgPath = getRelPathFromImageTypeId(i);
	displayNow(frontsURLroot +imgPath +"/" + picRelUrl);
}

/* ------------- PRIVATE ------------- */

function DEAD_getRelPathFromImageTypeId(i) {
	if (i >= imageTypes.length) i = imageTypes.length-1; // range check, so we don't ask for a bigger image than our maximum.

	itPWH = imageTypes[i].split('|');
	imgPath = itPWH[0];
	// alert (imageTypes[i]);
	
	return imgPath;
}

// actually put the image into the holding block
function DEAD_displayNow(inUrl) {
	// alert(inUrl);
	$('imageCase').style.backgroundImage="url(\"" +inUrl +"\")";
	$('imageCase').style.display="block";
}
