/* Creation date: 1/21/2004 */
//
//declare variables and arrays
//
BrowserCookieTest();
var NumColors=0;// Colors Counter
var TotalColors=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));
//arrays for cookie values
//arrays for cookie values
var ColorCode = new Array();//image display page URL array
var SelectedColors = new Array();
var WallColorCode = new Array();//image display page URL array
var FrameColorCode = new Array();//image display page URL array
var OuterMatColorCode = new Array();//image display page URL array
var InnerMatColorCode = new Array();//image display page URL array
var NumWallColors=0;
var NumFrameColors=0;
var NumOuterMatColors=0;
var NumInnerMatColors=0;
var PhotoHeight;
var PhotoWidth;
var rawImage;
var loadcounter;
//initialize color selections on page
var Colors = GetCookie('Decor');
if (Colors != null)	{
	SelectedColors = Colors.split('*');
	WallColorCode = SelectedColors[0].split('!');
	NumWallColors=WallColorCode[0];
	if (SelectedColors.length > 1) {
		FrameColorCode = SelectedColors[1].split('!');
		NumFrameColors=FrameColorCode[0];
		}
	if (SelectedColors.length > 2)  {
		OuterMatColorCode = SelectedColors[2].split('!');
		NumOuterMatColors=OuterMatColorCode[0];
		}
	if (SelectedColors.length > 3)	{
		InnerMatColorCode = SelectedColors[3].split('!');
		NumInnerMatColors=InnerMatColorCode[0];
		}
	}
// initialize photo information
var DecorateInfo=GetCookie('PhotoDecor');
if (DecorateInfo != null)	{
	var PictureInfo = new Array();
	PictureInfo=DecorateInfo.split('*');
	var SelectedThumbnail=PictureInfo[0];
	var SelectedName=PictureInfo[1];
	var SelectedPhoto="thumbnails"+SelectedThumbnail+".JPG";
	var PhotoPageURL=PictureInfo[2]+".htm";
	var PictureNumber=PictureInfo[3];
	}
else {	var hasFavorites=GetCookie('NumPictures');
			if (hasFavorites != null)	{
				window.alert("You must select a photo prior to using this site feature. Click OK below to proceed to your favorites album.");
				window.location='new-my-favorites.htm';
			}
			else {	window.alert("You must select a photo prior to using this site feature. Click OK below to proceed to the on-line gallery index page.");
						window.location='gallery_bridge_page.htm';
			}
}		
//
function goBack()	{
window.location=PhotoPageURL;
}
//
function showDecorColors()
{
for (var i=1; i<= NumWallColors; i++) {
    switch (i) {
    case 1:
    document.getElementById("wallcover1").style.backgroundColor = WallColorCode[1];
    case 2:
    document.getElementById("wallcover2").style.backgroundColor = WallColorCode[2];
    case 3:
    document.getElementById("wallcover3").style.backgroundColor = WallColorCode[3];
    case 4:
    document.getElementById("wallcover4").style.backgroundColor = WallColorCode[4];
    case 5:
    document.getElementById("wallcover5").style.backgroundColor = WallColorCode[5];
	 case 6:
    document.getElementById("wallcover6").style.backgroundColor = WallColorCode[6];
    }
}
for (var i=1; i<= NumFrameColors; i++) {
    switch (i) {
    case 1:
    document.getElementById("framecolor1").style.backgroundColor = FrameColorCode[1];
    case 2:
    document.getElementById("framecolor2").style.backgroundColor = FrameColorCode[2];
    case 3:
    document.getElementById("framecolor3").style.backgroundColor = FrameColorCode[3];
	 case 4:
    document.getElementById("framecolor4").style.backgroundColor = FrameColorCode[4];
    case 5:
    document.getElementById("framecolor5").style.backgroundColor = FrameColorCode[5];
    case 6:
    document.getElementById("framecolor6").style.backgroundColor = FrameColorCode[6];
    }
}
for (var i=1; i<= NumOuterMatColors; i++) {
    switch (i) {
    case 1:
    document.getElementById("outermatcolor1").style.backgroundColor = OuterMatColorCode[1];
    case 2:
    document.getElementById("outermatcolor2").style.backgroundColor = OuterMatColorCode[2];
    case 3:
    document.getElementById("outermatcolor3").style.backgroundColor = OuterMatColorCode[3];
	 case 4:
    document.getElementById("outermatcolor4").style.backgroundColor = OuterMatColorCode[4];
    case 5:
    document.getElementById("outermatcolor5").style.backgroundColor = OuterMatColorCode[5];
    case 6:
    document.getElementById("outermatcolor6").style.backgroundColor = OuterMatColorCode[6];
    }
}
for (var i=1; i<= NumInnerMatColors; i++) {
    switch (i) {
    case 1:
    document.getElementById("innermatcolor1").style.backgroundColor = InnerMatColorCode[1];
    case 2:
    document.getElementById("innermatcolor2").style.backgroundColor = InnerMatColorCode[2];
    case 3:
    document.getElementById("innermatcolor3").style.backgroundColor = InnerMatColorCode[3];
	 case 4:
    document.getElementById("innermatcolor4").style.backgroundColor = InnerMatColorCode[4];
    case 5:
    document.getElementById("innermatcolor5").style.backgroundColor = InnerMatColorCode[5];
    case 6:
    document.getElementById("innermatcolor6").style.backgroundColor = InnerMatColorCode[6]; 
    }
}
}
//
// size thumbnail by hiding behind wallpaper and then use DOM to get and reset
function sizeThumbnail() {
	document.getElementById("sizephoto").innerHTML ="<img id=\"sizeselectedpic\" src="+SelectedPhoto+">";
	var rawThumbHeight=document.getElementById("sizeselectedpic").height;
	var rawThumbWidth=document.getElementById("sizeselectedpic").width;
	var rawAspectRatio=rawThumbWidth/rawThumbHeight;
	var PhotoHeight=rawThumbHeight;
	var PhotoWidth=rawThumbWidth;
	//If necessary adjust image to fit window height
	PhotoHeight=100;
	PhotoWidth=Math.floor(PhotoHeight*rawAspectRatio);
	if (PhotoWidth < 100) {
    	PhotoWidth=100;
    	PhotoHeight=Math.floor(PhotoWidth/rawAspectRatio);
   }
}
 
function selectWallpaper(color){
	document.getElementById("wallcover").style.backgroundColor = WallColorCode[color];
}
//
function selectFrame(color) {
	document.getElementById("frame").style.backgroundColor = FrameColorCode[color];
	document.getElementById("innerframe").style.backgroundColor = FrameColorCode[color];
}
//
function selectOuterMat(color)	{
	document.getElementById("outermat").style.backgroundColor = OuterMatColorCode[color];
}
//
function selectInnerMat(color)	{
	document.getElementById("innermat").style.backgroundColor = InnerMatColorCode[color];
}
//
function MakeFrameNarrow()	{
	document.getElementById("frame").style.visibility = 'hidden';
}
//
function MakeFrameWide()	{
	document.getElementById("frame").style.visibility =  'visible';
}
//
function purchasePhoto(){
var PurchaseInfo=PictureNumber+"*"+SelectedThumbnail+"*"+SelectedName;
SetCookie('PhotoPurchase',PurchaseInfo,exp)
window.location="purchase-photo.htm"
}
//
// 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 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;
}
//
// 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";
	}
}

