function LayerCollection()
{
   this.length = 0;
   for (var i = 0; i < arguments.length; i++)
   {
      var obj = getObj(arguments[i]);
      this[arguments[i]] = obj;
      this[this.length++] = obj;
   }
}

function getObj(layerName)
{
   if (document.layers)
   {
      var obj = new Object();
      var lObj =  document.layers[layerName];
      obj.style = lObj;
      obj.offsetHeight = lObj.clip.height;
      obj.offsetLeft = lObj.clip.left;
      return obj;
   }
   if (document.all)
      return document.all[layerName];
   if (document.getElementById && document.getElementsByTagName)
      return document.getElementById(layerName);
   if (document.getElementById && !document.getElementsByTagName)
   {
      var obj = new Object();
      var obj = document.getElementById(layerName);
      obj.offsetHeight =  document.getElementById(layerName).style.pixelHeight;
      obj.offsetLeft =  document.getElementById(layerName).style.pixelLeft;
      return obj;
   }
}

var visibleHeight = 0;
var contTop   = 100;
var startTop = 100;
var maxTop = 100;
var minTop;
var contHeight;
var scrollableHeight;
var Layers;
var interv;
var y;
var x;
var lastscroll;
var anonsheight = 260;
var footheight = 170;
var obLeft;


function init() {
if (self.innerHeight) {
x=self.innerWidth;
y=self.innerHeight; } // ns
else if (document.documentElement && document.documentElement.clientHeight) {
x = document.documentElement.clientWidth;
y = document.documentElement.clientHeight;} // ie6 strict
else if (document.body) {
x = document.body.clientWidth;
y = document.body.clientHeight;} // other ie

visibleHeight=y;
Layers = new LayerCollection('cont', 'b01', 'b02', 'b03', 'b04', 'box0', 'a02', 'menu_v', 'a', 'flash', 'arrows');
//Layers = new LayerCollection('cont', 'b', 'box0', 'a02', 'menu_v', 'a', 'flash');

contHeight = Layers['cont'].offsetHeight;
vHeight = Layers['menu_v'].offsetHeight;
obLeft = Layers['box0'].offsetLeft;

Layers['b01'].style.left = obLeft + "px";
Layers['b04'].style.left = obLeft + "px";
Layers['b02'].style.left = obLeft + 230 + "px";
Layers['b03'].style.left = obLeft + 850 - 140 + "px";

Layers['menu_v'].style.top = y - footheight - 50 - anonsheight - vHeight  +  "px";
Layers['box0'].style.height = y - 10 + "px";
Layers['a'].style.height = (y - 105) + "px";
Layers['a02'].style.height = (y - 105) + "px";
Layers['flash'].style.top = ((y-170)/2)-228 + "px";
Layers['b01'].style.top = y - 180 + "px";
Layers['b02'].style.top = y - 105 + "px";
Layers['b04'].style.top = y - 105 + "px";
Layers['b03'].style.top = y - 180 + "px";

minTop = maxTop - contHeight  + visibleHeight -  maxTop - 120;

if (contHeight < visibleHeight-200)
	{
	Layers['arrows'].style.display = "none";
	Layers['arrows'].style.width = "0px";
	}

if ( y < 630) {
minTop =  maxTop - contHeight  + visibleHeight - maxTop - (y-500);
Layers['menu_v'].style.top = 630 - footheight - 50 - anonsheight - vHeight +"px";
Layers['flash'].style.top = 4 + "px";
}

if ( y < 460 ) { minTop =  maxTop - contHeight  + 460 - maxTop; }
scrollableHeight = maxTop - minTop;

if ( y < 630 ) {
Layers['box0'].style.height = "620px";
Layers['b01'].style.top = "470px";
Layers['b04'].style.top = "545px";
Layers['b02'].style.top = "545px";
Layers['b03'].style.top = "470px";
Layers['a'].style.height = "555px";
Layers['a02'].style.height = "555px";
}
}


//////////////////////// ON RESAZE FUNCTION //////////////// NEED ADDS!!!!!!!
function follow_y() {
if (y >=contHeight + contTop &&  y > lastscroll && contTop < 0 ) {
Layers['cont'].style.top = (y - contHeight)+"px" ;
}
if (y>=contHeight) { lastscroll=contHeight;}
if (y >=  contHeight ) {
visibleHeight = contHeight;
Layers['cont'].style.top = "100px";
} else { visibleHeight= y;}
}
/////////////////////// END

function startScroll(direction) {
scroll(direction);
interv = setInterval('scroll(' + direction + ')', 20);
}

function stopScroll() {
if (interv)
clearInterval(interv);
lastscroll=contTop+minTop;
}

function startScrollSpeed(direction, speed) {
scrollSpeed(direction, speed);
interv = setInterval('scroll(' + direction + ')', 20);
}

function stopScroll() {
if (interv)
clearInterval(interv);
lastscroll=contTop+minTop;
}

function scrollSpeed (direction, speed, relativePosition)
{
if ( contHeight > y - 220 )
	{
	if (!relativePosition)
		contTop += parseInt(direction) * speed;
	else
		contTop = relativePosition;
	if (contTop > maxTop)
		{
		contTop = maxTop;
		stopScroll();
		}
	if (contTop < minTop)
		{
		contTop = minTop;
		stopScroll();
		}
	Layers['cont'].style.top = contTop + "px";
	return false;
	}
}


function scroll(direction, relativePosition)
{
if ( contHeight > y - 220 )
	{
	if (!relativePosition)
		contTop += parseInt(direction) * 16;
	else
		contTop = relativePosition;
	if (contTop > maxTop)
		{
		contTop = maxTop;
		stopScroll();
		}
	if (contTop < minTop)
		{
		contTop = minTop;
		stopScroll();
		}
	Layers['cont'].style.top = contTop + "px";
	return false;
	}
}

function resizey() { init(); /*follow_y();*/ }

window.onresize = resizey;