// variations on scrollpane ofr calendar and themes

function ThinTopscrollpane(id,theme,content,title,width,height)
	{
		this.inherit=ScrollPane;
		this.inherit(id,theme,content,title,width,height,true)
		this.makeTop = thinMakeTop;
		this.init();
	}
function thinMakeTop()
{
	topbar = "<div align=\"right\" style=\"cursor:move;font-size:8px;height:11px;padding:1\"><span style=\"font-family:Arial,Helevetica;size:9px;color:"+this.theme['topText']+";\"></span>&nbsp;&nbsp;&nbsp;<a href=\"javascript:"+this.id+".close()\" style=\"color:black;text-decoration:none;cursor:hand;\"><img name = \""+this.id+"close\"alt =\"close\" src=\""+this.theme["buttonClose"]+"\" border=\"0\" align=\"absmiddle\"></a></div>";
    temp = this.makeLayer(this.id+"top",this.clipW,topbar);
    return temp;
}
function ThemePane(id,theme,content,title,width,height)
	{
		this.inherit=ScrollPane;
		this.inherit(id,theme,content,title,width,height,true)
		this.makeTop = themeMakeTop
		this.init();
	}
function themeMakeTop()
{
	topbar = "<div style=\"width:267px;cursor:move;font-size:8px;line-height:8px;padding:1px;height:26px;\"><span style=\"font-family:Arial,Helevetica;size:9px;color:"+this.theme['topText']+";\"></span>&nbsp;&nbsp;&nbsp;<div style=\"position:absolute;left:190px;top:1px;visibility:inherit;\"><a href=\"javascript:"+this.id+".close()\" style=\"color:black;text-decoration:none;cursor:hand;\"><img name = \""+this.id+"close\"alt =\"close\" src=\""+this.theme["buttonClose"]+"\" border=\"0\"></a></div></div>";
    temp = this.makeLayer(this.id+"top",this.clipW,topbar);
    return temp;
}//
	// new OBJECTS!!!
	//
	// 
	//  _____________
	// | SuperSprite |__________________________________________________
	// |																|
	// |     update(html (string)) -- change content					|
	// |     wipe(direction (bool), increment (int), time in ms (int))	|
	// |																|
	// |________________________________________________________________|
	//
	function SuperSprite(id,html)
	
	{
		this.update = SprUpdate;
		this.fade = fade;
		this.wipe = wipe;
		this.rwipe = rwipe;
		this.rFade = rFade;
		this.setWipe = setWipe;
		this.setOpacity = setOpacity;
		this.percentVisible=100;
		this.setDisplay = setDisplay;
		this.inherit = Sprite;
		this.inherit(id,html);
	}
	function setDisplay(bool)
	{
		if(bool)
			dis ="block";
		else
			dis="none";
		for(this.i=0;this.i<this.layer.length;this.i++)
			this.layer[this.i].display=dis;
	}
	function wipe(direction,dimension,time,noReset)
	{
		if(this.busy)
			return;
		this.busy=true;
		this.direction =direction;
		if (direction)
		{
			if(!noReset){
			this.hide();
			this.percentVisible=0;
			}else{time=time*(100-this.percentVisible)/100;}
			this.setWipe(dimension);
			this.show();
		}else{
			this.show();
			this.percentVisible=100;
		}
		
		this.rwipe(direction,dimension,time,(new Date()).getTime(),this.percentVisible)
	}
	
	function rwipe(direction,dimension, time, fatherTime,offset)
	{	
		 now = (new Date()).getTime(); 
  		 ratio = (now - fatherTime)/time;
		 //increment = 100 * ratio ;
		
		if(direction){
			this.percentVisible=offset + (100-offset)*ratio
			if (this.percentVisible>100){
				this.percentVisible=100;
				this.setWipe(dimension);
				this.show();
				this.busy=false;
				return;
			}
		}else{
			this.percentVisible= 100 - 100 * ratio;
			if (this.percentVisible<0){
				this.percentVisible=0;
				this.setWipe(dimension);
				this.hide();
				this.busy=false;
				return;
			}
		}
		this.setWipe(dimension);
		wastedTime = (new Date()).getTime() - now;
    	this.stack= setTimeout(this.id+".rwipe("+direction+",'"+dimension+"',"+time+","+fatherTime+","+offset+")",  wastedTime);
		
	}
 function fade(direction,end,time)
	{	
		this.busy=true;
		if (direction)
		{
			this.hide();
			this.percentVisible=0;
			this.setOpacity();
			this.show();
		}else{
			this.show();
			this.percentVisible=end;
		
		}
		
		this.rFade(direction,end,time,(new Date()).getTime())
	}
	
	function rFade(direction,end, time, fatherTime)
	{	
		 now = (new Date()).getTime(); 
  		 ratio = (now - fatherTime)/time;
		 increment = end * ratio;
		if(direction){
			this.percentVisible=increment;
			if (this.percentVisible>end){
				this.percentVisible=end;
				this.show();this.busy=false;
				return;
			}
		}else{
			this.percentVisible= end - increment;
			if (this.percentVisible<0){
				this.percentVisible=0;
				this.hide();this.busy=false;
				return;
			}
		}
		this.setOpacity();
		wastedTime = (new Date()).getTime() - now;
    	this.stack=setTimeout(this.id+".rFade("+direction+","+end+","+time+","+fatherTime+")",  10+wastedTime);
		
	} 
	function setWipe(dimension)
	{	
		//document.body.innerHTML+=this.percentVisible+" ";
		switch(dimension)
		{
			case 'hl':
				clipLayer(this.content,0,0,this.clipW*this.percentVisible/100,this.clipH);
				break;
			case 'hr':
				clipLayer(this.content,this.clipW-this.clipW*this.percentVisible/100,0,this.clipW,this.clipH);
				break;
			case 'vt':
				clipLayer(this.content,0,0,this.clipW,this.clipH*this.percentVisible/100);
				break;
			case 'vb':
				clipLayer(this.content,0,this.clipH-this.clipH*this.percentVisible/100,this.clipW,this.clipH);
				break;
		
		}
	}
	function setOpacity()
	{
		for(this.i=0;this.i<this.layer.length;this.i++)
		{
			this.layer[this.i].MozOpacity=this.percentVisible/100;
			this.layer[this.i].filter="alpha(Opacity="+this.percentVisible+")";
		}
	}
	function SprUpdate(html)
	{
		ly=getLayer(this.content);
		if(ns){
			ly.document.open();
			ly.document.write(html);
			ly.document.close();
		}else{
			ly.innerHTML=html;
		}
	}
	//  ______________
	// | image looper |__________________________________________________
	// |                                                                |
	// |      image looper extends  Super   sprite;                     |
	// |      and switchesthe image inside.                             |
	// |                                                                |
	// |      ImageLooper(id,layerID,imagePath,num_images)              |
	// |                                                                |
	// |________________________________________________________________|
	//
	
	function ImageLooper(imageRef,imagePath,numImages,extension,autoStart)
	{	
	
		this.id="document.images[\""+imageRef.id+"\"].looper";
		this.loader = ILloader;
		this.autoStart = autoStart;
		imageRef.onload = this.loader
		this.loadImages = loadImages;
		this.loaded=0;
		this.setImage = setImage;
		this.start = ILoopStart;
		this.loop = ILoopLoop;
		this.stop = ILoopStop
		this.imagePointer = imageRef
	    this.loadImages(imagePath,numImages,extension);
		if(autoStart)
			this.start(autoStart);
	}
	function ILloader()
	{
	
	}
	function setImage()
	{
		
		this.imagePointer.src = this.images[this.index].src;
	}
	function loadImages(imagePath,numImages,extension){
	
		this.images = new Array(new Image());
		this.images[0].src = imagePath+"."+extension;
		for(this.i=1;this.i<numImages;this.i++)
		{
			this.images[this.i] = new Image();
			//alert(imagePath+this.i+"."+extension);
			this.images[this.i].src = imagePath+(this.i+1)+"."+extension;
			this.images[this.i].onload=this.loader;
		}
		
	}
	function ILoopStart(interval)
	{
		if (this.busy)
			return;
		this.busy = true;
		this.index = 0;
		this.setImage();
		this.loop(interval);
		
	}
	function ILoopStop()
	{
		this.busy=false;
		clearTimeout(this.stack)
		this.index=0;
		this.setImage();
	}
	function ILoopLoop(interval)
	{

		this.index++;
		if(this.index==this.images.length)
			this.index=0;
		this.setImage()
		
		//alert(this.index)
	 	this.stack = setTimeout("if("+this.id+")"+this.id+".loop("+interval+");",interval);
	}

	//  __________________
	// |Static ScrollPane |_____________________________________________
	// |                                                                |
	// |    removes the top bar from the scrollpane object,             |
	// |    which removes it's draggability, but not the                |
	// |    focus blur focus differences if in the theme                |
	// |________________________________________________________________|
	//
	function SecretarySprite(id,ref)
		{
			this.inherit = SuperSprite;
			this.inherit(id,ref);
			this.typeText = typeText;
			this.stopTyping = typeStop;
			this.startCursor = function sc(){};
			this.killCursor = function kc(){};
/*private*/ this.rTT = blah;

		}
	function blah()
	{   
		now = (new Date()).getTime()
		nxtchar = this.text.substr(this.tCounter-1,1);
		
		this.update(this.text.substring(0,this.tCounter),1);
		this.tCounter++;
		if (this.tCounter==this.text.length){
			this.killCursor();
			this.update(this.html,1);
			this.busy=false;
			this.done = true;
			if(this.bla=document.getElementById('narr')){
				setTimeout("spkrinit()",500);

			}
			return;
		}
		rnow = (new Date()).getTime(); wt = rnow-now;
		if (wt<this.speed)
			wt = this.speed;

		this.stack = setTimeout(this.id+".rTT()",wt);

	}
	function JournalPane(id,theme,content,title,width,height)
	{	
		this.inherit = ScrollPane;
		this.inherit(id,theme,content,title,width,height);
		this.cursorNode = document.createElement('SPAN');
		this.cursorNode.innerHTML = "&nbsp;";
		this.cursorNode.style.visibility="visible";
		this.cursorNode.style.position="relative";
		this.cursorNode.style.color="#cc0000";
		this.cursorNode.style.fontWeight="bolder";
		this.consoleNode=document.getElementById(this.content);
		if(ns6)
		this.textNode = document.createElement('DIV');
		else
		this.textNode = document.createElement('SPAN');
		this.textNode.style.visibility="visible";
		this.textNode.style.position="relative";
		this.textNode.style.overflow="hidden";
		if(ns6)
		this.textNode.style.width=width-30;
		this.consoleNode.appendChild(this.textNode);
		this.consoleNode.appendChild(this.cursorNode);
		this.tCounter=0
		this.type="static"
		this.maxHeight-=this.yOffset[2];
		this.yOffset[2]=0;
		this.topH=0;
		this.interrupted = false;
		this.done = true;
		this.layer[1]=this.layer[0];
		this.yOffset[1]=this.yOffset[0];
		this.xOffset[1]=this.xOffset[0];
		this.doLayout();
		this.typeText = typeText;
		this.stopTyping = typeStop;
		this.resume = JPresume;
		this.parseMouse = this.parseXY;
		this.parseXY= JPparseXY;
		this.killCursor = KI_killCursor;
		this.toggleCursor = KBtoggleCursor;
		this.blink = KBcursorBlink;
		this.startCursor=KI_startCursor;
		this.update = SPupdate2;
		this.doLayout =SPdoLayout2;
		// special journal pane button MO
		//createMouseOver(document.images[this.id+"buttonUp"],'images/jup_mo.gif');
		//createMouseOver(document.images[this.id+"buttonDown"],'images/j_down_mo.gif');
		//dnim = document.images[this.id+"buttonDown"];
		//upim.onmouseout=function uimt(){this.src='images/j_up.gif'};
		//upim.onmouseover=function uimvr(){this.src='images/jup_mo.gif'};
		//dnim.onmouseout=function dnmt(){this.src='images/j_down.gif'};
		//dnim.onmouseover=function dnmvr(){this.src='images/j_down_mo.gif'};

		//this.focus = JPfocus
/*private*/ this.rTT = rTT;
		
	}
	function JPfocus(z)
	{
 		
	}
	function JPparseXY(x,y)
	{
		(!this.busy) // avoid interruptions during typing
			this.parseMouse(x,y);
	
	}
	function typeText(text,html,speed)
	{
		if (this.busy)
			return;
		//this.update("");
		//guiManager.dBug(this.scrollFlag);
		this.text=text;
		this.cursorTimeout =null;
		this.interrupted = false;
		this.done = false;
		this.html=html;
		this.tCounter=0;
		this.speed=speed;
		this.busy = true;
		this.rTT();
		this.isFocused= true;
		this.startCursor();
		
	}
	function KI_startCursor()
	{
		this.isFocused= true;
		this.blink();

	}
	function KI_killCursor()
	{

		this.isFocused=false
		clearTimeout(this.cursorTimeout);
		this.cursorPhase=true; 
		this.toggleCursor();
	}
	function KBtoggleCursor()
	{
	if(this.cursorPhase)
			this.cursorNode.innerHTML="&nbsp;";
		else
			this.cursorNode.innerHTML="_";
		this.cursorPhase = !this.cursorPhase;
	}
	function KBcursorBlink()
	{
		if (!this.isFocused)
			return;
		this.toggleCursor();
		this.cursorTimeout = setTimeout(this.id+".blink()",500);
		
	}
	function typeStop(finish){
		if (this.done)
			return;
		clearTimeout(this.stack);
		if(finish){
		    this.done = true;
			
			if (this.scrollFlag) 						// scrollbar already present
				this.update(this.html,1);               // scroll to end
			else
				this.update(this.html);
			//alert(this.contentHeight);
			//alert(this.maxHeight);
			//this.guiManager.dBug(this.maxHeight+" "+this.contentHeight+this.layer[0].height);
			//this.focus();
			this.killCursor();                 // else show from top
		}
		this.busy=false;
		this.killCursor();
	}
	function JPresume()
	{
		if (!this.done){
			this.busy = true;
			this.startCursor();
			this.rTT();	
		}
	}
	function rTT()
	{   
		now = (new Date()).getTime();
		nxtchar = this.text.substr(this.tCounter-1,1);
		
		this.update(this.text.substring(0,this.tCounter),1);
		this.tCounter++;
		if (this.tCounter==this.text.length){
			this.killCursor();
			this.update(this.html,1);
			
			this.busy=false;
			this.done = true;

			return;
		}
		rnow = (new Date()).getTime(); wt = rnow-now;
		if(nxtchar =="." || nxtchar =="?" || nxtchar =="!"){
			if(this.sc>26)
			wt = 1200;
			else
			wt = 600;
			this.sc=0;
		}
		this.sc++;
		if (wt<this.speed)
			wt = this.speed;

		this.stack = setTimeout(this.id+".rTT()",wt);

	}
	function SPdoLayout2(END_FLAG)
{
	if (!END_FLAG)
		END_FLAG = 0;
    this.panelWidth = this.clipW-this.theme['buttonSize'];
    this.layer[2].width = this.clipW-3;
	if(ns6){ // adjuast for stupid mozilla padding implementation
			wdiff=getWidth(this.content)-this.clipW;
			this.layer[2].width = this.clipW-wdiff;
			
			}
	this.layer[1].width = this.clipW;
	for (i=3;i<this.layer.length;i++)
		this.xOffset[i]= this.panelWidth;
    
 //   if(this.textNode)
    this.contentHeight = this.textNode.offsetHeight;
 //   else
//    this.contentHeight = getHeight(this.content);
	//alert(this.contentHeight)
	//guiManager.dBug('contentHeight: '+this.contentHeight+' maxH);
	if ((this.contentHeight)<=this.maxHeight)
    {
		
        this.panelHeight = this.clipH-this.yOffset[2];
		if(ie)
		this.layer[2].height= this.panelHeight;
        this.scrollFlag=false;
        for(i=3;i<7;i++)
            this.layer[i].visibility="hidden";
        this.yOffset[7] = this.clipH - this.theme['buttonSize'];

    }
    if (this.contentHeight>this.maxHeight)
    {   
		this.clipH = this.maxHeight;
		this.layer[2].height= this.contentHeight;
        this.layer[2].width = this.panelWidth;
        this.contentHeight = ns ? this.layer[2].document.height : (getLayer(this.content)).offsetHeight;
        this.panelHeight = this.clipH - this.yOffset[2];
        clipLayer(this.layer[2],0,0+(this.contentHeight-this.panelHeight)*END_FLAG,this.panelWidth,this.panelHeight-1*END_FLAG);  
		this.scrollFlag = true;
		

    }
	if (this.scrollFlag)
    {

	    this.yOffset[3] = this.yOffset[2];
	    this.yOffset[4] = this.yOffset[2];
	    this.yOffset[5] = this.clipH - this.theme['buttonSize'];
	
	    clipLayer(this.layer[3],0,0,this.theme["buttonSize"],this.clipH-this.yOffset[2]);
	    this.setBgColor(this.layer[3],"scrollBar");
	        ht=Math.floor( this.panelHeight* (this.panelHeight-2*this.theme["buttonSize"]) /this.contentHeight);
			this.layer[6].height = ht;
	        this.scrollBoxHeight = ht;
			clipLayer(this.layer[6],0,0,this.theme['buttonSize'],this.scrollBoxHeight);
			//if (this.scrollBoxHeight<30)
				//this.layer[6].borderWidth=0;;
			this.setBgColor(this.layer[6],"scrollBox");
	        this.scrollMultiplier = this.contentHeight/(this.panelHeight-2*this.theme["buttonSize"]);
	        this.scrollMax = this.clipH-this.theme["buttonSize"]-this.scrollBoxHeight;
	        this.scrollMin = this.yOffset[4]+this.theme["buttonSize"];
	        this.yOffset[6]=this.yOffset[2]+this.theme["buttonSize"];
		if (END_FLAG)
			this.scrollToEnd();
		if (this.visible)
		{
		for(i=3;i<7;i++)
	            this.layer[i].visibility="visible";
		}
    }
	if(w3||ie)
	{
	this.layer[0].width = (ns6) ? this.clipW : (this.clipW+this.theme["borderWidth"]*2);
    this.layer[0].height = (ns6) ? this.maxHeight : (this.clipH+this.theme["borderWidth"]*2);
	}
	if (ns)
	{
		clipLayer(this.layer[0],0,0,this.clipW+this.theme["borderWidth"]*2,this.clipH+this.theme["borderWidth"]*2);
	}
		
	this.setXY();
    
    

}
	function SPupdate2(html,END_FLAG)
    {   
       if(this.scrollFlag)
	   		this.scrollTo(0);
			this.textNode.innerHTML = html
		
		
        this.setBgColor(this.layer[2],"bgColor");
		if (END_FLAG)
        	this.doLayout(1);
		else
        	this.doLayout(0);
		

    }

