function shSmoothSlideShow(pdivIDName,prandomDisplay,pslideShowDelay,plinkDestination,ptransitionTime,ptransitionType,pslideInfoDelay,pisCentered,pstretchingMode,pslideHeight,pslideWidth,pmySlideData,pOnCompleteSlideFunc)
{
this.currentIter=0;
this.lastIter=0;
this.maxIter=0;
this.slideShowElement="";
this.slideShowData=pmySlideData;
this.slideShowInit=1;
this.slideShowDelay=pslideShowDelay;
this.articleLink="";
this.divIDName=pdivIDName;
this.randomDisplay=prandomDisplay;
this.linkDestination=plinkDestination;
this.transitionTime=ptransitionTime;
this.transitionType=ptransitionType;
this.slideInfoDelay=pslideInfoDelay;
this.isCentered=pisCentered;
this.stretchingMode=pstretchingMode;
this.slideHeight=pslideHeight;
this.slideWidth=pslideWidth;
this.onCompleteSlideFunc=pOnCompleteSlideFunc;
this.slideInfoZoneName='slideInfoZone'+this.divIDName;
this.slideElementName='slideElement'+this.divIDName;
if(this.randomDisplay=='yes')this.slideShowData.sort(randOrd);else this.slideShowData.sort();
if(this.transitionType=='automatic')
{
  this.initSlideShowAutomatic($(this.divIDName));
}
else
{
  this.initSlideShowControls($(this.divIDName));
}
}

if(typeof addLoadEvent!='function')
{
  function addLoadEvent(func){
  var oldonload=window.onload;
  if(typeof window.onload!='function')
  {
    window.onload=func;
  }
  else
  {
    window.onload=function()
	{
	oldonload();
	func();
	};
  }
  }
}

function randOrd(){
  return(Math.round(Math.random())-0.5);
}

shSmoothSlideShow.prototype.onCompleteSlide=function()
{
  this.onCompleteSlideFunc();
};

shSmoothSlideShow.prototype.runSlide=function()
{
  if(this.transitionType=='automatic')
  {
    this.doSlideShowAutomatic();
  }
  else
  {
    this.doSlideShowControls(1);
  }
};

shSmoothSlideShow.prototype.initSlideShowAutomatic=function(element)
{
  this.slideShowElement=element;element.style.display="block";
  this.articleLink=document.createElement('a');
  this.articleLink.className='global';
  element.appendChild(this.articleLink);
  if(this.slideShowData[0][1]=='')
  {
  //  this.articleLink.href=''; NNNN
	//this.articleLink.target=''; NNNN
  }
  else
  {
    this.articleLink.href=this.slideShowData[0][1];
	this.articleLink.target=this.linkDestination;
  }
  
  this.maxIter=this.slideShowData.length;
  for(i=0;i<this.maxIter;i++)
  {
    var currentImg=document.createElement('img');
	currentImg.setAttribute('id',this.slideElementName+parseInt(i));
	currentImg.style.position="absolute";
	currentImg.style.left="0px";
	currentImg.style.top="0px";
	currentImg.src=this.slideShowData[i][0];
	this.articleLink.appendChild(currentImg);
	currentImg.currentOpacity=new shFx.Opacity(currentImg,{duration:parseInt(this.transitionTime)});
	currentImg.currentOpacity.setOpacity(0);
  }
  var slideInfoZone=document.createElement('div');
  slideInfoZone.setAttribute('id',this.slideInfoZoneName);
  slideInfoZone.combo=new shFx.Combo(slideInfoZone);slideInfoZone.combo.o.setOpacity(0);
  this.articleLink.appendChild(slideInfoZone);
};
  
