// DEBUG: var externalURL = "http://www.webonaut.com/";

var iFrm = false;
var btu_scroller = false;
var mySlide = false;
var dimensionInterval = false;

var __init__ = function() {
	menu = $('mainmenu');
	if (menu) menu = new DropMenu(menu);
	setDimension();

	$$('div#content_data a').each(function(aTag) {
		if (aTag.childNodes.length == 1 && aTag.innerHTML.indexOf('img') >= 0) {
			aTag.className += " noBorderBottom";
		}
	});

	if (externalURL != "") {	
		iFrm = new Element('iframe', {
			'src': externalURL,
			'frameborder': "0",
			'marginheight': "0",
			'marginwidth': "0",
			'class': "loading"
		});

		iFrm.injectInside($('main_content').set('html', ''));

		setDimension();

		iFrm.addEvent('load', function(e) {
			iFrm.className="";
		});					
		dimensionInterval = window.setInterval("setDimension()", 150);
	} else {
		$('main_content').className = "max";
		window.onresize = setDimension;
		setDimension();
	}
	
	btu_scroller = $('btu_scroller');
	if (btu_scroller && btu_scroller.get("html") != "") {
		btu_scroller.setStyle('visibility', 'visible');
		var is_MARQUEE = (btu_scroller && btu_scroller.nodeName == "MARQUEE");
		if (!is_MARQUEE) {
			var btu_mooquee = new mooquee(btu_scroller, {
				marHeight: 25,
				marWidth: '100%',
				marSpacing: 10,
				speed: 25,
				pause: 150000,
				steps: 1,
				direction: 'left', // left | right | top | bottom
				pauseOnOver: true,
				pauseOnLinksOnly: true
			});
		}

		btu_scroller.addEvents({
			'mouseenter': function(){
			    btu_scroller.setStyles({
					'color': '#C2DEEF'
				});
				if (is_MARQUEE) btu_scroller.scrollDelay=100000;
			},
			'mouseleave': function(){
			    btu_scroller.setStyles({
					'color': ''
				});
				if (is_MARQUEE) btu_scroller.scrollDelay=100;
			}
		});
	}
	// alert($(document.body).getScrollSize().y + "/" + $(document.body).getCoordinates().height);
	
}

function setDimension() {
	var _coords1 = $("helper_layer").getCoordinates();
	var doboScroll = $(document.body).getScrollSize();
	var doboCoords = $(document.body).getCoordinates();
	var isIE6 = (typeof $('main_content').style.maxWidth == "undefined");
	var _h_extra = doboScroll.y - doboCoords.height;
	var _w_extra = doboScroll.x - doboCoords.width;
	if (iFrm) {

		if (isIE6) {
			_h_extra = (_h_extra >= 20) ? 20 : 0;
			if (_w_extra > 0) _h_extra -= 20; // vertical scrollbar is visible
		} else {
			_h_extra = (_h_extra > 0) ? 20 : 0;
		}

		var _w = _coords1.width -221 -25;
		var _h = _coords1.height -150 -15 + _h_extra;
		$('main_content').setStyles({'padding': '10px 0 0 10px' }).className="";
		iFrm.setStyles({
			'width': _w + "px",
			'height': _h + "px"
		});
	} else if (isIE6) { 
		var _w = doboCoords.width -221 -35;
		_w = (_w < 862) ? _w + 'px' : '872px';
		$('content_data').setStyles({'width': _w }).className="";
	} else {
		var _w = doboCoords.width -221 -25 - _w_extra;
		_w = (_w < 862) ? _w + 'px' : '872px';
		$('main_content').setStyles({'width': _w }).className="";
	}
}

function TrimString(trimString) {
	trimString = String(trimString).replace(/^\s+/g, "");
	return trimString.replace(/\s+$/g, "");
}

window.addEvent("domready", __init__);

