/*
 * $Revision: 1.19 $, $Date: 2008/12/17 09:44:52 $
 */

function detect_browsers() {
	isDOM = (document.getElementById) ? 1:0; // DOM1 browser (MSIE 5+, Netscape 6, Opera 5+)
	Explorer4 = (document.all && document.all.item) ? 1:0; // Microsoft Internet Explorer 4+
	Netscape = (document.layers) ? 1:0; // Netscape 4.*
	Opera = (window.opera) ? 1:0; // Opera
	Opera5 = (Opera && isDOM) ? 1:0; // Opera 5+
	Explorer5 = (isDOM && Explorer4) ? 1:0; // MSIE 5+
	Konqueror = (isDOM && navigator.appName == 'Konqueror'); // Konqueror
	Mozilla = (isDOM && !Explorer4 && !Opera) ? 1:0; // Mozilla & Netscape 6.*
}

// defines initial offset
var Yb = 0;

//
function init_window_refs() {
	// browser window properties
	if (Explorer5) {
		sliding.Yp = function() { return document.body.scrollTop }
		sliding.winWidth = function() { return document.body.clientWidth }

	} else if (Netscape || Mozilla || Opera5 || Opera || Konqueror) {
		sliding.Yp = function() { return window.pageYOffset }
		sliding.winWidth = function() { return window.innerWidth }
	}

	// browser specific left offset
	if (Konqueror || Opera5) {
		sliding.leftOffset = 0;
	} else if (Netscape) {
		sliding.leftOffset = -6;
	} else if (Mozilla) {
		sliding.leftOffset = -8;
	} else if (Opera) {
		sliding.leftOffset = 8;
	} else {
		sliding.leftOffset = 0;
	}

	sliding.getLeftOffset = function() {
		var w = sliding.winWidth();
		w = (w < sliding.maxWinWidth) ? sliding.maxWinWidth : w;
		return Math.floor((w / 2) + sliding.fromCenter) + sliding.leftOffset;
	}
}

/**
 * should be called after 'sliding' layer has been created
 */
function init_object_refs() {
	// get layer ref to style object
	if (Explorer5) {
		sliding.style = document.all.sliding.style;

	} else if (Netscape) {
		sliding.style = document.sliding;

	} else if (Opera5 || Opera || Mozilla || Konqueror) {
		sliding.style = document.getElementById('sliding').style;
	}

	// layer top and left properties
	if (Explorer5) {
		sliding.top = function(v) { if (v) sliding.style.pixelTop = v; return sliding.style.pixelTop; }
		sliding.left = function(v) { if (v) sliding.style.pixelLeft = v; return sliding.style.pixelLeft; }

	} else if (Netscape || Opera5 || Opera || Mozilla || Konqueror) {
		sliding.top = function(v) { if (v) sliding.style.top = v; return sliding.style.top; }
		sliding.left = function(v) { if (v) sliding.style.left = v; return sliding.style.left; }
	}

	// function to add top offset
	if (!Mozilla && !Konqueror && !Opera) {
		sliding.addTopOffset = function(v) { sliding.top(sliding.top() + v); }
	} else {
		sliding.addTopOffset = function(v) { sliding.top((parseInt(sliding.top()) + v) + 'px'); }
	}

	if (Explorer5) {
		sliding.winHeight = function() {
			if( document.body.scrollHeight > document.body.offsetHeight ) {return document.body.scrollHeight;
			} else {return document.body.offsetHeight + document.body.offsetTop;}
		}
	} else if (Netscape || Mozilla || Opera5 || Opera || Konqueror) {
		sliding.winHeight = function() {
			if (Konqueror || navigator.appName == 'Netscape' || Opera) {return document.body.scrollHeight;}
			else {return window.innerHeight + window.scrollMaxY;}
		}
	}
}

// do the scrolling.
// this function may not contain any browser specific code
var Xb = 0;
function windowPos() {
	var Yp = sliding.stalled ? 0 : sliding.Yp();
	if (Yp != Yb) {
		var smooth = (Yp - Yb) / 10;

		if (smooth > 0) {
			smooth = Math.ceil(smooth);
		} else {
			smooth = Math.floor(smooth);
		}

		if (smooth > 0 && (parseInt(sliding.top()) + sliding.height) > (sliding.winHeight() - 50)) {
			return;
		}

		sliding.addTopOffset(smooth);
		Yb += smooth;
	}

	var w = sliding.winWidth();
	if (Xb != w) {
		sliding.left(sliding.getLeftOffset());
		Xb = w;
	}
}

function sliding_start() {
	detect_browsers();
	init_window_refs();

	var locationX = sliding.getLeftOffset();
	var locationY = 6; // from page top

	// choose right element type for object
	if (Explorer5 || Mozilla || Opera5 || Opera || Konqueror) {
		htmltag = '<div ID="sliding" style="left: ' + locationX + 'px; top: ' + locationY + 'px; width: ' + sliding.width + 'px; height: ' + sliding.height + 'px; position: absolute;">' + sliding.banner + '</div>';

	} else if (Netscape) {
		// FIXME: the sliding.banner may contain IFRAME for flash banner, which is incompatible with Netscape4
		htmltag = '<layer name="sliding" left="' + locationX + '" top="' + locationY +'" width="' + sliding.width + '" height="' + sliding.height + '" >' + sliding.banner + '</layer>';
	}

	document.write (htmltag);
	init_object_refs();

	window.setInterval('windowPos()', 25);
}

if (screen.width > sliding.screenMinWidth && sliding.banner) {
	sliding_start();
}