function stretchImg(imgTag,mode,sWidth,sHeight)
{
  var xFactor,yFactor,imgWidth,imgHeight=0;
  var imgRef=document.getElementById(imgTag);
  if(imgRef){imgWidth=imgRef.offsetWidth;imgHeight=imgRef.offsetHeight;if(mode=='noStretch')
  {
    return imgHeight;
  }
  if((imgHeight*imgWidth)==0)
  {
    return 0;
  }
  switch(mode)
  {
  case 'stretchX':xFactor=sWidth/imgWidth;imgWidth=sWidth;imgHeight=imgHeight*xFactor;break;
  case 'stretchY':yFactor=sHeight/imgHeight;imgHeight=sHeight;imgWidth=imgWidth*yFactor;break;
  case 'stretchBest':xFactor=sWidth/imgWidth;yFactor=sHeight/imgHeight;
  if(xFactor<=yFactor){imgWidth=sWidth;imgHeight=imgHeight*xFactor;}
  else{imgHeight=sHeight;imgWidth=imgWidth*yFactor;}break;
  default:}imgRef.style.width=Math.round(imgWidth)+'px';imgRef.style.height=Math.round(imgHeight)+'px';  
  return Math.round(imgHeight);
  }return 0;
}

function centerDiv(divIDName,elementName)
{
  var noPx=document.childNodes?'px':0;
  if((elementName!='')&&(document.getElementById(elementName).offsetHeight))
  {
    var maincontentclientHeight=document.getElementById(divIDName).offsetHeight;
	if(document.getElementById(elementName))
	{
	  document.getElementById(elementName).style.top=(maincontentclientHeight-document.getElementById(elementName).offsetHeight)/2+noPx;
	}
  }
}

function setDivSize(stretchMode,maxHeight,maxWidth,isCentered,imgName,divName)
{
  var noPx=document.childNodes?'px':0;
  if(stretchMode!='stretchBest')
  {
    document.getElementById(divName).style.width=document.getElementById(imgName).offsetWidth+noPx;document.getElementById(divName).style.height=document.getElementById(imgName).offsetHeight+noPx;
  }
  else
  {document.getElementById(divName).style.width=document.getElementById(imgName).offsetWidth<maxWidth?document.getElementById(imgName).offsetWidth+noPx:maxWidth+noPx;if(isCentered)document.getElementById(divName).style.height=maxHeight+noPx;else document.getElementById(divName).style.height=document.getElementById(imgName).offsetheight<maxHeight?document.getElementById(imgName).offsetHeight+noPx:maxHeight+noPx;}
  if(isCentered=='yes') centerDiv(divName,imgName);
}

shSmoothSlideShow.prototype.setInitDivSize=function()
{
  var noPx=document.childNodes?'px':0;
  var shCurHeight=0;
  for(i=0;i<this.maxIter;i++)
  {
    shCurHeight=stretchImg(this.slideElementName+i,this.stretchingMode,this.slideWidth,this.slideHeight);
  }
  setDivSize(this.stretchingMode,this.slideHeight,this.slideWidth,this.isCentered,this.slideElementName+'0',this.divIDName);
  $(this.slideElementName+'0').currentOpacity.setOpacity(1);
  if(this.onCompleteSlideFunc)
  {
    shcw[this.divIDName][6]=new CCallWrapper(this,50,'onCompleteSlide');
	CCallWrapper.asyncExecute(shcw[this.divIDName][6]);
  }
};

shSmoothSlideShow.prototype.nextSlideShowAutomatic=function()
{
  this.lastIter=this.currentIter;
  this.currentIter++;
  if(this.currentIter>=this.maxIter)
  {
    this.currentIter=0;
	this.lastIter=this.maxIter-1;
  }
  if(this.slideShowData[this.currentIter][1]=='')
  {
    //this.articleLink.href='#'; NNNN
	//this.articleLink.target='_self'; NNNN
    this.articleLink.href='';
	this.articleLink.target='';	
  }
  else
  {
    this.articleLink.href=this.slideShowData[this.currentIter][1];
  }
  this.doSlideShowAutomatic();
  this.slideShowInit=0;
};

shSmoothSlideShow.prototype.shOnComplete=function(cIter,lIter,divName,stretchingMode,slideHeight,slideWidth,isCentered,elementName)
{
  setDivSize(stretchingMode,slideHeight,slideWidth,isCentered,elementName+parseInt(cIter),divName);
};

