var myTimer;
var isOver  = false;
var wid;
var ok;
var hlink;
var cur;
var elem;
var mx;
var started=false;

var counter=0;

function Clicked(){
	document.location='http://yandex.ru/';
}
function PressHlink(){
	//document.location=hlink;
	Press();
}
function FadeIn(el){
	elem = el;
	if(counter<100)
	{
		counter+=10;
		el.style.opacity=counter/100;
		el.style.filter='alpha(opacity='+counter+')';
		setTimeout("FadeIn(elem)", 15);
	}
}
function FadeOut(el){
	elem = el;
	if(counter>0)
	{
		counter-=10;
		el.style.opacity=counter/100;
		el.style.filter='alpha(opacity='+counter+')';
		setTimeout("FadeOut(elem)", 15);
	}
	else
	{
		el.style.display='none';
	}
}
function Press(){
	cur.className='button_pressed';
	setTimeout("UnPress()", 200);
}
function UnPress(){
	cur.className='button';
}
function MoveBgOut(){
	if(wid>-510){
		cur.style.backgroundPosition=wid;
		wid-=10;
		myTimer = setTimeout("MoveBgOut(cur)",10);
	}
}function getwindow() {
 var d = document, v = window, w, h, l, t;
 if( typeof v.innerWidth==='number' ) {
  w = v.innerWidth;
  h = v.innerHeight;
  l = v.pageXOffset;
  t = v.pageYOffset;
 } else if( ( v = d.documentElement ) &&
   typeof v.clientWidth==='number' &&
   v.clientWidth !== 0 || ( v = d.body ) ) {
  w = v.clientWidth;
  h = v.clientHeight;
  l = v.scrollLeft;
  t = v.scrollTop;
 }
 return {w: w, h: h, l: l, t: t};
}

function getmouse( e ) {
  e = e || window.event || {};
  var moux, mouy, w = getwindow(),
   minx = w.l,
   miny = w.t,
   maxx = w.w + w.l,
   maxy = w.h + w.t;
  if( typeof e.pageX==='number' ) {
    moux = e.pageX;
    mouy = e.pageY;
  } else {
    moux = e.x + w.l;
    mouy = e.y + w.t;
  }
  mx=moux;
}
if( window.captureEvents ) { window.captureEvents( Event.MOUSEMOVE ); }
window.onscroll = getmouse;
window.onresize = getmouse;
window.document.onmousemove = getmouse;

	


function StartBg(scur, l) {
	ok=false;
	cur=scur;
	hlink=l;
	cur.style.backgroundImage='url(bg.jpg)';
	cur.style.backgroundRepeat='no-repeat';
	cur.style.backgroundPosition=-500;
	wid=-500;
	myTimer = setTimeout("MoveBg(cur)",100);
}
function getWidth(el) {
   var w = el.offsetWidth;
   return w;
}
function getAbsPos(el) {
   var r = { x: el.offsetLeft, y: el.offsetTop };
   if (el.offsetParent)
   {
       var tmp = getAbsPos(el.offsetParent);
       r.x += tmp.x;
       r.y += tmp.y;
   }
   return r;
}
function MoveBg(cur){
	if(wid<-500+getWidth(cur)+10){
		cur.style.backgroundPosition=wid;
		wid+=10;
		myTimer = setTimeout("MoveBg(cur)",30);
	}
	else
	{
		cur.style.backgroundImage='none';
		PressHlink();
	}
}
function StopBg(){
	clearTimeout(myTimer);
	MoveBgOut();
}




function HideRight() {
	if (!isOver) { 
		counter=100;
		FadeOut(document.getElementById('go'));
	}
}
function OverRight() { 
	clearTimeout(myTimer); 
	isOver = true; 
	counter=100;
	FadeOut(document.getElementById('go'));
	PressHlink();
}
function StopRight() { 
	clearTimeout(myTimer);
	isOver = false; 
	myTimer = setTimeout("HideRight()",100);
}
function StartRight(scur, l){
	cur=scur;
	hlink=l;
	clearTimeout(myTimer);
	isOver=true;
	var r = getAbsPos(cur);
	var gobut = document.getElementById('go');
	gobut.style.display='inline';
	gobut.style.top = r.y;
	gobut.style.left=r.x+getWidth(cur); 
	counter=0;
	FadeIn(gobut);
}


function StartMove(scur, l) {
	cur=scur;
	hlink=l;
	cur.style.backgroundImage='url(bg.jpg)';
	cur.style.backgroundRepeat='no-repeat';
	cur.style.backgroundPosition=-500;
	wid=-500;
}
function OveringMove() {
	if(wid<-500+getWidth(cur)+10){
		cur.style.backgroundPosition=wid;
		wid+=2;
	}
	else
	{
		wid=-500;
		cur.style.backgroundImage='none';
		PressHlink();
	}
		
}
function StopMove(){
	MoveBgOut();
}


function StartMouse(scur, l) {
	cur=scur;
	hlink=l;
	var pos = getAbsPos(cur);
	if(mx-pos.x<5) started=true;
	cur.style.backgroundImage='url(bg.jpg)';
	cur.style.backgroundRepeat='no-repeat';
	cur.style.backgroundPosition=-500;
	wid=-500;
}
function OveringMouse() {
	//var mouse = getmouse();
	if(started)
	{
		var pos = getAbsPos(cur);
		var bgpos = mx-pos.x-500;
		if((bgpos<getWidth(cur)-500))
		{
			if(started) cur.style.backgroundPosition=bgpos;
			wid=bgpos;
		}
	}
		
}
function StopMouse(){
	if(wid+500>=getWidth(cur)-10)
	{
		PressHlink();
		cur.style.backgroundImage='none';
	}
	else
	{
		MoveBgOut();
	}
	started=false;
}

