//declare variables and arrays
//
ResetURL();
var message="Copyrighted Image. Please consider purchasing a print.";
var NumPics=0;// counter of actual pictures
var TotalPics=0;//counter so total number of pictures isn't exceeded
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));
//
// variables for building cookie data about favorites and ordering
var PictureNumber; 
var PictureName; 
var PictureLocation;
var ThumbnailLocation;
var ImageLocation;
//
// variables for fitting picture and adjusting size
var rawImageHeight;
var rawImageWidth;
var rawAspectRatio;
var PhotoHeight;
var PhotoWidth;
var initialHeight;
var initialWidth;
var incrementHeight;
var decrementHeight;
//
// variables for image bar location
var imagebarTop;
var imagebarLeft;
var imagebarLength=428;
//
// Screen dimensions. Do this instead of getting actual inside screen dimensions
// since most people need full screen display to view image properly anyway.
var ScreenWidth=window.screen.width;
var ScreenHeight=window.screen.height;
var WindowHeight=420;
var CellHeight=470;
if (ScreenHeight <= 600 ) {
	WindowHeight=300;
	CellHeight=350;
}
// make it a little more difficult to steal an image
document.oncontextmenu=new Function("alert(message);return false")
//
function clickIE4(){
if (event.button==2){
alert(message);
return false;
}
}
function clickNS4(e){
if (document.layers||document.getElementById&&!document.all){
if (e.which==2||e.which==3){
alert(message);
return false;
}
}
}
if (document.layers){
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=clickNS4;
}
else if (document.all&&!document.getElementById){
document.onmousedown=clickIE4;
}
//
// 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
return cookieEnabled;
}
//
// Resize photo to fit screen
function RetrieveResizeDimensions()	{
	rawImageHeight=document.images.mainpic.height;
	rawImageWidth=document.images.mainpic.width;
	rawAspectRatio=rawImageWidth/rawImageHeight;
	PhotoHeight=rawImageHeight;
	PhotoWidth=rawImageWidth;
//If necessary adjust image to fit window height
	if (PhotoHeight > WindowHeight)	{
		PhotoHeight=WindowHeight;
		PhotoWidth=PhotoHeight*rawAspectRatio;
	}
//If necessary adjust image to fit width
	if (PhotoWidth > ScreenWidth - 50) {
		PhotoWidth=ScreenWidth-50;
		PhotoHeight=PhotoWidth/rawAspectRatio;
	}
	document.images.mainpic.height=PhotoHeight;
	document.images.mainpic.width=PhotoWidth;
//Set resizing variables for enlargement feature
	initialHeight=PhotoHeight;
	initialWidth=PhotoWidth;
	incrementHeight=Math.round((rawImageHeight - initialHeight) / 2);
	if (incrementHeight < 30) {incrementHeight=Math.round((rawImageHeight - initialHeight))};
	}
