﻿// JScript File
/*///////////////////////////////// Album Scripts ///////////////////////////////////////*/


function getY( oElement )
{
    var iReturnValue = 0;
    while( oElement != null ) {
        iReturnValue += oElement.offsetTop;
        oElement = oElement.offsetParent;
    }
    return iReturnValue;
}

function getX( oElement )
{
    var iReturnValue = 0;
    while( oElement != null ) {
        iReturnValue += oElement.offsetLeft;
        oElement = oElement.offsetParent;
    }
    return iReturnValue;
}


function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01.
if (!n){return 0;}
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

//checked
function R_swapImageNext(params){
        if (params.isTweening){return true;}
   var TB = document.getElementById(params.indexTBname);
   var a_img = document.getElementById(params.imgName);
   if ((TB != null) && (a_img != null)){if (TB.style.display == ''){AlbumPullDown(params);}}
	R_Stop(params);   
	
	if(params.counter == (params.imgs.length - 1)){
    		params.counter = -1;
	}
	params.counter ++;
	 MM_swapImage(params.imgName, '', params.imgs[params.counter]);
	IS_SwapUrlAndCaption(params.imgName,params.captionName,params.targets[params.counter],params.caps[params.counter],params.titles[params.counter]); 
}

//checked
function R_swapImageBack(params){
        if (params.isTweening){return true;}
    var TB = document.getElementById(params.indexTBname);
    var a_img = document.getElementById(params.imgName);
   if ((TB != null) && (a_img != null)){if (TB.style.display == ''){AlbumPullDown(params);}}
	R_Stop(params);   
	
	if(params.counter == 0){
    params.counter = (params.imgs.length);}
    params.counter--;
    MM_swapImage(params.imgName, '', params.imgs[params.counter]);
    IS_SwapUrlAndCaption(params.imgName,params.captionName,params.targets[params.counter],params.caps[params.counter],params.titles[params.counter]); 
}

//checked
function R_StopStart(params){
	if (params.rotate==1){
		params.rotate=0;
		changeImage(params.PauseBtName ,params.PlayImgUrl);
	}else{
		params.rotate=1;
		randomImages(params);	
		changeImage(params.PauseBtName ,params.PauseImgUrl);
	}
}

function R_Stop(params){
	    stopTimers(params);
		params.rotate=0;
		changeImage(params.PauseBtName ,params.PlayImgUrl);
}

