//This uses source replacement as oppose to node replacement
var currentIndex = 0;
var picturesTableArray = new Array();
var tableElementsArray = new Array();
var viewsImagesArray= new Array();
var viewsLoadedStatusArray= new Array();
var viewsLoadedImagesArray= new Array();
var loadedImages = 0;
var testImages = 0;
var loadBars = new Array();
var pageHasFinished = false;


function setScrollBarColours()
	{
		document.body.style.scrollbarBaseColor = '#31656B';
	     document.body.style.scrollbarArrowColor='FFCF00';
	};
	
function setSpecificScrollBarColours(A,B)
	{
	  document.body.style.scrollbarBaseColor = A;
	  document.body.style.scrollbarArrowColor= B;
	};
	
/* ================================================
   Set up all arrays with data for the screen 
   ================================================*/


function buildPicturesTableArray() 
    {


	  var aTable        	= findObject("PicturesTable",0);
	  var leftPicture   	= findObject("leftPictureL",0);
//	  var leftPictureP   	= findObject("leftPictureP",0);
	  var tableL			= findObject("tableL",0);
//	  var tableP			= findObject("tableP",0);
	  var itemTitle			= findObject("itemTitle",0);
	  var itemType      	= findObject("itemType",0);
	  var itemStyle     	= findObject("itemStyle",0);
	  var itemAvailability = findObject("itemAvailability",0);
	  var tblSpacer         = findObject("tableSpacer",0);
	  var progressBar   	= findObject("progressBar",0);
	  var heightSpacer       = findObject("heightSpacer",0);
	  var websiteLink		= findObject('websiteLink',0);
	  var collectionIcon	= findObject('collectionIcon',0);
	  
//	  loadingObject 	= findObject("loading",1);
//      loadingGifObject  =  findObject("loadingGif",1);
	  
	  var j;	  
      picturesTableArray = [aTable,leftPicture,itemTitle,itemStyle , itemType,
	  						itemAvailability,tableL,tblSpacer,progressBar,heightSpacer, websiteLink, collectionIcon ];
							
	  for (j = 0; j< 8; j++)
		   {
			var loadBarObject 		= findObject("load"+(j+1),0);
			var loadBarTableObject  = findObject("tableLoad"+(j+1),0);
			loadBars[j] = [loadBarTableObject, loadBarObject];
	       };	 
	//alert('picture array done');
	 };

	
function buildObjectArray() 
    {
		buildPicturesTableArray();
	 	var i;
	 	for (i = 0; i <numberOfItems; i++)
	 	 	{
	      	var aTable = findObject("Table"+i,0);
	      	tableElementsArray[i] = aTable;
	     	};
	 };


function buildViewsArray()
	{
	 var i;
	 var j; 
	 for(i=0; i < numberOfItems; i++) 
   		{var view0;
		 var image1;
		 view0  = "../../images/prices/"+tableData[i][1]+"/"+tableData[i][7]+"/"+tableData[i][10]+"/views/"+tableData[i][8]+"-V.jpg";
		 //alert(view0);
		 viewsImagesArray[i] = view0;
		 viewsLoadedStatusArray[i] = 0;
		  image1 = new Image();
		  //image1.height = '240';
		  //if (tableData[currentIndex][11] == 0)
		  //	image1.width = '343';
		 // else
		  //	image1.width = '168';
		  //image1.style.align="center";
		  image1.src = view0;
		  viewsLoadedImagesArray[i] = image1;
   		};
	 //alert('end views array');
	};
	
 /* ================================================
   functions to show data
   ================================================*/
 function showCollectionButton(index)
    {	
	    var temp; 
		temp = picturesTableArray[11];
		//alert(collectionID);
         if ((tableData[index][14] !== 0) && (collectionID == 0))
		  temp.style.visibility="visible"; 	  
	 	 else
		  temp.style.visibility = "hidden";		
	};
	
 function showWebsiteLink(index)
    {	
	    var temp; 
		temp = picturesTableArray[10];
		//temp1 = findObject('wlink',0);
		//alert(temp1.href);
		//alert(temp1.href);		
         if (tableData[index][13] == 3) 
		  {temp.innerHTML =  "<a id=\"wlink\" href=\"http:\/\/" + tableData[index][15] +"\" target=\"\_blank\"> Link to "+tableData[index][15]+"<\/a>";
		   //temp1.href = "http://"+ tableData[index][15];
		   //alert(temp.innerHTML);
		   temp.style.visibility="visible"; }	  
	 	 else
		  temp.style.visibility = "hidden";		
	};
	
 function highlightCurrentPic(thumbId)
    {
//	 alert(currentThumb);
 	 //alert('current picture');	 
	 if (typeof(thumbId) !== "undefined")
	     {temp = findObject(currentThumb,0);
//		  temp.style.border="#ffffff 2px solid";  white border
          //alert('found object');
		  temp.style.border="0"; 		  
	 	  currentThumb = thumbId; };
	 //alert('found object');	  
	 temp = findObject(currentThumb,0);
	 temp.style.border="#FFDD00 2px solid"; 
	     
	};
	

