// JavaScript Document
var ClassCallOutText = "After School Enrichment programs in Art and Science offered at many schools in the North Atlanta area";
var CampCallOutText = "Summer, Winter Break and other camp programs offered at many locations throughout the North Atlanta area";
var EventsCallOutText = "Birthday Parties, Scout Functions, Field Trips, Parent's Night Out, etc.";
var PreSchoolArtPopupCaption = "Pre School Art";
var PopupRoot = "";
var SiteRoot = "";

var CookiePairs = Array ();
var BackStack = Array ();
var NextStack = Array ();
var Now = new Date ();
var Expired = new Date ( Now.getTime () - 28 * 24 * 60 * 60 * 1000 );

function SetCookie ( Name, Value )
{
	if ( Value != null && Value != "" )
		document.cookie = Name + "=" + escape ( Value ) + "; path=/"
	else
		DeleteCookie ( Name );
}

function GetCookie ( Name )
{
	for ( Index = 0; Index < CookiePairs.length; Index++ )
	{
		Pair = CookiePairs[Index].split ( "=" );
		if ( Pair[0] == Name )
			return unescape ( Pair[1] );
	}
	
	return null;
}

function DeleteCookie ( Name )
{
	document.cookie = Name + "=null; path=/; expires=0";
}

function PushNext ( URL )
{
	NextStack[NextStack.length] = URL;
	SetCookie ( "NextStack", NextStack.join ( "!" ));
}

function PopNext ()
{
	if ( NextStack.length > 0 )
	{
		Result = NextStack[NextStack.length - 1];
		
		if ( --NextStack.length == 0 )
			DeleteCookie ( "NextStack" )
		else
			SetCookie ( "NextStack", NextStack.join ( "!" ));
	}
	else
		Result = null;
		
	return Result;
}

function GoNext ( Search, Replace )
{
	if ( NextStack.length > 0 )
		if ( arguments.length == 2 )
			window.location.href = PopNext ().replace ( Search, Replace )
		else
			window.location.href = PopNext ();
}

function PushBack( URL )
{
	BackStack[BackStack.length] = URL;
	SetCookie ( "BackStack", BackStack.join ( "!" ));
}

function PopBack ()
{
	if ( BackStack.length > 0 )
	{
		Result = BackStack[BackStack.length - 1];

		if ( --BackStack.length == 0 )
			DeleteCookie ( "BackStack" )
		else
			SetCookie ( "BackStack", BackStack.join ( "!" ));
	}
	else
		Result = null;
		
	return Result;
}

function GoBack ( Search, Replace )
{
	if ( BackStack.length > 0 )
		if ( arguments.length == 2 )
			window.location.href = PopBack ().replace ( Search, Replace )
		else
			window.location.href = PopBack ();
}

function PushCurrent ()
{
	PushBack ( window.location.href );
}

function PushAndGo ( URL )
{
	PushBack ( window.location.href );
	window.location.href = URL;
}

function PushCurrentAndNext ( NextURL )
{
	PushCurrent ();
	PushNext ( NextURL );
}

function ClearStacks ()
{
	DeleteCookie ( "BackStack" );
	DeleteCookie ( "NextStack" );
	BackStack.length = 0;
	NextStack.length = 0;
}

function SetStacks ()
{
	var Entries;

	CookiePairs = document.cookie.split ( "; " );
	
	Entries = GetCookie ( "BackStack" );
	if ( Entries != null )
	{
		BackStack = Entries.split ( "!" )
		if ( BackStack.length == 1 && BackStack[0] == "null" )
			BackStack = Array ();
	}
	else
		BackStack = Array ();

	Entries = GetCookie ( "NextStack" );
	if ( Entries != null )
	{
		NextStack = Entries.split ( "!" )
		if ( NextStack.length == 1 && NextStack[0] == "null" )
			NextStack = Array ();
	}
	else
		NextStack = Array ();

}

function ScrollTo ( Container )
{
	window.scrollTo ( 0, $(Container).offsetTop );
}

function ShowPopup( ) 
{
 return overlib(OLresponseAJAX, TEXTPADDING,0,
  WRAP, BORDER,2,  SCROLL, 
  MIDX,0, RELY,100);
}

