var movTime = 20;
var movTimeToHoverClose = 1000;
var movMove = 10;
var movOffsetCorrector = -2;

/**
 * MovContent
 */
function MovContent() {	
	this.container;
	this.link = new Array();
	this.className;
	this.onMove = 0;
	this.mode = "hidden";
	this.height = 0;
	
	this.init = function(cntId, linkId, hghclassext) {		
		this.container = document.getElementById(cntId);
		
		for(var lc = 0; lc < linkId.length; lc++) {
			this.link[lc] = document.getElementById(linkId[lc]);
		}
		
		this.className = this.container.className.split("_")[0];
		this.container.style.visibility = "hidden";
		this.container.style.display = "block";
		var csscltmp = this.container.className;
		this.container.className = this.className + hghclassext;
		this.height = this.getCurrentHeight();
		this.container.className = csscltmp;
		this.container.style.display = "";
		this.container.style.visibility = "";
	};
	
	this.getCurrentHeight = function() {
		var height = this.container.offsetHeight;
		if(height < 0) height = 0;
		return height;		
	};
	
	this.show = function() {
		this.onMove++;
		
		var _obj = this;
		var onMove = this.onMove;
		
		this.container.style.visibility = "hidden";
		this.container.style.overflow = "hidden";		
		this.container.style.display = "block";
		
		var currentHeight = this.getCurrentHeight();
		var steps = Math.ceil((this.height - currentHeight) / movMove);		
		
		for(var sc = 1; sc < steps; sc++) {
			var cbk = MovContent.callChangeHeight(this, currentHeight + (movMove * sc), onMove);
			setTimeout(cbk, (movTime * (sc - 1)));		
		}
		
		setTimeout(function() { _obj.open(onMove); }, (movTime * steps));
	};
	
	this.hide = function() {
		this.onMove++;
		
		var _obj = this;
		var onMove = this.onMove;
		
		var currentHeight = this.getCurrentHeight();
		var steps = Math.ceil(currentHeight / movMove);		
		
		this.container.style.visibility = "hidden";
		this.container.style.overflow = "hidden";
		this.container.style.display = "block";
		this.container.className = this.className;
		
		for(var sc = 1; sc < steps; sc++) {					
			var cbk = MovContent.callChangeHeight(this, currentHeight - (movMove * sc), onMove);
			setTimeout(cbk, (movTime * sc));		
		}
		
		setTimeout(function() { _obj.close(onMove); }, (movTime * steps));
	};
	
	this.changeHeight = function(par, onMove) {
		// alert(_obj + par + " ¦ " + onMove + " ¦ " + _obj.onMove);
		if(this.onMove == onMove) {
			this.container.style.height = par + "px";
		}
	};
	
	this.open = function(onMove) {
		if(this.onMove == onMove) {
			this.container.style.height = "";
			this.container.style.display = "block";
		}
	}
	
	this.close = function(onMove) {
		if(this.onMove == onMove) {
			this.container.className = this.className;
			this.container.style.display = "";
			this.container.style.visibility = "";
			this.container.style.overflow = "";
		}
	};
}

MovContent.callChangeHeight = function(_obj, context,context2){
	return function(){
    	_obj.changeHeight(context,context2);
  	}
}


/**
 * MoveByClick
 */
function MovByClick(cntId, linkId) {
	
	// Constructor
	this.init(cntId, linkId, "");
	this.mode = "hidden";
	for(var lc = 0; lc < this.link.length; lc++) {
		this.link[lc]._obj = this;
		this.link[lc].onclick = function() {
			if(this._obj.mode == "hidden") {
				this._obj.mode = "visible";
				this._obj.show();
			} else {
				this._obj.mode = "hidden";
				this._obj.hide();
			}
			return false;
		};
	}
}

MovByClick.prototype = new MovContent();


/**
 * MovRemoteByClick
 */
