/************************************************************************** 
*************************************************************************** 
*  Program Name: $Id: gallery.js,v 1.20 2007/08/25 23:21:53 neo Exp $
*  Program Author:  Michael T. Schock
*  Creation Date: 05-15-2006
*  CVS Revision: $Revision: 1.20 $
*  Copyright (c) 2006
*************************************************************************** 
*************************************************************************** 
*  Program Summary:
*  Javascript functions for the thumbnail galleries
*
*
*************************************************************************** 
**************************************************************************/

//  Page variables
var imageIndex = 0;
var maxImage = 0;

//!  Scroll Image
/**  This function will scroll the images (Thumbnails) either up or down.  */
function Scroll_Thumbs(direction)
{
	//  Variables
	var containerObj;
	var tableLength;
	var cellData;
	var rowObj;
	var cellObj;
	
	//  Get the initial vars
	containerObj = document.getElementById('Thumbs');
	tableLength = containerObj.rows.length;
	maxImage = tableLength - 3;
	
	//  Shrink or grow the image
	if(direction == 'down')
	{
		if(imageIndex <= maxImage)
		{
			//  Get the cell data
			cellData = containerObj.rows[0].cells[0].innerHTML;
			
			//  Create a new row on the end of the table
			rowObj = containerObj.insertRow(tableLength);
			
			//  Add a new cell to the row
			cellObj = rowObj.insertCell(0);
			
			//  Set the data into the cell
			cellObj.innerHTML = cellData;
			
			//  Delete the first row
			containerObj.deleteRow(0);
				
			//  Increment the image counter
			imageIndex++;
		}
	}
	else if(direction = 'up')
	{
		if(imageIndex > 0)
		{
			//  Get the cell data
			cellData = containerObj.rows[(tableLength - 1)].cells[0].innerHTML;
			
			//  Insert a new row at the beginning of the table
			rowObj = containerObj.insertRow(0);
		
			//  Add a new cell object
			cellObj = rowObj.insertCell(0);
			
			//  Set the data into the cell
			cellObj.innerHTML = cellData;
			
			//  Delete the last row of the table
			containerObj.deleteRow(tableLength);
		
			//  Decrement the image counter
			imageIndex--;
		}
	}
}


//!  Display Main Image
/**  This function will display an image in the image iframe.  */
function Display_Image(pictureName)
{
	//  Set the image to the loader gif
	document.getElementById('Image_Display').src = '../Graphics/loader.gif';
	
	//  Set the new image into the display box
	if(pictureName != '')
		document.getElementById('Image_Display').src = '../Images/Resized_Images/n_' + pictureName;
	
	//  Log the image
	document.getElementById('Image_Logger').src = 'display_logger.php?Image_Name=' + pictureName;
	
	//  Set the image name into the hidden field
	document.getElementById('Image_Name').value = pictureName;
	
	//  Get the pricing and size information
	Ajax_Load(pictureName);
}


//!  Ajax Load
/**  Get the Ajax Data.  */
function Ajax_Load(image)
{
	//  Variables
	var imageName = '';
	var imageNameFull = '';
	var nameOffset = 0;
	
	//  Turn off pricing
	return(0);
	
	//  Set the URL
	url='get_price.php?Image_Name=' + image;
	
	//  Process XML Data
	Load_XML_Doc(url, Process_Request_Change);
}

