/***********************************************
*               MSAPI JS ScrollBox             *
*                                              *
*   Ver.: 1.0.61113                            *
*   Author: Alexandr Majorov                   *
*   Contact: ICQ 827159                        *
*            mailto: majorsoft@majorsoft.ru    *
*----------------------------------------------*
*                www.MAJORSOFT.ru              *
***********************************************/

window.onerror = null;

var topMargin = 115;
var Duration = 1000;

var B_NS6 = (!document.all && document.getElementById);
var B_NS4 = (document.layers);
var B_IE4 = (document.all);

function SBox_LayerObject(id,center){
	if (B_NS6){
		this.obj = document.getElementById(id).style;
		this.obj.center = center ;
		return this.obj;
	}else if(B_IE4){
		this.obj = document.all[id].style;
		this.obj.center = center ;
		return this.obj;
	}else if(B_NS4){
		this.obj = document.layers[id];
		this.obj.center= center ;
		return this.obj;
	}
}

function SBox_SetLayer(){
	floatLyr = new SBox_LayerObject('ScrollBox', pageWidth * .111);
	window.setInterval("SBox_main()", 10)
}

function SBox_ObjectFloat(){
	if (B_NS4 || B_NS6){
		findHt = window.innerHeight;
	} else if(B_IE4){
		findHt = document.body.clientHeight;
	}
}

function SBox_main(){
	if (B_NS4){
		this.currentY = document.layers["ScrollBox"].top;
		this.scrollTop = window.pageYOffset;
		SBox_mainTrigger();
	}else if(B_NS6){
		this.currentY = parseInt(document.getElementById('ScrollBox').style.top);
		this.scrollTop = scrollY;
		SBox_mainTrigger();
	} else if(B_IE4){
		this.currentY = ScrollBox.style.pixelTop;
		this.scrollTop = document.body.scrollTop;
		SBox_mainTrigger();
	}
}

function SBox_mainTrigger(){
	var newTargetCoordY = this.scrollTop + this.topMargin;
	if ( this.currentY != newTargetCoordY ){
		if ( newTargetCoordY != this.targetY ){
			this.targetY = newTargetCoordY;
			SBox_StartFloating();
		}
	SBox_Animate();
	}
}

function SBox_StartFloating(){
	var now = new Date();
	this.A = this.targetY - this.currentY;
	this.B = Math.PI / ( 2 * this.Duration );
	this.C = now.getTime();
	if (Math.abs(this.A) > this.findHt){
		this.D = this.A > 0 ? this.targetY - this.findHt : this.targetY + this.findHt;
		this.A = this.A > 0 ? this.findHt : -this.findHt;
	}else {
		this.D = this.currentY;
	}
}

function SBox_Animate(){
	var now = new Date();
	var newY = this.A * Math.sin( this.B * ( now.getTime() - this.C ) ) + this.D;
	newY = Math.round(newY);
	if (( this.A > 0 && newY > this.currentY ) || ( this.A < 0 && newY < this.currentY )){
		if ( B_IE4 )document.all.ScrollBox.style.pixelTop = newY;
		if ( B_NS4 )document.layers["ScrollBox"].top = newY;
		if ( B_NS6 )document.getElementById('ScrollBox').style.top = newY + "px";
	}
}


function SBox_Menu(){
	if(B_NS6||B_NS4){
		pageWidth = innerWidth;
		pageHeight = innerHeight;
		SBox_SetLayer();
		SBox_ObjectFloat();
	}else if(B_IE4){
		pageWidth = document.body.clientWidth;
		pageHeight = document.body.clientHeight;
		SBox_SetLayer();
		SBox_ObjectFloat();
	}
}


//SBox_Menu();
