var browser = new browsercheck();

function browsercheck()
{
	b_version=navigator.appVersion.toLowerCase();
	b_agent=navigator.userAgent.toLowerCase();
	this.dom=document.getElementById?1:0
	this.opera5=b_agent.indexOf("opera 5")>-1
	this.ie5=(b_version.indexOf("msie 5")>-1 && this.dom && !this.opera5)?1:0;
	this.ie6=(b_version.indexOf("msie 6")>-1 && this.dom && !this.opera5)?1:0;
	this.ie7=(b_version.indexOf("msie 7")>-1 && this.dom && !this.opera5)?1:0;
	this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
	this.ie=this.ie4||this.ie5||this.ie6||this.ie7;
	this.mac=b_agent.indexOf("mac")>-1;
	this.ns6=(this.dom && parseInt(b_version) >= 5)?1:0;
	this.ns4=(document.layers && !this.dom)?1:0;
	this.ns=this.ns4||this.ns6;
	this.supported=this.ie||this.ns||this.opera5;
}

function exception(message)
{
	alert(message);
	return false
}

function layerexists(obj,nest)
{
	if(!browser.supported) return exception('unspported browser');
	nest=(!nest)?"":'document.'+nest+'.';
	evnt=browser.dom?document.getElementById(obj):browser.ie4?document.all[obj]:browser.ns4?eval(nest+"layers." +obj):0;	
	if (evnt)
	{
    return true;
	}
	else
	{
    return false;
	}
}

function instance(obj,nest)
{
	if(!browser.supported) return exception('unspported browser');
	nest=(!nest)?"":'document.'+nest+'.';
	this.evnt=browser.dom?document.getElementById(obj):browser.ie4?document.all[obj]:browser.ns4?eval(nest+"layers." +obj):0;	
	if(!this.evnt) return exception('Layer "'+obj+'" does not exist or invalid nest referance');
	this.css=browser.dom||browser.ie4?this.evnt.style:this.evnt;
	this.ref=browser.dom||browser.ie4?document:this.css.document;
	this.x=parseInt(this.css.left)||this.css.pixelLeft||this.evnt.offsetLeft||0;
	this.y=parseInt(this.css.top)||this.css.pixelTop||this.evnt.offsetTop||0;
	this.w=this.evnt.offsetWidth||this.css.clip.width||this.ref.width||this.css.pixelWidth||0;
	this.h=this.evnt.offsetHeight||this.css.clip.height||this.ref.height||this.css.pixelHeight||0;
	this.clipbounds=0;
	if((browser.dom || browser.ie4) && this.css.clip)
	{
		this.clipbounds=this.css.clip;
		this.clipbounds=this.clipbounds.slice(5,this.clipbounds.length-1);
		this.clipbounds=this.clipbounds.split(' ');
		for(var i=0;i<4;i++){this.clipbounds[i]=parseInt(this.clipbounds[i])}
	}
	this.cliptop=this.css.clip.top||this.clipbounds[0]||0;
	this.clipright=this.css.clip.right||this.clipbounds[1]||this.w||0;
	this.clipbottom=this.css.clip.bottom||this.clipbounds[2]||this.h||0;
	this.clipleft=this.css.clip.left||this.clipbounds[3]||0;
 	this.instance = obj + "Object";
 	eval(this.instance + "=this");
	
  return this
}

instance.prototype.width = function()
{
  return this.evnt.offsetWidth||this.css.clip.width||this.ref.width||this.css.pixelWidth||0
}

instance.prototype.height = function()
{
  return this.evnt.offsetHeight||this.css.clip.height||this.ref.height||this.css.pixelHeight||0
}

instance.prototype.moveTo = function(x,y)
{
	this.css.left=this.x=x;
	this.css.top=this.y=y;
}

instance.prototype.moveBy = function(x,y)
{
	this.css.left=this.x+=x;
	this.css.top=this.y+=y
}

instance.prototype.show = function()
{
  this.css.visibility="visible"
}

instance.prototype.hide = function()
{
  this.css.visibility="hidden"
}

instance.prototype.setSize = function(w,h)
{
	if (w>=0) this.css.pixelWidth=this.css.width=w;
	if (h>=0) this.css.pixelHeight=this.css.height=h;
}

instance.prototype.setBounds = function(x,y,w,h)
{
	this.moveTo(x,y);
	this.setSize(w,h);
}

instance.prototype.centerIn = function(w, h)
{
	x = (w - this.w) / 2;
	y = (h - this.h) / 2;
	if (x<0) x=0;
	if (y<0) y=0;
	this.moveTo(x, y);
}

instance.prototype.screenCenter = function()
{
	w=browser.dom?document.body.clientWidth:window.innerWidth;
	h=browser.dom?document.body.clientHeight:window.innerHeight;
	this.centerIn(w, h);
}

instance.prototype.write = function(text,startHTML,endHTML)
{
	if(browser.ns4)
	{
  	if(!startHTML){startHTML=""; endHTML=""}
		this.ref.open("text/html");
		this.ref.write(startHTML+text+endHTML);
		this.ref.close()
	}
	else
		this.evnt.innerHTML=text
}

