
//----------------------------------------------------------------------------------------
//
//  NASAImages.js
//
//  developer: JJ Ventrella (: also Julia Smith, Sam Stoller, & other Archivists :)
//  Internet Archive 
//  Latest update: June 29, 2009
//
//  This is the Javascript required to create the main visual elements and behavior 
//  for the NASAImages.org home page. A few other JavaScript files are required as 
//  well. This file initializes and updates those JavaScript files.
//
//  Besides being an inviting front-end to nasaimages.org, the main purpose of the home 
//  page is to send 'curated' search queries to the Luna engine, where everything else 
//  happens (viewing thumbnails, getting image details, seeing movies, creating slide 
//  shows, etc.). 
//
//  Note that this uses jquery. 
//
//----------------------------------------------------------------------------------------


//-------------------------------------------------
// include the required JavaScripts....
//-------------------------------------------------
var head = document.getElementsByTagName('head')[0];	

//-------------------------------------------------
// URL string for linking into Luna
//-------------------------------------------------
var SERVER_ADDRESS_STRING = "/luna/servlet/view/";


//----------------------------------------------------------
// positions and proportions for the various components 
//----------------------------------------------------------
var SEARCH_REGION_WIDTH			= 230;
var SEARCH_REGION_TOP			=  25;
var SEARCH_REGION_TOP			=  25;
var ABOUT_AREA_LEFT				= 300;
var MINIMUM_CENTER_X			= 470;
var CENTER_SHIFT_X				= 60;
var BOTTOM_LINKS_TOP 			= 570;

//---------------------------------
// DOM Elements
//---------------------------------
var search				= null;
var bottomLinks			= null;
var nasa_gov			= null;
var archiveLink			= null;
var moonLand			= null;
var showcase			= null;

//--------------------------------------
// some variables
//--------------------------------------
var shift			=  0;
var windowRight		=  0;
var windowBottom	=  0;
var browserWidth	=  0;
var browserHeight	=  0;
var centerX			=  0;
var initialized		= false;