shSmoothSlideShow.prototype.doSlideShowAutomatic=function()
{
  if(this.slideShowInit==1)
  {
    this.currentIter=0;
	this.slideShowInit=0;
	shcw[this.divIDName][1]=new CCallWrapper(this,500,'setInitDivSize');
	CCallWrapper.asyncExecute(shcw[this.divIDName][1]);
	shcw[this.divIDName][2]=new CCallWrapper(this,parseInt(this.slideInfoDelay),'showInfoSlideShowAutomatic');
	CCallWrapper.asyncExecute(shcw[this.divIDName][2]);
	shcw[this.divIDName][3]=new CCallWrapper(this,parseInt(this.slideShowDelay)-400,'hideInfoSlideShowAutomatic');
	CCallWrapper.asyncExecute(shcw[this.divIDName][3]);
	shcw[this.divIDName][4]=new CCallWrapper(this,parseInt(this.slideShowDelay),'nextSlideShowAutomatic');
	CCallWrapper.asyncExecute(shcw[this.divIDName][4]);
  }
  else
  {
    $(this.slideElementName+parseInt(this.lastIter)).currentOpacity.custom(1,0);
	$(this.slideElementName+parseInt(this.currentIter)).currentOpacity.custom(0,1);
	setDivSize(this.stretchingMode,this.slideHeight,this.slideWidth,this.isCentered,this.slideElementName+parseInt(this.currentIter),this.divIDName,this.mainDivName);
	shcw[this.divIDName][2]=new CCallWrapper(this,parseInt(this.slideInfoDelay),'showInfoSlideShowAutomatic');
	CCallWrapper.asyncExecute(shcw[this.divIDName][2]);
	shcw[this.divIDName][3]=new CCallWrapper(this,parseInt(this.slideShowDelay)-400,'hideInfoSlideShowAutomatic');
	CCallWrapper.asyncExecute(shcw[this.divIDName][3]);
	shcw[this.divIDName][4]=new CCallWrapper(this,parseInt(this.slideShowDelay),'nextSlideShowAutomatic');
	CCallWrapper.asyncExecute(shcw[this.divIDName][4]);
  }
};

shSmoothSlideShow.prototype.showInfoSlideShowAutomatic=function()
{
  with(this){
    if((slideShowData[currentIter][2]=='')&&(slideShowData[currentIter][3]=='')) return;
	articleLink.removeChild($(slideInfoZoneName));
	var slideInfoZone=document.createElement('div');
	slideInfoZone.setAttribute('id',slideInfoZoneName);
	slideInfoZone.combo=new shFx.Combo(slideInfoZone);
	slideInfoZone.combo.o.setOpacity(0);
	var slideInfoZoneTitle=document.createElement('h2');
	slideInfoZoneTitle.innerHTML=slideShowData[currentIter][2];
	slideInfoZone.appendChild(slideInfoZoneTitle);
	var slideInfoZoneDescription=document.createElement('p');
	slideInfoZoneDescription.innerHTML=slideShowData[currentIter][3];
	slideInfoZone.appendChild(slideInfoZoneDescription);
	articleLink.appendChild(slideInfoZone);
	slideInfoZone.combo.o.custom(0,0.7);
	slideInfoZone.combo.h.custom(0,slideInfoZone.combo.h.el.offsetHeight);
  }
};
		
