/**
 *	Function Name	:	fnSetFooterStyle
 *	Description		:	This function decides between 2 footer CSS classes, based on the size of the
 *						window vs. content.
 *  Input Paramters : 	Content Div ID, Footer Div ID, Absolute Footer Class Name, Static Footer Class Name
 */
function fnSetFooterStyle(strContentAreaIDp, strFooterAreaIDp, strAbsolFootClsp, strStatcFootClsp)
{
	var strAbsFooterL = strAbsolFootClsp;	//Copy the absolute positioned footer name from the parameter
	if (strAbsolFootClsp.substr(0,1) == ".")	// Remove leading "." if necessary
	{
		strAbsFooterL = strAbsolFootClsp.substr(1);
	}
	var strStcFooterL = strStatcFootClsp;	//Copy the static positioned footer name from the parameter
	if (strStatcFootClsp.substr(0,1) == ".")	// Remove leading "." if necessary
	{
		strStcFooterL = strStatcFootClsp.substr(1);
	}
	var strLookingForL = "." + strAbsFooterL;	//Create a variable for class to be searched in CSS for

	var intWindowHeightL = 0;	// Determine the window height
	if (navigator.appName.indexOf("Microsoft") != -1)
		intWindowHeightL = document.documentElement.clientHeight;
	else
		intWindowHeightL = window.innerHeight;

	var intContentHeightL = document.getElementById(strContentAreaIDp).scrollHeight; // Determine the content height
	var intMenuHeightL = document.getElementById("MenuArea").scrollHeight; 			 // Determine the menu area height
	if (intContentHeightL < intMenuHeightL)
	{
		//Fix for when content is smaller than menu area: use the menu area height and set content height to menu height
		intContentHeightL = intMenuHeightL;
		document.getElementById(strContentAreaIDp).style.height = intMenuHeightL + "px";
	} 

	var intHeaderHeightL = 130; //Indicate header height (determined in CSS)
	var intFooterHeightL = 28;	//Indicate footer height (determined in CSS)

	// Add size of header and footer to content height
	intContentHeightL = intContentHeightL + intHeaderHeightL + intFooterHeightL;

	if (intWindowHeightL > intContentHeightL)
	{
		//Window is bigger than content. set Style to pin footer to bottom of window using absolute position style
		document.getElementById(strFooterAreaIDp).className = strAbsFooterL;
	}
	else
	{
		//Content is bigger than window. set Style to put footer after content using static position style
		document.getElementById(strFooterAreaIDp).className = strStcFooterL;
	}	
}

/**
 *	Function Name	:	fnBuildMenu	
 *	Description 	:	Build the menu dynamically here, so it is changed once for all pages
 */
function fnBuildMenu()
{
	var boolIE6 = (typeof document.documentElement.style.maxHeight=="undefined") ? true : false; 

	document.write('<h3>Navigation:</h3>');
	document.write('<ul>');
	document.write('<li><a href="#">Who We Are</a>');
	document.write('	<ul>');
	document.write('		<li><a href="Overview.html">Overview</a></li>');
	document.write('		<li><a href="History.html">Our History</a></li>');
	document.write('		<li><a href="Staff.html">Our Staff</a></li>');
	document.write('		<li><a href="Directors.html">Board of Directors</a></li>');
	document.write('	</ul></li>');
	document.write('<li><a href="#">Where We Serve</a>');
	document.write('	<ul>');
	document.write('		<li><a href="AboutVologda.html">Vologda</a></li>');
	document.write('		<li><a href="AboutCherepovets.html">Cherepovets</a></li>');
	document.write('	</ul></li>');
	document.write('<li><a href="#">What We Do</a>');
	document.write('	<ul>');
	document.write('	<li><a href="Vologda.html">Comfort Vologda</a></li>');
	document.write('	<li><a href="Cherepovets.html">Comfort Cherepovets</a></li>');
	document.write('	<li><a href="Bookstore.html">Living Word Bookstore</a></li>');
	document.write('	</ul></li>');
	document.write('<li><a href="Calendar.html">Events</a></li>');
	document.write('<li><a href="Opportunities.html">Get Involved</a></li>');
	document.write('<li><a href="NewsNewsletters.html">News & Links</a></li>');
	if (!boolIE6)
	{	//Most content will not be supported in IE6 or earler, so don't load the menu items
		document.write('<li><a href="#">Photos & Video</a>');
		document.write('	<ul>');
		document.write('	<li><a href="Photos.html">Photo Slideshows</a></li>');
		document.write('	<li><a href="Videos.html">Videos</a></li>');
		document.write('	</ul></li>');
	}
//	document.write('<li><a href="#">Mailing List</a></li>');
	document.write('<li><a href="Contact.html">Contact Us</a></li>');
	document.write('</ul>');
}

/**
 *	Function Name	:	fnBuildLinks	
 *	Description 	:	Build a series of images and links. Done here so updates affect all pages.
 */