//----------------------------------------------------------------------
function InitializeNASAImages()
{
	var body = document.getElementsByTagName( "body" )[0];

	//-----------------------------------------------------------
	// Search (include the form for keyword entry)
	//-----------------------------------------------------------
	search = document.createElement( "div" );
	search.style.position = "absolute";
	search.style.top  = SEARCH_REGION_TOP;
	search.style.left = 0; // gets set later
	
	search.style.background = "url('http://www.nasaimages.org/search.jpg')";
	search.style.width = 200;
	search.style.height = 40;

	search.innerHTML = "<nobr><form name=form1 action= " + SERVER_ADDRESS_STRING + "search?' + t1 + '&search=Search' method='post' onSubmit='return validate()'><input name=q type=text   value='' size=15 style='border: #000000 1px solid; background: url(http://www.nasaimages.org/formBackground.jpg);'> <input name=b1 type=submit value='Search'><br><font size = 2 face='arial' color = #dddddd ></font></form></nobr>";
	
	body.appendChild( search );

	//-----------------------------------------------------------
	// Search (include the form for keyword entry)
	//-----------------------------------------------------------
	moonLand = document.createElement( "div" );
	moonLand.style.position = "absolute";
	moonLand.style.top  = SEARCH_REGION_TOP + 100;
	moonLand.style.left = 0; //gets set later...

	// this version uses the 'img src' method
	//moonLand.innerHTML = "<img src = sponsor_land_background_with_comet.jpg>";
	
	// this version uses the 'background' method
	moonLand.style.background = "url('http://www.nasaimages.org/sponsor_land_background_with_comet.jpg')";
	moonLand.style.width = 221;
	moonLand.style.height = 550;

	body.appendChild( moonLand );
	
	
	//-----------------------------------------------------------
	// Featured Collections
	//-----------------------------------------------------------
	featured = document.createElement( "div" );
	featured.style.position = "absolute";
	featured.style.left = ABOUT_AREA_LEFT  + 400;
	featured.style.top  = SEARCH_REGION_TOP + 140;
	//previous version...	
	/*
	featured.innerHTML = "<font size = 3 face='arial' color = #999999 ><nobr><br><br>Featured<br>Collections</nobr></font>";
	*/

	//'background' version...
	featured.style.width	= 80;
	featured.style.height	= 31;
	featured.style.background = "url('http://www.nasaimages.org/Featured.jpg')";
	
	body.appendChild( featured );

	//-----------------------------------------------------------
	// Eclips
	//-----------------------------------------------------------
	eclips = document.createElement( "div" );
	eclips.style.position = "absolute";
	eclips.style.left = ABOUT_AREA_LEFT + 400;
	eclips.style.top  = SEARCH_REGION_TOP + 208;
	eclips.style.width	= 65;
	eclips.style.height	= 47;
	eclips.style.background = "url('./eclips.jpg')";
	$( eclips ).mouseover	( function(e) { mouseOverEclips(); } );
	$( eclips ).mouseout	( function(e) { mouseOutEclips	(); } );
	$( eclips ).mousedown	( function(e) { openLink( "http://www.nasaimages.org/luna/servlet/view/search?q=eclips%20LIMIT:nasaNAS~10~10,nasaNAS~12~12,nasaNAS~13~13,nasaNAS~16~16,nasaNAS~20~20,nasaNAS~22~22,nasaNAS~2~2,nasaNAS~4~4,nasaNAS~5~5,nasaNAS~6~6,nasaNAS~7~7,nasaNAS~8~8,nasaNAS~9~9,NSVS~3~3,NVA2~13~13,NVA2~14~14,NVA2~15~15,NVA2~1~1,NVA2~4~4,NVA2~8~8,NVA2~9~9,NVA2~16~16,NVA2~17~17,NVA2~18~18,NVA2~19~19,NVA2~20~20,NVA2~21~21,NVA2~22~22,NVA2~23~23,NVA2~25~25,NVA2~26~26,NVA2~24~24,NVA2~27~27,NVA2~28~28,NVA2~29~29,NVA2~30~30,NVA2~31~31,NVA2~32~32,NVA2~33~33,NVA2~34~34,NVA2~35~35,NVA2~36~36,NVA2~37~37,NVA2~38~38,NVA2~39~39,NVA2~40~40,NVA2~41~41,NVA2~42~42,NVA2~43~43,NVA2~44~44,NVA2~45~45,NVA2~46~46,NVA2~47~47,NVA2~48~48,NVA2~49~49,NVA2~50~50,NVA2~51~51,NVA2~52~52,NVA2~53~53,NVA2~54~54,NVA2~55~55,NVA2~56~56,NVA2~57~57,NVA2~58~58,NVA2~59~59,NVA2~60~60,NVA2~61~61,NVA2~62~62"); } );

	body.appendChild( eclips );
	

	//-----------------------------------------------------------
	// Videographer
	//-----------------------------------------------------------
	videographer = document.createElement( "div" );
	videographer.style.position = "absolute";
	videographer.style.left		= ABOUT_AREA_LEFT + 400;
	videographer.style.top		= SEARCH_REGION_TOP + 283;
			
	//previous version...	
	/*
	videographer.innerHTML
	= "<a href = 'http://www.nasaimages.org/luna/servlet/view/search?q=%22NVA2~81~81%22&search=Search'><img src = collections/video_small.jpg border = 0></a>";
	*/

	//'background' version...
	videographer.style.width	= 60;
	videographer.style.height	= 82;
	videographer.style.background = "url('./video_small.jpg')";
	$( videographer ).mouseover	( function(e) { mouseOverVideographer(); } );
	$( videographer ).mouseout	( function(e) { mouseOutVideographer (); } );
	$( videographer ).mousedown	( function(e) { openLink( "http://www.nasaimages.org/luna/servlet/view/search?q=%22NVA2~81~81%22&search=Search"); } );
	
	body.appendChild( videographer );	
	
	//-----------------------------------------------------------
	// Showcase
	//-----------------------------------------------------------
	showcase = document.createElement( "div" );
	showcase.style.position = "absolute";
	showcase.style.left = ABOUT_AREA_LEFT - 100;
	showcase.style.top  = SEARCH_REGION_TOP + 382;
	showcase.style.width	= 112;
	showcase.style.height	= 112;
	showcase.style.background = "url('./showcase.jpg')";
	$( showcase ).mouseover	( function(e) { mouseOverShowcase(); } );
	$( showcase ).mouseout	( function(e) { mouseOutShowcase	(); } );
	$( showcase ).mousedown	( function(e) { openLink( "http://www.nasaimages.org/showcase/showcase.html"); } );
	
	body.appendChild( showcase );

	//-----------------------------------------------------------
	// bottom links
	//-----------------------------------------------------------
	bottomLinks = document.createElement( "div" );
	bottomLinks.style.position = "absolute";
	bottomLinks.style.top  = BOTTOM_LINKS_TOP;
	bottomLinks.style.left = 0;
	bottomLinks.innerHTML 
	= "<div style='position: absolute; width: 100%'>"
	+ "<div style='width: 700px; margin-left: auto; margin-right: auto;'>"
	//+ "<iframe style='background: black' marginheight='0px' marginwidth='0px' frameborder='0' width='700px' scrolling='no' src='http://www.nasaimages.org/footer_inc.html'><p>This browser does not support iframes.</p></iframe>"
	+ "</div>"
	+ "</div>";
	
	body.appendChild( bottomLinks );

	//-----------------------------------------------------------
	// Archive Link
	//-----------------------------------------------------------
	/*
	archiveLink = document.createElement( "div" );
	archiveLink.style.position = "absolute";
	archiveLink.style.top  = 110;
	archiveLink.style.left = 15;
	archiveLink.style.borderBottom = '2px solid #000000';
	archiveLink.innerHTML = "<L1><a href = 'http://www.archive.org/' target = 'blank' ><img src = Archive.jpg border = 0 ></img></a>"
	body.appendChild( archiveLink );

	$( archiveLink ).mouseover	( function(e) { mouseOverArchive(); } );
	$( archiveLink ).mouseout	( function(e) { mouseOutArchive	(); } );
	*/
	
	archiveLink = document.createElement( "div" );
	archiveLink.style.position = "absolute";
	archiveLink.style.top  = 110;
	archiveLink.style.left = 12;
	archiveLink.style.width	= 97;
	archiveLink.style.height	= 34;
	archiveLink.style.borderBottom = '2px solid #000000';
	archiveLink.style.background = "url( 'http://www.nasaimages.org/Archive.jpg' )";
	$( archiveLink ).mouseover	( function(e) { mouseOverArchive(); } );
	$( archiveLink ).mouseout	( function(e) { mouseOutArchive	(); } );
	$( archiveLink ).mousedown	( function(e) { openLinkInNewWindow( "http://www.archive.org/" ); } );
	
	
	archiveLink.innerHTML
	= "<a href = 'http://www.nasaimages.org/'></a>";
	
	
	body.appendChild( archiveLink );

	//-----------------------------------------------------------
	// visit nasa.gov
	//-----------------------------------------------------------
	/*
	nasa_gov = document.createElement( "div" );
	nasa_gov.style.position = "absolute";
	nasa_gov.style.left = 0; //gets set later...
	nasa_gov.style.top	= BOTTOM_LINKS_TOP + 60;	
	nasa_gov.style.border = '1px solid #000000';
	nasa_gov.innerHTML 
	= "<a href='http://www.nasa.gov/' target='blank'"
	+ "<img src = 'NASA.gov.jpg' border = 0></a>";
	body.appendChild( nasa_gov );
	
	$( nasa_gov ).mouseover	( function(e) { mouseOverNASAGov(); } );
	$( nasa_gov ).mouseout	( function(e) { mouseOutNASAGov	(); } );
	*/

	nasa_gov = document.createElement( "div" );
	nasa_gov.style.position = "absolute";
	nasa_gov.style.left = 0; //gets set later...
	nasa_gov.style.top	= BOTTOM_LINKS_TOP + 60;	
	nasa_gov.style.width	= 114;
	nasa_gov.style.height	= 34;
	nasa_gov.style.background = "url( 'http://www.nasaimages.org/NASA.gov.jpg' )";
	nasa_gov.style.border = '1px solid #000000';
	
	$( nasa_gov ).mouseover	( function(e) { mouseOverNASAGov(); } );
	$( nasa_gov ).mouseout	( function(e) { mouseOutNASAGov	(); } );
	$( nasa_gov ).mousedown	( function(e) { openLinkInNewWindow( "http://www.nasa.gov/" ); } );
	
	body.appendChild( nasa_gov );


/*
	//-----------------------------------------------------------
	// add this button
	//-----------------------------------------------------------
	addThis = document.createElement( "div" );
	addThis.style.position = "absolute";
	addThis.style.top	= 80;	
	addThis.style.left = 0; //gets set later...
	addThis.innerHTML 
	= "<iframe style='background: transparent' marginheight='0px' marginwidth='0px' frameborder='0' width='300px' height='300' scrolling='no' src='addThis.html'>"
	+ "<p>This browser does not support iframes.</p>"
	+ "</iframe>";
	body.appendChild( addThis );
*/

	InitializeCollections();

	//-----------------------------------------------------------------------------------------------------
	// this is necessary to get things positioned right (this also gets invoked when the user resizes the window)
	//-----------------------------------------------------------------------------------------------------
	arrangeElementsAccordingToBrowserWidthAndHeight();

	initialized = true;

}//----------------------------------------------------------------------

