//=======================================================
// Popup Fucntions
//
// Used for:
//           Essentials popup and 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
//=======================================================

var overlayOpacity = 0.8;	// controls transparency of shadow overlay
var overlayDuration = 0.2;	// shadow fade in/out duration

Event.observe(window, 'load', createLightBox, false);

//--------------------
// Hide Popup Function
//--------------------
function hidePopup( popupBox )
{
    //hidePopup() is passed by the flash only so it defaults to hide all of them
	if( document.getElementById('IntContentCase') != null )
	{
		document.getElementById("IntContentCase").style.visibility = "visible";	
		document.getElementById("IntContentCase").style.height = "632px";	
		document.getElementById("IntContentCase").style.overflow = "auto";
		//alert("I Found IntContentCase");
	} else {
		//alert("I Didn't Find IntContentCase");
	}
	document.getElementById('popupEssentials').style.visibility = "hidden";
	new Effect.Fade('popupGrey', { duration: overlayDuration});
	if( document.getElementById('popupHolder') != null )
	{
		document.getElementById('popupHolder').style.visibility = "hidden";
	}
	if( document.getElementById('popupEvents') != null )
	{
		document.getElementById('popupEvents').style.visibility = "hidden";
	}
	document.getElementById('popupMapHolder').style.visibility = "hidden";
}

function createLightBox()
{
	var objBody = document.getElementsByTagName("body").item(0);
		
	var objOverlay = document.createElement("div");
	objOverlay.setAttribute('id','popupGrey');
	objOverlay.style.display = 'none';
	objBody.appendChild(objOverlay);
}


Object.extend(Element, {
	getWidth: function(element) {
	   	element = $(element);
	   	return element.offsetWidth; 
	},
	setWidth: function(element,w) {
	   	element = $(element);
    	element.style.width = w +"px";
	},
	setHeight: function(element,h) {
   		element = $(element);
    	element.style.height = h +"px";
	},
	setTop: function(element,t) {
	   	element = $(element);
    	element.style.top = t +"px";
	},
	setLeft: function(element,l) {
	   	element = $(element);
    	element.style.left = l +"px";
	},
	setSrc: function(element,src) {
    	element = $(element);
    	element.src = src; 
	},
	setHref: function(element,href) {
    	element = $(element);
    	element.href = href; 
	},
	setInnerHTML: function(element,content) {
		element = $(element);
		element.innerHTML = content;
	}
});




function getPageSize(){
	
	var xScroll, 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, 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;
}



//--------------------
// Show Popup Function
//--------------------
function showPopup( popupBox )
{
	var arrayPageSize = getPageSize();
	Element.setWidth('popupGrey', arrayPageSize[0]);
	Element.setHeight('popupGrey', arrayPageSize[1]);
	new Effect.Appear('popupGrey', { duration: overlayDuration, from: 0.0, to: overlayOpacity });
	if( document.getElementById('IntContentCase') != null )
	{
		document.getElementById("IntContentCase").style.visibility = "hidden";	
		document.getElementById("IntContentCase").style.overflow = "hidden";
		document.getElementById("IntContentCase").style.height = "5px";	
	}
	document.getElementById(popupBox).style.visibility = "visible";
}

//--------------------
// Show Map Popup Function
//--------------------
function popupMapShow( popupStr )
{
	switch( popupStr )
	{
		case "popupAreaMap":
			so = new SWFObject("/flash/area_map.swf", "arm", "997", "595", "8", "#666");
			break;
		case "popupCommunityMap":
			so = new SWFObject("/flash/comm_map.swf", "cmm", "997", "595", "8", "#666");
			break;
		default:
			so = new SWFObject("/flash/area_map.swf", "arm", "997", "595", "8", "#666");
			break;
	}
	so.addParam("wmode", "transparent");
	so.write("popupMapCase");
	document.getElementById('flashcontent').innerHTML = "empty me";
	showPopup( "popupMapHolder" );
	var arrayPageSize = getPageSize();
	Element.setWidth('popupGrey', arrayPageSize[0]);
	Element.setHeight('popupGrey', arrayPageSize[1]);
	new Effect.Appear('popupGrey', { duration: overlayDuration, from: 0.0, to: overlayOpacity });
}

//-------------------------------
// Show Essentials Popup Function
//-------------------------------
function showEss( pelement )
{
		var so = new SWFObject("/fileadmin/images/flash/essentials_popUp1.swf", "ess", "650", "400", "8", "#000");
		so.addVariable("whereAt", pelement );
		so.addParam("wmode", "transparent");
		so.write("flashcontent");
		showPopup( "popupEssentials" );
}

//-----------------------------------
// Show Sub Essentials Popup Function
//-----------------------------------
function showEss2( pelement )
{
		var so = new SWFObject("/fileadmin/images/flash/essentials_popUp1.swf", "ess", "650", "400", "8", "#000");
		so.addVariable("whereAt", pelement );
		so.addParam("wmode", "transparent");
		so.write("flashcontent");
		showPopup( "popupEssentials" );
}

//-----------------------------------
// Show Sub Events Popup Function
//-----------------------------------
function showEvents( pelement )
{
		var so = new SWFObject("../flash/events_popup_a.swf", "event", "650", "400", "8", "#000");
		so.addVariable("whereAt", pelement );
		so.addParam("wmode", "transparent");
		so.write("eventscontent");
		showPopup( "popupEvents" );
}

//-------------------------------
// Show Amenities Popups Function
//-------------------------------
var toggleme = 0;
function showAmenitiesPopup( popupStr )
{
	switch( popupStr )
	{
		case "ski":
			so = new SWFObject("/flash/amenities_ski.swf", "amn", "650", "400", "8", "#000");
			break;
		case "hike":
			so = new SWFObject("/flash/amenities_hike.swf", "ams", "650", "400", "8", "#000");
			break;
		case "alpine":
			so = new SWFObject("/flash/amenities_alpine.swf", "amn", "650", "400", "8", "#000");
			break;
		case "southpeak":
			so = new SWFObject("/flash/amenities_southpeak.swf", "amn", "650", "400", "8", "#000");
			break;
		case "pemi":
			so = new SWFObject("/flash/amenities_pemipark.swf", "amn", "650", "400", "8", "#000");
			break;
		case "skating":
			so = new SWFObject("/flash/amenities_skating.swf", "amn", "650", "400", "8", "#000");
			break;
		default:
			so = new SWFObject("/flash/amenities_ski.swf", "amn", "650", "400", "8", "#000");
			break;
	}
	so.addParam("wmode", "transparent");
	so.write("popupCase");
	showPopup( "popupHolder" );
}