//Browser check

function Is(){ 
this.agent=navigator.userAgent.toLowerCase ();
this.major = parseInt(navigator.appVersion);
this.minor = parseFloat(navigator.appVersion);
  this.ns = ((this.agent.indexOf('mozilla')!=-1) && (this.agent.indexOf('spoofer')==-1)
  && (this.agent.indexOf('compatible') == -1) && (this.agent.indexOf('opera')==-1)
  && (this.agent.indexOf('webtv')==-1));
if (this.ns) {
	this.ns7=(this.agent.indexOf('netscape/7')!=-1);
    this.ns6=(this.agent.indexOf('netscape6')!=-1);
     }
  this.dom=(document.getElementById && document.createElement)?1:0;
  this.opera=window.opera?1:0;
  this.mac=this.agent.indexOf("Mac")>-1
  this.bw=(this.dom && !this.opera)
  return this
}
is=new Is() //Browsercheck object 

//Debug function ******************
function Err (cod, id){
var er=new Array();
er[0]='Cannot find the layer '+id+' Check IDs';
er[1]='Lost target for event.';
er[2]='Too old or unsupported browser ';
er[3]='Problems with client size';
er[4]='Cannot get coordinates of mouse';
er[5]='No images to preload?';
   		alert(er[cod]);
  return false
 }

//Setup of generic layers ********************
function divs (id){
  this.ref=document.getElementById(id); if (!this.ref) Err(0, id);
  this.css=this.ref.style;
  this.h= parseInt (this.css.height = this.ref.offsetHeight) +'px';
  this.w= parseInt (this.css.width  = this.ref.offsetWidth);
  this.x= parseInt (this.css.left =  this.ref.offsetLeft);
  this.y= parseInt (this.css.top  = this.ref.offsetTop);
   this.c=0 //Clip values
  if(is.dom  && this.css.clip) {
  this.c=this.css.clip; this.c=this.c.slice(5,this.c.length-1);
  this.c=this.c.split(' ');
  for(var i=0;i<4;i++){this.c[i]=parseInt(this.c[i])}
  }
  this.ct=this.css.clip.top||this.c[0]||0;
  this.cr=this.css.clip.right||this.c[1]||this.w||0
  this.cb=this.css.clip.bottom||this.c[2]||this.h||0;
  this.cl=this.css.clip.left||this.c[3]||0
  this.id=id;
  this.obj=id+"Obj"; eval (this.obj+"=this");
  return this
}
divs.prototype.moveIt = function(x,y){ this.x=x;this.y=y; this.css.left=x; this.css.top=y}
divs.prototype.moveBy = function(x,y){ this.x=this.x+x;this.y=this.y+y; this.css.left=this.x+x; this.css.top=this.y+y}
divs.prototype.showIt = function(){this.css.visibility="visible"}
divs.prototype.hideIt = function(){this.css.visibility="hidden"}
divs.prototype.writeIt = function (cont){this.ref.innerHTML=cont;}
divs.prototype.clipTo = function (t,r,b,l,setwidth){
			this.ct=t; this.cr=r; this.cb=b; this.cl=l
			this.css.clip="rect("+t+","+r+","+b+","+l+")";
			if(setwidth){
                		this.css.pixelWidth=this.css.width=r;
				this.css.pixelHeight=this.css.height=b
				  }
		}

   //Clipping object by ******

  divs.prototype.clipBy = function(t,r,b,l,setwidth){
   this.clipTo(this.ct+t,this.cr+r,this.cb+b,this.cl+l,setwidth)
 }

//Clip animation ************

  divs.prototype.clipIt = function(t,r,b,l,step,fn,wh){
  tstep=Math.max(Math.max(Math.abs((t-this.ct)/step),Math.abs((r-this.cr)/step)),
  Math.max(Math.abs((b-this.cb)/step),Math.abs((l-this.cl)/step)))

   if(!this.clipactive){
    this.clipactive=true; if(!wh) wh=0; if(!fn) fn=0
    this.clip(t,r,b,l,(t-this.ct)/tstep,(r-this.cr)/tstep,
    (b-this.cb)/tstep,(l-this.cl)/tstep,tstep,0, fn,wh)
    }
}

divs.prototype.clip = function(t,r,b,l,ts,rs,bs,ls,tstep,astep,fn,wh){
  if(astep<tstep){
    if(wh) eval(wh);
    astep++;
    this.clipBy(ts,rs,bs,ls,1);
    this.tim=setTimeout(this.obj+".clip("+t+","+r+","+b+","+l+","+ts+","+rs+","
      +bs+","+ls+","+tstep+","+astep+",'"+fn+"','"+wh+"')",50)
  }else{
    this.clipactive=false; this.clipTo(t,r,b,l,1);
    if(fn) eval(fn)
  }
}

//Slide animation ***********

divs.prototype.slideIt = function(endx,endy,inc,speed,limit){
  if(!this.slideactive){
    var distx = endx - this.x;
    var disty = endy - this.y
    var num = Math.sqrt(Math.pow(distx,2)+Math.pow(disty,2))/inc
    var dx = distx/num; var dy = disty/num
    this.slideactive = 1;
    this.slide(dx,dy,endx,endy,speed,limit)
    }
  }

divs.prototype.slide = function(dx,dy,endx,endy,speed,limit) {
	 if(this.slideactive&&
  (Math.floor(Math.abs(dx))<Math.floor(Math.abs(endx-this.x))||
    Math.floor(Math.abs(dy))<Math.floor(Math.abs(endy-this.y)))){
    this.moveBy(dx,dy); if (limit && this.x<=limit) this.hideIt()
    setTimeout(this.obj+".slide("+dx+","+dy+","+endx+","+endy+","+speed+","+limit+")",speed)
  }else{
    this.slideactive = 0;
	 this.moveIt(endx,endy);
  }
}


// screen size object ********
function pageSize(){
  this.width=(is.ns) ? innerWidth  : document.body.clientWidth;
  this.height=(is.ns) ? innerHeight : document.body.clientHeight;
  return ;
  }

//**************************    External page loading   *************************************

//There are separate buffers as an argument[1].
//Otherwise the different scrollobj always read the same buffer.
// Accept:
//      arguments[0]    -  Flag. 'load_page'; or 'page_loaded'
//      arguments[1]    -  Iframe as a buffer. Cannot use the same buffer. for every skroller
//                              must be separate Iframe-buffer
//      arguments[2]    - src of page to load.
//Every external page must have in body tag <id=body onload = parent.pageManager ('buffer','page_loaded')


// if only first argument specified then it loads the content from the string

        function pageManager() {
        var args = pageManager.arguments;

        // first call. Load page into Iframe
        if (args[0]=='load_page')
                document.getElementById(args[1]).src = args[2];

       //Second call page with argument: loaded into buffer
 if (args[0]=="page_loaded") {

       objs[0].css.height="auto";//force ns to resize
       objs[0].ref.innerHTML = window.frames.buffer.document.getElementById('body').innerHTML;

       //free the buffer. Actually does not work
       window.frames.buffer.document.location.href='about:blank';

      
     // Second call without argument. content is in string
 }else
     {
     objs[0].css.height="auto";//force ns to resize
     objs[0].ref.innerHTML = args[0]; //load from string

   
     }
  }
  
  





