var jsContractImgUrl = "../images/one_minute/minu.gif";
var jsExpandImgUrl = "../images/one_minute/plus.gif"; 

function jsfExplorerShowHide(id)
{
	imgObj=null;
	divObj=null;
	classObj=null;
	
	if(document.getElementById("jsIdExplorerShowHideDiv"+id))
	{
		divObj = document.getElementById("jsIdExplorerShowHideDiv"+id);
	}
	if(document.getElementById("jsIdExplorerShowHideClass"+id))
	{
		classObj = document.getElementById("jsIdExplorerShowHideClass"+id);
	}
	if(document.getElementById("jsIdShowHideImg"+id))
	{
		imgObj = document.getElementById("jsIdShowHideImg"+id);
	}
	if(divObj.style.display=="none")
	{
		if(divObj)
		{
			divObj.style.display = 'block';
		}			
		if(classObj)
		{	
			classObj.className="expanded";
		}
		if(imgObj)
		{
			imgObj.src = jsExpandImgUrl;
		}
	}
	else
	{
		if(divObj)
		{
		divObj.style.display = 'none';
		}
		if(classObj)
		{
		classObj.className = classObj.className.replace("expanded", "");
		}
		if(imgObj)
		{
			imgObj.src = jsContractImgUrl;
		}
	}
}

reelImages = new Array("../_images/en/img_reel_01.jpg","../_images/en/img_reel_02.jpg");
reelCaptions = new Array("Caption 1 goes here Lorem ipsum dolor sit amet, consectetuer adipiscing elit.","Caption 2 goes here Lorem ipsum dolor sit amet, consectetuer adipiscing elit.");
var reelCount = 0;
var imageCaption

function jsfShowReelLoad(){
	if (document.getElementById('imageNavigator')){
		reel = document.getElementById('imageNavigator');
		reel.style.display = 'block';
		imageCaption = document.getElementById('imageCaption');
		imageCaption.innerHTML = reelCaptions[0];
		imageCaption.style.display = 'block';
	}

}


