var D = document;
var nc = ( navigator.userAgent.indexOf("MSIE") == -1 && navigator.userAgent.indexOf("Opera") == -1 ) ? 1 : 0;
var OFFSET_X = 0;
var OFFSET_Y = 0;

if( nc ) { D.write('<LINK HREF="css/main_nc.css" REL="StyleSheet">'); }

//#########################################################

function wopen( url, target, w, h, asize, title, res ) 	{
	if( !url ) {
		event.cancelBubble = true;
		event.returnValue = false;
		return;
	}
	if( !target ) target = '_blank';
	if( !w ) w = 550;
	if( !h ) h = 400
	r = res ? 0 : 1;
	if( asize && !title && !res ) r = 0;

	w = parseInt( w, 10 );
	h = parseInt( h, 10 );
	var aw = screen.availWidth;
	var ah = screen.availHeight;
	if( w > aw ) w = aw;
	if( h > ah ) h = ah;

	var left = Math.round( ( aw - w ) / 2 );
	var top = Math.round( ( ah - h ) / 2 );
	var wd = window.open( url, target, 'channelmode= 0, directories=0, fullscreen=0, height='+h+'px, width='+w+'px, location=0, menubar=0, resizable='+r+', scrollbars=1, status=0, toolbar=0, top='+top+'px, left='+left+'px' );
}

//#########################################################

function inPopup( obj, w, h ) {
	if( !obj || !obj.href ) return false;
	event.returnValue = false;
	if( !w ) w = 0; w = parseInt( w ); if( !w || isNaN( w ) ) w = 550; 
	if( !h ) h = 0; h = parseInt( h ); if( !h || isNaN( h ) ) h = 350;
	wopen( obj.href, "", w, h );
	return false;
}

//#########################################################

function go( url ) {
	if ( url ) { top.location.href = url; }
}

//#########################################################

function winfull( url, target ) {
	if ( !url ) { return false; }
	if ( !target ) { target = '_blank'; }
    var wd = window.open( url, target, 'fullscreen=1, scrollbars=1, toolbar=0' );
}

//#########################################################

function showFullImage( obj ) {
	if( !obj || !obj.src ) return;
	var file  = obj.src;
	var text  = obj.alt;
	var slide = !SLIDESHOW ? 0 : 1;
	wopen( SERVER_URL+"show_image.php?file="+file+"&text="+encodeURI( text )+"&slide="+slide, "_blank", 1050, 768 );
}

//#########################################################

function get_object_offset( obj ) {
	var x = y = 0;
	while ( true ) {
		x += obj.offsetLeft;
		y += obj.offsetTop;
		if ( !obj.offsetParent ) { break; }

		obj = obj.offsetParent;
	}
	OFFSET_X = x;
	OFFSET_Y = y;
}

//#########################################################

function wait( mode ) {
	var obj = D.getElementById( "progress_bar" );
	if( obj ) { 
		obj.className = !mode ? "hide" : "show";  
		h = obj.style.height ? parseInt( obj.style.height ) : 50;
		obj.style.top = ( getDocumentHeightCenter() - h ) + "px";
	}
}

//#########################################################

// Vertical scrolling position
function getBodyScrollTop() { return self.pageYOffset || ( D.documentElement && D.documentElement.scrollTop ) || ( D.body && D.body.scrollTop ); }
// Document height with scrolling
function getDocumentHeight() { return ( D.body.scrollHeight > D.body.offsetHeight ) ? D.body.scrollHeight : D.body.offsetHeight; }
// Get window heght
function getClientHeight() { return D.compatMode=='CSS1Compat' && !window.opera ? D.documentElement.clientHeight : D.body.clientHeight; }
// Vertical document center with scrolling
function getDocumentHeightCenter() { return parseInt( getClientHeight() / 2 ) + getBodyScrollTop(); }