instance.prototype.clipTo = function(top,right,bottom,left,setDimensions)
{
	this.cliptop=top;
	this.clipright=right;
	this.clipbottom=bottom;
	this.clipleft=left;
	if(browser.ns4)
	{
		this.css.clip.top=top;
		this.css.clip.right=right;
		this.css.clip.bottom=bottom;
		this.css.clip.left=left;
	}
	else
	{
		if(top<0)top=0;
		if(right<0)right=0;
		if(bottom<0)bottom=0;
		if(left<0)left=0;
		this.css.clip="rect("+top+","+right+","+bottom+","+left+")";
		if(setDimensions) this.setSize(right,bottom);
	}
}

instance.prototype.clipBy = function(top,right,bottom,left,setDimensions)
{
	this.clipTo(this.cliptop+top,this.clipright+right,this.clipbottom+bottom,this.clipleft+left,setDimensions)
}

instance.prototype.clip = function(top,right,bottom,left,topstep,rightstep,bottomstep,leftstep,count,counter,onfinish,onprogress,interval)
{
	if(counter<count)
	{
		if(onprogress) eval(onprogress);
		counter++
		this.clipBy(topstep,rightstep,bottomstep,leftstep,1);
		this.cliptimer=setTimeout(this.instance+".clip("+top+","+right+","+bottom+","+left+","+	topstep+","+rightstep+","+bottomstep+","+leftstep+","+
			count+","+counter+",'"+onfinish+"','"+onprogress+"',"+interval+")",interval);
	}
	else
	{
		this.clipactive=false;
		this.clipTo(top,right,bottom,left,1);
		if(onfinish) eval(onfinish)
	}
}

instance.prototype.clipTill = function(top,right,bottom,left,step,onfinish,onprogress,interval)
{
	count=Math.max(Math.max(Math.abs((top-this.cliptop)/step),Math.abs((right-this.clipright)/step)),
		Math.max(Math.abs((bottom-this.clipbottom)/step),Math.abs((left-this.clipleft)/step)))
	if (this.clipactive) this.stopclip();
	this.clipactive=true;
	theinterval=interval?interval:40;
	this.clip(top,right,bottom,left,(top-this.cliptop)/count,(right-this.clipright)/count,
		(bottom-this.clipbottom)/count,(left-this.clipleft)/count,count,0,onfinish,onprogress,theinterval)
}

instance.prototype.stopclip = function()
{
	if (this.cliptimer&&this.clipactive)
	{
		this.clipactive=false;
		clearTimeout(this.cliptimer);
	}
}

instance.prototype.slide = function(x,y,xstep,ystep,onfinish,onprogress,interval)
{
	if (this.slideactive&&
		(Math.floor(Math.abs(xstep))<Math.floor(Math.abs(x-this.x))||
		 Math.floor(Math.abs(ystep))<Math.floor(Math.abs(y-this.y))))
	{
		this.moveBy(xstep,ystep);
		if(onprogress) eval(onprogress);
		this.slidetimer=setTimeout(this.instance+".slide("+x+","+y+","+xstep+","+ystep+",'"+onfinish+"','"+onprogress+"',"+interval+")",interval);
	}
	else
	{
		this.slideactive=false;
		this.moveTo(x,y);
		if(onfinish) eval(onfinish)
	}
}

instance.prototype.slideTill = function(x,y,step,onfinish,onprogress,interval)
{
	if (this.slideactive) this.stopslide();
	xdistance=x-this.x;
	ydistance=y-this.y;
	distance=Math.sqrt(Math.pow(xdistance,2)+Math.pow(ydistance,2));
	count=distance/step;
	xstep=(xdistance)/count;
	ystep=(ydistance)/count;
	theinterval=interval?interval:40;
	this.slideactive=true;
	this.slide(x,y,xstep,ystep,onfinish,onprogress,theinterval)
}

instance.prototype.stopslide = function()
{
	if (this.slidetimer&&this.slideactive)
	{
		this.slideactive=false;
		clearTimeout(this.slidetimer);
	}
}

instance.prototype.examextent = function(w, h, restore)
{
	if (restore)
	{
		savew=w;
		saveh=h;
		this.setSize(w,h);
		if (this.width()>w||this.height()>h) result=true; else result=false;
		this.setSize(savew,saveh);
	}
	else
	{
		this.setSize(w,h);
		if (this.width()>w||this.height()>h) result=true; else result=false;
	}
	return result;
}

instance.prototype.initializescroll = function(container,kind,floor,ceil,step,stride,interval)
{
	w=container.width();
	h=container.height();
	container.clipTo(0, w, h, 0, false);
	container.css.overflow='hidden';
	kind=kind?kind:'vertical';
	floor=floor?floor:0;
	ceil=ceil?ceil:0;
	if (kind=='horizental')
	{
		this.scrollkind='horizental';
		this.setBounds(0,floor,-1,h-floor-ceil);
		this.limit=w-this.width();
	}
	else
	{
		this.scrollkind='vertical';
		this.setBounds(floor,0,w-floor-ceil,-1);
		this.limit=h-this.height();
	}
	this.show();
	this.scrollstep=step?step:4;
	this.scrollstride=stride?stride:12;
	this.scrollinterval=interval?interval:40;
}

instance.prototype.scroll = function(grow,fast)
{
	if (this.limit>0) return false;
	if (this.scrollkind=='vertical')
	{
		x=this.x;
		y=grow?this.limit:0;
	}
	else
	{
		x=grow?this.limit:0
		y=this.y;
	}
	slidestep=fast?this.scrollstride:this.scrollstep;
	this.slideTill(x,y,slidestep,null,null,this.scrollinterval);
}

instance.prototype.stopscroll = function()
{
	this.stopslide()
}