function jsfMoveReel(direction){
	
	
	

	var imageReel = document.getElementById('imageReel');

	if (direction == "next"){
		
		
		if (reelCount < (reelImages.length - 1)) {
			
			imageReel.src = reelImages[++reelCount];		
			
			imageCaption = document.getElementById('imageCaption');
			imageCaption.innerHTML = reelCaptions[reelCount];
			imageReel.alt = reelCaptions[reelCount];
		
		
			reelLinkPrev = document.getElementById('reelPrev');
			
			reelLinkPrev.className = "";
			
			/*reelLinkPrev.class = "";*/
			reelLinkNext = document.getElementById('reelNext');
			if (reelCount == (reelImages.length - 1)) {
				

				reelLinkNext.className = "hide";
				/*reelLinkNext.class = "hide";*/
			} else {
				reelLinkNext.className = "";
				/*reelLinkNext.class = "";*/
			}	
		}
	}
	
	if (direction == "prev"){
		if (reelCount > 0) {
			imageReel.src = reelImages[--reelCount];
			 
			imageCaption = document.getElementById('imageCaption');
			imageCaption.innerHTML = reelCaptions[reelCount];
			imageReel.alt = reelCaptions[reelCount];
			
			reelLinkNext = document.getElementById('reelNext');
			reelLinkNext.className = "";
		/*	reelLinkNext.class = "";*/
		
		reelLinkPrev = document.getElementById('reelPrev');
		if (reelCount == 0) {
				
				reelLinkPrev.className = "hide";
				/*reelLink.class = "hide";*/
			} else {
				reelLinkPrev.className = "";
				/*reelLink.class = "";*/
			}	
		}
	}
}

		function Init_Items_Array()
		{
			var arrayToReturn = new Array();
			
			//get hold of the wrapping node
			var wrapperNode = document.getElementById( this.mainContainerEleId );
						
			//find the divs within the wrapping node
			var divsArray = wrapperNode.getElementsByTagName( "div" );
			
			var itemsArrayCount = 0;
			
			//go through the array and inspect the class name
			for( var i=0; i<divsArray.length; i++ )
			{
				if( divsArray[i].className == 'rotatorItem' )
				{
					arrayToReturn[itemsArrayCount] = divsArray[i];
					itemsArrayCount++;
				}
			}
			
			return arrayToReturn;
		}

		function Show( itemPosition )
		{
			//add one to the current position so we can use this number in the nav
			this.intCurrentPosition = itemPosition;
									
			//go through the global array of rotation items
			for( var i=0; i<this.objItemsArray.length; i++ )
			{
				if( i != itemPosition )
				{
					this.objItemsArray[i].style.display = "none";
				}
				else
				{
					this.objItemsArray[i].style.display = "block";
				}
			}
			
			//draw the nav
			this.drawNav();
		}

		//writes the navigation for the rotation items
		function Draw_Nav()
		{
			//find the element and the span within it
			var navList = document.getElementById( this.navEleId ).getElementsByTagName( "A" );
			var prevItem = navList[0];
			var nextItem = navList[1];
			if( this.intCurrentPosition+1<this.objItemsArray.length && this.intCurrentPosition-1>=0 )//when you can go forwards and backwards
			{
				prevItem.className = "";
				nextItem.className = "";
			}
			else if( this.intCurrentPosition+1<this.objItemsArray.length )//if it is the first element change the previus button to class="hide"
			{
				//console.log( "Can go forward" );
				prevItem.className = "hide";
				nextItem.className = "";
			}
			else if( this.intCurrentPosition-1>=0 )//if it is the last element change the next button to class="hide"
			{
				//console.log( "Can go backwards" );
				prevItem.className = "";
				nextItem.className = "hide";
			}
			else //only one image in reel
			{
				prevItem.className = "hide";
				nextItem.className = "hide";
			}
		}
		
		function Do_Forward()
		{
			this.intCurrentPosition+1<this.objItemsArray.length?this.show( this.intCurrentPosition+1 ):this.show( this.intCurrentPosition );
			return false;
		}
		
		function Do_Back()
		{
			this.intCurrentPosition-1>=0?this.show( this.intCurrentPosition-1 ):this.show( this.intCurrentPosition );
			return false;
		}
		
		function ItemRotatorObj( intCurrentPosition, mainContainerEleId, navEleId, prevId, nextId )
		{
			//init obj properties
			this.intCurrentPosition = intCurrentPosition;
			this.mainContainerEleId = mainContainerEleId;
			this.navEleId = navEleId;
			this.prevId = prevId;
			this.nextId = nextId;
			
			//assign methods to class
			this.initItemsArray = Init_Items_Array;
			this.show = Show;
			this.doForward = Do_Forward;
			this.doBack = Do_Back;
			this.drawNav = Draw_Nav;
			
			//init the array using a class method
			this.objItemsArray = this.initItemsArray();
			
			//do the stuff for first load
			this.show( 0 );
			
			//show the nav
			document.getElementById( this.navEleId ).style.display = "block";
		}
		
		//global vars
		var myItemRotatorObj;
		

if (window.addEventListener)
{
	window.addEventListener("load", jsfOnLoad, false);
}
else
{
	if (window.attachEvent)
	{
		window.attachEvent("onload", jsfOnLoad);
	}
	else
	{
	if (document.getElementById)
		{
			window.onload = jsfOnLoad;
		}
	}
}



function jsfOnLoad()
{
	
	for(i=1;i<20;i++)
	{
		if(divObj = document.getElementById("jsIdExplorerShowHideDiv"+i))
		{
			jsfExplorerShowHide(i);
		}
	}
	if( document.getElementById( "jsRotationHolder" ) )
	{
		myItemRotatorObj = new ItemRotatorObj( 0, "jsRotationHolder", "jsRotationNav", "reelPrev", "reelNext" );
	}
	
	jsfShowReelLoad(); 
}