function ShowPopupSticky( ) 
{
 
 if ( $('PleaseWait') )
 {
		$('PleaseWait').update();
 }
 return overlib(OLresponseAJAX, TEXTPADDING,0, CAPTIONPADDING,4,
  CAPTION,"Imagine That!",
  WRAP, BORDER,2, STICKY, CLOSECLICK,  SCROLL, PRINT,
  MIDX,0, RELY,100);
}

function ShowIFrame( url ) 
{
       return overlib(OLiframeContent(url,
        550, 350, 'FullPopup', 1),
        WIDTH,550, TEXTPADDING,0, BORDER,2, STICKY, CLOSECLICK, DRAGGABLE,
        CAPTIONPADDING,4, CAPTION,'Example with iframe and AJAX content.&nbsp; '
        +'Draggable via the caption.',
        MIDX,0, MIDY,0, 
        STATUS,'Draggable example with iframe and AJAX content');
}

function DoPopup ( Page, Sticky )
{
	if ( Sticky )
	{
		OLgetAJAX(PopupRoot + Page, ShowPopupSticky, 300, 'Popup');	
	}
	else
	{
		OLgetAJAX(PopupRoot + Page, ShowPopup, 300, 'Popup');	
	}
}

function ShowArtist ( url )
{
	$("ArtistPage").hide();
	$("ArtistPage").update(); 

	new Ajax.Request( url, 
			{  
				onComplete: 
					function(transport)
					{       
						var response = transport.responseText || url;
						$("ArtistPage").update(response); 					 	
						new Effect.Appear ( "ArtistPage", { duration : 0.25 } );
					}     
			}
		); 
}

function LoadFragment ( Fragment, Container)
{
//	$(Container).hide();
//	$(Container).update(); 
	url = SiteRoot + Fragment;

	new Ajax.Request( url, 
			{  
				method : 'get',
				requestHeaders: ["If-Modified-Since", "Thu, 1 Jan 1970 00:00:00 GMT"],
				onComplete: 
					function(transport)
					{       
						var response = transport.responseText || url;
						$(Container).update(response);
//						$(Container).show();
//						new Effect.Appear ( Container, { duration : 0.5 } );
					}     
			}
		); 
}

function lastModified () 
{
	if (Date.parse(document.lastModified) != 0) 
	{
		$( 'last_modified' ).update ("Last modified: " + Date(document.lastModified));
	}
	else
	{
		$( 'last_modified' ).update ();
	}
}

function SetTitle ( title )
{
	document.title = title;
	$('HeaderText').update(title);
}

function LoadMainHome()
{
	LoadFragment ( "home.html", "main-subpage" );
	SetTitle ( "Imagine That! and Future Tech" );
}

function LoadDirections()
{
	LoadFragment ( "Directions/home.html", "main-subpage" );
	SetTitle ( "Maps & Directions" );
}

function LoadMap()
{
	LoadFragment ( "Directions/Locations.php", "main-subpage" );
	SetTitle ( "Locations" );
}

function LoadMapCamp()
{
	LoadFragment ( "Directions/LocationsCamps.php", "main-subpage" );
	SetTitle ( "Locations of Camps" );
}

function LoadDirectionsList ()
{
	new Ajax.Request( SiteRoot + 'Directions/BuildList.php', 
			{  
				parameters : { Camps : $('Camps').checked, Classes : $('Classes').checked },
				onComplete: 
					function(transport)
					{       
						var response = transport.responseText || url;
						$( 'directions' ).update(response); 					 	
					}     
			}
		); 
}

/*--------- Policies Pages ----------*/

function LoadPolicies()
{
	LoadFragment ( "Policies/index.html", "main-subpage" );
	SetTitle ( "Imagine That! Policies" );
}

function LoadPoliciesHome()
{
	LoadFragment ( "Policies/home.html", "Policies-subpage" );
	SetTitle ( "Imagine That! Policies" );
}

function LoadCampFAQ( Container )
{
	LoadFragment ( "Policies/CampFAQ.html", Container );
	SetTitle ( "Frequently Asked Camp Questions" );
}

function LoadClassFAQ( Container )
{
	LoadFragment ( "Policies/ClassFAQ.html", Container );
	SetTitle ( "Frequently Asked Class Questions" );
}

function LoadLEGODisclaimer()
{
	LoadFragment ( "LEGO/Disclaimer.html", "LEGO-Disclaimer" );
}

function LoadFeesInfo()
{
	LoadFragment ( "Classes/Schedules/FeesInfo.html", "FeesInfo" );
}

