window.$=function(id)
{
	return document.getElementById(id);
}

function getTarget(e)
{
	return window.event ? window.event.srcElement : e.currentTarget;
}

function getEvent(e)
{
	return window.event ? window.event : e;
}

function show(id)
{
	if (typeof id=='string')	$(id).style.display='block';
	else id.style.display='block';
}

function hide(id)
{
	if (typeof id=='string')	$(id).style.display='none';
	else id.style.display='none';
}

function cssTransform(id, x, y, w, h)
{
	var el=id;
	if (typeof el=='string')	el=$(id);
	
	if (x)	el.style.left=''+x+'px';
	if (y)	el.style.top=''+y+'px';
	if (w)	el.style.width=''+w+'px';
	if (h)	el.style.height=''+h+'px';
}

function cssLeft(id, value)
{
	var el=id;
	if (typeof el=='string')	el=$(id);
	
	if (!el)	return false;

	if (typeof value=='undefined')
	{
		return parseInt(el.style.left.replace(/px/, ''));
	}
	
	el.style.left=''+value+'px';	
}

function cssTop(id, value)
{
	var el=id;
	if (typeof el=='string')	el=$(id);
	
	if (!el)	return false;

	if (typeof value=='undefined')
	{
		return parseInt(el.style.top.replace(/px/, ''));
	}
	
	el.style.top=''+value+'px';	
}

function cssWidth(id, value)
{
	var el=id;
	if (typeof el=='string')	el=$(id);
	
	if (!el)	return false;

	if (typeof value=='undefined')
	{
		return parseInt(el.style.width.replace(/px/, ''));
	}
	
	el.style.width=''+value+'px';	
	
	return true;
}

function cssHeight(id, value)
{
	var el=id;
	if (typeof el=='string')	el=$(id);
	
	if (!el)	return false;

	if (typeof value=='undefined')
	{
		return parseInt(el.style.height.replace(/px/, ''));
	}
	
	el.style.height=''+value+'px';	
	
	return true;
}

function cssMove(id, x, y)
{
	var el=id;
	if (typeof el=='string')	el=$(id);
	
	if (x)	el.style.left=''+x+'px';
	if (y)	el.style.top=''+y+'px';
}

function getTimer()
{
	return new Date();
}

function random(n)
{
	return Math.floor(Math.random()*n);
}

var _preload=[];
function preloadImage(url)
{
	var pre;
	
	if (typeof url=='object')
	{
		for(var i=0; i<url.length; i++)
		{
			pre=new Image();
			pre.src=url[i];
			
			_preload.push(pre);
		}
	}
	else
	{
		pre=new Image();
		pre.src=url;
		
		_preload.push(pre);		
	}
}

function preloadImages(url)	{preloadImage(url);}

function existsClass(el, clname)
{
	var cl=el.className;
	
	var reg=new RegExp('(^| )'+clname+'( |$)', 'gi');
	
	if (reg.test(cl))	return true;
	else	return false;	
}

function addClass(el, clname)
{
	if(!existsClass(el, clname))
	{
		var cl=el.className;
		var sp=' ';
		if (cl=='')	sp='';
		
		el.className+=sp+clname;
	}
}

function delClass(el, clname)
{
	if(existsClass(el, clname))
	{
		var cl=el.className;
		
		var reg=new RegExp('(^| )'+clname+'( |$)', 'gi');
		cl=cl.replace(reg, '$1');
		cl=cl.replace(/  /, ' ');
		if (cl==' ')	cl='';
		
		el.className=cl;
	}
}

function getTop(id)
{
	var e=id;
	if (typeof id=='string')	e=$(id);
	
	var il=0;

	while(e.tagName!='BODY' && e.tagName!='HTML')
	{
		il+=e.offsetTop;
		e=e.offsetParent;
	}
	il+=e.offsetTop;
	
	return il;
}

function getLeft(id)
{
	var e=id;
	if (typeof id=='string')	e=$(id);
	
	var il=0;

	while(e.tagName!='BODY' && e.tagName!='HTML')
	{
		il+=e.offsetLeft;
		e=e.offsetParent;
	}
	il+=e.offsetLeft;

	return il;
}

