// Industri javascript stuff - Tig

// keep track of the console state
var consoleOpen = false;
// opject type for diff browsers
var objH = null;
// console size
var consoleHeight = 530;
// console 'appear speed' constant
var consoleSpeed = 0.5; 
// keep track of the 'thumb index' page
var thumbIdx = '0';
// keep track of current state on change
var trans = 0;

if (document.images) {
	news = new Image(48,33);
	news.src = "/img/nNews.jpg";
	newsA = new Image(48,33);
	newsA.src = "/img/nNewsA.jpg";
	newsC = new Image(48,33);
	newsC.src = "/img/nNewsC.jpg";

	dl = new Image(86,33);
	dl.src = "/img/nDownloads.jpg";
	dlA = new Image(86,33);
	dlA.src = "/img/nDownloadsA.jpg";
	dlC = new Image(86,33);
	dlC.src = "/img/nDownloadsC.jpg";

	shots = new Image(93,33);
	shots.src = "/img/nScreenshots.jpg";
	shotsA = new Image(93,33);
	shotsA.src = "/img/nScreenshotsA.jpg";
	shotsC = new Image(93,33);
	shotsC.src = "/img/nScreenshotsC.jpg";

	thanks = new Image(59,33);
	thanks.src = "/img/nThanks.jpg";
	thanksA = new Image(59,33);
	thanksA.src = "/img/nThanksA.jpg";
	thanksC = new Image(59,33);
	thanksC.src = "/img/nThanksC.jpg";

	howto = new Image(72,33);
	howto.src = "/img/nHowto.jpg";
	howtoA = new Image(72,33);
	howtoA.src = "/img/nHowtoA.jpg";
	howtoC = new Image(72,33);
	howtoC.src = "/img/nHowtoC.jpg";

} // doc.img

function flip(img,ref) {
	if (document.images) {
		document.images[img].src = eval(ref + ".src");
	}
} // flip

function onOff(id) {
	var op = null;
	if (document.getElementById) {
		op = document.getElementById(id);
	} else if (document.all) {
		op = document.all[id];
	} else if (document.layers) {
		op = document.layers[id];
	}
	
	if (!op) {
		return 
	} else if (op.style) {
		if (op.style.display == "none") { 
			op.style.display = ""; 
		} else { 
			op.style.display = "none"; 
		}
	} else { 
		op.visibility = "show"; 
	}
} // onOff

// increases window height from 0
function consoleSize(h) {
	objH.style.height = h + 'px';
}

// slide the window 
function consoleSlide(h) {
	objH.style.top = '-'+ h +'px';
}

function fadeId(id) {
  	obj = document.getElementById(id);
  	setOpacity(obj, 0);
  	//obj.style.visibility = 'visible';
  	fadeIn(id,0);
} // fadeId

function fadeOutId(id) {
  	obj = document.getElementById(id);
  	setOpacity(obj, 100);
  	//obj.style.visibility = 'visible';
  	fadeOut(id,100);
} // fadeOutId

function setOpacity(obj, opacity) {
	if (opacity <= 0) {
		trans = 1;
	} else {
		trans = 0;
	}

	opacity = (opacity == 100)?99.999:opacity;
	// IE/Win
	obj.style.filter="alpha(opacity:"+opacity+")";

	// Safari<1.2, Konqueror
	obj.style.KHTMLOpacity=opacity/100;

	// Older Mozilla and Firefox
	obj.style.MozOpacity=opacity/100;

	// Safari 1.2, newer Firefox and Mozilla, CSS3
	obj.style.opacity=opacity/100;
}

function fadeIn(objId,opacity) {
	if (document.getElementById) {
		obj = document.getElementById(objId);
		if (opacity <= 100) {
			setOpacity(obj, opacity);
			opacity += 10;
			window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 100);
		}
	}
} // fadeIn

function fadeOut(objId,opacity) {
	if (document.getElementById) {
		obj = document.getElementById(objId);
		if (opacity >= 0) {
			setOpacity(obj, opacity);
			opacity -= 25;
			window.setTimeout("fadeOut('"+objId+"',"+opacity+")", 50);
		}
	}
} // fadeOut

// looks like the window slides down or up
function console(id) {
	var i = 0;

	// set objH	
	if (document.getElementById) {
		objH = document.getElementById(id);
	} else if (document.all) {
		objH = document.all[id];
	} else if (document.layers) {
		objH = document.layers[id];
	}

	if (objH) {
		if (objH.style) {
			if (consoleOpen) {
				for (i=0;i<consoleHeight;i++) {
					setTimeout("consoleSlide('"+ i +"')",eval(consoleSpeed * i));
				} // for
			} else {
				for (i=0;i<=consoleHeight;i++) {
					setTimeout("consoleSize('"+ i +"')",eval(consoleSpeed * i));
				} // for
			} // open or closed
		} // opH.style
	} // opH
} // console

function archive() {
	if (consoleOpen) {
		// hide console
		console('console');
		setTimeout("onOff('console');onOff('archive');consoleSize('0');consoleSlide('0')",eval(consoleSpeed * consoleHeight));
		consoleOpen = false;
	} else {
		console('console');
		onOff('console');
		setTimeout("onOff('archive');fadeId('archiveIdx');",eval(consoleSpeed * consoleHeight));
		consoleOpen = true;
	}
} // archive

function thumbs() {
	if (consoleOpen) {
		// hide console
		console('thumbs');
		setTimeout("onOff('thumbs');onOff('thumbsIdx');consoleSize('0');consoleSlide('0')",eval(consoleSpeed * consoleHeight));
		consoleOpen = false;
	} else {
		console('thumbs');
		onOff('thumbs');
		setTimeout("onOff('thumbsIdx');fadeId('thm');",eval(consoleSpeed * consoleHeight));
		consoleOpen = true;
	}
} // thumbs

function noFlash(urlDetails,id) {
	if (trans == 1) {
		ajaxpage(urlDetails,id);
		setTimeout("fadeId('thm')",800);
	} else {
		setTimeout("noFlash('"+ urlDetails +"','"+ id +"')",100);	
	}
} // noFlash

// called when a thumb set change requested is made
function nextThumbs(urlDetails,id,direction,idxMax) {
	// direction is either 'n'ext or 'p'revious
	if (direction == 'n') {
		thumbIdx = eval(thumbIdx + 6) ;
	} else if (direction == 'p') {
		thumbIdx = eval(thumbIdx - 6);
	}
	// now validate the index page
	if (thumbIdx > idxMax) {
		thumbIdx = 0;
	}
	if (thumbIdx < 0) {
		thumbIdx = eval(idxMax - (idxMax % 6));
	}
	// fade out the current thumbs
	fadeOutId('thm');
	// call the new ones
	setTimeout("noFlash('"+ urlDetails +"&t="+ thumbIdx  +"','"+ id +"')",500);
} // nextThumbs

// called when a thumb is selected
function shotChange(urlDetails) {
	// close the index
	thumbs();
	setTimeout("window.location='http://"+ window.location.hostname +"/shots.php?"+ urlDetails +"'",eval(consoleSpeed * consoleHeight));
}

