PulldownLayer = function(trigger, layer)
{
	var Event = net.curoko.Event;
	var Element = net.curoko.Element;
	
	//initialize
	if(typeof(trigger)=="string")
	{
		trigger = document.getElementById(trigger);
		//console.log(trigger);
	}
	if(typeof(layer)=="string")
	{
		layer = document.getElementById(layer);
		//console.log(layer);
	}
	var modifiedTop = 0;
	var modifiedLeft = 0;
	var tBounds = Element.getBounds(trigger);
	var lBounds = Element.getBounds(layer);
	//console.log(layer.offsetWidth);
	var layerBaseWidth = layer.offsetWidth;
	var layerBaseHeight = layer.offsetHeight;
	layer.style.position = "absolute";
	layer.style.overflow = "hidden";
	layer.style.zIndex = 999;
	//console.log( trigger.offsetWidth );
	layer.style.left = tBounds.right - trigger.offsetWidth +"px";
	layer.style.top = tBounds.bottom +"px";
	lBounds = Element.getBounds(layer);//require to get bounds again
	layer.style.height = 0;
		
	var timer;//unique timer
	var slideLayer = function(distination, ratio){
		var current = layer.offsetHeight;
		layer.style.display = "block";
		//console.log(layer.offsetHeight);
		if (timer) clearInterval(timer);
		timer = setInterval(function(){
			var distance = distination - current;
			current += distance * ratio;
			layer.style.height = current + "px";
			//console.log(layer.style.height);
			if (Math.abs(distance) < 1 / ratio) {
				clearInterval(timer);
				current = distination;
				layer.style.height = current + "px";
				if (current == layerBaseHeight) 
					lBounds = Element.getBounds(layer);
			}
		}, 33);
	}
	this.onMouseMove = function(e)
	{
		var tOutBound = !(tBounds.left < e.clientX && e.clientX < tBounds.right && tBounds.top < e.clientY && e.clientY < tBounds.bottom);
		var lOutBound = !(lBounds.left < e.clientX && e.clientX < lBounds.right && lBounds.top < e.clientY && e.clientY < lBounds.bottom);
		//console.log(tOutBound+","+lOutBound);
		if (tOutBound && lOutBound) {
			//console.log("out");
			slideLayer(0, 0.5);
			Event.removeListener(document, "mousemove", "onMouseMove", this);
		}
	}
	this.extendLayer = function(e)
	{
		//console.log("extend");
		Event.addListener(document, "mousemove", "onMouseMove", this);
	}
	this.relocate = function()
	{
		var tBounds = Element.getBounds(trigger);
		var lBounds = Element.getBounds(layer);
		layer.style.left = tBounds.right - trigger.offsetWidth + modifiedLeft + "px";
		layer.style.top = tBounds.bottom + modifiedTop + "px";
	}
	this.showLayerFunc = function(){ slideLayer(layerBaseHeight, 0.5); }
	//this.initialize = function(trigger, layer)
	//{
		//
	//}
	this.modifyLayer = function(top, left)
	{
		if(top) modifiedTop = top;
		if(left) modifiedLeft = left;
		this.relocate();
	}
	Event.addListener(trigger, "mouseover", "showLayerFunc", this);
	Event.addListener(trigger, "mouseout", "extendLayer", this);
	Event.addListener(window, "resize", "relocate", this);
	
};
