/**
Using:
Zastosowanie do rozwijania jednego submenu
require utils.js

window.expandableSections=new ExpandableSections()
//pozycje docelowe - relatywne względem
window.expandableSections.sectionPosition={left:184,top:30,width:416,height:500}
style:
#expandableSectionx {
	position: absolute;
	display: none;
	z-index: 50;
	top: 0px;
	width: 1px;
}
uruchomienie:
window.expandableSections.showSection(1)
ukrycie:
window.expandableSections.hideContener(); 
*/
function ExpandableSections(){
	//conf
	this.sectionPosition;//{left:184,top:30,width:416,height:500}
	//end conf
	this.fps=24;
	this.hideSectionTimeout=2000;
	window.topMenuTimerId=null;
	window.topMenuClipTimerId=null; 
	this.utils=new utils()	  
	this.bSw=true;
	document.ondblclick=function() { 
		expandableSections.hideContener(); 
	}
    this.showSection=function(id){
		this.resetTimer();
		if(this.curId!=null)this.hideContener();
		if(id!=='')this.showContener(id);
	};
	this.hideSection=function(id){
		this.resetTimer();
		window.topMenuTimerId=setInterval('expandableSections.hideContener()',this.hideSectionTimeout);
	};
	this.resetTimer=function(){
		this.bSw=true;
		clearInterval(window.topMenuTimerId);
		window.topMenuTimerId=null;
		clearInterval(window.topMenuClipTimerId);
		window.topMenuClipTimerId=null;
	};
	this.switchSection=function(id){
		window.event.cancelBubble=true;
		if(this.bSw){
		    	this.showSection(id);
		   		this.bSw= !this.bSw;
		    }else{
		    	this.hideContener();
		    };
	};
	this.hideContener=function(){
		this.resetTimer()
		var id=this.curId;
		if(id==null)return;
		this.curId=null;
		this.findContener(id).style.display='none';
	};
	this.showContener=function(id){
	    if(typeof(this.mdestPos)=='undefined'){
		    this.mdestPos=parseInt(this.findContener(id).style.left);
		};
	    this.curId=id;
	    this.setStartPosition();
	    this.findContener(id).style.display='inline';
	    this.clipLoop();
	    window.topMenuClipTimerId=setInterval('expandableSections.clipLoop()',this.fps);
	};
	this.setStartPosition=function(){
		this.obRef=this.findContener(this.curId)
		this.utils.setDivPos(this.obRef,'left',this.sectionPosition.left);
		this.utils.setDivPos(this.obRef,'top',this.sectionPosition.top);
		var d=70;
		this.clipPos=[-1,this.sectionPosition.width/2+d,50,this.sectionPosition.width/2-d]	
	};
	this.clipLoop=function(){
    	var steps={x:15,y:10};
		this.clipPos[1]+=steps.x;
		this.clipPos[3]-=steps.x;
		if(this.clipPos[1]<=this.sectionPosition.width ){
		    this.utils.clipDiv(this.obRef,this.clipPos);
		    return;
		    };
		this.clipPos[2]+=steps.y;
		if(this.clipPos[2]<=this.sectionPosition.height){
		    this.utils.clipDiv(this.obRef,this.clipPos);
		    return;
		    }
		this.resetTimer();
	};
	this.findContener=function(id){
		return document.getElementById('expandableSection'+id);
	};
	this.getCurId=function(){
		return this.curId;
	};
};
