// JavaScript Document

function ts_center_img ( o_img ) {
	//alert ( 'ts_center_img ( o_img:' + o_img + ' )' );
	if ( o_img.offsetWidth ) {
		var img_w 		= o_img.offsetWidth;
		var img_h 		= o_img.offsetHeight;
		
		var o_bleed 	= o_img.parentNode; //document.getElementById ( 'bleed' );
		var bleed_w 	= o_bleed.offsetWidth;
		var bleed_h 	= o_bleed.offsetHeight;
		
		var img_ratio 	= img_h / img_w;
		var new_h 		= Math.ceil ( bleed_w * img_ratio );
		var new_x 		= 0;
		var new_y 		= 0;
		if ( bleed_h > new_h ) {
			// ---	set the image to bleed horizontally
			img_ratio 	= img_w / img_h;
			o_img.style.width 	= Math.ceil ( bleed_h * img_ratio ) + "px";
			o_img.style.height 	= bleed_h + "px";
			// ---	center align
			var new_x 	= Math.ceil ( - ( ( o_img.offsetWidth - o_bleed.offsetWidth ) /2 ) );
		} else {
			// ---	set the image to bleed vertically
			o_img.style.width 	= bleed_w + "px";
			o_img.style.height 	= new_h + "px";
			// ---	middle align
			var new_y 	= Math.ceil ( - ( ( o_img.offsetHeight - o_bleed.offsetHeight ) /3 ) );
		}
		o_img.style.marginLeft 	= new_x + "px";
		o_img.style.marginTop 	= new_y + "px";
	} else {
		o_img.style.width 	= '100%';
		o_img.style.height 	= '100%';
	}
}

function ts_show_info ( id ) {
	//alert ( 'ts_show_info ( id:' +id + ') ' );
	// ---	turn off class .ts-info_bkdg
	var 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 == "ts-info_bkgd" ) {
			oDivs[ d ].style.display 	= "none";
		}
	}
	if ( id ) {
		document.getElementById ( 'ts-info_bkgd' + id ).style.display 	= 'block';
	}
}

var detail 		= "";
function show_enlarged ( imgurl ) {
	var tmp_img 	= new Image ();
	tmp_img.src 	= imgurl;
	detail 			= "show";
	document.getElementById ( 'enlarged' ).style.display 			= 'block';
	document.getElementById ( 'enlarged_item' ).style.marginLeft 	= '-100px';
	tmp_img.onload = function () {
		if ( detail == "show" ) {
			var o_img 	= document.getElementById ( 'enlarged_img' );
			o_img.src 	= imgurl;
			var margin_left 	= Math.round ( ( ( o_img.width /2 ) * -1 ) +100 ) +'px';
			document.getElementById ( 'enlarged_item' ).style.marginLeft 	= margin_left;
			detail 		= "close";
		}
	}
}

function close_enlarged () {
	document.getElementById ( 'enlarged_img' ).src 					= '/_inc/img/loading.gif';
	document.getElementById ( 'enlarged' ).style.display 			= 'none';
	document.getElementById ( 'enlarged_item' ).style.marginLeft 	= '-200px';
}





