//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);
//	  alert('jim left picture');
	  var leftPicture   	= findObject("leftPictureL",0);
//	  alert(leftPicture);
//	  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; 
	 
//	 VIDEO - 2011		 
     if (tableData[0][7] !== 15) 
			{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.src = view0;
		  		viewsLoadedImagesArray[i] = image1;
   				};
			 }
	  else
	  		{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]+".mov";
		  		//alert(view0);
				viewsLoadedImagesArray[i] = view0;
   				};
			 }
	};
	
 /* ================================================
   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 if (tableData[index][13] == 4) 
		  {temp.innerHTML =  tableData[index][15] ;
		   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 showVideo()	
{
// if wmode is transparent, it works for IE but you cannt see the buttons
// doesnt work for mozila. <PARAM NAME=\"wmode\" VALUE=\"transparent\">, wmode= \"transparent\"   bgcolor="#ffffff" 
   var line0='<OBJECT    CODEBASE=\"http:\/\/www.apple.com\/qtactivex\/qtplugin.cab\" WIDTH= \"220\" HEIGHT= \"190\" CLASSID= \"clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B\" >';
//	alert(line0);
		var line1='<PARAM NAME=\"controller\" VALUE=\"true\">  <PARAM NAME=\"kioskmode\" VALUE=\"true\"> <PARAM NAME=\"type\" VALUE=\"video\/quicktime\">  <PARAM NAME=\"target\" VALUE=\"myself\"> <PARAM NAME=\"cache\" VALUE=\"true\"> <PARAM NAME=\"autoplay\" VALUE=\"false\"> <PARAM NAME=\"src\" VALUE= \"'+viewsLoadedImagesArray[currentIndex]+' \"> <PARAM NAME=\"pluginspage\" VALUE=\"http:\/\/www.apple.com\/quicktime\/download\/index.html\">';
//	alert(line1);
	var line2='<EMBED  src="' + viewsLoadedImagesArray[currentIndex] + '" WIDTH= \"220\" HEIGHT= \"190\" autoplay= \"false\" type= \"video\/quicktime\"  target= \"myself\" border= \"0\" controller= \"true\" kioskmode= \"true\" cache= \"true\" pluginspage=\"http:\/\/www.apple.com\/quicktime\/download\/index.html\"> <\/EMBED><\/OBJECT>';
//	alert(line2);
   document.getElementById("leftPictureL").innerHTML=line0+line1+line2;
};



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;

//	 	 VIDEO - 2011		 

		 		showCollectionButton(index);
		 		showWebsiteLink(index);
	 	 		picturesTableArray[2].innerHTML= tableData[currentIndex][3];
		 		if(tableData[currentIndex][6] == "")
					picturesTableArray[3].innerHTML= tableData[currentIndex][4];
		 		else
				    if (tableData[currentIndex][7] !== 15)		    
	 	    		     picturesTableArray[3].innerHTML= tableData[currentIndex][4]+' , '+tableData[currentIndex][6];
					else
					      picturesTableArray[3].innerHTML= tableData[currentIndex][4];
						  
	 	 			picturesTableArray[4].innerHTML= tableData[currentIndex][5];
		 			if ((tableData[currentIndex][13] == 1) || (tableData[currentIndex][13] == 2))
//	 	   picturesTableArray[5].innerHTML= 'Available, &copy;' +tableData[currentIndex][2]; 
//         No longer display the year , 2011
		   				picturesTableArray[5].innerHTML= 'Available. &copy;' ; 
		 			else
//	 	   picturesTableArray[5].innerHTML= 'In private collection, &copy;' +tableData[currentIndex][2]; 
//         No longer display the year , 2011
		   				picturesTableArray[5].innerHTML= 'In private collection. &copy;' ; 
				 
//		 alert(priceDisplay);

//       not showing prices anymore, 2011
//		 			showTable();
		 if (tableData[currentIndex][7] !== 15)
		 	     showEnlargedView();
			else
			     showVideo();
 
    };
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;
	  };
	  
/* ================================================
   test functions for video
   ================================================*/

function showDetails1 (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;

//	 	 VIDEO - 2011		 

		 		showCollectionButton(index);
		 		showWebsiteLink(index);
	 	 		picturesTableArray[2].innerHTML= tableData[currentIndex][3];
		 		if(tableData[currentIndex][6] == "")
					picturesTableArray[3].innerHTML= tableData[currentIndex][4];
		 		else
				    if (tableData[currentIndex][7] !== 15)		    
	 	    		     picturesTableArray[3].innerHTML= tableData[currentIndex][4]+' , '+tableData[currentIndex][6];
					else
					      picturesTableArray[3].innerHTML= tableData[currentIndex][4];
						  
	 	 			picturesTableArray[4].innerHTML= tableData[currentIndex][5];
		 			if ((tableData[currentIndex][13] == 1) || (tableData[currentIndex][13] == 2))
//	 	   picturesTableArray[5].innerHTML= 'Available, &copy;' +tableData[currentIndex][2]; 
//         No longer display the year , 2011
		   				picturesTableArray[5].innerHTML= 'Available. &copy;' ; 
		 			else
//	 	   picturesTableArray[5].innerHTML= 'In private collection, &copy;' +tableData[currentIndex][2]; 
//         No longer display the year , 2011
		   				picturesTableArray[5].innerHTML= 'In private collection. &copy;' ; 
				 
//		 alert(priceDisplay);

//       not showing prices anymore, 2011
//		 			showTable();
		 if (tableData[currentIndex][7] !== 15)
		 	     showEnlargedView();

 
    };
