//=======================================================
// Popup Fucntions
//
// Used for:
//           Internal page popups.
//
// Notes:
//        'popupGrey': Black see-through background that
//                     overcoats the site when a popup is
//                     enabled.
//
// Controls:
//          Pass hidePopup/showPopup a div's ID and it
//          will perform the action.
//
// Popup Scripts copyright amplifystudios.com
//=======================================================

//--------------------
// Hide Popup Function
//--------------------
function hidePopup( popupBox )
{
	dg(popupBox).style.visibility = "hidden";
	dg('popupGrey').style.display = "none";
}

//--------------------
// Show Popup Function
//--------------------
function createLightBox()
{
	if( !dg('popupGrey') )
	{
		var objBody = document.getElementsByTagName("body").item(0);
			
		var objOverlay = document.createElement("div");
		objOverlay.id = 'popupGrey';
		objOverlay.style.visibility = "visible";
		objOverlay.style.display = 'none';
		objBody.appendChild(objOverlay);
	}
}

function showPopup( popupBox )
{
	switch( popupBox )
	{
		case "lakeclub":
			var so = new SWFObject("flash/LakeClub_popupImages.swf", "ess", "465", "387", "8", "#000");
			so.write("lakeclubcont");
			break;
		case "goldenfarm":
			var so = new SWFObject("flash/GoldenFarm_popupImages.swf", "ess", "465", "387", "8", "#000");
			so.write("goldenfarmcont");
			break;
		case "millpondpark":
			var so = new SWFObject("flash/MillPond_popupImages.swf", "ess", "465", "387", "8", "#000");
			so.write("millpondparkcont");
			break;
		case "bearcreekpark":
			var so = new SWFObject("flash/BearCreek_popupImages.swf", "ess", "465", "387", "8", "#000");
			so.write("bearcreekparkcont");
			break;
		case "trailsgreenway":
			var so = new SWFObject("flash/Trails_popupImages.swf", "ess", "465", "387", "8", "#000");
			so.write("trailsgreenwaycont");
			break;
		
	}
	createLightBox();
	var arrayPageSize = getPageSize();
	dg('popupGrey').style.width = (arrayPageSize[0]) + "px";
	dg('popupGrey').style.height = (arrayPageSize[1]) + "px";
	dg('popupGrey').style.display = "block";
	dg(popupBox).style.left = (((arrayPageSize[0]) - 805) / 2) + "px";
	dg(popupBox).style.visibility = "visible";
}

function dg( o ) { return document.getElementById( o ); }

function popupMapShow( popupStr )
{
	switch( popupStr )
	{
		case "popupAreaMap":
			/*so = new SWFObject("/flash/area_map.swf", "arm", "997", "595", "8", "#666");*/
			dg('popupMapCase').innerHTML = "<a href=\"javascript:hidePopup('popupMapHolder')\"><img src=\"../images/Areamap.png\" border=\"0\"></a>";
			break;
		case "popupCommunityMap":
			/*so = new SWFObject("/flash/comm_map.swf", "cmm", "997", "595", "8", "#666");*/
			dg('popupMapCase').innerHTML = "<a href=\"javascript:hidePopup('popupMapHolder')\"><img src=\"../images/Communitymap.jpg\" border=\"0\"></a>";
			break;
		default:
			/*so = new SWFObject("/flash/area_map.swf", "arm", "997", "595", "8", "#666");*/
			dg('popupMapCase').innerHTML = "<a href=\"javascript:hidePopup('popupMapHolder')\"><img src=\"../images/Communitymap.jpg\" border=\"0\"></a>";
			break;
	};
	/*so.addParam("wmode", "transparent");
	so.write("popupMapCase");
	dg('flashcontent').innerHTML = "empty me";*/
	createLightBox();
	var arrayPageSize = getPageSize();
	dg('popupGrey').style.width = arrayPageSize[0].toString() + "px";
	dg('popupGrey').style.height = arrayPageSize[1].toString() + "px";
	dg('popupGrey').style.display = "block";
	dg('popupMapHolder').style.left = ((arrayPageSize[0].toString() - 997) / 2) + "px";
	dg('popupMapHolder').style.visibility = "visible";
}

function getPageSize(){
	
	var xScroll;
	var yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth;
	var windowHeight;
	
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight + 50;
	} else { 
		pageHeight = yScroll + 50;
	}


	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return arrayPageSize;
}