function R_Start(params){
		params.rotate=1;
		randomImages(params);	
		changeImage(params.PauseBtName ,params.PauseImgUrl)
}
//checked
function restartImageTimer(params){
	if (params.rotate == 0){
		R_Start(params);
		stopTimers(params);
		params.randomTimer = setTimeout('randomImages(' + params.id + ')', params.delay);
	}
}
//checked
function startResetTimer(params){
	stopTimers(params);
	params.restartTimer = setTimeout('restartImageTimer(' + params.id + ')', params.delayPause);
}
//checked
function stopTimers(params){
	try
		{clearTimeout(params.randomTimer);}
	catch (ex){}
	try
		{clearTimeout(params.restartTimer);}
	catch (ex){}
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function openAlbumWindow (infoPage)
{
        // openInfoWindow opens the passed html page parameter in a remote window. 
        // You can create more remote windows by naming the new window object a 
        // different name. 
        if (infoPage == '' || infoPage == 'noClick') {
            return false;
        }else{
            var newWind = window.open(infoPage,'info','width=800,height=600,scrollbars=yes,menubar=yes,resizable=1');

            if (newWind.opener == null)
            {
                newWind.opener = window;
            }
            else
            {
                    newWind.focus();
            }
        } 
}
function AlbumPullDown(params)
{
        var TB = document.getElementById(params.indexTBname);
        var a_img = document.getElementById(params.imgName);
        if (parseInt(params.tweenType) > 0)
        {
            a_img = document.getElementById(params.tweenDivName);
        }
        var cap_box = document.getElementById(params.captionName);
        if ((TB != null) && (a_img != null)){
            if (TB.style.display == 'none'){
                R_Stop(params);
                a_img.style.display='none';
                TB.style.display = '';
                if (cap_box != null) {cap_box.style.display='none';}
             }else{
                R_Start(params);
                a_img.style.display='';
                TB.style.display = 'none';
                if (cap_box != null) {cap_box.style.display='';}
             }
        }
}

function SelectAlbumIndex(params,selection)
{
        if (params.isTweening){return true;}
        var TB = document.getElementById(params.indexTBname);
        var a_img = document.getElementById(params.imgName);
         if (parseInt(params.tweenType) > 0)
        {
            a_img = document.getElementById(params.tweenDivName);
        }
        if ((TB != null) && (a_img != null)){
            
             
              if (parseInt(params.tweenType) == 0)
              {
                params.counter = selection;  
                MM_swapImage(params.imgName, '', params.imgs[params.counter]); 
              }else if (parseInt(params.tweenType) == 1){
                   if (selection >  params.counter){tween_H_Forward2Ind(params,selection,'L');}else{tween_H_Back2Ind(params,selection,'L');}
               }else if (parseInt(params.tweenType) == 2){
                   if (selection >  params.counter){tween_H_Forward2Ind(params,selection,'R');}else{tween_H_Back2Ind(params,selection,'R');}
               }else if (parseInt(params.tweenType) == 3){
                   if (selection >  params.counter){tween_V_Forward2Ind(params,selection,'U');}else{tween_V_Back2Ind(params,selection,'U');}
               }else if (parseInt(params.tweenType) == 4){
                   if (selection >  params.counter){tween_V_Forward2Ind(params,selection,'D');}else{tween_V_Back2Ind(params,selection,'D');} 
              }else
              {
              params.counter = selection;  
                if (params.counter < params.imgs.length) {MM_swapImage(params.imgName3, '', params.imgs[params.counter +1]);}
                if (params.counter > 0) {MM_swapImage(params.imgName, '', params.imgs[params.counter -1]);} 
              }
	        IS_SwapUrlAndCaption(params.imgName,params.captionName,params.targets[params.counter],params.caps[params.counter],params.titles[params.counter]); 
	        a_img.style.display='';
            TB.style.display = 'none'; 
            params.resetWhenDoneTweening = true;
        }
}

function detachOnClick(element)
{
    if(element.detachEvent){
        element.detachEvent('onclick',functionref);
    }
    else if (element.removeEventListener){
        element.removeEventListener('click',functionref);
    }
    else element.onclick='';
}


function IS_SwapUrlAndCaption(imgID,capID,newUrl,newCap,newTitle)
{
	var theImg = document.getElementById(imgID);
	if (theImg != null){
		theImg.title = newTitle;
		theImg.onclick = function(){openAlbumWindow(newUrl)}; ;
		if ( newUrl == 'noClick') {
		        theImg.style.cursor = '';
		}else{
		        theImg.style.cursor = 'pointer';
		}
		
	}
	var cap = document.getElementById(capID);
	if (cap != null){
	    cap.innerText = newCap;
	    cap.innerHTML = newCap;
	    if (newCap == ' ' || newCap == '' || newCap == '&nbsp;')
	        {cap.style.display='none';}
	        else
	        {cap.style.display='';}
	    }
}

//checked
function preloadImgs(params){

  for(var i=0;i< params.imgs.length;i++){
    MM_preloadImages(params.imgs[i]);
  }
}
//checked
//=========================================================================
//=========================================================================
function randomImages(params){

	if (params.rotate==0){return;}
	if (params.isTweening){
	    stopTimers(params);
        params.randomTimer =  setTimeout('randomImages(' + params.id +')', params.delay);
        return;
	}
  if((params.counter == (params.imgs.length -1)) || (params.counter < 0)){
    params.counter = 0;
  }else{
        if (parseInt(params.tweenType) == 0)
        {
            params.counter++;
        }
  }
  
  var box = document.getElementById(params.tweenDivName);
  
  if (parseInt(params.tweenType) == 0){
        MM_swapImage(params.imgName, '', params.imgs[params.counter]);
  } else if (parseInt(params.tweenType) == 1){
         box.scrollLeft = getIntWidth(box); 
         tween_HL_Forward(true,params);
  } else if (parseInt(params.tweenType) == 2){
        box.scrollLeft = getIntWidth(box); 
        tween_HR_Forward(true,params); 
  } else if (parseInt(params.tweenType) == 3){
         box.scrollTop = getIntHeight(box); 
        tween_VU_Forward(true,params);
  } else if (parseInt(params.tweenType) == 4){
        box.scrollTop = getIntHeight(box); 
        tween_VD_Forward(true,params);
  }
  
  IS_SwapUrlAndCaption(params.imgName2,params.captionName,params.targets[params.counter],params.caps[params.counter],params.titles[params.counter]); 
  
  SetupIndexClasses(params);
  stopTimers(params);
  params.randomTimer =  setTimeout('randomImages(' + params.id +')', params.delay);
}
//=========================================================================
//=========================================================================


function changeImage(ImageID, strSrc) // 1 visible, 0 hidden
{
    if(document.layers)	   //NN4+
    {
        if (document.layers[ImageID]){ 
            document.layers[ImageID].src = strSrc;
        }
    }
    else if(document.getElementById)	  //gecko(NN6) + IE 5+
    {
        var obj = document.getElementById(ImageID);
        if (obj){
            obj.src = strSrc;
        }
    }
    else if(document.all)	// IE 4
    {
        if (document.all[ImageID]){
            document.all[ImageID].src = strSrc;
        }
    }
}

function toggleBox(szDivID, iState) // 1 visible, 0 hidden
{
    if(document.layers)	   //NN4+
    {
       document.layers[szDivID].visibility = iState ? "show" : "hide";
    }
    else if(document.getElementById)	  //gecko(NN6) + IE 5+
    {
        var obj = document.getElementById(szDivID);
        obj.style.visibility = iState ? "visible" : "hidden";
    }
    else if(document.all)	// IE 4
    {
        document.all[szDivID].style.visibility = iState ? "visible" : "hidden";
    }
}



function getIntHeight(obj)
{
    var tbh = obj.style.height;
	tbh = tbh.replace('px','');	
	return parseInt(tbh);
}

function getIntWidth(obj)
{
	var tbw = obj.style.width;
	tbw = tbw.replace('px','');	
	return parseInt(tbw);
}



function getSpeed(current,total)
{
	var answer = parseInt(total / 70) + 1;
	return answer;
}

//============================== To the Left ============================

function tween_HL_Back(isFirstCall,params)
{	
    if (params.isTweening && isFirstCall){return true;}
	if (params.counter  == 0) {return true;}

	var box = document.getElementById(params.tweenDivName);
	if (box){
		var boxW = getIntWidth(box);
		var pixelsLeft = box.scrollLeft % boxW;
		if (box.scrollLeft > 0)
		{
			if (isFirstCall) 
			{
				box.scrollLeft = box.scrollLeft - getSpeed(boxW - pixelsLeft,boxW);
				pixelsLeft = box.scrollLeft % boxW;
								params.isTweening = true;
			}

			if (pixelsLeft > 0)
			{
	 			box.scrollLeft = box.scrollLeft - getSpeed(boxW - pixelsLeft,boxW);
				pixelsLeft = box.scrollLeft % boxW;
				try {clearTimeout(params.tweenTimer);}catch (ex){}
				params.tweenTimer = setTimeout('tween_HL_Back(false,' + params.id + ')', 1);
			}
		}else{
			//happens in the end of a cycle
            if (box.scrollLeft == 0){
			    params.counter -=1 ;
			    MM_swapImage(params.imgName2,'', params.imgs[params.counter]);
			    try {clearTimeout(params.tweenTimer);}catch (ex){}
			    params.tweenTimer = setTimeout('finish_H_Back(' + params.id + ')',50);
			}
		}
	}
}

function tween_HL_Forward(isFirstCall,params)
{	
    if (params.isTweening && isFirstCall){return true;}
	if (params.counter == params.imgs.length -1) {return true;}

	var TB = document.getElementById(params.tweenTableName);
	var box = document.getElementById(params.tweenDivName);
	
	if (box){
		var boxW = getIntWidth(box);
		var pixelsLeft = box.scrollLeft % boxW;
		if (box.scrollLeft < (getIntWidth(TB) - getIntWidth(box)))
		{
			if (isFirstCall) {
				box.scrollLeft = box.scrollLeft +  getSpeed(pixelsLeft,boxW);
				pixelsLeft = box.scrollLeft % boxW;
								params.isTweening = true;
			}

			if (pixelsLeft > 1)
			{
	 			box.scrollLeft = box.scrollLeft +  getSpeed(pixelsLeft,boxW);
				pixelsLeft = box.scrollLeft % boxW;
				try {clearTimeout(params.tweenTimer);}catch (ex){}
				params.tweenTimer = setTimeout('tween_HL_Forward(false,' + params.id + ')',1);
			}
		}else{
			//happens in the end of a cycle
            if (box.scrollLeft >= (getIntWidth(TB) - getIntWidth(box))){
			    params.counter +=1 ;
			    MM_swapImage(params.imgName2,'', params.imgs[params.counter]);
			    try {clearTimeout(params.tweenTimer);}catch (ex){}
			    params.tweenTimer = setTimeout('finish_H_Forward(' + params.id + ')',50);
			} 
		}
	}
}

///  H functions 

// needs to be done to switch directly using numbers ~~~~~~~
function tween_H_Forward2Ind(params,targetIndex,dir)
{
	if (params.counter  == params.imgs.length -1) {return true;}
    if (params.isTweening){return true;}
	var box = document.getElementById(params.tweenDivName);
	if (box){
	        box.scrollLeft = getIntWidth(box);
	        if (targetIndex > params.counter) {
    		    MM_swapImage(params.imgName3,'', params.imgs[targetIndex]);
	    	    params.counter = targetIndex - 1;
		        try {clearTimeout(params.tweenTimer);}catch (ex){}
			    params.tweenTimer = setTimeout('tween_H' + dir + '_Forward(true,' + params.id + ')',50);
		    }
	}

}


function tween_H_Back2Ind(params,targetIndex,dir)
{
    if (params.isTweening){return true;}
	if (params.counter  == 0) {return true;}
	var box = document.getElementById(params.tweenDivName);
	if (box){
	        box.scrollLeft = getIntWidth(box);
	        if (targetIndex < params.counter) {
    		    MM_swapImage(params.imgName,'', params.imgs[targetIndex]);
	    	    params.counter = targetIndex + 1;
		        try {clearTimeout(params.tweenTimer);}catch (ex){}
			    params.tweenTimer = setTimeout('tween_H' + dir + '_Back(true,' + params.id + ')',50);
		    }
	}

}

function finish_H_Forward(params)
{
	var box = document.getElementById(params.tweenDivName);
	box.scrollLeft = getIntWidth(box);
	if (params.counter < params.imgs.length -1) {
		MM_swapImage(params.imgName3,'', params.imgs[params.counter +1]);
	}else{
	    MM_swapImage(params.imgName3,'', params.imgs[0]);
	}
	MM_swapImage(params.imgName,'', params.imgs[params.counter -1]);
 IS_SwapUrlAndCaption(params.imgName2,params.captionName,params.targets[params.counter],params.caps[params.counter],params.titles[params.counter]); 
  SetupIndexClasses(params); 
  params.isTweening = false;
  if (params.resetWhenDoneTweening){R_Stop(params);   params.randomTimer =  setTimeout('R_Start(' + params.id + ')', params.delay); params.resetWhenDoneTweening = false;}
}


function finish_H_Back(params)
{
	var box = document.getElementById(params.tweenDivName);
	box.scrollLeft = getIntWidth(box);
	if (params.counter > 0) {
		MM_swapImage(params.imgName,'', params.imgs[params.counter -1]);
	}else{
	    MM_swapImage(params.imgName,'', params.imgs[params.imgs.length -1]);
	}
	MM_swapImage(params.imgName3,'', params.imgs[params.counter +1]);
    IS_SwapUrlAndCaption(params.imgName2,params.captionName,params.targets[params.counter],params.caps[params.counter],params.titles[params.counter]); 
    SetupIndexClasses(params); 
    params.isTweening = false;
if (params.resetWhenDoneTweening){R_Stop(params);   params.randomTimer =  setTimeout('R_Start(' + params.id + ')', params.delay); params.resetWhenDoneTweening = false;}
}


//============================== To the Right ============================

function tween_HR_Forward(isFirstCall,params)
{	
	
if (params.counter == params.imgs.length -1) {return true;}
    if (params.isTweening && isFirstCall){return true;}
	var box = document.getElementById(params.tweenDivName);
	if (box){
		var boxW = getIntWidth(box);
		var pixelsLeft = box.scrollLeft % boxW;
		if (box.scrollLeft > 0)
		{
			if (isFirstCall) 
			{
				box.scrollLeft = box.scrollLeft - getSpeed(boxW - pixelsLeft,boxW);
				pixelsLeft = box.scrollLeft % boxW;
				params.isTweening = true;
			}

			if (pixelsLeft > 0)
			{
	 			box.scrollLeft = box.scrollLeft - getSpeed(boxW - pixelsLeft,boxW);
				pixelsLeft = box.scrollLeft % boxW;
				try {clearTimeout(params.tweenTimer);}catch (ex){}
				params.tweenTimer = setTimeout('tween_HR_Forward(false,' + params.id + ')', 1);
			}
		}else{
			//happens in the end of a cycle

			params.counter +=1 ;
			MM_swapImage(params.imgName2,'', params.imgs[params.counter]);
			try {clearTimeout(params.tweenTimer);}catch (ex){}
			params.tweenTimer = setTimeout('finish_H_Forward(' + params.id + ')',50);
		}
	}
}



function tween_HR_Back(isFirstCall,params)
{	
	if (params.counter  == 0) {return true;}
    if (params.isTweening && isFirstCall){return true;}
	var TB = document.getElementById(params.tweenTableName);
	var box = document.getElementById(params.tweenDivName);
	

	if (box){
		var boxW = getIntWidth(box);
		var pixelsLeft = box.scrollLeft % boxW;
		if (box.scrollLeft < (getIntWidth(TB) - getIntWidth(box)))
		{
			if (isFirstCall) {
				box.scrollLeft = box.scrollLeft +  getSpeed(pixelsLeft,boxW);
				pixelsLeft = box.scrollLeft % boxW;
				params.isTweening = true;
			}

			if (pixelsLeft > 1)
			{
	 			box.scrollLeft = box.scrollLeft +  getSpeed(pixelsLeft,boxW);
				pixelsLeft = box.scrollLeft % boxW;
				try {clearTimeout(params.tweenTimer);}catch (ex){}
				params.tweenTimer = setTimeout('tween_HR_Back(false,' + params.id + ')',1);
			}
		}else{
			//happens in the end of a cycle

			params.counter -=1 ;
			MM_swapImage(params.imgName2,'', params.imgs[params.counter]);
			try {clearTimeout(params.tweenTimer);}catch (ex){}
			params.tweenTimer = setTimeout('finish_H_Back(' + params.id + ')',50);
		}
	}
}

//============================== Upward ============================

function tween_VU_Back(isFirstCall,params)
{	
	if (params.counter  == 0) {return true;}
    if (params.isTweening && isFirstCall){return true;}
	var box = document.getElementById(params.tweenDivName);
	if (box){
		var boxH = getIntHeight(box);
		var pixelsLeft = box.scrollTop % boxH;
		if (box.scrollTop > 0)
		{
			if (isFirstCall) 
			{
				box.scrollTop = box.scrollTop - getSpeed(boxH - pixelsLeft,boxH);
				pixelsLeft = box.scrollTop % boxH;
                params.isTweening = true;
			}

			if (pixelsLeft > 0)
			{
	 			box.scrollTop = box.scrollTop - getSpeed(boxH - pixelsLeft,boxH);
				pixelsLeft = box.scrollTop % boxH;
				try {clearTimeout(params.tweenTimer);}catch (ex){}
				params.tweenTimer = setTimeout('tween_VU_Back(false,' + params.id + ')', 1);
			}
		}else{
			//happens in the end of a cycle

			params.counter -=1 ;
			MM_swapImage(params.imgName2,'', params.imgs[params.counter]);
			try {clearTimeout(params.tweenTimer);}catch (ex){}
			params.tweenTimer = setTimeout('finish_V_Back(' + params.id + ')',50);
		}
	}
}

function tween_VU_Forward(isFirstCall,params)
{	
	if (params.counter == params.imgs.length -1) {return true;}
    if (params.isTweening && isFirstCall){return true;}
	var TB = document.getElementById(params.tweenTableName);
	var box = document.getElementById(params.tweenDivName);
	

	if (box){
		var boxH = getIntHeight(box);
		var pixelsLeft = box.scrollTop % boxH;
		if (box.scrollTop < (getIntHeight(TB) - getIntHeight(box)))
		{
			if (isFirstCall) {
				box.scrollTop = box.scrollTop +  getSpeed(pixelsLeft,boxH);
				pixelsLeft = box.scrollTop % boxH;
				params.isTweening = true;
			}

			if (pixelsLeft > 1)
			{
	 			box.scrollTop = box.scrollTop +  getSpeed(pixelsLeft,boxH);
				pixelsLeft = box.scrollTop % boxH;
				try {clearTimeout(params.tweenTimer);}catch (ex){}
				params.tweenTimer = setTimeout('tween_VU_Forward(false,' + params.id + ')',1);
			}
		}else{
			//happens in the end of a cycle

			params.counter +=1 ;
			MM_swapImage(params.imgName2,'', params.imgs[params.counter]);
			try {clearTimeout(params.tweenTimer);}catch (ex){}
			params.tweenTimer = setTimeout('finish_V_Forward(' + params.id + ')',50);
		}
	}
}



// V functions
// needs to be done to switch directly using numbers ~~~~~~~
function tween_V_Forward2Ind(params,targetIndex,dir)
{
	if (params.counter  == params.imgs.length -1) {return true;}
	    if (params.isTweening){return true;}
	var box = document.getElementById(params.tweenDivName);
	if (box){
	        box.scrollTop = getIntHeight(box);
	        if (targetIndex > params.counter) {
    		    MM_swapImage(params.imgName3,'', params.imgs[targetIndex]);
	    	    params.counter = targetIndex - 1;
		        try {clearTimeout(params.tweenTimer);}catch (ex){}
			    params.tweenTimer = setTimeout('tween_V' + dir + '_Forward(true,' + params.id + ')',50);
		    }
	}

}


function tween_V_Back2Ind(params,targetIndex,dir)
{
	if (params.counter  == 0) {return true;}
	    if (params.isTweening){return true;}
	var box = document.getElementById(params.tweenDivName);
	if (box){
	        box.scrollTop = getIntHeight(box);
	        if (targetIndex < params.counter) {
    		    MM_swapImage(params.imgName,'', params.imgs[targetIndex]);
	    	    params.counter = targetIndex + 1;
		        try {clearTimeout(params.tweenTimer);}catch (ex){}
			    params.tweenTimer = setTimeout('tween_V' + dir + '_Back(true,' + params.id + ')',50);
		    }
	}

}

function finish_V_Forward(params)
{
	var box = document.getElementById(params.tweenDivName);
	box.scrollTop = getIntHeight(box);
	if (params.counter < params.imgs.length -1) {
		MM_swapImage(params.imgName3,'', params.imgs[params.counter +1]);
	}else{
	    	MM_swapImage(params.imgName3,'', params.imgs[0]);
	}
	MM_swapImage(params.imgName,'', params.imgs[params.counter -1]);
    IS_SwapUrlAndCaption(params.imgName2,params.captionName,params.targets[params.counter],params.caps[params.counter],params.titles[params.counter]); 
    SetupIndexClasses(params); 
   params.isTweening = false; 
   if (params.resetWhenDoneTweening){R_Stop(params);   params.randomTimer =  setTimeout('R_Start(' + params.id + ')', params.delay); params.resetWhenDoneTweening = false;}
}


function finish_V_Back(params)
{
	var box = document.getElementById(params.tweenDivName);
	box.scrollTop = getIntHeight(box);
	if (params.counter > 0) {
		MM_swapImage(params.imgName,'', params.imgs[params.counter -1]);
	}else{
		MM_swapImage(params.imgName,'', params.imgs[params.imgs.length -1]);
	}
	MM_swapImage(params.imgName3,'', params.imgs[params.counter +1]);
 IS_SwapUrlAndCaption(params.imgName2,params.captionName,params.targets[params.counter],params.caps[params.counter],params.titles[params.counter]); 
  SetupIndexClasses(params); 
  params.isTweening = false;
  if (params.resetWhenDoneTweening){R_Stop(params);   params.randomTimer =  setTimeout('R_Start(' + params.id + ')', params.delay); params.resetWhenDoneTweening = false;}
}


//============================== Downward ============================

function tween_VD_Forward(isFirstCall,params)
{	
    if (params.isTweening && isFirstCall){return true;}
if (params.counter == params.imgs.length -1) {return true;}
	var box = document.getElementById(params.tweenDivName);
	if (box){
		var boxH = getIntHeight(box);
		var pixelsLeft = box.scrollTop % boxH;
		if (box.scrollTop > 0)
		{
			if (isFirstCall) 
			{
				box.scrollTop = box.scrollTop - getSpeed(boxH - pixelsLeft,boxH);
				pixelsLeft = box.scrollTop % boxH;
				params.isTweening = true;
			}

			if (pixelsLeft > 0)
			{
	 			box.scrollTop = box.scrollTop - getSpeed(boxH - pixelsLeft,boxH);
				pixelsLeft = box.scrollTop % boxH;
				try {clearTimeout(params.tweenTimer);}catch (ex){}
				params.tweenTimer = setTimeout('tween_VD_Forward(false,' + params.id + ')', 1);
			}
		}else{
			//happens in the end of a cycle

			params.counter +=1 ;
			MM_swapImage(params.imgName2,'', params.imgs[params.counter]);
			try {clearTimeout(params.tweenTimer);}catch (ex){}
			params.tweenTimer = setTimeout('finish_V_Forward(' + params.id + ')',50);
		}
	}
}


function tween_VD_Back(isFirstCall,params)
{	
	if (params.counter  == 0) {return true;}
    if (params.isTweening && isFirstCall){return true;}
	var TB = document.getElementById(params.tweenTableName);
	var box = document.getElementById(params.tweenDivName);
	

	if (box){
		var boxH = getIntHeight(box);
		var pixelsLeft = box.scrollTop % boxH;
		if (box.scrollTop < (getIntHeight(TB) - getIntHeight(box)))
		{
			if (isFirstCall) {
				box.scrollTop = box.scrollTop +  getSpeed(pixelsLeft,boxH);
				pixelsLeft = box.scrollTop % boxH;
				params.isTweening = true;
			}

			if (pixelsLeft > 1)
			{
	 			box.scrollTop = box.scrollTop +  getSpeed(pixelsLeft,boxH);
				pixelsLeft = box.scrollTop % boxH;
				try {clearTimeout(params.tweenTimer);}catch (ex){}
				params.tweenTimer = setTimeout('tween_VD_Back(false,' + params.id + ')',1);
			}
		}else{
			//happens in the end of a cycle

			params.counter -=1 ;
			MM_swapImage(params.imgName2,'', params.imgs[params.counter]);
			try {clearTimeout(params.tweenTimer);}catch (ex){}
			params.tweenTimer = setTimeout('finish_V_Back(' + params.id + ')',50);
		}
	}
}

//// ================== Index stuff ================================================

function setObjText(obj,text)
{

    if (obj.innerHTML || obj.innerHTML == '') { 
             obj.innerHTML = text; 
             obj.innerHTML = obj.innerHTML.replace('&nbsp;','');
    } 
    if (obj.innerText  || obj.innerHTML == '') { 
             obj.innerText = text; 
             obj.innerText = obj.innerText.replace('&nbsp;',''); 
    } 
}


function SetupIndexClasses(params)
{
    
    for (var i = 0;i<params.imgs.length;i++){
        var oneBase = i + 1; 
         var ind = document.getElementById('AlbumIndex' + params.relID + '_' + oneBase); 
         if (ind) {
                if (ind.className != params.indexHoverClass){
                    if (i == (params.counter)){
                        ind.className = params.indexSelectedClass;
                    }else{
                        ind.className = params.indexDefaultClass;
                    }
                }
         }else{
            return true;
         }
    }
}


function mOverIndex(params,i)
{
    if (i==params.counter + 1){return true;}
    var indexDiv = document.getElementById('AlbumIndex' + params.relID + '_' + i);
    if (indexDiv){indexDiv.className = params.indexHoverClass;}else{return true;}
    var popup = document.getElementById('IndexPopup' + params.relID);
   popup.style.visibility = 'hidden';
   popup.style.display = 'block'; 
    var indexTitle = document.getElementById('IndexTitle' + params.relID);
    if (indexTitle) {setObjText(indexTitle,params.titles[i-1]);}
   var indexCaption = document.getElementById('indexCaption' + params.relID);
    if (indexCaption) {setObjText(indexCaption,params.caps[i-1]);} 
   if (popup){popup.style.left = (getX(indexDiv) - (popup.offsetWidth / 2))  +'px'; popup.style.top = (getY(indexDiv)- popup.offsetHeight) + 'px';} 
   popup.style.visibility = 'visible';
}

function mOutIndex(params,i)
{
    var indexDiv = document.getElementById('AlbumIndex' + params.relID + '_' + i);
    if (indexDiv){
        if (i == (1 + params.counter)){
              indexDiv.className = params.indexSelectedClass;
        }else{
              indexDiv.className = params.indexDefaultClass;
        }
    }else{return true;}
    var popup = document.getElementById('IndexPopup' + params.relID);
   if (popup){   popup.style.visibility = 'hidden';}
}

function mClickIndex(params,selection)
{



        var TB = document.getElementById(params.indexTBname);
        var a_img = document.getElementById(params.imgName);
//////         if (parseInt(params.tweenType) > 0)
//////        {
//////            a_img = document.getElementById(params.tweenDivName);
//////        }
//////        if ((TB != null) && (a_img != null)){
//////            params.counter = selection;  
//////             MM_swapImage(params.imgName2, '', params.imgs[params.counter]);
//////              if (parseInt(params.tweenType) > 0)
//////              {
//////                if (params.counter < params.imgs.length) {MM_swapImage(params.imgName3, '', params.imgs[params.counter +1]);}
//////                if (params.counter > 0) {MM_swapImage(params.imgName, '', params.imgs[params.counter -1]);} 
//////              }
//////	        IS_SwapUrlAndCaption(params.imgName,params.captionName,params.targets[params.counter],params.caps[params.counter],params.titles[params.counter]); 
            SelectAlbumIndex(params,selection-1 );
	        a_img.style.display='';
            TB.style.display = 'none'; 
///////   }

}

function AlbumParams()
{
							// delay in milliseconds between image swaps 1000 = 1 second 
							    
	this.id = '';
	this.relID = '0';
	this.delay = 5000;
	this.delayPause = 5000;
	this.randomTimer = null;
	this.restatTimer = null;
	this.tweenTimer = null;
	this.counter = 0;
	this.rotate = 1;
	this.PauseBtName = '';
	this.PauseImgUrl=  '';
	this.PlayImgUrl ='';
	this.tweenTableName='';
	this.tweenDivName='';
    this.indexDefaultClass ='';
    this.indexHoverClass = '';
    this.indexSelectedClass= '';
	
	this.imgName = '';
	this.imgName2 = '';
	this.imgName3 = '';
	this.indexTBname = '';
						// Comma separated list of images to rotate 
	this.imgs = null;

	this.captionName = '';
						// Comma separated list of captions to rotate 
	this.caps = null;

							// Comma separated list of titles to rotate  with images
	this.titles = null;
				// Comma separated list of target URLs to rotate  with images
	this.targets = null;
	            // to block new calls while animation is on.
	this.isTweening = false;
	this.resetWhenDoneTweening = false
}


