//declare variables and arrays
//
var NumPics=0;// counter of actual pictures
var TotalPics=0;//counter so total number of pictures isn't exceeded
var loadcounter=0;
var i;//generic counter
var expDays = 360;//cookie expiration in number of days
var exp = new Date(); 
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
//arrays for cookie values
var PictureDetails = new Array();
var PictureInfo = new Array();
var PictureNumber = new Array();
var PictureName = new Array ();//images names array
var PicturePageURL = new Array();//image display page URL array
var ThumbnailLocation = new Array();
var PictureLocation = new Array();
var ThumbnailURL = new Array ();//thumbnail URL array
var ImageURL = new Array();
var rawImages=new Array();
//
// Main load photos routine
//
function LoadThumbnails()
{
NumPics = GetCookie('NumPictures');
if (NumPics != null) 
	{
	var Pictures=GetCookie('PictureDetails'); //Get Packed Cookie
	PictureDetails=Pictures.split('*');
	for (i=0; i < NumPics; i++)		{
	PictureInfo=PictureDetails[i].split('!');
		PictureNumber[i] = PictureInfo[0];
		PictureName[i] = PictureInfo[1];
		PictureLocation[i]=PictureInfo[2];
		PicturePageURL[i]=PictureLocation[i]+".htm";
		ThumbnailLocation[i]=PictureInfo[3];
		ThumbnailURL[i]="thumbnails"+ThumbnailLocation[i]+".JPG";	
		ImageURL[i]="images"+PictureInfo[4]+".JPG";
		rawImages[i]=new Image();
		rawImages[i].onload=Showload;
		rawImages[i].onerror=Showerror;
		rawImages[i].src=ThumbnailURL[i];
		}
	}
}
//
function Showload()
{
loadcounter++;
}
//
function Showerror(count)
{
window.alert("A thumbnail image failed to load and will be skipped. Please report this by using our comments page or email. Thank you.");
loadcounter++;
}
// Main Set Picture Cookie Routine
// Add Items
function AddItem(Details) 
{
var PicturesArrayDetails;
TotalPics = GetCookie('NumPictures');
if (TotalPics == null) {TotalPics = 0};
TotalPics++;
var Pictures=GetCookie('PictureDetails'); //Get Current Packed Cookie
SetCookie('NumPictures',TotalPics,exp); // Increase picture counts
if (Pictures != null)
{
PicturesArrayDetails = Pictures+Details+"*"//Append New Photo Details
}
else
{PicturesArrayDetails = Details+"*";}
SetCookie('PictureDetails',PicturesArrayDetails,exp);
window.location = window.location;
}
//
function purchasePhoto(count){
var PurchaseInfo=PictureNumber[count]+"*"+ThumbnailLocation[count]+"*"+PictureName[count];
SetCookie('PhotoPurchase',PurchaseInfo,exp)
window.location="purchase-photo.htm"
}
//
function decoratePhoto(count){
var DecorateInfo=ThumbnailLocation[count]+"*"+PictureName[count]+"*"+PictureLocation[count]+"*"+PictureNumber[count];
SetCookie('PhotoDecor',DecorateInfo,exp)
window.location="new-decorate.htm"
}
//
// Delete Items
//
function DeleteItem(count) 
{
NumPics = GetCookie('NumPictures');
var NewNumPics=NumPics-1;
// Condense Arrays
var j=0; //index used to collapse array
for (var i=count; i < NumPics; i++)
{
	PictureDetails[i]=PictureDetails[i+1];
	PictureName[i] = PictureName[i+1];
	PictureLocation[i] = PictureLocation[i+1];
	PicturePageURL[i] = PicturePageURL[i+1];
	ThumbnailLocation[i]=ThumbnailLocation[i+1]
	ThumbnailURL[i] = ThumbnailURL[i+1];
	ImageURL[i]=ImageURL[i+1];
	PictureNumber[i]=PictureNumber[i+1];
}
// Rewrite Cookies
NumPics=NewNumPics;
DeleteCookie('NumPictures');
DeleteCookie('PictureDetails');
for (var i=0; i < NumPics; i++)
{
var Details=PictureDetails[i];
AddItem(Details);
}
window.location = window.location;
}
// Generic Set Cookie Routine
function SetCookie (name, value) {  
var argv = SetCookie.arguments;  
var argc = SetCookie.arguments.length;  
var expires = (argc > 2) ? argv[2] : null;  
var path = (argc > 3) ? argv[3] : null;  
var domain = (argc > 4) ? argv[4] : null;  
var secure = (argc > 5) ? argv[5] : false; 
//var curCookie = name + "=" + escape(value) +
//      ((expires) ? "; expires=" + expires.toGMTString() : "") +
//     ((path) ? "; path=" + path : "") +
//      ((domain) ? "; domain=" + domain : "") +
//      ((secure) ? "; secure" : "");
var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
		("; path=/") + 
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
document.cookie = curCookie;
}
//
// Generic get cookie and return cookie value routine
//
function GetCookie (name) {  
var arg = name + "=";  
var alen = arg.length;  
var clen = document.cookie.length;  
var i = 0;  
while (i < clen) {    
var j = i + alen;    
if (document.cookie.substring(i, j) == arg)      
return getCookieVal (j);    
i = document.cookie.indexOf(" ", i) + 1;  
if (i == 0) break;   
}  
return null;
}
//
// Generic determine cookie value routine
//
function getCookieVal (offset) {  
var endstr = document.cookie.indexOf (";", offset);  
if (endstr == -1)    
endstr = document.cookie.length;  
return unescape(document.cookie.substring(offset, endstr));
}
// Generic Delete Cookie Routine
//
function DeleteCookie (name) {  
var cval = GetCookie (name);  
document.cookie = name + "=" + cval + "; expires=Wed, 04-Feb-2004 00:00:01 GMT";
}
// Browser test - right now album only support IE4+ and NS6+ with script and cookies enabled
//
function BrowserCookieTest()
{
var cookieEnabled = new Boolean (false);
cookieEnabled=(navigator.cookieEnabled)? true : false;
var getElement = new Boolean (false);
getElement=(document.getElementById)? true: false;
if (cookieEnabled && getElement)	{
	return
	}
	else {
	window.alert ("You must have Cookies enabled and be using a supported browser (Internet Explorer 5 or later, Netscape 6 or later, or another modern browser) to use this site feature. Click OK below to go to the on-line gallery index page");
	window.location="gallery_bridge_page.htm";
	}
}