//-------------------------------------------------------------------------------------------
function mouseOverShowcase()
{
	showcase.style.background = "url('./showcase_mouse_over.jpg')";
	
}//----------------------------------------------------------------------

//-------------------------------------------------------------------------------------------
function mouseOutShowcase()
{
	showcase.style.background = "url('./showcase.jpg')";

}//----------------------------------------------------------------------


//-------------------------------------------------------------------------------------------
function mouseOverArchive()
{
	archiveLink.style.borderBottom = '2px solid #778899';
	
}//----------------------------------------------------------------------

//-------------------------------------------------------------------------------------------
function mouseOutArchive()
{
	archiveLink.style.borderBottom = '2px solid #000000';

}//----------------------------------------------------------------------


//-------------------------------------------------------------------------------------------
function mouseOverNASAGov()
{
	nasa_gov.style.border = '1px solid #556677';
	
}//----------------------------------------------------------------------

//-------------------------------------------------------------------------------------------
function mouseOutNASAGov()
{
	nasa_gov.style.border = '1px solid #000000';

}//----------------------------------------------------------------------


//-------------------------------------------------------------------------------------------
function openLink( url )
{
	window.location.href = url;

}//----------------------------------------------------------------------


//-------------------------------------------------------------------------------------------
function openLinkInNewWindow( url )
{
	window.open( url )

}//----------------------------------------------------------------------




