
if ( top.window.frames.length < 1 ) {
	top.location = 'http://ub3.underblob.com/?wp=' + this.location;
}

var curr_img;
var curr_http 	= 'http://' + location.hostname + '/';
//var curr_num;
var isMSIE = /*@cc_on!@*/false;
function show_main_img ( tn_num ) {
	//alert ( 'show_main_img ( tn_num:' + tn_num + ' )' );
	curr_num 	= tn_num;
	// ---	turn off all the strokes on div.thumb
	oDivs 	= document.getElementsByTagName ( "div" );
	for ( d = 0;  d < oDivs.length;  d++ ) {
		// cl_name = oDivs[ d ].getAttribute ( �class� ); // does NOT work in IE
		cl_name = oDivs[ d ].className;
		if ( cl_name == "thumb_on" ) {
			oDivs[ d ].className 	= "thumb_visited";
		}
	}
	var tn_img 	= document.getElementById ( 'tn' + tn_num );
	tn_img.parentNode.className 	= "thumb_on";
	document.getElementById ( 'controls' ).style.display 	= 'block';
	document.getElementById ( 'loader' ).style.display 		= 'block';
	// ---	set the image properties
	var o_img 	= document.getElementById ( 'main_img' );
	o_img.style.display 	= 'none';
	if ( isMSIE ) 	o_img.style.filter 		= 'Alpha(opacity=0)';
	else 			o_img.style.opacity 	= 0;
	
	var tn_src 	= tn_img.src;
	o_img.src 	= tn_src.replace ( '/tn/', '/' );
	o_img.onload = function () {
		// ---	Set the height and maintain proportions
		o_img.removeAttribute( 'height' );
		o_img.removeAttribute( 'width' );
		var maxh 	= 470;
		var maxw 	= 600
		var ogh 	= o_img.height;
		var ogw 	= o_img.width;
		console.log( 'ogw: ' + ogw );
		console.log( 'ogh: ' + ogh );
		if ( ogh > ogw ) {
			var scale 		= maxh / ogh;
			console.log( 'maxh scale: ' +scale );
			o_img.height 	= Math.round( ogh * scale );
			o_img.width 	= Math.round( ogw * scale );
		} else {
			var scale 		= maxw / ogw;
			console.log( 'maxw scale: ' +scale );
			o_img.height 	= Math.round( ogh * scale );
			o_img.width 	= Math.round( ogw * scale );
		}
		document.getElementById ( 'loader' ).style.display 	= 'none';
		setTimeout ( 'center_img ()', 50 );
	}
	curr_img = o_img.src;
	// ---	get captions
	xml_file 	= '/inc/xml/' + gdir + '.xml';
	node_name 	= curr_img.replace ( curr_http + gdir + '/', '' );
	node_name 	= node_name.replace ( '.jpg', '' );
	getXML ( xml_file, node_name );
}
function center_img () {
	var o_img 	= document.getElementById ( 'main_img' );
	o_img.style.display 	= 'block';
	//o_img.style.marginLeft 	= '-' + Math.round ( o_img.width /2 ) + 'px';
	o_img.style.marginLeft 	= '-' + String( Math.round ( o_img.width /2 ) ) + 'px';
	var img_alpha 	= new OpacityTween ( o_img, Tween.linear, 0, 100, 1 );
	img_alpha.start ();
}
function next_img () {
	//alert ( 'next_img ()' );
	( curr_num >= arr_img.length -2 ) 	? key = 0 	: key = curr_num +1;
	show_main_img ( key );
}
function prev_img () {
	//alert ( 'prev_img ()' );
	( curr_num < 1 ) 	? key = arr_img.length -2 	: key = curr_num -1;
	show_main_img ( key );
}

function email_img () {
	//alert ( 'email_img ()' );
	top.location 	= 'mailto:?subject=image%20from%20underblob&body='
					+ this.location + '/' + curr_num;
}
function load_img () {
	//alert ( 'load_img ()' );
	if ( curr_num || curr_num === 0 ) 	show_main_img ( curr_num );
}

function hide_controls () {
	//alert ( 'hide_controls ()' );
	document.getElementById ( 'menu-rollout' ).style.display 		= 'none';
	document.getElementById ( 'main_img-rollout' ).style.display 	= 'block';
	o_ctrl 	= document.getElementById ( 'controls' );
	var t1 	= new Tween ( o_ctrl.style, 'bottom', Tween.strongEaseInOut, 0, -45, 0.5, 'px' );
	t1.start ();
}
function show_controls () {
	//alert ( 'show_controls ()' );
	document.getElementById ( 'menu-rollout' ).style.display 		= 'block';
	document.getElementById ( 'main_img-rollout' ).style.display 	= 'none';
	o_ctrl 	= document.getElementById ( 'controls' );
	var t1 	= new Tween ( o_ctrl.style, 'bottom', Tween.strongEaseInOut, -45, 0, 0.5, 'px' );
	t1.start ();
}
function show_fullsize ( o_img ) {
	//alert ( 'show_fullsize ( o_img:' + o_img + ' );' );
	this.location 	= o_img.src;
}


