//--------------------------------------------------------------------
// class foldingEdge:	folds the edge of a website
// var   class:			classname of the folding div element
//--------------------------------------------------------------------

function foldingEdge( id){
	this.htmlstatus = 0;
	this.id = id;
	this.margin = 1077;
	this.width = 50;
	this.height = 50;
	this.foldTimer = false;
	this.unfoldTimer = false;
	// animation speed 
	this.speed = 1;
	// folded width
	this.maxWidth = 440;
	// starting width
	this.minWidth = 50;
	// growing width
	this.widthGrowingRate = 10;
	// growing height
	this.heightGrowingRate = 6.5	;
	// html for the edge
	this.html = "";
}
// fold the edge
foldingEdge.prototype.fold = function(){
	if(this.width < this.maxWidth){
		// stop unfold action
		clearTimeout(this.unfoldTimer);
		
		// calc new borders
		this.margin -= this.widthGrowingRate;
		this.width += this.widthGrowingRate;
		this.height += this.heightGrowingRate;
		
		// activate background image 
		if(/*this.width > 200*/true){
			$("." + this.id).css({"background-image":"url(image/page.png)"});
			
		}
		// set new borders
		$("." + this.id).css({"width":this.width+"px","height":this.height+"px","margin-left":this.margin+"px"});	
		
		// recursive call
		var self = this;	
		this.foldTimer = setTimeout(function (){ self.fold();},this.speed);	
		
		// set HTML
		if(this.width == this.maxWidth && this.html){
			$("." + this.id)[0].innerHTML = this.html;
			this.htmlstatus = 1;
		}
	}
}
// defold the edge
foldingEdge.prototype.defold = function(){
	if(this.width > this.minWidth){
		
		// stop fold action
		clearTimeout(this.foldTimer);
		
		// reset HTML
		if(this.width == this.maxWidth){
			$("." + this.id)[0].innerHTML = "";
		}
		
		// calc new borders
		this.margin += this.widthGrowingRate;
		this.width -= this.widthGrowingRate;
		this.height -= this.heightGrowingRate;
		
		// reset background image
		if(this.width < this.minWidth+this.widthGrowingRate){
			$("." + this.id).css({"background-image":"none"});
			
		}
		
		
		
		// calculate new borders
		$("." + this.id).css({"width":this.width+"px","height":this.height+"px","margin-left":this.margin+"px"});
		
		// recursive call
		var self = this;
		this.unfoldTimer = setTimeout(function(){self.defold();},this.speed);
	}
}

foldingEdge.prototype.setHTML = function( html){
	this.html = html;
}

function checkMouseoutEvent(e){
	if (!e) var e = window.event;
	var tg = (window.event) ? e.srcElement : e.target;
	if (tg.nodeName != 'DIV') return;
	var reltg = (e.relatedTarget) ? e.relatedTarget : e.toElement;
	while (reltg != tg && reltg.nodeName != 'BODY')
		reltg= reltg.parentNode
	if (reltg== tg) return;
	edge.defold();
	
}
