var current_image = document.getElementById('selected_image');
var current_text = null;

var current_section = "port2011";
var current_tab = '';

function change_opacity( elm, o ) {

	elm.style.opacity = o;
	elm.style.MozOpacity = o;
	elm.style.KhtmlOpacity = o;
	elm.style.filter = "Alpha(Opacity=" + ( o * 100 ) + ")";

} //end function

function glow( what ) {

	if( what == current_image ) return;

	change_opacity( what, 1 );

} //end function

function fade( what ) {

	if( what == current_image ) return;

	change_opacity( what, 0.6 );

} //end function

function show( what ) {

	if( what == current_image ) return;

	//fade out the current image
	change_opacity( current_image, 0.6 );

	//update the current image
	current_image = what;

	var main_image = document.getElementById('main_image');

	//get the name of the image that should be selected
	var image_name = what.src.replace( '_thumb', '' );

	//change the image
	main_image.src = image_name;
	
	//get the name of the text section
	var text_name = image_name.replace( /^.*\/([a-zA-Z0-9]+)\.jpg$/, "$1" );
	
	//get the text section
	var text_elm = document.getElementById( "text_" + text_name );
	if( text_elm == null ) { //if null, try knocking off the last digit and try again
		text_name = text_name.substr( 0, text_name.length - 1); 
		var text_elm = document.getElementById( "text_" + text_name );
	}
	
	//show the text (and hide the last text)
	if( current_text ) current_text.style.display = 'none';
	if( text_elm ) text_elm.style.display = 'block';
	
	//update current text
	if( text_elm ) current_text = text_elm;

} //end function

//preload images
var images = new Array();
var image_names = new Array( "port2011", "port2010-1", "port2010-2", "port2008", "models01", "models02", "models03" ); 
for( var i = 0; i < image_names.length; i++ ) {
	images['g_' + image_names[i]] = new Image(); images['g_' + image_names[i]].src = "images/tabs/portfolio/g_" + image_names[i] + ".jpg";
	images['w_' + image_names[i]] = new Image(); images['w_' + image_names[i]].src = "images/tabs/portfolio/w_" + image_names[i] + ".jpg";
	images['b_' + image_names[i]] = new Image(); images['b_' + image_names[i]].src = "images/tabs/portfolio/b_" + image_names[i] + ".jpg";
} //end for