function fnBuildLinks()
{
		/* PayPal donate ********/
	document.write('<form action="https://www.paypal.com/cgi-bin/webscr" method="post">');
	document.write('	<input type="hidden" name="cmd" value="_s-xclick">');
	document.write('	<input type="hidden" name="hosted_button_id" value="KZGZ6VAYLYG7Q">');
	document.write('	<input type="image" src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="Donate using PayPal!">');
	document.write('	<img alt="" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">');
	document.write('</form>');
		/* Facebook link ********/
	document.write('<a style="display:block;margin-top:15px;width:148px;height:40px;" href="http://www.facebook.com/group.php?gid=129193501628"><img src="./images/findusonfacebook.gif" alt="Comfort Foundation on Facebook" width="131px" height="40px" /></a>');
		/* Twitter link ********/
	document.write('<a style="display:block;margin-top:15px;width:148px;height:36px;" href="http://twitter.com/#!/ComfortFound"><img src="http://twitter-badges.s3.amazonaws.com/follow_bird_us-a.png" alt="Comfort Foundation on Twitter" /></a>');
		/* Good Search link ********/
	document.write('<a style="display:block;margin-top:15px;width:148px;height:60px;" href="http://www.goodsearch.com/" TARGET="_blank">');
	document.write('    <img src="http://www.goodsearch.com/_gfx/gs-cause-120x60.gif" width="120px" height="60px" alt="Support Comfort Foundation by using GoodSearch!" />');
	document.write('</a>');
}

function fnBuildSliderImages(boolLarge)
{
	var strImages = "Image01,Image02,Image03,Image04,Image05,Image06,Image07,Image08,Image09,Image10,"
	strImages += "Image11,Image12,Image13,Image14,Image15,Image16,Image17,Image18,Image19,Image20,";
	strImages += "Image21,Image22,Image23,Image24,Image25";
	var aryImageList = 	strImages.split(",");
	var aryNewArray = new Array();
	var intStartingImg = Math.floor(Math.random()*25);

	for(var iImg=intStartingImg;iImg<=aryImageList.length-1;iImg++)
		aryNewArray.push(aryImageList[iImg]);
	for(var iImg=0;iImg<=intStartingImg-1;iImg++)
		aryNewArray.push(aryImageList[iImg]);
	strImages = aryNewArray.join(",");

	var strImgLocation = "";
	var strElementID = "";
	if (boolLarge)
	{
		strImgLocation = "images/slide_lg/";
		strElementID = "#slider_lg";
	}
	else
	{
		strImgLocation = "images/slide_sm/";
		strElementID = "#slider_sm";
	}

	fnCreateSlideshow(strImages, strImgLocation,strElementID,false);
}

function fnBuildSliderImagesOld(boolLarge)
{
	var strImages = "Image01,Image02,Image03,Image04,Image05,Image06,Image07,Image08,Image09,Image10,"
	strImages += "Image11,Image12,Image13,Image14,Image15,Image16,Image17,Image18,Image19,Image20,";
	strImages += "Image21,Image22,Image23,Image24,Image25,Image26,Image27,Image28";
	var aryImageList = 	strImages.split(",");
	var intStartingImg = Math.floor(Math.random()*25);
	var strImageList = '<ul>';
	var strImgLocation = "";
	var strElementID = "";
	if (boolLarge)
	{
		strImgLocation = "images/slide_lg/";
		strElementID = "slider_lg";
	}
	else
	{
		strImgLocation = "images/slide_sm/";
		strElementID = "slider_sm";
	}

	//Resort images to make random
	for(var iImg=intStartingImg;iImg<=aryImageList.length-1;iImg++)
		strImageList += '<li><img src="' + strImgLocation + aryImageList[iImg] +'.JPG" alt="" /></li>';
	for(var iImg=0;iImg<=intStartingImg-1;iImg++)
		strImageList += '<li><img src="' + strImgLocation + aryImageList[iImg] +'.JPG" alt="" /></li>';

	strImageList += '</ul>';

	document.getElementById(strElementID).innerHTML = strImageList;
}

function fnBuildVologdaImages()
{
	var strImages = "001,002,003,004,005,006,007,008,009,010,011,012,013,014,015,016,017,018,020,";
	strImages += "021,022,023,024,025,026,027,028,029,030,031,032,033,034,035,036,037,038,039,040,";
	strImages += "041,042,043,044,045,046,047,050,051,052,053,054,055,056,057,058,059,060,061";
	var	strImgLocation = "images/Vologda/";
	var strElementID = "#divSlideshow";

	fnCreateSlideshow(strImages, strImgLocation,strElementID,true);
}

function fnBuildCherepovetsImages()
{
	var strImages = "001,002,003,004,005,006,007,007a,008,009,009a,010,011,012,013,014,015,016,017,018,018a,019,020,";
	strImages += "021,022,023,024,025,026,027,028,029,030,031,032,033,034,035,036,037,038,039,040,";
	strImages += "041,042,043,044,045,046,047,048,049,050,051";
	var	strImgLocation = "images/Cherepovets/";
	var strElementID = "#divSlideshow";

	fnCreateSlideshow(strImages, strImgLocation,strElementID,true);
}


function fnCreateSlideshow(strListOfImagesP, strImageLocationP, strElementP, boolIncludeMapP)
{
	var aryImageList = 	strListOfImagesP.split(",");
	var strFunction = "$(function(){$('"+strElementP+"').crossSlide({sleep: 2,fade: 1}, [";
	if (boolIncludeMapP) strFunction += "{src:'"+strImageLocationP+"map.gif'},";

	for(var iImg=0;iImg<=aryImageList.length-1;iImg++)
		aryImageList[iImg] = "{src:'"+strImageLocationP+aryImageList[iImg]+".jpg'}";

	strFunction += aryImageList.join(",") + "])});";

	setTimeout(strFunction,10);		//setTimeout...the great converter of string data into executable code!
}