//
// Constuct Image Toolbar
//
function constructImageBar() {
imagelocation();

var thecontents="<p style=\"position:absolute\; top:"+imagebarTop+"px\; left:"+imagebarLeft+"px\; background-color: #EDEEE8\; border: 0px; font-size: 11px\; vertical-align:middle\; margin: 0px\; padding: 0px\;\ height: 14px\;\"><a  id=\"addfav\" href=\"javascript:AddItem()\">Add to Album</a>|<a   href=\"../new-my-favorites.htm\">My Album</a>|<a   href=\"../my-slideshow-preload.htm\">Slide Show</a>|<a s href=\"javascript:void(0)\" onclick=\"javascript:increasePhotoSize()\;return false\;\" id=\"incsize\">Enlarge</a>|<a  href=\"javascript:void(0)\" onclick=\"javascript:decreasePhotoSize()\;return false\;\" id=\"decsize\">Reduce</a>|<a  href=\"javascript:decoratePhoto()\">Decorate</a>|<a  href=\"javascript:purchasePhoto()\">Add to Cart</a>|<a href=\"javascript:viewCart()\">View Cart</a></p>";

document.getElementById("imagebardiv").innerHTML=thecontents;
disableIncrease();
disableDecrease();
if (incrementHeight > 4) {enableIncrease();}
}
//
//Enlarge Photo up to Raw Dimensions and reduce to Screen fit dimensions
function increasePhotoSize()	{
	if (PhotoHeight < rawImageHeight) {
		enableDecrease();
		PhotoHeight=PhotoHeight+incrementHeight;
		PhotoWidth=PhotoWidth=PhotoHeight*rawAspectRatio;
		document.images.mainpic.height=PhotoHeight;
		document.images.mainpic.width=PhotoWidth;
		if (PhotoHeight >= rawImageHeight) {disableIncrease();}
	}
}	
//
function decreasePhotoSize()	{
	if (PhotoHeight > initialHeight)	{
		enableIncrease();
		PhotoHeight=PhotoHeight-incrementHeight;
		PhotoWidth=PhotoWidth=PhotoHeight*rawAspectRatio;
		document.images.mainpic.height=PhotoHeight;
		document.images.mainpic.width=PhotoWidth;
		if (PhotoHeight <= initialHeight) {disableDecrease();}
	}
}	
function enableIncrease()	{
		document.getElementById("incsize").style.color="#000080";
}
function disableIncrease()	{
		document.getElementById("incsize").style.color="#CACACA";
}
function enableDecrease()	{
	document.getElementById("decsize").style.color="#000080";
}
function disableDecrease()	{
		document.getElementById("decsize").style.color="#CACACA";
}
//
// determine where to place toolbar
function imagelocation()	{
	var xtop=document.getElementById("mainpic").offsetTop;;
	var lefttop=document.getElementById("mainpic").offsetLeft;
//		imagebarTop=xtop-30;
		imagebarTop=9;
		if (imagebarLength > initialWidth) {
	imagebarLeft=(lefttop+Math.floor(initialWidth/2)) - Math.floor(imagebarLength/2);
	}
	else imagebarLeft=lefttop+initialWidth-imagebarLength;
}
//
function decoratePhoto(){
var DecorateInfo=ThumbnailLocation+"*"+PictureName+"*"+PictureLocation;
SetCookie('PhotoDecor',DecorateInfo,exp)
var SelectedPhoto="../thumbnails/"+ThumbnailLocation+".JPG";
var rawImages=new Image();
rawImages.onload=Showload;
rawImages.onerror=Showerror;
rawImages.src=SelectedPhoto;
}
//
// On Load Handler
function Showload()
{
window.location="../new-decorate.htm"
}
//
//
function Showerror(count)
{
window.alert("The thumbnail of the image failed to load. Please report this by using our comments page or email. Thank you.");
}
//
//
function purchasePhoto(){
var PurchaseInfo=PictureNumber+"*"+ThumbnailLocation+"*"+PictureName;
SetCookie('PhotoPurchase',PurchaseInfo,exp)
window.location="../purchase-photo.htm"
}
//
function viewCart() {
var thispagesURL='squam.boaters.home.att.net/'+PictureLocation+'.htm';
window.location="http://emartnet.com/cart/odb/cart.odb?merchantID=1375&logoUrl=http%3A//squam.boaters.home.att.net/logo-150x50.jpg&return="+thispagesURL;
}
// Main Picture Cookie Routines
//
// Add Items
function AddItem() {
	TotalPics = GetCookie('NumPictures');
	var PictureDetails;
	if (TotalPics == null) {TotalPics = 0};
	TotalPics++;
	if (TotalPics <13)	{
		var Pictures=GetCookie('PictureDetails'); //Get Current Packed Cookie
		SetCookie('NumPictures',TotalPics,exp); // Increase picture counts
		if (Pictures != null)	{
			PictureDetails = 	Pictures+PictureNumber+"!"+PictureName+"!"+PictureLocation+"!"+ThumbnailLocation+"!"+ImageLocation+"!*";
			}
		else {
			PictureDetails = PictureNumber+"!"+PictureName+"!"+PictureLocation+"!"+ThumbnailLocation+"!"+ImageLocation+"!*";
		}
		SetCookie('PictureDetails',PictureDetails,exp);
		window.location = window.location;
		}
else window.alert("Limit of 12 photos in your album. Please visit your album page to make room");
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));
}
//
function ResetURL()	{
var componentsURL=new Array();
componentsURL=document.URL.split('/');
var numberComponents=componentsURL.length;
var RevisedPictureLocation="http://squam.boaters.home.att.net/"+componentsURL[numberComponents-2]+"/"+componentsURL[numberComponents-1].substring(0,componentsURL[numberComponents-1].length-4)+".htm";
if ( componentsURL[numberComponents-3].toLowerCase() != "squam.boaters.home.att.net")	{
		window.location=RevisedPictureLocation;
		}
}