/*--------- Science Pages ----------*/

function LoadScience(Container)
{
	LoadFragment ( "Science/index.html", Container );
}

function LoadScienceHome ()
{
	LoadFragment ( "Science/home.html", "Science-subpage" );
	SetTitle ( "Science Programs" );
}

function LoadSciencePreSchool ()
{
	LoadPreSchool('Science-subpage', 'Science')
}

/*--------- Art Pages ----------*/

function LoadArt(Container)
{
	LoadFragment ( "Art/index.html", Container );
	SetTitle ( "Art Programs" );
}

function LoadArtHome ()
{
	LoadFragment ( "Art/home.html", "Art-subpage" );
	SetTitle ( "Art Programs" );
}


function LoadArtPreSchool ()
{
	LoadPreSchool('Art-subpage', 'Art')
}

/*--------- Technology Pages ----------*/

function LoadTechnology(Container)
{
	LoadFragment ( "Technology/index.html", Container );
}

function LoadTechnologyHome()
{
	LoadFragment ( "Technology/home.html", "Technology-subpage" );
	SetTitle ( "Technology Programs" );
}


/*--------- Slide Show Pages ----------*/

function LoadSlideshow(Container)
{
	LoadFragment ( "slideshows/index.html", Container );
}

function LoadSlideshowHome()
{
	LoadFragment ( "slideshows/home.html", "Slideshow-subpage" );
	SetTitle ( "Slide Shows" );
}

/*--------- PreSchool Pages ----------*/

function LoadPreSchool(Container, Page)
{
	LoadFragment ( "PreSchool/index.php?page=" + Page, Container );
}

function LoadPreSchoolHome ()
{
	LoadFragment ( "PreSchool/home.html", "PreSchool-subpage" );
	SetTitle ( "Pre School Programs" );
}

function LoadPreSchoolArt ()
{
	LoadFragment ( "PreSchool/Art.html", "PreSchool-subpage" );
	SetTitle ( "Pre School Art Programs" );
}

function LoadPreSchoolScience ()
{
	LoadFragment ( "PreSchool/Science.html", "PreSchool-subpage" );
	SetTitle ( "Pre School Science Programs" );
}

function LoadPreSchoolTechnology ()
{
	LoadFragment ( "PreSchool/Technology.html", "PreSchool-subpage" );
	SetTitle ( "Pre School Technology Programs" );
}

function LoadPreSchoolClasses ()
{
	LoadFragment ( "PreSchool/Classes.html", "PreSchool-subpage" );
	SetTitle ( "Pre School Classes" );
}

function LoadPreSchoolCamps ( Container )
{
	LoadFragment ( "PreSchool/Camps/index.html", Container );
	SetTitle ( "Pre School Camps" );
}

function LoadPreSchoolCampsHome ( Container )
{
	LoadFragment ( "PreSchool/Camps/home.html", Container );
	SetTitle ( "Pre School Camps" );
}

function LoadPreSchoolSummerCamp ( Container )
{
	LoadFragment ( "PreSchool/Camps/Summer.html", Container );
	SetTitle ( "Pre School Summer Camps" );
}

function LoadPreSchoolWinterBreak ( Container )
{
	LoadFragment ( "PreSchool/Camps/WinterBreak.html", Container );
	SetTitle ( "Pre School Winter Break Camps" );
}

/*--------- Elementary School Pages ----------*/

function LoadElementary(Container, Page)
{
	LoadFragment ( "Elementary/index.php?page=" + Page, Container );
}

function LoadElementaryHome ()
{
	LoadFragment ( "Elementary/home.html", "Elementary-subpage" );
	SetTitle ( "Elementary School Programs" );
}

function LoadElementaryArt ()
{
	LoadFragment ( "Elementary/Art.html", "Elementary-subpage" );
	SetTitle ( "Elementary School Art Programs" );
}

function LoadElementaryScience ()
{
	LoadFragment ( "Elementary/Science.html", "Elementary-subpage" );
	SetTitle ( "Elementary School Science Programs" );
}

function LoadElementaryTechnology ()
{
	LoadFragment ( "Elementary/Technology.html", "Elementary-subpage" );
	SetTitle ( "Elementary School Technology Programs" );
}

function LoadElementaryCamps ( Container )
{
	LoadFragment ( "Elementary/Camps/Summer.html", Container );
	SetTitle ( "Elementary School Summer Camps" );
}

