/*mrj.effects.slide = function (params)
{
	e = mrj.newElement(e);
	e.htmlElement.style.clip = "rect(0px 30px 30px 0px)";
	//alert("SLIDE");
}*/

mrj.Element.prototype.setOpacity = function (opacity)
{
	if (mrj.isInternetExplorer())
	{
		this.htmlElement.style.filter = "alpha(opacity=" + opacity + ")";
	}
	else
	{
		this.htmlElement.style.MozOpacity = opacity / 100;
	}
}

mrj.Element.prototype.getOpacity = function ()
{
	var opacity;
	
	if (mrj.isInternetExplorer())
	{
		if (this.htmlElement.filters[0] == undefined)
			return 100;
		
		opacity = parseInt_wd(this.htmlElement.filters[0].opacity, 100)
	}
	else
	{
		if (this.htmlElement.style.MozOpacity == "")
			opacity = 1;
		else
			opacity = this.htmlElement.style.MozOpacity;
			
		opacity *= 100;
	}
	
	return opacity;
}



mrj.Element.prototype.setMask = function (left, top, width, height)
{
	var pos = this.getPos();
	if (this.mask != undefined)
	{
		pos.left += this.mask.left
		pos.top += this.mask.top
	}

	this.setPos(pos.left - left, pos.top - top); 
	this.mask = { left: left, top: top, width: width, height: height };
	this.htmlElement.style.clip = "rect( " + 
		top + "px " + 
		(left + width) + "px " +  
		(top + height) + "px " +  
		left + "px)";  
}

mrj.Element.prototype.clearMask = function ()
{
	var pos = this.getPos();
	this.setPos(pos.left + this.maskOffset.left, pos.top + this.maskOffset.top);
	this.htmlElement.style.clip = "";  
	this.maskOffset = undefined; 
}

mrj.Element.prototype.slide = function (params)
{
	var e = this;
	var hSpeed = null;
	var vSpeed = null;
	var containerSize = this.scrollContainer.getSize();
	var w = this.getWidth();
	var h = this.getHeight();

	if (params.height != undefined)
		vSpeed = (params.height > containerSize.height ? 1 : -1) * (params.vSpeed != undefined ? params.vSpeed : 3);
	
	if (params.width != undefined)
		hSpeed = (params.width > containerSize.width ? 1 : -1) * (params.hSpeed != undefined ? params.hSpeed : 3);
	
	var ch = containerSize.height;
	var cw = containerSize.width;
//	var console = document.getElementById("console");

	this.setInterval(
		"slide",
		function ()
		{
			if (vSpeed != null)
			{
				ch += ((h + 1) - ch) / vSpeed;
				
				if ((vSpeed > 0 && ch >= params.height) || (vSpeed < 0 && ch <= params.height))
				{
					ch = params.height;
					vSpeed = null;
				}
 
				e.scrollContainer.setHeight(ch);
				e.setTop(-(h - ch));
			}
			
			if (hSpeed != null)
			{
				cw += ((w + 1) - cw) / hSpeed;
				
				if ((hSpeed > 0 && cw >= params.width) || (hSpeed < 0 && cw <= params.width))
				{
					cw = params.width;
					hSpeed = null;
				}
 
				e.scrollContainer.setWidth(cw);
				e.setLeft(-(w - cw));
			}
			
			if (hSpeed == null && vSpeed == null)
			{
				e.clearInterval("slide");
			}
				
		}, 10);
}

mrj.Element.prototype.fade = function (params)
{
	var e = this;
	if (params.delay != undefined)
	{
		var delay = params.delay;
		params.delay = undefined;
		this.setTimeout("fade", function () { e.fade(params) }, delay);
		return;
	}
	
	var speed = (params.speed == undefined ? 5 : params.speed);
	var opacity = (params.opacity == undefined ? 0 : params.opacity);
	
	var curOpacity = this.getOpacity();
	var step = (opacity > curOpacity ? 1 : -1) * speed;
	
	if (step > 0 && opacity > 100) opacity = 100;
	if (step < 0 && opacity < 0) opacity = 0;
		
	this.setInterval(
		"fade",
		function ()
		{
			var newOpacity = curOpacity + step;
			if ((step > 0 && newOpacity >= opacity) || (step < 0 && newOpacity < opacity))
			{
				newOpacity = opacity;
				step = null;	
			}

			curOpacity = newOpacity;
			e.setOpacity(newOpacity);
			
			if (step == null)
			{
				if (params.onComplete != undefined) params.onComplete(e);
				e.clearInterval("fade");
			}
				
		}, 10);
}

mrj.Element.prototype.setInterval = function (id, func, interval)
{
	if (this.htmlElement.intervals == undefined) this.htmlElement.intervals = new Array();
	if (this.htmlElement.intervals[id] != undefined) this.clearInterval(id);
	this.htmlElement.intervals[id] = setInterval(func, interval);
}

mrj.Element.prototype.clearInterval = function (id)
{
	clearInterval(this.htmlElement.intervals[id]);
	this.htmlElement.intervals[id] = undefined;
}

mrj.Element.prototype.setTimeout = function (id, func, timeout)
{
	if (this.htmlElement.timeouts == undefined) this.htmlElement.timeouts = new Array();
	if (this.htmlElement.timeouts[id] != undefined) this.clearTimeout(id);
	this.htmlElement.timeouts[id] = setTimeout(func, timeout);
}

mrj.Element.prototype.clearTimeout = function (id)
{
	clearTimeout(this.htmlElement.timeouts[id]);
	this.htmlElement.timeouts[id] = undefined;
}

mrj.Element.prototype.setScrollable = function (scrollable)
{
	if (scrollable == undefined) scrollable = true;
	
	if (scrollable)
	{
		var parentElement = this.htmlElement.parentNode.mrjElement;
		this.scrollContainer = parentElement.createNestedElement("div", this);
		this.scrollContainer.htmlElement.style.overflow = "hidden";
		this.scrollContainer.htmlElement.style.position = "relative";
		this.htmlElement.style.position = "relative";
	}
	
}