shSmoothSlideShow.prototype.hideInfoSlideShowAutomatic=function()
{
  with(this)
  {
    if((slideShowData[currentIter][2]=='')&&(slideShowData[currentIter][3]==''))return;
    $(slideInfoZoneName).combo.o.custom(0.7,0);}};shSmoothSlideShow.prototype.initSlideShowControls=function(element)
	{
	  with(this)
	  {
	    slideShowElement=element;element.style.display="block";maxIter=slideShowData.length;
		for(i=0;i<maxIter;i++)
		{
		  var currentImg=document.createElement('img');currentImg.setAttribute('id',slideElementName+parseInt(i));
		  currentImg.style.position="absolute";
		  currentImg.style.left="0px";
		  currentImg.style.bottom="0px";
		  currentImg.style.margin="0px";
		  currentImg.src=slideShowData[i][0];
		  element.appendChild(currentImg);
		  currentImg.currentOpacity=new shFx.Opacity(currentImg,{duration:parseInt(transitionTime)});
		  currentImg.currentOpacity.setOpacity(0);
		}
		var shCurHeight=0;
		for(i=0;i<this.maxIter;i++)
		{
		  shCurHeight=stretchImg(this.slideElementName+i,this.stretchingMode,this.slideWidth,this.slideHeight);
		}
		var leftArrow=document.createElement('a');
		leftArrow.className='left';
		leftArrow.onclick=function(){
		  pushPrevSlideShowControls();
		};
		
		element.appendChild(leftArrow);
		var rightArrow=document.createElement('a');
		rightArrow.className='right';
		rightArrow.onclick=function()
		{
	      pushNextSlideShowControls();
		};
		element.appendChild(rightArrow);
		var slideInfoZone=document.createElement('div');
		slideInfoZone.setAttribute('id',slideInfoZoneName);
		slideInfoZone.combo=new shFx.Combo(slideInfoZone);
		slideInfoZone.combo.o.setOpacity(0);
		element.appendChild(slideInfoZone);
		slideShowInit=1;
	  }
	};
	
	shSmoothSlideShow.prototype.destroySlideShowControls=function(element)
	{
		var myClassName=element.className;
		var newElement=document.createElement('div');
		newElement.className=myClassName;
		element.parentNode.replaceChild(newElement,element);
	};
	shSmoothSlideShow.prototype.pushNextSlideShowControls=function()
	{
		shcw[this.divIDName][3]=new CCallWrapper(this,10,'hideInfoSlideShowControls');
		CCallWrapper.asyncExecute(shcw[this.divIDName][3]);
		shcw[this.divIDName][4]=new CCallWrapper(this,500,'nextSlideShowControls');
		CCallWrapper.asyncExecute(shcw[this.divIDName][4]);
	};
	
	shSmoothSlideShow.prototype.pushPrevSlideShowControls=function()
	{
		shcw[this.divIDName][3]=new CCallWrapper(this,10,'hideInfoSlideShowControls');
		CCallWrapper.asyncExecute(shcw[this.divIDName][3]);
		shcw[this.divIDName][5]=new CCallWrapper(this,500,'prevSlideShowControls');
		CCallWrapper.asyncExecute(shcw[this.divIDName][5]);
	};
	
	shSmoothSlideShow.prototype.nextSlideShowControls=function()
	{
		with(this){lastIter=currentIter;currentIter++;
		if(currentIter>=maxIter)
		{
			currentIter=0;lastIter=maxIter-1;
		}
		slideShowInit=0;doSlideShowControls(1);
	}
};

shSmoothSlideShow.prototype.prevSlideShowControls=function()
{
	with(this)
	{
		lastIter=currentIter;currentIter--;
		if(currentIter<=-1)
		{
			currentIter=maxIter-1;
			lastIter=0;
		}
		
		slideShowInit=0;
		doSlideShowControls(2);
	}
};

shSmoothSlideShow.prototype.doSlideShowControls=function(position)
{
	with(this)
	{
		if(slideShowInit==1){
			currentIter=0;
			slideShowInit=0;
			shcw[this.divIDName][1]=new CCallWrapper(this,500,'setInitDivSize');
			CCallWrapper.asyncExecute(shcw[this.divIDName][1]);
			shcw[this.divIDName][2]=new CCallWrapper(this,parseInt(this.slideInfoDelay),'showInfoSlideShowControls');
			CCallWrapper.asyncExecute(shcw[this.divIDName][2]);
		}
		else
		{
			if(position==1){if(currentIter!=0){
				$(slideElementName+parseInt(currentIter)).currentOpacity.options.onComplete=
				function()
				{
					$(slideElementName+parseInt(lastIter)).currentOpacity.setOpacity(0);
					setDivSize(stretchingMode,slideHeight,slideWidth,isCentered,slideElementName+parseInt(currentIter),divIDName);
				};
				$(slideElementName+parseInt(currentIter)).currentOpacity.custom(0,1);
			}
			else
			{
				$(slideElementName+parseInt(currentIter)).currentOpacity.setOpacity(1);
				$(slideElementName+parseInt(lastIter)).currentOpacity.custom(1,0);
				setDivSize(stretchingMode,slideHeight,slideWidth,isCentered,slideElementName+parseInt(currentIter),divIDName);
			}
		}
		else
		{
			if(currentIter!=maxIter-1)
			{
				$(slideElementName+parseInt(currentIter)).currentOpacity.setOpacity(1);
				$(slideElementName+parseInt(lastIter)).currentOpacity.custom(1,0);
				setDivSize(stretchingMode,slideHeight,slideWidth,isCentered,slideElementName+parseInt(currentIter),divIDName);
			}
			else
			{
				$(slideElementName+parseInt(currentIter)).currentOpacity.options.onComplete=
				function()
				{
					$(slideElementName+parseInt(lastIter)).currentOpacity.setOpacity(0);
					setDivSize(stretchingMode,slideHeight,slideWidth,isCentered,slideElementName+parseInt(currentIter),divIDName);
				};
				$(slideElementName+parseInt(currentIter)).currentOpacity.custom(0,1);
			}
		}
		shcw[this.divIDName][2]=new CCallWrapper(this,parseInt(this.slideInfoDelay),'showInfoSlideShowControls');
		CCallWrapper.asyncExecute(shcw[this.divIDName][2]);
	}
}
};

