// custom pagination scripts based on prototype and script.aculo.us
/* for Copper Development Assocation
/* copper.org
/* initial date: 2008-11-21
*/

function pageList(thisElementId,elementId,container,effectType,elDuration,oDuration){
	var element = thisElementId;

	
	tabs = $(element).up('ul').select('li');
	tabs.each(function(tabnodes){
		$(tabnodes).removeClassName('active');				   
	});
	var pelement = element.up('li');
	$(pelement).addClassName('active');
	
	cchildren = $(container).childElements();
	Effect.Appear(elementId,{
		delay:0.1,
		duration:elDuration,
		queue: 'end',
		beforeStart: function(childnode){
			
			// begin function to set width for loading indicator
			var ploadingwidth = $('pagelistloadingindicator').up().getWidth();
			$('pagelistloadingindicator').setStyle({'width':ploadingwidth+'px'});
			// find tallest month and make the loading indicator that tall
			var ds = [];
			ploadingheights = $('pagelistloadingindicator').up().childElements();
			ploadingheights.each(function(divnode){
				if($('pagelistloadingindicator')==$(divnode)){
						
				}else{
					ds.push(divnode);
					//alert('height=' + $(divnode).getHeight());
				}
			});
			lNewSize = 0;
			 if (ds[0].getHeight()>ds[1].getHeight()){
			  if (ds[2] && ds[0].getHeight()>ds[2].getHeight){
				lNewSize=parseInt(lNewSize)+parseInt(ds[0].getHeight());
			  }
			  else{
				if(ds[2] && ds[2].getHeight>ds[1].getHeight()){
				  lNewSize=parseInt(lNewSize)+parseInt(ds[2].getHeight); 
				}
				else{
				  lNewSize=parseInt(lNewSize)+parseInt(ds[1].getHeight());
				}
			  }
			}
			else{
			  if (ds[2] && ds[1].getHeight()>ds[2].getHeight){
				lNewSize=parseInt(lNewSize)+parseInt(ds[1].getHeight());
			  }
			}
			//alert(lNewSize);
			$('pagelistloadingindicator').up().setStyle({'min-height':lNewSize+'px'});
			$('pagelistloadingindicator').setStyle({'height':lNewSize+'px'});
			
			// end
			
			$('pagelistloadingindicator').show();
			
			
			cchildren.each(function(childnode){
				  if(childnode == $('pagelistloadingindicator')){
					  
				  }else{
					  switch (effectType)
					  {
						case "Squish":
						  Effect.Squish(childnode,{duration: oDuration})
						  break;
						case "Shrink":
						  Effect.Shrink(childnode,{duration: oDuration})
						  break;
						case "Fade":
						  Effect.Fade(childnode,{duration: oDuration})
						  break;
						case "BlindUp":
						  Effect.BlindUp(childnode,{duration: oDuration})
						  break;
						default:
						  Effect.Fade(childnode,{duration: oDuration})
						  break;
					  }
				  }
			});
		},
		afterFinish: function(){
			Effect.Fade('pagelistloadingindicator',{duration:0.8})
		}
		
	});
}



