/* 
 *  folding navigation layers for France Loisirs
 *
 *  @author Micha Horn <horn@burdadirect.de> <info@michahorn.de>
 *  @version 1.1
 */
 
var foldingLayerObject  = {
	
	/* Standard values */
	
	interval: null,
	req: null,
	categoryId: null,
	categoryUrl: null,
	categoryPath: null,
	navigationLayerContentId: 'bdi_navigationLayerContent',
	
	/* Style values */
	
	divWidth: 490,
	divHeight: 157,
	divScaleY: 1,
	divLeft: 10,
	buttonWidth: 98,
	
	/* temporary vars */
	
	tmpNavPoint: null,
	tmpDivElement: null,
	tmpDivScaleY: null,
	
	/* Physical motion values */
	
	duration: 1,
	rate: 1.115,
	
	/* Methods */
	
	getXMLHttpRequest: function() {
	   var httpReq = null;
	   if (window.XMLHttpRequest) {
	      httpReq = new XMLHttpRequest();
	   }  else if (typeof ActiveXObject != "undefined") {
	      httpReq = new ActiveXObject("Microsoft.XMLHTTP");
	   }
	   return httpReq;
	},
	
	sendRequest: function (url, handler) {
	   this.req = this.getXMLHttpRequest();
	   if(this.req) {
	      this.req.onreadystatechange = handler;
	      this.req.open("get", url, true);
	      this.req.send(null);
	   }
	},
	
	getNavigationLayerContent: function () {
		
		function setNavigationLayerContent() {
			if(foldingLayerObject.req.readyState == 4) {	
				var getElement = document.getElementById(foldingLayerObject.navigationLayerContentId).innerHTML = foldingLayerObject.req.responseText;		
			}
		}
		
		this.categoryUrl = this.categoryPath + this.categoryId;
		this.sendRequest(this.categoryUrl,setNavigationLayerContent);
	},
	
	setCategoryPath: function(clientURL) {
		this.categoryPath = clientURL+'/xml/html/category/?category_id=';
	},
	
	setCategoryId: function(categoryId) {
		this.categoryId = categoryId;
	},
	
	getCategoryId: function() {
		return this.categoryId;
	},

	setNavigationLayerContentId: function(contentId) {
		this.navigationLayerContentId = contentId;
	},
	
	startMotion: function(navPoint,divElement,action,categoryId) {
		
		if(navPoint && divElement) {			
			/* Set category identification */		
			this.setCategoryId(categoryId);
					
			this.x = getElement('id', divElement, 0);      
			this.x.style.height = this.divScaleY+'px';
				
			/* temporary filing */
			this.tmpNavPoint = navPoint;
			this.tmpDivElement = divElement;
		}
		else {	
			this.divScaleY = this.tmpDivScaleY;
			this.x = getElement('id', this.tmpDivElement, 0);			
			this.x.style.height = this.divScaleY+'px';			
			navPoint = this.tmpNavPoint;		
		}
		
		if (navPoint < 5) leftSpace = this.divLeft+this.buttonWidth*navPoint;
		if (navPoint >= 5) leftSpace = (this.buttonWidth*navPoint-this.divWidth)+(this.buttonWidth-this.divLeft-2);
		this.x.style.visibility = 'visible';
		this.x.style.width = this.divWidth+'px';
		this.x.style.left = leftSpace+'px';  
				
		if(!this.interval && action == 'open') {
			if (divElement) this.getNavigationLayerContent(); 
			this.interval = setInterval('foldingLayerObject.openBox()',this.duration);
		}
		if(action == 'close') { 
			this.closeBox();
		}		
	},	

	openBox: function() {		
	    if((this.divScaleY *= this.rate) < this.divHeight){
			this.divScaleY *= this.rate;
			this.x.style.height = this.divScaleY+'px';			
			
			/* temporary filing */			
			this.tmpDivScaleY = this.divScaleY;
			
	    }
	    else {
			clearInterval(this.interval);
			this.interval = null;	    
			this.x.style.height = this.divHeight+'px';			
			
			/* temporary filing	*/	
			this.tmpDivScaleY = this.divHeight;									    	
	    }	
	},
	
	closeBox: function() {
		clearInterval(this.interval);
		this.interval = null;	
       	this.divScaleY = 1;                        
        this.x.style.height = this.divScaleY+'px';
        this.x.style.visibility = 'hidden';			
	}
}


