var Go = 0;
var OnIt = 0; 
var Pos = 0; var defOff = 0;
var HisWidth = 600;
var MaxWidth = 550; var OneWidth = 110;
var LastSel = 0; var topURLS = new Array();
var ToSpd = 0; var CurSpd = 0;
var VToSpd = 0; var VCurSpd = 0; 
var VLastRoll = 0; var VertRoll = 0;
var isIE = (navigator.appName.indexOf("Microsoft") !=-1);
function firstMove() {
//	var obj = document.getElementById('tops');
//	obj.onclick = "mouseclick()";
//	obj.onmouseover='mousing()' ;
//	obj.onmousemove='mousing()' ;
//	obj.onmouseout='mousedrop()';
//	defOff = obj.offsetLeft + obj.parentNode.offsetLeft + 299;
	var divPos = new ElementPosition("tops");
//	if (isIE) { alert('is IE!'); defOff -= 135; }
	defOff = divPos.x;
	secondMove();
	Go = 1;
}
function gofotogen() {
	if (!Go) return;
	var obj = document.getElementById('fotogen');
	obj.style.visibility = 'visible';
	ajax_loadContent('fotogen', '/video.html');
}
function hidefotogen() {
	if (!Go) return;
	var obj = document.getElementById('fotogen');
	obj.style.visibility = 'hidden';
}

function mousedrop() {
	if (!Go) return;
	OnIt = 0;
	if (LastSel > 0) {
		var last = document.getElementById('l'+LastSel);
		last.style.backgroundColor = "#000000";
		LastSel = 0;
	}
}
function mouseclick() {
	if (!Go) return;
//	alert('to: ' + ToSpd + '\n cur:' + CurSpd);
//	return false;
	var RealSel = LastSel;
	if (RealSel > 0) {
		while (RealSel > Math.ceil(MaxWidth / OneWidth)) {
			RealSel = RealSel - Math.ceil(MaxWidth / OneWidth);
		}
		window.location = topURLS[RealSel];
	}
}
function mousing( e ) {
	if (!Go) return;

	OnIt = 1;
	Pos = ( e.x ? e.x : e.clientX )- defOff; 

}
bigLoop();
function ElementPosition(param){
	var x=0, y=0;
	var obj = (typeof param == "string") ? document.getElementById(param) : param;
	if (obj) {
		x = obj.offsetLeft;
		y = obj.offsetTop;
		var body = document.getElementsByTagName('body')[0];
		while (obj.offsetParent && obj!=body){
			x += obj.offsetParent.offsetLeft;
			y += obj.offsetParent.offsetTop;
			obj = obj.offsetParent;
		}
	}
	this.x = x;
	this.y = y;
}
function bigLoop() {
	VToSpd = VertRoll * 10;
	if (VCurSpd != VToSpd) {
		if (VCurSpd < VToSpd) VCurSpd++;
		if (VCurSpd > VToSpd) VCurSpd--;
	}
	if (VCurSpd != 0) {
		var roll = document.getElementById('rights');
		roll.scrollTop += Math.round(VCurSpd/10);
	}
	window.status = VCurSpd;
	if (Number(CurSpd) == 'NaN') {alert('doh!');CurSpd = 0;}
	if (OnIt) {
		var middle = (HisWidth/2);// - 120;
		var gears = 1; // on / off;
		var maxspeed = 10; //hmmm...
		var dist = middle - Pos;
		var spd = Math.abs(dist) / middle;
		var way = dist / Math.abs(dist);
		var spda = spd;
		spd = Math.floor(spd * 10) * 10;
		var maxspeed = 50;
		if (spd > maxspeed) spd = maxspeed;
		ToSpd = spd * way;
	} else { ToSpd = 0; }
	if (ToSpd != CurSpd) {
		//var diff = (ToSpd - CurSpd) / Math.abs(ToSpd - CurSpd);
		if (ToSpd > CurSpd) CurSpd++;
		if (ToSpd < CurSpd) CurSpd--;
		//CurSpd += diff * 1;
	}
	if (CurSpd != 0) {
		var obj = document.getElementById('tops');
		if (CurSpd > 0 && obj.scrollLeft <= 1 ) 
			obj.scrollLeft = MaxWidth;
		if (CurSpd < 0 && obj.scrollLeft >= MaxWidth)
			obj.scrollLeft = 0;

		obj.scrollLeft -= Math.round(CurSpd/10);


		//if (MaxWidth > HisWidth) { 
		/*
		if (way == 1 && obj.scrollLeft <= 1 ) {
			obj.scrollLeft = MaxWidth;
		}
		if (way == -1 && obj.scrollLeft >= MaxWidth) {
			obj.scrollLeft = 0;
		}
		if (way) 
			obj.scrollLeft -= way * spd;
		*/
		//}

		var id = Math.round((obj.scrollLeft+Pos) / OneWidth + 0.5);
		if (LastSel != id) {
			if (LastSel > 0) {
				var last = document.getElementById('l'+LastSel);
				last.style.backgroundColor = "#000000";
				//if (last.hasChildNodes()) {
				//	var limg = last.childNodes[0];
				//	if (limg) limg.style.width = '80px';
				//}

				//last.style.borderColor = "#000000";
				//last.style.content = "url('http://www.ama.ru/layouts/images_first/norm_holder.gif')";
			}
			var obje = document.getElementById('l'+id);
			if (obje) {
				LastSel = id;
				obje.style.backgroundColor = "#f6f597";
				//if (obje.hasChildNodes()) {
				//	var imge = obje.childNodes[0];
				//	imge.style.width = '85px';
				//}
				//obje.style.content = "url('http://www.ama.ru/layouts/images_first/hl2_holder.gif')";
				//obje.style.borderColor = "#e0be90";
			}
		}
	}
	setTimeout("bigLoop()", 10);
}
