#! /usr/bin/perl -w
#
########################################
#
#	displays media page for DTN site
#	written by benjamin ramey
#	bsr@rameydesign.net
#	april, 2004
#
########################################

$data_file = "./data/media_data.txt";

print "Content-type: text/html\n\n";

&Print_Top_HTML;

&Print_Albums;
&Print_Middle_HTML;
&Print_Videos;

&Print_Bottom_HTML;

################################################################################################################################################
#	SUB ROUTINES FOR DYNAMIC HTML
################################################################################################################################################

##############prints out photo albums from data file##############
sub Print_Albums
{
	my $album_name = 0;
	my $album_link = 0;
	my $album_counter = 0;
	my $display_album = 0;

	print "<tr>\n";

	open( INFILE, "$data_file" ) or print "<span style='font-weight: bold; color: red'>ERROR: Could not open $data_file.</span>";

	while( (my $file_line = <INFILE>) && ($file_line !~ m/<\/albumsection>/) )
	{
		if( $file_line =~ m/<album>/ )
		{
			if( $album_counter == 4 ) { print "</tr>\n<tr>\n"; $album_counter = 0; }

			while( ($file_line = <INFILE>) && ($file_line !~ m/<\/album>/) )
			{
				if( $file_line =~ m/<name>(.*)<\/name>/ ) { $album_name = $1; }

				#if( $file_line =~ m/<link>(.*)<\/link>/ ) { $album_link = $1; }
				#$album_link =~ s/([ ,',",\\,\/,-])/sprintf( "%%%lx", (unpack( "C", $1 )) )/eg;

				if( $file_line =~ m/<inside>(.*)<\/inside>/ )
				{
					if( $1 eq 'none' ) { $display_album = 1; }
					else { $display_album = 0; }
				}
				
				if( $file_line =~ m/<imagefolder>(.*)<\/imagefolder>/ ) { $album_folder = $1; }
			}

			if( $display_album )
			{
				print<<"HTML";
        		<td align="center" valign="top" width="25%"><a href="javascript:Album_Open( '$album_folder' )">
				<img src="graphics/media/album_icon.gif" width="60" height="53" border="0"></a><br>
        				$album_name
		</td>
HTML
				$album_counter++;
			}

		}
	}

	close( INFILE );

	if( $album_counter < 4 )
	{
		my $num_fillers = 4 - $album_counter;

		for( my $i = 1; $i <= $num_fillers; $i++ )
		{
			print<<"HTML";
        		<td align="center" valign="top" width="25%">&nbsp;
		</td>
HTML
		}
	}

	print "</tr>\n";
}

##############prints out videos from data file##############
sub Print_Videos
{	
	my $video_name = 0;
	my $video_link = 0;
	my $video_image = 0;
	my $video_counter = 0;

	print "<tr>\n";

	open( INFILE, "$data_file" ) or print "<span style='font-weight: bold; color: red'>ERROR: Could not open $data_file.</span>";

	while( (my $file_line = <INFILE>) && ($file_line !~ m/<\/videosection>/) )
	{
		if( $file_line =~ m/<video>/ )
		{
			if( $video_counter == 4 ) { print "</tr>\n<tr>\n"; $video_counter = 0; }
			
			while( ($file_line = <INFILE>) && ($file_line !~ m/<\/video>/) )
			{
				if( $file_line =~ m/<name>(.*)<\/name>/ ) { $video_name = $1; }
				if( $file_line =~ m/<link>(.*)<\/link>/ ) { $video_link = $1; }
				if( $file_line =~ m/<image>(.*)<\/image>/ ) { $video_image = $1; }
			}

			print<<"HTML";
		<td align="center" valign="top" width="25%"><a href="javascript:void(0)" onclick="Video_Open( '$video_link' )">
			<img src="$video_image" width="100" height="75" border="0"></a><br>
			<br>
			$video_name
		</td>
HTML

			$video_counter++;
		}
	}

	close( INFILE );

	if( $video_counter < 4 )
	{
		my $num_fillers = 4 - $video_counter;

		for( my $i = 1; $i <= $num_fillers; $i++ )
		{
			print<<"HTML";
        		<td align="center" valign="top" width="25%">&nbsp;
		</td>
HTML
		}
	}

	print "</tr>\n";
}
	
################################################################################################################################################
#	SUB ROUTINES FOR PRINTING GENERIC HTML
################################################################################################################################################