shSmoothSlideShow.prototype.showInfoSlideShowControls=function()
{
	with(this){
		if((slideShowData[currentIter][2]=='')&&(slideShowData[currentIter][3]==''))return;
		slideShowElement.removeChild($(slideInfoZoneName));
		var slideInfoZone=document.createElement('div');slideInfoZone.setAttribute('id',slideInfoZoneName);
		slideInfoZone.combo=new shFx.Combo(slideInfoZone);
		slideInfoZone.combo.o.setOpacity(0);
		var slideInfoZoneTitle=document.createElement('h2');
		slideInfoZoneTitle.innerHTML=slideShowData[currentIter][2];
		slideInfoZone.appendChild(slideInfoZoneTitle);
		var slideInfoZoneDescription=document.createElement('p');
		slideInfoZoneDescription.innerHTML=slideShowData[currentIter][3];
		slideInfoZone.appendChild(slideInfoZoneDescription);
		slideShowElement.appendChild(slideInfoZone);
		slideInfoZone.combo.o.custom(0,0.7);
		slideInfoZone.combo.h.custom(0,slideInfoZone.combo.h.el.offsetHeight);
	}
};

shSmoothSlideShow.prototype.hideInfoSlideShowControls=function()
{
	with(this){if((slideShowData[currentIter][2]=='')&&(slideShowData[currentIter][3]==''))return;
	$(slideInfoZoneName).combo.o.custom(0.7,0);
}};

function CCallWrapper(aObjectReference,aDelay,aMethodName,aArgument0,aArgument1,aArgument2,aArgument3,aArgument4,aArgument5,aArgument6,aArgument7,aArgument8,aArgument9)
{
	this.mId='CCallWrapper_'+(CCallWrapper.mCounter++);
	this.mObjectReference=aObjectReference;
	this.mDelay=aDelay;
	this.mTimerId=0;
	this.mMethodName=aMethodName;
	this.mArgument0=aArgument0;
	this.mArgument1=aArgument1;
	this.mArgument2=aArgument2;
	this.mArgument3=aArgument3;
	this.mArgument4=aArgument4;
	this.mArgument5=aArgument5;
	this.mArgument6=aArgument6;
	this.mArgument7=aArgument7;
	this.mArgument8=aArgument8;
	this.mArgument9=aArgument9;
	CCallWrapper.mPendingCalls[this.mId]=this;
}

CCallWrapper.prototype.execute=function()
{
	this.mObjectReference[this.mMethodName](this.mArgument0,this.mArgument1,this.mArgument2,this.mArgument3,this.mArgument4,this.mArgument5,this.mArgument6,this.mArgument7,this.mArgument8,this.mArgument9);
	delete CCallWrapper.mPendingCalls[this.mId];
};

CCallWrapper.prototype.cancel=function()
{
	clearTimeout(this.mTimerId);
	delete CCallWrapper.mPendingCalls[this.mId];
};

CCallWrapper.asyncExecute=
  function(callwrapper)
  {
	  CCallWrapper.mPendingCalls[callwrapper.mId].mTimerId=setTimeout('CCallWrapper.mPendingCalls["'+callwrapper.mId+'"].execute()',callwrapper.mDelay);
  };
  
CCallWrapper.mCounter=0;CCallWrapper.mPendingCalls={};