//!  Process the XML Data
/**  Function to process the returned data.  */
function Parse_Data(xmlData)
{
	//  Variables
	var rowObj;
	var colObj;
	var dataObj;
	var titleObj;
	var descriptionObj;
	var yearObj;
	var divObj;
	var rowCount;
	var tableObj;
	var tableBodyObj;
	var tableRowObj;
	var tableHeaderObj;
	var tableCellObj;
	var cellText;
	var clickText;
	var sizeHtml;
	var priceHtml;
	var loop;
	var index;
	
	//  Get the div object where the table will go.
	divObj = document.getElementById('Payment_Information');
	
	//  Get the old table obj and delete it
	if(divObj.childNodes[0])
	{
		tableObj = divObj.childNodes[0];
		divObj.removeChild(tableObj);
	}
	
	//  Get the row count
	dataObj = xmlData.getElementsByTagName('data');
	titleObj = dataObj[0].getElementsByTagName('title');
	descriptionObj = dataObj[0].getElementsByTagName('description');
	yearObj = dataObj[0].getElementsByTagName('year');
	rowCount = dataObj.length;
	
	
	//  Create the table
	tableObj = document.createElement("table");
	
	//  Create the body
	tableBodyObj = document.createElement("tbody");
		
	//  Create the title row
	if(titleObj[0].firstChild.data != '')
	{
		tableRowObj = document.createElement("tr");
		tableHeaderObj = document.createElement("th");
		tableHeaderObj.innerHTML = titleObj[0].firstChild.data.substring(7);
		tableRowObj.appendChild(tableHeaderObj);
		tableHeaderObj.style.backgroundColor = "#967761";
		if(titleObj[0].firstChild.data == "Title: ")
			tableHeaderObj.style.color = "black";
		else
			tableHeaderObj.style.color = "#3b041e";
		tableHeaderObj.style.fontSize = "12pt";
		tableHeaderObj.style.fontWeight = "Bold";
		tableHeaderObj.style.textAlign = "center";
		tableHeaderObj.colSpan = 2;
		tableBodyObj.appendChild(tableRowObj);
	}
		
	//  Create blank row
	tableRowObj = document.createElement("tr");
	tableCellObj = document.createElement("td");
	tableCellObj.innerHTML = '&nbsp;';
	tableRowObj.appendChild(tableCellObj);
	tableCellObj.style.backgroundColor = "#967761";
	tableCellObj.style.color = "#3b041e";
	tableCellObj.style.fontSize = "8pt";
	tableCellObj.colSpan = 2;
	tableBodyObj.appendChild(tableRowObj);
	
	//  Create the Year row
	if(yearObj[0].firstChild.data != '')
	{
		tableRowObj = document.createElement("tr");
		tableCellObj = document.createElement("td");
		tableCellObj.innerHTML = yearObj[0].firstChild.data.substring(6);;
		tableRowObj.appendChild(tableCellObj);
		tableCellObj.style.backgroundColor = "#967761";
		if(yearObj[0].firstChild.data == "Year: ")
			tableCellObj.style.color = "#3b041e";
		else
			tableCellObj.style.color = "#3b041e";
		tableCellObj.style.fontSize = "10pt";
		tableCellObj.colSpan = 2;
		tableBodyObj.appendChild(tableRowObj);
	}
		
	//  Create the description row
	if(descriptionObj[0].firstChild.data != '')
	{
		tableRowObj = document.createElement("tr");
		tableCellObj = document.createElement("td");
		tableCellObj.innerHTML = descriptionObj[0].firstChild.data.substring(6);;
		tableRowObj.appendChild(tableCellObj);
		tableCellObj.style.backgroundColor = "#967761";
		if(descriptionObj[0].firstChild.data == "Desc: ")
			tableCellObj.style.color = "#3b041e";
		else
			tableCellObj.style.color = "#3b041e";
		tableCellObj.style.fontSize = "10pt";
		tableCellObj.colSpan = 2;
		tableBodyObj.appendChild(tableRowObj);
	}
		
	//  Create blank row
	tableRowObj = document.createElement("tr");
	tableCellObj = document.createElement("td");
	tableCellObj.innerHTML = '&nbsp;';
	tableRowObj.appendChild(tableCellObj);
	tableCellObj.style.backgroundColor = "#967761";
	tableCellObj.style.color = "#3b041e";
	tableCellObj.style.fontSize = "8pt";
	tableCellObj.colSpan = 2;
	tableBodyObj.appendChild(tableRowObj);
	
	//  Create the column headers row
	tableRowObj = document.createElement("tr");
	tableCellObj = document.createElement("td");
	cellText = document.createTextNode('Size');
	tableCellObj.appendChild(cellText);
	tableRowObj.appendChild(tableCellObj);
	tableCellObj.style.backgroundColor = "#967761";
	tableCellObj.style.color = "#3b041e";
	tableCellObj.style.fontSize = "10pt";
	tableCellObj.style.textAlign = "center";
	tableCellObj.style.fontWeight = "Bold";
	tableCellObj = document.createElement("td");
	cellText = document.createTextNode('Price');
	tableCellObj.appendChild(cellText);
	tableRowObj.appendChild(tableCellObj);
	tableCellObj.style.backgroundColor = "#967761";
	tableCellObj.style.color = "#3b041e";
	tableCellObj.style.fontSize = "10pt";
	tableCellObj.style.textAlign = "center";
	tableCellObj.style.fontWeight = "Bold";
	tableBodyObj.appendChild(tableRowObj);
		
	//  Loop through the xml file
	for(loop = 0; loop < rowCount; loop++)
	{
		//  Get the column count
		priceObj = dataObj[loop].getElementsByTagName('picprice');
		sizeObj = dataObj[loop].getElementsByTagName('picsize');
		priceNoteObj = dataObj[loop].getElementsByTagName('picpricenote');
		
		//  Create the header row
		tableRowObj = document.createElement("tr");
		
		//  Create the header
		tableCellObj = document.createElement("td");
		
		if(priceNoteObj[0].firstChild.data != 'None')
		{
			sizeHtml = sizeObj[0].firstChild.data + '<br><font style="font-size:8pt">' + priceNoteObj[0].firstChild.data + '</font>';
		}
		else
		{
			sizeHtml = sizeObj[0].firstChild.data;
		}
		
		//  Set the text into the header
		tableCellObj.innerHTML = sizeHtml;
		
		//  Append the header to the row
		tableRowObj.appendChild(tableCellObj);
		tableCellObj.style.backgroundColor = "#967761";
		tableCellObj.style.color = "#3b041e";
		tableCellObj.style.fontSize = "10pt";
		tableCellObj.style.textAlign = "center";
		
		//  Create the header
		tableCellObj = document.createElement("td");
		
		//  Get the title data
		priceHtml = "$" + priceObj[0].firstChild.data;
		
		//  Set the text into the header
		tableCellObj.innerHTML = priceHtml;
		
		//  Append the header to the row
		tableRowObj.appendChild(tableCellObj);
		tableCellObj.style.backgroundColor = "#967761";
		tableCellObj.style.color = "#3b041e";
		tableCellObj.style.fontSize = "10pt";
		tableCellObj.style.textAlign = "center";
		
		//  Append the row to the table
		tableBodyObj.appendChild(tableRowObj);
		
		//  Create Button Row
		tableRowObj = document.createElement("tr");
		tableCellObj = document.createElement("td");
		clickText = "Buy_Image('" + sizeObj[0].firstChild.data + "')";
		tableCellObj.innerHTML = '<input type="button" value="Purchase" onclick="' + clickText + '">';
		tableRowObj.appendChild(tableCellObj);
		tableCellObj.style.textAlign = "center";
		tableCellObj.colSpan = 2;
		tableBodyObj.appendChild(tableRowObj);
		
	}
	
	//  Append the table body to the table
	tableObj.appendChild(tableBodyObj);
	
	//  Append the table to the div
	divObj.appendChild(tableObj);
	
	//  Set appropriate styles for the table
	tableObj.style.width = "100%";
	tableObj.id = "Created_Table";
}

//!  Buy the image
/**  Set the image size and submit the page to go to the shopping cart.  */
function Buy_Image(imageSize)
{
	//  Set the image size
	document.getElementById('Image_Size').value = imageSize;
	
	//  Set the page action
	document.getElementById('Page_Action').value = "Add_To_Cart";
	
	//  Submit the page
	document.Data_Form.submit();
}