/*--------- Middle School Pages ----------*/

function LoadMiddle(Container, Page)
{
	LoadFragment ( "Middle/index.php?page=" + Page, Container );
}

function LoadMiddleHome ()
{
	LoadFragment ( "Middle/home.html", "Middle-subpage" );
	SetTitle ( "Middle School Programs" );
}

function LoadMiddleArt ()
{
	LoadFragment ( "Middle/Art.html", "Middle-subpage" );
	SetTitle ( "Middle School Art Programs" );
}

function LoadMiddleScience ()
{
	LoadFragment ( "Middle/Science.html", "Middle-subpage" );
	SetTitle ( "Middle School Science Programs" );
}

function LoadMiddleTechnology ()
{
	LoadFragment ( "Middle/Technology.html", "Middle-subpage" );
	SetTitle ( "Middle School Technology Programs" );
}

function LoadMiddleCamps ( Container )
{
	LoadFragment ( "Middle/Camps/Summer.html", Container );
	SetTitle ( "Middle School Summer Camps" );
}

/*--------- Camp Pages ----------*/

function LoadCamps( Container, Page)
{
	LoadFragment ( "Camps/index.php?Page=" + Page, Container );
}

function LoadCampsHome ()
{
	LoadFragment ( "Camps/home.html", "Camps-subpage" );
	SetTitle ( "Camps" );
}

/*--------- Summer Camp ----------*/

function LoadSummerCamp(Container, Page)
{
	LoadFragment ( "Camps/Summer/index.php?page=" + Page, Container );
}

function LoadSummerCampHome ()
{
	LoadFragment ( "Camps/Summer/home.html", "Summer-subpage" );
	SetTitle ( "Summer Camps" );
}

function LoadSummerCampFees ()
{
	LoadFragment ( "Camps/Summer/Fees.html", "Summer-subpage" );
	SetTitle ( "Summer Camp Fees" );
}

function GetSummerCamps ()
{
	LoadFragment ( "Camps/Summer/GetCamps.php", "Summer-subpage" );
	SetTitle ( "Summer Camp Schedules" );
}

function ShowSummerCamps ()
{
	$('PleaseWait').update('Please wait, retrieving list');
	OLpostAJAX(SiteRoot + 'Camps/Summer/ShowCamps.php',$('GetSummerCamps').serialize(), ShowPopupSticky, 300, 'FullPopup');	
}

function LoadSummerCampPrograms()
{
	LoadFragment ( "Camps/Summer/Programs/index.html", "Summer-subpage"  );
}

function LoadSummerCampProgramsHome ()
{
	LoadFragment ( "Camps/Summer/Programs/home.html", "SummerPrograms-subpage" );
	SetTitle ( "Summer Camp Programs" );
}

function LoadSummerCampScience ()
{
	LoadFragment ( "Camps/Summer/Programs/Science.html", "SummerPrograms-subpage" );
	SetTitle ( "Summer Camp Science & Technology Programs" );
}

function LoadSummerCampArt ()
{
	LoadFragment ( "Camps/Summer/Programs/Art.html", "SummerPrograms-subpage" );
	SetTitle ( "Summer Camp Art Programs" );
}

function LoadSummerCampTechnology ()
{
	LoadFragment ( "Camps/Summer/Programs/Technology.html", "SummerPrograms-subpage" );
	SetTitle ( "Summer Camp Technology Programs" );
}

function LoadSummerCampCombinations ()
{
	LoadFragment ( "Camps/Summer/Programs/Combinations.html", "SummerPrograms-subpage" );
	SetTitle ( "Summer Camp Combination Programs" );
}

/*--------- Winter Break ----------*/

function LoadWinterBreak(Container)
{
	LoadFragment ( "Camps/WinterBreak/index.html", Container );
}

function LoadWinterCampHome ()
{
	LoadFragment ( "Camps/WinterBreak/home.html", "Winter-subpage" );
	SetTitle ( "Winter Break Camps" );
}

function LoadWinterCamps ()
{
	LoadFragment ( "Camps/WinterBreak/ShowCamps.php", "Winter-subpage" );
	SetTitle ( "Winter Break Schedule" );
}

function ShowWinterCamps ()
{
	OLgetAJAX(SiteRoot + 'Camps/WinterBreak/ShowCamps.php', ShowPopupSticky, 300, 'FullPopup');	
}