//----------------------------------------------------------------------
function ResizeNASAImages()
{
	if ( initialized )
	{
		arrangeElementsAccordingToBrowserWidthAndHeight();
	}
	
}//----------------------------------------------------------------------

//-------------------------------------------------------------------------------------------
function mouseOverVideographer()
{
	videographer.style.background = "url('./video_small_mouse_over.jpg')";
	
}//----------------------------------------------------------------------

//-------------------------------------------------------------------------------------------
function mouseOutVideographer()
{
	videographer.style.background = "url('./video_small.jpg')";

}//----------------------------------------------------------------------

//-------------------------------------------------------------------------------------------
function mouseOverEclips()
{
	eclips.style.background = "url('./eclips_mouse_over.jpg')";
	
}//----------------------------------------------------------------------


//-------------------------------------------------------------------------------------------
function mouseOutEclips()
{
	eclips.style.background = "url('./eclips.jpg')";

}//----------------------------------------------------------------------



//----------------------------------------------------------------------
function arrangeElementsAccordingToBrowserWidthAndHeight()
{
	browserWidth	= document.body.clientWidth;
	browserHeight	= document.body.clientHeight;

	centerX = browserWidth / 2;
	
	centerX -= CENTER_SHIFT_X;

	if ( centerX < MINIMUM_CENTER_X )
	{
		centerX = MINIMUM_CENTER_X;
	}

	var moonLeft = browserWidth - 245;
	
	if ( moonLeft < centerX + 350 )
	{
		moonLeft = centerX + 350;
	}
	
	var leftShifted = moonLeft + 40;

	bottomLinks.style.left	= centerX - 350;
	moonLand.style.left		= moonLeft;
	eclips.style.left		= leftShifted;
	featured.style.left		= leftShifted;
	videographer.style.left	= leftShifted;
	showcase.style.left	    = leftShifted;
	search.style.left		= leftShifted - 5; 
	nasa_gov.style.left		= leftShifted;
	//addThis.style.left		= leftShifted - 130;
	bottomLinks.style.top	= BOTTOM_LINKS_TOP;	
	//alert("Resizing collections now");
	ResizeCollections();
}//----------------------------------------------------------------------