##############displays top of media page##############
sub Print_Top_HTML
{
	print <<"HTML";
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Disciple the Nations - Photos/Videos</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="dtn.css" />
<link rel="stylesheet" type="text/css" href="dtn_media.css" />

<SCRIPT SRC="ssm.js" language="JavaScript1.2">

//Dynamic-FX slide in menu v6.5 (By maXimus, maximus@nsimail.com)
//Site: http://maximus.ravecore.com/
//For full source, and 100's more DHTML scripts, visit http://www.dynamicdrive.com

</SCRIPT>
<SCRIPT SRC="ssmItems_media.js" language="JavaScript1.2"></SCRIPT>
<script language="javascript" type="text/javascript">
<!--
function Album_Open( which_album )
{
	window.open( "albums.pl?album=" + which_album, "_blank", "height=500, width=600" );
}
function Video_Open( which_video )
{
	window.open( "./video_pages/" + which_video, "_blank", "height=350, width=400" );
}
//-->
</script>
<script language="javascript" type="text/javascript" src="random_verse.js"></script>

</head>

<body>
<a name="top"></a>
<div align="left">
<table cellpadding="0" cellspacing="0" width="100%">
<tr>
	<td class="first_strip" colspan="3"><a name="#top"><img src="graphics/spacer.gif" border="0" width="1" height="10" /></a></td>
</tr>
<tr>
	<td class="second_strip_top" colspan="3"><img src="graphics/spacer.gif" border="0" width="1" height="10" /></td>
</tr>
<tr>
	<td align="left" colspan="2">
	<table cellpadding="0" cellspacing="0" border="0" width="100%">
	<tr>
		<td>&nbsp;</td>
		<td align="right">
			<span style="font-size: 12px; margin-right: 10px" align="center">
				<a href="home.htm" class="location">home</a> | 
				<a href="whoweare.pl" class="location">who we are</a> | 
				<a href="resources.pl" class="location">resources</a> | 
				<a href="prayer.pl" class="location">prayer requests</a> | 
				<a href="travel.pl" class="location">mission & travel</a> | 
				<a href="media.pl" class="location">photos/videos</a>
			</span>
		</td>
	</tr>
	</table>
	</td>
	<td><img src="graphics/spacer.gif" border="0" width="1" height="20" /></td>
</tr>
<tr>
	<td valign="top" style="background-image: url( graphics/media/sidebar_bg.gif );" width="195">
		<img src="graphics/media/sidebar_dtn_logo.gif" /><br />
		<img src="graphics/media/sidebar_media.gif" />
	</td>
	<td width="100%" valign="top" class="content_table" align="left">
		<table cellpadding="0" cellspacing="0" style="margin-top: 2px" width="100%">
		<tr>
			<td valign="bottom" align="left">
				<img src="graphics/media/media_title.gif" /> <br />
				<span class="location" style="margin-left: 15px;">
				<script language="javascript" type="text/javascript">
				<!--
					Random_Verse();
				//-->
				</script>
				</span>
			</td>
		</tr>
		<tr>
			<td align="center">
			<table cellpadding="0" cellspacing="0" width="100%" class="sub_link_div">
			<tr>
				<td align="center">
				<a href="#photo_albums" class="sub_link_table">photo albums</a> | 
				<a href="#videos" class="sub_link_table">videos</a>
				</td>
			</tr>
			</table>
			</td>
		</tr>
		</table>
		<table class="section_table" cellpadding="0" cellspacing="0" border="0">
		<tr>
			<td class="corner">&nbsp;</td>
			<td class="header" align="left"><!--TITLE-->Photo Albums<!--END_TITLE-->&nbsp;&nbsp;&nbsp;<a name="photo_albums" id="photo_albums"> </a></td>
			<td>&nbsp;</td>
		</tr>
		<tr>
			<td align="left" valign="top">&nbsp;</td>
			<td colspan="2" class="content_column">
				<table width="100%"  border="0" cellpadding="5" cellspacing="0" class="content_column">
<!--BEGIN_ALBUMS-->
HTML
}

##############displays middle of media page##############
sub Print_Middle_HTML
{
	print<<"HTML";
<!--END_ALBUMS-->
        				</table>
			</td>
		</tr>
		</table>

		<table class="section_table" cellpadding="0" cellspacing="0" border="0">
		<tr>
			<td class="corner">&nbsp;</td>
			<td class="header" align="left"><!--TITLE-->Videos<!--END_TITLE-->&nbsp;&nbsp;&nbsp;<span class="top_anchor"><a name="videos" href="#top">/ top /</a></span></td>
			<td>&nbsp;</td>
		</tr>
		<tr>
			<td align="left" valign="top">&nbsp;</td>
			<td colspan="2" class="content_column">
				<table width="100%"  border="0" cellpadding="5" cellspacing="0" class="content_column">
<!--BEGIN_VIDEOS-->
HTML
}


##############displays bottom of media page##############
sub Print_Bottom_HTML
{
	print <<"HTML";
<!--END_VIDEOS-->
				</table>
			</td>
		</tr>
		</table>

	</td>
	<td><img src="graphics/spacer.gif" width="15" height="1" /></td>
</tr>
<tr>
	<td><img src="graphics/spacer.gif" border="0" width="1" height="20" /></td>
	<td align="center" style="padding: 5px 0px 5px 0px">
		<span style="font-size: 12px" align="center">
			<a href="whoweare.pl">who we are</a> | 
			<a href="resources.pl">resources</a> | 
			<a href="prayer.pl">prayer requests</a> | 
			<a href="travel.pl">travel info</a> | 
			<a href="media.pl">photos/videos</a>
		</span>
	</td>
	<td>&nbsp;</td>
</tr>
<tr>
	<td class="second_strip_bottom" colspan="3"><img src="graphics/spacer.gif" border="0" width="1" height="10" /></td>
</tr>
<tr>
	<td class="first_strip" colspan="3">all site content copyright of Disciple the Nations, all rights reserved | site designed by <a href="http://www.rameydesign.net" target="_blank" class="first_strip">ramey design</a></td>
</tr>
</table>
</div>
</body>
</html>
HTML
}






