/*
	
	Transitory, the Exhibition Script.
	Copyright © Corporation Eightt.
	
	Coded by the henchmonkeys at Eightt,
	who want you to learn from some of
	their great techniques herein.
	
	Specific Page Author: Taldar Baddley.
	
*/




normalityIndex = 0;
sanityStatus = 0;
imageObject = new Image();
initialTheta = new Image();
initialOmega = new Image();
bumFree = '';
foregroundLayer = 'theta';
/*selectric = new Object;
namePlate = new Object;*/

function startupItems() {
	// Select Random Numbers
	var idTheta = selectRdm();
	var idOmega = selectRdm();
	
	// Compose urls
	var srcTheta = '..\/work\/' + getInfo(idTheta).body + '\/' + getInfo(idTheta).index + '\/s.jpg';
	var srcOmega = '..\/work\/' + getInfo(idOmega).body + '\/' + getInfo(idOmega).index + '\/s.jpg';
	
	// Fill and Align Images
	/*document.getElementById('pictotheta').src = srcTheta;
	document.getElementById('pictotheta').style.marginLeft = (((document.getElementById('pictotheta').offsetWidth) / (-2)) + 'px');
	document.getElementById('pictotheta').style.marginTop = (((document.getElementById('pictotheta').offsetHeight) / (-2) + 20) + 'px');
	document.getElementById('pictomega').src = srcOmega;
	document.getElementById('pictomega').style.marginLeft = (((document.getElementById('pictomega').offsetWidth) / (-2)) + 'px');
	document.getElementById('pictomega').style.marginTop = (((document.getElementById('pictomega').offsetHeight) / (-2) + 20) + 'px');
	*/
	
	initialTheta.src = srcTheta;
	initialTheta.onload = placeTheta;
	initialOmega.src = srcOmega;
	initialOmega.onload = placeOmega;
	
	// Fill Titles
	document.getElementById('thetatitle').innerHTML = getInfo(idTheta).title;
	document.getElementById('omegatitle').innerHTML = getInfo(idOmega).title;
	
	// Finish Loading
	setTimeout('animSpawn("alpha", "opacity", "", 1, 0, 0.5)', 2000);
	setTimeout('document.getElementById("alpha").style.display = "none"', 2500);
	
	// Commence Normality
	setTimeout('commenceNormality()', 2000);
	
}

function placeTheta() {
	document.getElementById('pictotheta').src = initialTheta.src;
	document.getElementById('pictotheta').style.marginLeft = (((initialTheta.width) / (-2)) + 'px');
	document.getElementById('pictotheta').style.marginTop = (((initialTheta.height) / (-2) + 20) + 'px');
}

function placeOmega() {
	document.getElementById('pictomega').src = initialOmega.src;
	document.getElementById('pictomega').style.marginLeft = (((initialOmega.width) / (-2)) + 'px');
	document.getElementById('pictomega').style.marginTop = (((initialOmega.height) / (-2) + 20) + 'px');
}





function togglePic() {
	// Determine Element to Animate
	if (foregroundLayer == 'theta') {
		selectric = 'pictotheta';
		namePlate = 'thetatitle';
		animSpawn('theta', 'opacity', '', 1, 0, 0.5);
		foregroundLayer = 'omega';
	} else {
		selectric = 'pictomega';
		namePlate = 'omegatitle';
		animSpawn('theta', 'opacity', '', 0, 1, 0.5);
		foregroundLayer = 'theta';
	}
	
	setTimeout(('toggleHelper("' + selectric + '", "' + namePlate + '")'), 500);
	
	/*// New Random
	newId = selectRdm();
	
	// Fill New Image and Align
	newSrc = '..\/work\/' + getInfo(newId).body + '\/' + getInfo(newId).index + '\/s.jpg';
	setTimeout('selectric.src = newSrc', 500);
	var newStyle = selectric.offsetWidth;
	newStyle = newStyle / -2;
	setTimeout(('selectric.style.marginLeft = "' + newStyle + 'px"'), 5000);
	
	// Fill Title
	setTimeout('namePlate.innerHTML = getInfo(newId).title', 500);*/
	
}

function toggleHelper(selectric, namePlate) {
	bumFree = selectric;
	// Fill New Image and Align
	var newId = selectRdm();
	var newSrc = '..\/work\/' + getInfo(newId).body + '\/' + getInfo(newId).index + '\/s.jpg';
	imageObject.src = newSrc;  // Preload only
	imageObject.onload = imagePlacement;
	
	// Fill Title
	document.getElementById(namePlate).innerHTML = getInfo(newId).title;
	
}

function imagePlacement() {
	document.getElementById(bumFree).src = imageObject.src;
	document.getElementById(bumFree).style.marginLeft = (((imageObject.width) / (-2)) + 'px');
	document.getElementById(bumFree).style.marginTop = (((imageObject.height) / (-2) + 20) + 'px');
}





function toggleNormality() {
	if (sanityStatus) {
		haltNormality();
	} else {
		togglePic();
		commenceNormality();
	}
}

function commenceNormality() {
	//togglePic();
	normalityIndex = setInterval('togglePic()', 10000);
	document.getElementById('boolinator').innerHTML = 'Pause';
	sanityStatus = 1;
}

function haltNormality() {
	clearInterval(normalityIndex);
	document.getElementById('boolinator').innerHTML = 'Resume';
	sanityStatus = 0;
}

function selectRdm() {
	return Math.floor(Math.random() * numberOfPhotographs);
}





