/*
 * set up signal to handle default case for
 * when no trailer has been displayed.
 */
var scrollBarSize = 15;
var maxHeight 	= 0;
var isNav	= (navigator.appName.indexOf("Netscape")  != -1);
var isIE   	= (navigator.appName.indexOf("Microsoft") != -1);
var version 	= parseInt(navigator.appVersion);



function getMaxHeight() {
	if(maxHeight != 0) return (maxHeight);

	if(null == document) return 0;
	for(var i = 0; i < document.all.length; i++) {
//        for(var tagName in window.document.all) {
		var tag = document.all[i];
		if(tag.style && 
			tag.offsetTop > 0) 
		{

			var sum = (tag.offsetTop + tag.offsetHeight);
			maxHeight = (maxHeight > sum) ? maxHeight : sum;
		}

        }
//	alert(document.all.length + ':' + maxHeight);
	return maxHeight;
}


function trailerHTML(tagName, isNav,isFixed,isVisible) {

	
	var trailerHTML;


	if(isNav) {
		trailerHTML =  '<br clear="all"><layer name="' + tagName + '" ' +
		(isFixed ? '' : 'left=0 top=0 ') +  
	        (isVisible ? '' : ' visibility=hide ') + ' z-index=1000> ';
	} else {
		trailerHTML = '<br clear="all"><div id="' + tagName + '" ' +
		' style="' +
		(isFixed ? '' : 'position:absolute;') +
		(isVisible ? '' : 'visibility:hidden;') + 'z-index:10000">'; 
	}

	trailerHTML += trailerText + (isNav ? '</layer>' : '</div>');

	return trailerHTML;
}

function isCssAbsPosMS(d) {
        var ss = d.styleSheets;
        for(var i = 0; i < ss.length; i++)  {

                var rules = ss[i].rules;
                for(var j = 0; j < rules.length; j++) {
                        if(rules[j].style.position == 'absolute') {
                                return true;
                        }
                }
        }
	
	for(var tag = 0; tag < d.all.length; tag++) {
//        for(var tag in d.all) {
                if(d.all[tag].style &&
                        (d.all[tag].style.position ==
                                'absolute')) {
                        return true;
                }

        }


        return false;
}

function isLayered() {

	var isLayer = ((top.document != '')
		&& top.document.layers.length != 0) ||
		document.layers.length != 0;  	
	return( isLayer); 
}
function isFrameOKMS() {
	if (top == window && 
		(4 == version && 0 == document.all.tags("FRAMESET").length) ||
		(3 == version && (top.frames && 0 == top.frames.length))) {
		return 1;
	}
	if(null == document.body) return 0; 
	var h = (document.body.clientWidth/screen.width);
        var w = (document.body.clientHeight/screen.height);
	var r = (h >=.3 && w >=.3 ) ? 1 : 0;
	return r;
}
function isFrameOKNetscape() {
	if (top == window && top.frames && 
		(0 == top.frames.length)) {
		return 1;
	}
	var h = (window.innerHeight/screen.height);
	var w = (window.innerWidth/screen.width);
	var r = (h >=.3 && w >=.3 ) ? 1 : 0;
	return r; 
}
var a = window.onload;
function positionTrailer() {
                if(isNav && (document.bessBar) &&
			document.bessBar.top == 0) {    
                        document.bessBar.top = window.document.height + 10;    
                        document.bessBar.visibility = 'visible';    
                        window.document.height += 200;
                }
		if (a && a != positionTrailer) {a()};
};

window.onload = positionTrailer;
/*
 * Test to see if window contains frames
 * or is contained within a frame
 */
if(isNav && version < 4) {
	if(top == window && top.frames && 
		(0 == top.frames.length)) {
		document.write(
			trailerHTML('bessBar',true,true,true));
	}

} else if( 	isNav && 
	top.document  &&
    	isFrameOKNetscape()
)  
{
		if(isLayered(document)) {
			document.write(trailerHTML('bessBar',
				true,false,false));
			document.bessBar.left = pageXOffset +
				(innerWidth - document.bessBar.clip.width)/2
				- scrollBarSize;
/*
			alert(top.document.height);
			document.bessBar.top = top.document.height + 10; 
			top.document.height += 200;
			document.bessBar.visibility = 'visible';
			alert(top.document.height);
*/
		} else {
			document.write(
				trailerHTML('bessBar',
					true,true,true));
			document.bessBar.left = pageXOffset +
				(innerWidth - document.bessBar.clip.width)/2
				- scrollBarSize;
		}
}
else if (
	isIE && 
    	isFrameOKMS()) 
{ 
		if(isCssAbsPosMS(document)) {
			document.write(trailerHTML('bessBar',
				false,false,false));
			document.all.bessBar.style.left = 
				document.body.scrollLeft +
				(document.body.offsetWidth - 
				document.all.bessBar.offsetWidth)/2;
			document.all.bessBar.style.top = getMaxHeight();
			document.all.bessBar.style.visibility = 'visible';
			
		} else {
			document.write(
				trailerHTML('bessBar',
					false,true,true));
		}
}

