// JavaScript Document
var move;
var f = 100;
var tf = 0;

for(var i=0;i<buts.length-1;i++){
	var buff= new Image();
	buff.src='images/but_'+i+'_o.png';	
}


window.onload=function(){
	for(var i=0;i<buts.length;i++){
		var but=new getObj('but_'+i);
		if(i!=buts.length-1){
			but.obj.target=buts[i][0];
			but.obj.cs=100;
			but.obj.onmouseover=butIn;
			but.obj.onmouseout=butOut;
			if(i && i<4){
				but.obj.onmouseup=reOrg;
			}
			
		}
		but.style.top=buts[i][3]+'px';
		but.style.left=buts[i][4]+'px';
		but.obj.state=0;
		but.obj.nr=i;
	}
}

function butIn(){
	var im=this.getElementsByTagName("img")[0];
	im.src='images/but_'+this.nr+'_o.png';
	if(this.state){
		this.style.zIndex=1000;
		this.ts=((this.nr)? 100 : 70);;
		clearInterval(this.sc);
		this.sc=setInterval('scale('+this.nr+')',40);
	}
}

function butOut(){
	var im=this.getElementsByTagName("img")[0];
	im.src='images/but_'+this.nr+'.png';
	if(this.state){
		this.ts=((this.nr)? 70 : 50);
		clearInterval(this.sc);
		this.sc=setInterval('scale('+this.nr+')',40);
	}
}

function reOrg(){
	
	loadSite(this.target);
	if(!this.state){
		rs = new Array( 1, 2, 3, 4, 5);
		for(var i=0;i<buts.length;i++){
			var but=new getObj('but_'+i);
			but.obj.ty =  ((i)? Math.floor(Math.random()*60) : -Math.floor(Math.random()*30));
			but.obj.ts=((i)? 70 : 50);
			but.obj.onmouseover=null;
			but.obj.onmouseout=null;
			but.obj.r=((i)? getMyR() : 0);
			but.obj.tl=but.obj.r*160+Math.floor(Math.random()*30);
		}
		move=setInterval('moveUp()',40);
	}
}

function resetScroll(){
window.scrollTo(0,0);
}

function moveUp(){
	df = (tf-f)/1.9;
	if (Math.abs(df)>0.5) {
	f += df;
		moveButs(f);
	} else {
		f=tf;
		moveButs(f);
		for(var i=0;i<buts.length;i++){
			var but=new getObj('but_'+i);
			if(i!=buts.length-1){
				but.obj.onmouseover=butIn;
				but.obj.onmouseout=butOut;
				but.obj.onmouseout();
				but.obj.cs=((i)? 70 : 50);
			}
			but.obj.state=1;
		}
		clearInterval(move);
	};
}

function moveButs(f){
	for(var i=0;i<buts.length;i++){
		var a=new getObj('but_'+i);
		var x=f/100;
		var bw=buts[i][1]*(a.obj.ts/100);
		var bwt=((a.obj.ts/100)*x)*buts[i][1];
		var bh=buts[i][2]*(a.obj.ts/100);
		var bht=((a.obj.ts/100)*x)*buts[i][2];
		a.style.width=Math.round(bw+bwt)+'px';
		a.style.height=Math.round(bh+bht)+'px';
		a.style.top=a.obj.ty+Math.round((parseInt(a.style.top)*x))+'px';
		a.style.left=a.obj.tl+Math.round((parseInt(a.style.left)*x))+'px';
		var im=a.obj.getElementsByTagName("img")[0];
		im.width=Math.round(bw+bwt);
		im.height=Math.round(bh+bht);
	}
}


function scale(nr){
	var nm='but_'+nr;
	var a=new getObj(nm);
	var im=a.obj.getElementsByTagName("img")[0];
	var ds = (a.obj.ts-a.obj.cs)/3;
	if (Math.abs(ds)>0.7) {
		a.obj.cs += ds;
		var f=a.obj.cs/100;
		a.style.width=Math.round(buts[nr][1]*f)+'px';
		a.style.height=Math.round(buts[nr][2]*f)+'px';
		im.width=Math.round(buts[nr][1]*f);
		im.height=Math.round(buts[nr][2]*f);
	} else {
		a.obj.cs=a.obj.ts;
		if(a.obj.ts<100){
			a.style.zIndex=0;
		}
		clearInterval(a.obj.sc);
	}
}

function getMyR() {
	if (rs.length>1) {
		r = Math.floor(Math.random()*(rs.length));
		r = rs[r];
		temp = new Array();
		for (var i = 0; i<rs.length; i++) {
			if (rs[i] != r) {
				temp.push(rs[i]);
			}
		}
		rs = temp;
	} else {
		r = rs[0];
	}
	return r;
}

function getWindowHeight() {
	var windowHeight=0;
	if (typeof(window.innerHeight)=='number') {
		windowHeight=window.innerHeight;
	} else {
		if (document.documentElement&&
			document.documentElement.clientHeight) {
			windowHeight=document.documentElement.clientHeight;
		} else {
			if (document.body&&document.body.clientHeight) {
				windowHeight=document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}

function getObj(name)
{
  if (document.getElementById)
  {
  	this.obj = document.getElementById(name);
	this.style = document.getElementById(name).style;
  }
  else if (document.all)
  {
	this.obj = document.all[name];
	this.style = document.all[name].style;
  }
  else if (document.layers)
  {
   	this.obj = document.layers[name];
   	this.style = document.layers[name];
  }
}


