
var ImageRotator = {
	ImagePointer : 0,
	GalleryLinks : null,
	LargeImageTag : null,
	GalleryItems : Array(),
	Timer : null,
	Loaded : false,
	Load : function()
	{
		
		if(ImageRotator.Loaded)return null;
		/* create the divs to hold the images*/
		var inPageDiv = document.createElement('div');	
		var imageContainerDiv = document.createElement('div');
		var thumbContainerDiv = document.createElement('div');
		var	thumbList = document.createElement('ul');
		/*set the class attribute for imageContainerDiv*/
		imageContainerDiv.setAttribute('class', 'image-container');
		thumbContainerDiv.setAttribute('class', 'thumb-container');
		inPageDiv.appendChild(imageContainerDiv);
		var tab12 = document.getElementById("tab-12");
		if(document.getElementsByClassName('in-page-images')==0)
		{
			return null;
		}
		if(tab12 != undefined){
			tab12.appendChild(inPageDiv);
				inPageDiv.appendChild(thumbContainerDiv);
				thumbContainerDiv.appendChild(thumbList);
		}else{
			if(document.getElementsByTagName('body')[0].className == "home scripted")
			{
				document.getElementById("first-p").parentNode.insertBefore(inPageDiv,document.getElementById("first-p"));
			}else{
				document.getElementById('form').parentNode.insertBefore(inPageDiv,document.getElementById('form'));
				inPageDiv.appendChild(thumbContainerDiv);
				thumbContainerDiv.appendChild(thumbList);
			}
		}	
		/* put imageContainerDiv in inPageDiv*/
	
		ImageRotator.GalleryLinks = document.getElementsByClassName('in-page-images');
		thumbList.setAttribute('id','mycarousel');
		thumbList.setAttribute('class','jcarousel-skin-tango');
		if(ImageRotator.GalleryLinks == 0){ return false; }
		ImageRotator.LargeImageTag = document.createElement('img');
		inPageDiv.setAttribute('id', 'inPage');
		inPageDiv.setAttribute('class', 'clearfix');
		ImageRotator.LargeImageTag.setAttribute('class','large-image-tag');
		var useAsFirst = true;
		for(var i = 0; i < ImageRotator.GalleryLinks.length; i++)
		{
			if(ImageRotator.GalleryLinks[i].href != undefined)
			{
				if(document.getElementsByClassName('subdocument') != undefined && document.getElementsByTagName('body')[0].className != "home scripted" || tab12 != undefined)
				{
					ImageRotator.LargeImageTag.setAttribute('class','large-image-tag-sidebar');		
				}else if(document.getElementsByTagName('body')[0].className == "home scripted")
				{
					ImageRotator.LargeImageTag.setAttribute('class','large-image-tag-home');
				}
				ImageRotator.GalleryLinks[i].href = ImageRotator.GalleryLinks[i].href.replace(/\/\d+\/\d+\//,'\/600\/300\/');
				if(useAsFirst)
				{
					
					ImageRotator.LargeImageTag.src = ImageRotator.GalleryLinks[i].href;
					useAsFirst = false;
					imageContainerDiv.appendChild(ImageRotator.LargeImageTag);
				}
					ImageRotator.GalleryItems[ImageRotator.GalleryItems.length] = ImageRotator.GalleryLinks[i];
					ImageRotator.GalleryLinks[i].onclick = function(){
						ImageRotator.LargeImageTag.src = this.href;
						return false;
					}
					var thumbListItem = document.createElement('li');
					thumbList.appendChild(thumbListItem);
					thumbListItem.appendChild(ImageRotator.GalleryLinks[i]);
			} 
		}
		var effectInterval;
		jQuery('#mycarousel').jcarousel({
			vertical: true,
			scroll: 1,
			animation: 2000
			
		});
			$('.jcarousel-next').hover(function() {
			effectInterval = setInterval(function() {
				$('.jcarousel-next').click(); // sample API call, check your plugin's docs for how it might actually be done
				}, 1);
				}, function() {
					clearInterval(effectInterval);
			});	
			$('.jcarousel-prev').hover(function() {
			effectInterval = setInterval(function() {
				$('.jcarousel-prev').click(); // sample API call, check your plugin's docs for how it might actually be done
				}, 1);
				}, function() {
					clearInterval(effectInterval);
			});		
		t = setTimeout("ImageRotator.Next()", 3000);

//		ImageRotator.GalleryLinks.style.display = 'none';
	ImageRotator.Loaded = true;
	},
	
	
	
	
	
	
	
	
	Next : function()
	{
		ImageRotator.LargeImageTag.src = ImageRotator.GalleryItems[ImageRotator.ImagePointer].href;
		if(ImageRotator.ImagePointer >=  ImageRotator.GalleryItems.length-1)
		{
			ImageRotator.ImagePointer = 0;
		}else{
			ImageRotator.ImagePointer++; 
		}
		t = setTimeout("ImageRotator.Next()", 5000);
		
	}
}

window.addToOnload(ImageRotator.Load);