function setOpacity(id, value)
{
	var el=id;
	if (typeof id=='string')	el=$(id);
	
	el.style.filter='alpha(opacity='+value+')';
	el.style.opacity=value/100;
}

var _g=[];
var _glen=0;

function _gNextFrame(id)
{
	_g[id].nextFrame();

	return;
}

function Changer(iden, attr, startValue, endValue, off)
{
	this.idImg=iden;
	this.id=_g.length;
	this.attr=attr;
	this.element=$(this.idImg);

	this.startValue=startValue;
	this.endValue=endValue;
	
	this.value=this.startValue;
	
	_glen++;
	_g.push(this);

	if (startValue>endValue)	this.inc=false;
	else	this.inc=true;
	
	this.off=off;
	
	if (this.inc)
	{
		if (this.startValue==null)	this.value=0;
		if (this.endValue==null)	this.endValue=100;

		this.setValue();
		show(this.idImg);
	}
	else
	{
		if (this.startValue==null)	this.value=100;
		if (this.endValue==null)	this.endValue=0;

		this.setValue();
		show(this.idImg);

	}

	return;
}

Changer.prototype.id=null;
Changer.prototype.element=null;
Changer.prototype.timer=10;
Changer.prototype.value=0;
Changer.prototype.v=1;
Changer.prototype.endValue=null;
Changer.prototype.startValue=null;
Changer.prototype.onEnd=null;
Changer.prototype.unit='px';
Changer.prototype.a=0;
Changer.prototype.isPauseEnd=false;
Changer.prototype.pauseEnd=0;
Changer.prototype.isPauseEnd=false;
Changer.prototype.backgroundX='0';
Changer.prototype.backgroundY='0';

Changer.prototype.start=function()
{
	this.nextFrame();
}

Changer.prototype.setValue=function()
{
	var style=$(this.idImg).style;
	var gvalue=''+this.value+this.unit;
	switch(this.attr)
	{
		case 'opacity':
		{
			style.filter='alpha(opacity='+this.value+')';
			style.opacity=(this.value/100);
		}
		break;
		case 'margin-left':
			style.marginLeft=gvalue;
		break;
		case 'margin-top':
			style.marginTop=gvalue;
		break;
		case 'margin-right':
			style.marginRight=gvalue;
		break;
		case 'margin-bottom':
			style.marginBottom=gvalue;
		break;
		case 'backgroundY':
		{
			style.backgroundPosition=''+this.backgroundX+this.unit+' '+gvalue;
		}
		break;
		case 'backgroundX':
		{
			style.backgroundPosition=''+gvalue+' '+this.backgroundY+this.unit;
		}
		break;
		case 'top':
			style.top=gvalue;
		break;
		case 'left':
			style.left=gvalue;
		break;
		case 'right':
			style.right=gvalue;
		break;
		case 'bottom':
			style.bottom=gvalue;
		break;
	}
}

Changer.prototype.nextFrame=function()
{
	if (!this.isPauseEnd)
	{
		this.v+=this.a;
		if (this.inc)	this.value+=this.v;
		else	this.value-=this.v;
		if (this.inc && this.value>this.endValue)	this.value=this.endValue;
		if (!this.inc && this.value<this.endValue)	this.value=this.endValue;
		this.setValue();
		if (this.listener!=null)	this.listener();
	}
	
	if ((this.inc && this.value==this.endValue) || (!this.inc && this.value==this.endValue))
	{
		if (!this.isPauseEnd)
		{
			if (this.pauseEnd)
			{
				this.isPauseEnd=true;
				setTimeout('_gNextFrame('+this.id+');', this.pauseEnd);
			
				return;
			}
		}
		
		this.isPauseEnd=true;
		
		if (this.isPauseEnd)
		{
			this.id=null;
			_glen--;
		
			if (_glen<=0)
			{
				_glen=0;
				_g=[];
			}
			
			if (this.off)	hide(this.idImg);
			if (this.onEnd)	this.onEnd();			
		}
		
		return;
	}
	else	setTimeout('_gNextFrame('+this.id+');', this.timer);
}