function addDays(myDate,days) 
{
    return new Date(myDate.getTime() + days*24*60*60*1000);
}

function setCookie(name, value, days)
{
	if(value == "")
	{
		var the_value = "true";
	}
	else
	{
		var the_value = value;
	}
	var the_date = addDays(new Date(), days);
	var the_cookie_date = the_date.toGMTString();
	var the_cookie = name + "=" + the_value;
	the_cookie = the_cookie + ";path=/;expires=" + the_cookie_date;
	//var nowString = addDays(new Date(), '0');
	//alert(nowString + "--" + the_cookie);
	document.cookie = the_cookie;
}

function getCookie(cookiename)
{
	var cookiestring=""+document.cookie;
	var index1=cookiestring.indexOf(cookiename);
	if (index1==-1 || cookiename=="") return ""; 
	var index2=cookiestring.indexOf(';',index1);
	if (index2==-1) index2=cookiestring.length; 
	return unescape(cookiestring.substring(index1+cookiename.length+1,index2));
}


// The following scripts and functions allow the header area 
// of the page to "collapse" in smaller window sizes

var ns	= (document.layers || (document.getElementById && !document.all)) ? true:false;
var ie	= (document.all) ? true:false;


window.onresize = function headresizer()
{
	winH = (ns)? (window.innerHeight) : document.body.offsetHeight
	
	var hVal = (winH - 495) + 50;
	
	if(hVal < 50)
	{
		hVal = 50;
	}
	if(hVal > 84)
	{
		hVal = 84;
	}
	hValue = hVal + 'px';
	setStyle('head', 'height', hValue);
	setCookie('hValue', hVal, '0.02');
}

function findheadsize()
{
	var the_cookie = getCookie("hValue");
	if(the_cookie == "")
	{
		winH = (ns)? (window.innerHeight) : document.body.offsetHeight
		
		var hVal = (winH - 495) + 50;
		
		if(hVal < 50)
		{
			hVal = 50;
		}
		if(hVal > 84)
		{
			hVal = 84;
		}
		hValue = hVal + 'px';
		setStyle('head', 'height', hValue);
		setCookie('hValue', hVal, '0.02');
		//alert("hVal found");
	}
	else
	{
		//alert(the_cookie);
	}
}


function headresize() {
	var the_cookie = getCookie("hValue");
	//alert("the_cookie ='" + the_cookie + "'");

	if(the_cookie > 0)
	{
		var hVal = the_cookie;
		var hValue = hVal + 'px';
		
		document.write('<STY' + 'LE\> \n'); //FS hide this from IE4.5 Mac by splitting the tag
		document.write('#head { \n');
		document.write('  height: ' + hValue + '\n');
		document.write('}\n');
		document.write('</STY' + 'LE\> \n');
	}
}



function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);



// The following functions run the photo gallery pages.
// They allow the scrolling thumbnail navigation.

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}


function change(id, newClass)
{
	if(document.getElementById(id) != null)
	{
		var identity = document.getElementById(id);
		identity.className = newClass;
	}
}


function loadContents(divID, divIDContents)
{
	var contents = document.getElementById(divIDContents).innerHTML;
	document.getElementById(divID).innerHTML = contents;
}


function setStyle(objID, style, value)
{
	document.getElementById(objID).style[style] = value;
}


function slideLayers(layer1, layer2, d, direction)
{
	var d = (d - 28);
	var i = (distance - d);
	
	if(direction == "left")
	{
		var dir = "-";
		var value = dir + (i);
		setStyle(layer1, 'left', value);
		
		var value = (d);
		setStyle(layer2, 'left', value);
	}
	
	if(direction == "right")
	{
		var dir = "-";
		var value = (i);
		setStyle(layer1, 'left', value);
		
		var value = dir + (d);
		setStyle(layer2, 'left', value);
	}
	
	
	if(d > 0)
	{
		func = "slideLayers('" + layer1 + "', '" + layer2 + "', " + d + ", '" + direction + "');";
		//alert(func);
		var slideID = window.setTimeout(func, 20);
	}
}

function move(position, direction)
{
	var group1 = position-1;
	var group2 = position;
	var group3 = position+1;
	
	if(group1 < 1)			group1 = numDots;
	if(group1 > numDots)	group1 = 1;
	if(group2 < 1)			group2 = numDots;
	if(group2 > numDots)	group2 = 1;
	if(group3 < 1)			group3 = numDots;
	if(group3 > numDots)	group3 = 1;
	
	var layer1	= 'dl' + group1;
	var layer2	= 'dl' + group2;
	var layer3	= 'dl' + group3;
	
	loadContents('a', layer1);
	loadContents('b', layer2); 
	loadContents('c', layer3);
	
	var slideID = clearTimeout(slideID);
	change('a', 'displayData');
	change('b', 'displayData');
	change('c', 'displayData');

	setStyle('a', 'left', '-252px');
	setStyle('b', 'left', '0px');
	setStyle('c', 'left', '252px');
		
	
	if(direction == "forward")
	{
		slideLayers('b', 'c', distance, 'left');
		
		document.getElementById("bLink").href = "javascript:move(" + group3 + ",'back');";
		document.getElementById("fLink").href = "javascript:move(" + group3 + ",'forward');";
		
		var value = "url(../_images/photo-galleries/bg-dots-" + (numDots) + "_" + (group3) + ".gif) top center no-repeat";
		var func = "setStyle('photoNavHeader', 'background', '" + (value) + "');"
		var finishedID = window.setTimeout(func, ((distance/25) * 28));
	}
	
	if(direction == "back")
	{
		slideLayers('b', 'a', distance, 'right');
		
		document.getElementById("bLink").href = "javascript:move(" + group1 + ",'back');";
		document.getElementById("fLink").href = "javascript:move(" + group1 + ",'forward');";
		
		var value = "url(../_images/photo-galleries/bg-dots-" + (numDots) + "_" + (group1) + ".gif) top center no-repeat";
		var func = "setStyle('photoNavHeader', 'background', '" + (value) + "');"
		var finishedID = window.setTimeout(func, ((distance/25) * 28));
	}
	
}


function showPhoto(imageNumber)
{
	var image = "../_images/" + galleryName + "/" + (imageNumber) + ".jpg";
	var value = "url(" + image + ") center center no-repeat";
	//alert(value);
	
	MM_preloadImages(image);
	setStyle('fullPhoto', 'background', value);
	clicked++;
	if(clicked == 1) noteColor = "#6E6A5A";
	if(clicked == 2) noteColor = "#545145";
	if(clicked == 3) noteColor = "#3B3930";
	//if(clicked == 4) noteColor = "#21201B";
	setStyle('galleryNote', 'color', noteColor);
}


MM_preloadImages('../_images/photo-galleries/bg-dots-6_1.gif','../_images/photo-galleries/bg-dots-6_2.gif','../_images/photo-galleries/bg-dots-6_3.gif','../_images/photo-galleries/bg-dots-6_4.gif','../_images/photo-galleries/bg-dots-6_5.gif','../_images/photo-galleries/bg-dots-6_6.gif','../_images/photo-galleries/bg-dots-5_1.gif','../_images/photo-galleries/bg-dots-5_2.gif','../_images/photo-galleries/bg-dots-5_3.gif','../_images/photo-galleries/bg-dots-5_4.gif','../_images/photo-galleries/bg-dots-5_5.gif');

headresize();

var clicked = 0;