/*--------- Teacher Workday ----------*/

function LoadTeacherWorkday(Container)
{
	LoadFragment ( "Camps/TeacherWorkday/index.html", Container );
}

function LoadTeacherWorkdayHome ()
{
	LoadFragment ( "Camps/TeacherWorkday/home.html", "TeacherWorkday-subpage" );
	SetTitle ( "Teacher Workday Camps" );
}

function LoadTeacherWorkdayCamps ()
{
	LoadFragment ( "Camps/TeacherWorkday/ShowCamps.php", "TeacherWorkday-subpage" );
	SetTitle ( "Teacher Workday Schedule" );
}

function ShowTeacherWorkdayCamps ()
{
	OLpostAJAX(SiteRoot + 'Camps/TeacherWorkday/ShowCamps.php','', ShowPopupSticky, 300, 'FullPopup');	
}

/*--------- Class Pages ----------*/

function LoadClasses(Container)
{
	LoadFragment ( "Classes/index.html", Container );
}

function GetClasses ()
{
	LoadFragment ( "Classes/GetClasses.php", "Classes-subpage" );
	SetTitle ( "Classes Schedules" );
}

function ShowClasses ()
{
 	if ( $('PleaseWait') )
 	{
		$('PleaseWait').update('Please wait, retrieving list');	
 	}
	OLpostAJAX(SiteRoot + 'Classes/ShowClasses.php',$('GetClasses').serialize(), ShowPopupSticky, 300, 'FullPopup');	
}

function LoadClassesHome ()
{
	LoadFragment ( "Classes/home.html", "Classes-subpage" );
	SetTitle ( "Classes" );
}

function LoadClassSchedules ()
{
	LoadFragment ( "Classes/Schedules.html", "Classes-subpage" );
	SetTitle ( "Class Schedules" );
}

function LoadClassSaturday ()
{
	LoadFragment ( "Classes/Saturday.html", "Classes-subpage" );
	SetTitle ( "Saturday Classes" );
}

function LoadClassHomeSchool ()
{
	LoadFragment ( "Classes/HomeSchool.html", "Classes-subpage" );
	SetTitle ( "Home School Classes" );
}

function LoadArtClassSchedules ( Container )
{
	LoadFragment ( "Classes/Schedules/Art.html", Container );
}

function LoadTechnologyClassSchedules ( Container )
{
	LoadFragment ( "Classes/Schedules/Technology.html", Container );
}

function LoadScienceClassSchedules ( Container )
{
	LoadFragment ( "Classes/Schedules/Science.html", Container );
}

function LoadClassSchedule ( url )
{
	LoadFragment ( url, "Schedule-subpage" );
}

function BuildClassSubjectSelect()
{
	new Ajax.Request( SiteRoot + 'Classes/BuildSubjectSelect.php', 
			{  
				parameters : $('GetClasses').serialize(true),
				onComplete: 
					function(transport)
					{       
						var response = transport.responseText || url;
						$( 'ClassSubjectSelect' ).update(response); 					 	
					}     
			}
		); 
}

/*--------- Employment Pages ----------*/

function LoadEmployment(Container)
{
	LoadFragment ( "Employment.html", Container );
	SetTitle ( "Employment Opportunities" );
}

/*--------- Events Pages ----------*/

function LoadEvents(Container, Page)
{
	LoadFragment ( "Events/index.php?page=" + Page, Container );
}

function LoadEventsHome ()
{
	LoadFragment ( "Events/home.html", "Events-subpage" );
	SetTitle ( "Parties & Events" );
}

function LoadBirthdays ( Container )
{
	LoadFragment ( "Events/Birthdays.html", Container );
	SetTitle ( "Birthday Parties" );
}

function LoadScouts ()
{
	LoadFragment ( "Events/Scouts.html", "Events-subpage" );
	SetTitle ( "Scout Functions" );
}

function ShowPartyBags ( )
{
	DoPopup( 'Events/PartyBags.html', true);	
}

function LoadPNO( Container )
{
	LoadFragment ( "Events/ParentsNightOut.html", Container );
	SetTitle ( "Parent's Night Out" );
}

function LoadFieldTrips( Container )
{
	LoadFragment ( "Events/FieldTrips.html",  "Events-subpage" );
	SetTitle ( "In-House Field Trips" );
}

/*--------- Google Maps ----------*/