function showEnlargedView() 
	{
     //alert("current Index "+currentIndex);
	 var leftPicture;
	 var browserType;
	 var aWidth; 
	 var aHeight;

 aHeight = viewsLoadedImagesArray[currentIndex].height;
 	 //alert(aHeight);
// This doesnt seem to center the picture - bug !!!
  if ((aHeight <240) && (aHeight > 0))
	               {calc = (240 - aHeight)-54;
				    //alert(calc);
				    if (calc > 0)
					    picturesTableArray[9].style.height= calc + "px";
				   }
	 else 
	 				picturesTableArray[9].style.height= "0px";
						 
     leftPicture  = picturesTableArray[1];
	 picturesTableArray[7].style.width= "1px";
//	leftPicture.onLoad= stopLoading();
	 leftPicture.src = viewsLoadedImagesArray[currentIndex].src;

     browserType = whichBrs();
	 aWidth = viewsLoadedImagesArray[currentIndex].width;
	

	  //alert(aWidth);	 
	 if (browserType !== 'Internet Explorer')
	    { if ((aWidth < 330) && (aWidth > 0))
	    			{calc = parseInt((330-aWidth)/2);
	     			 picturesTableArray[7].style.width= calc+"px"; }
		  else
		  			picturesTableArray[7].style.width= "1px";
	    };
		//alert(calc);
   
	};

	
function showDetails (index,thumbId) 
	{ 
	    //picturesTableArray[1].src = "../../images/Gifs/firstPicture256.gif";
     	//alert('jim Details');
//		loadingObject.visibility="visible";
//		loadingGifObject.visibility="visible";

//		startLoading();
        //alert(thumbId);
		highlightCurrentPic(thumbId); 
		 currentPicture = "Table"+index;
   	 	 currentIndex = index;
//	 	 haveLoadedImages = checkLoadedImages();
		 //alert(tableData[currentIndex][3]);
//		 alert(currentIndex);
         //alert('highlighted');
		 showCollectionButton(index);
		 showWebsiteLink(index);
		 
	 	 picturesTableArray[2].innerHTML= tableData[currentIndex][3];
		 if(tableData[currentIndex][6] == "")
			picturesTableArray[3].innerHTML= tableData[currentIndex][4];
		 else		    
	 	    picturesTableArray[3].innerHTML= tableData[currentIndex][4]+' , '+tableData[currentIndex][6];		 
	 	 picturesTableArray[4].innerHTML= tableData[currentIndex][5];
		 if ((tableData[currentIndex][13] == 1) || (tableData[currentIndex][13] == 2))
	 	   picturesTableArray[5].innerHTML= 'Available, &copy;' +tableData[currentIndex][2]; 
		 else
	 	   picturesTableArray[5].innerHTML= 'In private collection, &copy;' +tableData[currentIndex][2]; 
				 
//		 alert(priceDisplay);

		 showTable();
	     showEnlargedView();
 
    };
function showTable()
	{
	 var i;
	 var aTableObject; 
//	 alert(priceDisplay);
     for (i=0; i < numberOfItems; i++)
		 { 
	  	  aTableObject = tableElementsArray[i];		  
	      if ((currentIndex == i) && (priceDisplay !== 0) )
//          if (currentIndex == i) 			   
			    aTableObject.style.display="block";
		  else
		     aTableObject.style.display="none";
 		 };
		 //alert('show table');

	};

	  
function showPrices()
    {
     var i;
	 i = findObject("prices",0);
	 if((priceDisplay) == 1)
	      {priceDisplay = 0;
		   mess = 'Show Prices';
		   }
	 else
	      {priceDisplay = 1;
		   mess = 'Hide Prices';
		   };
      i.alt = mess;
	  showTable();
	  };
	  
function setPricesLabels()
    {
     var i;
	 i = findObject("prices",0);
	 if((priceDisplay) == 1)
	      {mess = 'Hide Prices';
		   }
	 else
	      {mess = 'Show Prices';
		   };
      i.alt = mess;
	  };