function writeFooter()
{
document.write('<tr><td colspan="2" bgcolor="#b51414" height="1"></td></tr>');
document.write('<tr height="1%"><td colspan="2" align="center" valign="top" class="header">');
document.write('<img src="/photography/images/spacer.gif"><br>');
document.write('<img src="/photography/images/spacer.gif"><br>');
document.write('all images &copy; 2005-2009 south12th. all rights reserved.</td></tr>');
}


function writeHeader()
{
document.write('<tr height="1%" valign="bottom">');
document.write('<td class="title">south<font color="#b51414" class="title">12th</font>photography</td>');
document.write('<td align="right" valign="bottom"><a class="header" href="/photography/index.html">home</a> | <a class="header" href="/photography/contact.html">contact</a> | <a class="header" href="/photography/stock.html">stock list</a> | <a class="header" href="/photography/search.php">search</a> | <!-- <a class="header" href="/photography/new.html">new</a> |--> <a class="header" href="/photography/gallery.php?my_lightbox">my lightbox</a> | <a class="header" href="/photography/purchase.html">pricing</a></td>');
document.write('</tr>');
document.write('<tr><td colspan="2" bgcolor="#b51414" height="1"></td></tr>');
}

function loadPageInNewWin(page) 
{
switch (page){
	case "42": 
	theURLtoLoad="/photography/snapshot.html";
	break;
	default : theURLtoLoad="/photography/snapshot.html";
	}
winName="newWin";
window.open(theURLtoLoad, winName, 'width=400,height=400')
}


function getCusername()
{
allcookies = document.cookie;
var pos = allcookies.indexOf("Cusername=");
if(pos != -1)
	{
	var start = pos + 10;
	var end=allcookies.indexOf(";",start);
	if(end ==-1) end = allcookies.length;
	var value=allcookies.substring(start,end);
	value=unescape(value);
	//document.write("Found cookie: " + value);
	return value;
	}
}

function getDefaultLightbox()
{
allcookies = document.cookie;
var pos = allcookies.indexOf("DefaultLightbox=");
if(pos != -1)
	{
	var start = pos + 16;
	var end=allcookies.indexOf(";",start);
	if(end ==-1) end = allcookies.length;
	var value=allcookies.substring(start,end);
	value=unescape(value);
	//document.write("Found cookie: " + value);
	return value;
	}
}

function checkLightbox(image_reference)
{
//alert('check');
currentLightbox=loadLightbox();
found=currentLightbox.indexOf(image_reference);
if(found != -1) {return true;}
else {return false;}
//alert(returnVal);
}

function loadLightbox()
{
// Gets the current lightbox contents from your cookies. Returns a string.
allcookies = document.cookie;
prefix = "lightbox=";
var pos = allcookies.indexOf(prefix);
if(pos != -1)
	{
	var start = pos + 9;
	var end=allcookies.indexOf(";",start);
	if(end ==-1) end = allcookies.length;
	var value=allcookies.substring(start,end);
	value=unescape(value);
	//document.write("Found cookie: " + value);
	return value;	
	}
	else {return "";}
}

function updateLightboxText(image_reference)
{
//alert("got to updateLBT with " + image_reference);
//Updates the text on the gallery.php page to show current state of that image -- in lightbox or not
//Show Add or remove text as appropriate for that image

	isInLB=checkLightbox(image_reference);
	if(navigator.family =="nn4") 
	{
		if(isInLB==true)
			{
			document.addToLB.document.write("javascript:removeFromLightbox('" + image_reference + "');");
			document.addToLB.document.close();
			}
		else
			{
			document.addToLB.document.write("javascript:addToLightbox('" + image_reference + "');");
			document.addToLB.document.close();
			}
	}
	else if(navigator.family =="ie4")
	{
		if(isInLB==true)
			{
			addToLB.innerHTML="<img src='/photography/images/lightbox.gif' border=0 width=17 height=17> image in lightbox (remove)";
			addToLB.href="javascript:removeFromLightbox('" + image_reference + "');";
			}
		else
			{
			addToLB.innerHTML="<img src='/photography/images/lightbox.gif' border=0 width=17 height=17> add image " + image_reference + " to lightbox";
			addToLB.href="javascript:addToLightbox('" + image_reference + "');";
			}
	}
	else if(navigator.family =="gecko")
	{
		if(isInLB==true)
			{
			document.getElementById("addToLB").innerHTML="<img src='/photography/images/lightbox.gif' border=0 width=17 height=17> image in lightbox (remove)";
			document.getElementById("addToLB").href="javascript:removeFromLightbox('" + image_reference + "');";
			}
		else
			{
			document.getElementById("addToLB").innerHTML="<img src='/photography/images/lightbox.gif' border=0 width=17 height=17> add image " + refArray[image_to_use] + " to lightbox";
			document.getElementById("addToLB").href="javascript:addToLightbox('" + image_reference + "');";
			}
	}

}


function removeFromLightbox(image_reference)
{
// Takes current lightbox (from cookie), removes image_reference, updates lightbox cookie

//load lightbox
//check whether image ref is in there
//remove the image
//rewrite lightbox to cookie
//if on lightbox page, reload to show image now gone
//if on other page, just change text on page to indicate removed
currentLightbox=loadLightbox();
//alert(currentLightbox);
toRemove=new RegExp("\'" + image_reference + "\'");
//alert(toRemove);
newLightbox=currentLightbox.replace(toRemove,"");
newLightbox=newLightbox.replace(/,,/,",");
newLightbox=newLightbox.replace(/^,/,"");
newLightbox=newLightbox.replace(/,$/,"");
//alert(newLightbox);
document.cookie="lightbox=" + newLightbox + ";path=/";			
updateLightboxText(image_reference);
}

function clearLightbox()
{
			document.cookie="lightbox=" + ";path=/";
			alert("Your lightbox has been cleared.");
}



function addToLightbox(image_reference)
{
	currentLightbox=loadLightbox();
	if(currentLightbox)
	{
		//alert('ligthbox has values');
		//first, check to see if this value is already in the lightbox
		searchFor="'" + image_reference + "'";
		found=currentLightbox.indexOf(searchFor);
		//alert(found + " " + currentLightbox + " " + searchFor);
		//if found, alert. if not (-1), go ahead and add
		if(found==-1)
			{
			newcookie=currentLightbox + ",'" + image_reference + "'";
			document.cookie="lightbox=" + newcookie + ";path=/";			
			}
		else
			{alert('This image is already in your lightbox.');}
		
	}
	else
	{
	//alert('lightbox is empty');
	document.cookie="lightbox='" + image_reference + "'"  + ";path=/";
	}
	updateLightboxText(image_reference);
}