function MovRemoteByClick(cntId, linkId, rmurl) {		
	
	this.addContent = function(_obj, status, responseText) {
		if(status == 200) {	
			_obj.loaded = true;
			_obj.container.innerHTML = responseText;
			_obj.container.style.visibility = "hidden";
			_obj.container.style.overflow = "hidden";
			var kheight = _obj.height;
			_obj.container.style.height = "";
			_obj.container.className = this.className; 
			_obj.height = _obj.getCurrentHeight();
			_obj.container.style.height = kheight + "px";
			if(_obj.mode == "visible") {
				_obj.show();
			}
		} else {
			_obj.loaded = false;
			if(_obj.mode == "visible") _obj.container.className = _obj.className + "_error";			
		}
	}
	
	// Constructor
	this.loaded = false;
	this.url = rmurl;
	this.init(cntId, linkId, "_loading");
	this.mode = "hidden";
	
	for(var lc = 0; lc < this.link.length; lc++) {
		this.link[lc]._obj = this;
		
		this.link[lc].onclick = function() {
			if(this._obj.mode == "hidden") {
				this._obj.mode = "visible";
				this._obj.show();
			} else {
				this._obj.mode = "hidden";
				this._obj.hide();
			}
			return false;
		};
	}
}

MovRemoteByClick.prototype = new MovContent();

MovRemoteByClick.prototype.open = function(onMove) {
	if(this.onMove == onMove) {
		this.container.style.height = this.height;
		this.container.style.visibility = "";
		this.container.style.overflow = "";
		if(this.loaded) {
			if(this.mode == "visible") {
				this.container.className = this.className;
				this.container.style.display = "block";
			}
		} else {
			this.container.className = this.className + "_loading";
			AJAXRemote.addJob(this, this.url, this.addContent);
		}
	}
}


/**
 * MovRemoteOpenByMouseOver
 */
function MovRemoteOpenByMouseOver(cntId, linkId, rmurl) {		
	
	this.addContent = function(_obj, status, responseText) {
		if(status == 200) {	
			_obj.loaded = true;
			_obj.overflow = "hidden";
			_obj.container.innerHTML = responseText;
			if(_obj.mode == "visible") _obj.open(this._obj.onMove);
		} else {
			_obj.loaded = false;
			_obj.container.className = _obj.className + "_error";			
		}
	}
	
	// Constructor
	this.loaded = false;
	this.url = rmurl;
	this.init(cntId, linkId, "_loading");
	this.mode = "hidden";
	
	for(var lc = 0; lc < this.link.length; lc++) {
		this.link[lc]._obj = this;		
		
		this.link[lc].onmouseover = function() {
			if(this._obj.mode == "hidden") {
				this._obj.onMove++;
				this._obj.mode = "visible";
				this._obj.open(this._obj.onMove);
			} 
			return false;
		};
		
		this.link[lc].onmouseout = function() {	
			if(this._obj.mode == "visible") {
				this._obj.onMove++;
				this._obj.mode = "hidden";
				this._obj.close(this._obj.onMove);
			}
			return false;
		}
	}
}

MovRemoteOpenByMouseOver.prototype = new MovContent();

MovRemoteOpenByMouseOver.prototype.open = function(onMove) {
	if(this.onMove == onMove) {
		if(this.loaded) {
			this.container.className = this.className;
			this.container.style.display = "block";
		} else {
			this.container.className = this.className + "_loading";		
			AJAXRemote.addJob(this, this.url, this.addContent);
		}
	}
}


/**
 * MovSimpleByClick
 */
function MovSimpleByClick(cntId, linkId) {
	// Constructor
	this.init(cntId, linkId, "");
	this.mode = "hidden";
	for(var lc = 0; lc < this.link.length; lc++) {
		this.link[lc]._obj = this;
		this.link[lc].onclick = function() {
			if(this._obj.mode == "hidden") {
				this._obj.mode = "visible";
				this._obj.open(this._obj.onMove);
			} else {
				this._obj.mode = "hidden";
				this._obj.close(this._obj.onMove);
			}
			return false;
		};
	}
}

MovSimpleByClick.prototype = new MovContent();

