  function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

  function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }
  
slideShow = function() {
	this.src=[];			
	this.w=[];
	this.h=[];
	this.srcsize=0;
	this.active=0;
	this.pos=0;
	
	this.divId="slideShowDiv";
	this.hiddenPicId="slideShowHiddenPicture";
	this.picId="slideShowPicture";
	this.floatingDivId="floatingDiv";
	this.controlsId="slideControls";
	this.divUpdated=0;
	this.picLoaded=0;
	
	this.div=null;
	this._addPicture = slideShow_addPicture;
	this._debug = slideShow_debug;	
	this._start=slideShow_start;
	this._show=slideShow_show;
	this._updateDiv=slideShow_updateDiv;
	this._change=slideShow_change;
	this._pictureLoaded=slideShow_pictureLoaded;
	this._divIsUpdated=slideShow_divIsUpdated;
	this._hide=slideShow_hide;
	this._next=slideShow_next;
	this._prev=slideShow_prev;
	this._finalUpdate=slideShow_finalUpdate;
}

function slideShow_addPicture(path,ww,hh) {
	this.src[this.srcsize]=path;
	this.w[this.srcsize]=ww;
	this.h[this.srcsize++]=hh;
}

function slideShow_debug() {
	alert(this.src);
	alert(this.w);
	alert(this.h);
}

function slideShow_start(position) {
	this.pos=position;
	if (this.active==0) 
		this._show();
	else
		this._change();
}

function slideShow_next() {
	cp=this.pos;
	cp++;
	if (cp>this.srcsize-1)
		cp=0;
	this._start(cp);
}
function slideShow_prev() {
	cp=this.pos;
	cp--;	
	if (cp<0)
		cp=this.srcsize-1;
	this._start(cp);
}
function slideShow_change() {
	this.divUpdated=0;
	this.picLoaded=0;
	document.getElementById(this.controlsId).style.display="none";
	document.getElementById(this.controlsId+"Close").style.display="none";
	
	theImg=document.getElementById(this.picId);
	theHiddenImg=document.getElementById(this.hiddenPicId);
	theImg.style.display="none";
	
	
	this.div=document.getElementById(this.divId);
	this.div.style.padding="10 10 10 10";
	
	divWidth=this.w[this.pos]+0;
	if (isIE)
		divWidth+=20;
	divHeight=this.h[this.pos]+30;
	
	pageWidth=document.body.scrollWidth;		
	clientHeight=document.body.clientHeight;
	
	divTop=(clientHeight-divHeight)/2;
	if (document.body.scrollTop)
		divTop+=document.body.scrollTop;	
	if (divTop<=10)
		divTop=30;
	
	divLeft=(pageWidth-divWidth)/2;
	
	new Effect.Appear(this.div, {duration:0.1});	
	new Effect.Morph(this.div, 
       {style:'width:'+divWidth+'px; height:'+divHeight+'px; top:'+divTop+'px;left:'+divLeft+'px;',
         duration:0.7});  
          
  this.slideControls=document.getElementById(this.controlsId);
  if (isIE)
  new Effect.Morph(this.slideControls, 
       {style:'width:'+(divWidth-15)+'px; height:'+(divHeight-30)+'px;',
         duration:0.7});
  else
    new Effect.Morph(this.slideControls, 
       {style:'width:'+divWidth+'px; height:'+(divHeight-30)+'px;',
         duration:0.7});
         	       
  window.setTimeout('myshow._divIsUpdated()',700);
  theHiddenImg.src=this.src[this.pos];     
}

function slideShow_pictureLoaded() {
	this.picLoaded=1;
	if (this.divUpdated==1) {
		this._finalUpdate();
  }
}
function slideShow_show() {
	theFloatingDiv=document.getElementById(this.floatingDivId);
	pageWidth=document.body.scrollWidth;		
	//pageHeight=document.body.offsetHeight;
	pageHeight=findPosY(document.getElementById('pageEnd'));
	theFloatingDiv.style.width=pageWidth+"px";
	theFloatingDiv.style.height=pageHeight+"px";
	
	new Effect.Appear(theFloatingDiv, 
       {duration:0.1, from:0, to:0.7});	
	this._updateDiv(this.w[this.pos],this.h[this.pos]);
	this._change();
	this.active=1; 
}

function slideShow_updateDiv(width,height) {
	width+=0;
	height+=30;
	this.div=document.getElementById(this.divId);

	pageWidth=document.body.scrollWidth;		
	clientHeight=document.body.clientHeight;
	
	divTop=(clientHeight-height)/2;
	
	if (document.body.scrollTop)
		divTop+=document.body.scrollTop;
		
	if (divTop<=10)
		divTop=30;
		
	this.div.style.left=(pageWidth-width)/2+"px";
	this.div.style.top=divTop+"px";
	this.div.style.width=width+"px";
	this.div.style.height=height+"px";	
}

function slideShow_divIsUpdated() {
	this.divUpdated=1;
	if (this.picLoaded==1) {
		this._finalUpdate();
  }
}

function slideShow_finalUpdate() {
		theHiddenImg=document.getElementById(this.hiddenPicId);
		theImg=document.getElementById(this.picId);
		theImg.src=theHiddenImg.src;		
		new Effect.Appear(theImg, 
	       {duration:0.5, from:0, to:1.0});
	  new Effect.Appear(document.getElementById(this.controlsId), 
	      {duration:0.5, from:0, to:0.5});	
	  new Effect.Appear(document.getElementById(this.controlsId+"Close"), 
	      {duration:0.5, from:0, to:1.0});	
}

function slideShow_hide() {
	theFloatingDiv=document.getElementById(this.floatingDivId);
	this.div=document.getElementById(this.divId);
	
	new Effect.Fade(theFloatingDiv, 
       {duration:0.1, from:0.7, to:0});	
       
	new Effect.toggle(this.div, 'Appear', {duration:0.1});
  
  this.active=0;
	this.divUpdated=0;
	this.picLoaded=0;  
}

