/**********************************************************************
newspaper.js contains declarations for the newspaper object and
declares an instance of the news object.
***********************************************************************/ 

// create a new article
function article (theID,theThumbnail,thePicture,theTitle,theCaption,theStory,theDate,thePhotos) {
    this.ID		= theID
    this.thumbnail    	= theThumbnail;
    this.picture	= thePicture;
    this.title		= theTitle
    this.caption	= theCaption
    this.story		= theStory
    this.date		= theDate
    this.photos		= thePhotos
}


// news constructor creates a new newspaper
function newspaper () {
    
    this.numberEntries = 0;                               // No articles when first created
    this.entries = new Array();                           // Array of entries is initially empty
    
    // Methods for newspaper object
    
    this.addEntry = newspaper_addArticle;                 // Specify method for adding an article
    this.display = newspaper_display;  			  // Specify method for displaying articles as index
    this.showSubStory = newspaper_showSubStory		  // Sub Story
    this.showMainStory = newspaper_showMainStory	  // Main Story
    this.showArchives = newspaper_showArchives		  // Archives
}


// newspaper_addArticle adds an article to the newspaper
function newspaper_addArticle (entryID, entryThumbnail, entryPicture, entryTitle, entryCaption, entryStory, entryDate, entryPhotots) {    
    this.numberEntries += 1;
    this.entries[this.numberEntries-1] = new article(entryID, entryThumbnail, entryPicture, entryTitle, entryCaption, entryStory, entryDate, entryPhotots);    
}

// newspaper_display outputs newspaper articles
function newspaper_display (startNo, showNo, HideNo) {
    
    strDisplay = "";

    strDisplay = strDisplay + '<table cellspacing=0 cellpadding=2 width="100%" border=0>'
    
    var countNo = 0;

    for (var i = startNo; countNo < showNo; i++) {
        
        
        if (i == HideNo){        
           i++;                
        }
        
        var my = this.entries[i];                                      
        
        strDisplay = strDisplay + '<tr>'
	strDisplay = strDisplay + '<td width=70>'
	strDisplay = strDisplay + '<a class="articlelink" href="news.htm?article=' + i + '" target="_self">'
	strDisplay = strDisplay + '<img src="' + my.thumbnail + '" border=0 height=50 width=70>'
	strDisplay = strDisplay + '</a>'
	strDisplay = strDisplay + '</td>'
	strDisplay = strDisplay + '<td>'
	strDisplay = strDisplay + '<a class="articlelink" href="news.htm?article=' + i + '" target="_self">'
	strDisplay = strDisplay + my.caption
	strDisplay = strDisplay + '</a>'
	strDisplay = strDisplay + '</td>'
	strDisplay = strDisplay + '</tr>'
	strDisplay = strDisplay + '<tr><td colspan=2><img src="images/divider.gif" border=0 height=1 width="100%"></td></tr>'
	
	countNo++;
	
	}

	strDisplay = strDisplay + '</table>'
	
	return strDisplay;
	
	
}


function newspaper_showSubStory (articleNo){

	var my = this.entries[articleNo];  
	
	document.write('<table cellspacing=0>')
	document.write('<tr><td class="gadgetheader">' + my.title +'</td><td class="gadgetheaderend"></td></tr>')
	document.write('<tr>')
	document.write('<td colspan=2 class="gadgetbody">')
	document.write('<table border=1 cellpadding=5 cellspacing=0 bordercolorlight="#336699" bordercolordark="#336699">')
	document.write('<tr>')
	document.write('<td bgcolor="#FFFFFF" bordercolor="#336699">')
	document.write('<a class="webtext" href="news.htm?article=' + articleNo + '" target="_self">');
	document.write('<img src="' + my.picture +'" border=0 width=215 height=160>')
	document.write( '</a>');
	document.write('</td>')
	document.write('</tr>')
	document.write('</table>')
	document.write('<a class="webtext" href="news.htm?article=' + articleNo + '" target="_self">');
	document.write(my.caption)
	document.write( '</a>');		
	document.write('</td>')
	document.write('</tr>')
	document.write('</table>')
}

function newspaper_showMainStory (articleNo) {

	var my = this.entries[articleNo];  
		
	document.write('<table cellspacing=0 width="100%">')
	document.write('<tr><td class="mainstorytitle"><div id="newsTitle">' + my.title + '</div></td><td class="gadgetheaderend"></td></tr>')
	document.write('<tr>')
	document.write('<td colspan=2 class="gadgetbody">')
	
		document.write('<table border=0 cellspacing=5 cellpadding=0 width="100%">')
		document.write('<tr>')
		document.write('<td valign="top" width=230>')
			document.write('<table border=1 cellpadding=5 cellspacing=0 bordercolorlight="#336699" bordercolordark="#336699">')
			document.write('<tr>')
			document.write('<td bgcolor="#FFFFFF" bordercolor="#336699">')
			document.write('<img NAME="imgDisplay" src="' + my.picture + '" border=0  width=215 height=160>')
			document.write('</td>')
			document.write('</tr>')
			document.write('</table>')
		document.write('</td>')
		document.write('<td valign="top">')
		document.write('<div class="webtext" id="newsStory">' + my.story + '</div>')
		
		   if (my.photos != "") {
			document.write('<br>')
			document.write('<a class="photoslink" href="album.htm?source=' + my.photos + '">')
			document.write('More pictures >>>')		
			document.write('</a>')
		   }
		   
		document.write('</td>')
		document.write('</tr>')
		document.write('</table>')					
		
	document.write('</td>')
	document.write('</tr>')
	document.write('</table>')

}

function newspaper_showArchives (startNo,hideNo,showNo) {
	
	var countNo = 0;
	
	if (showNo == 0) {
	   showNo = this.numberEntries - 1;
	}
	
	strDisplay = "";
	
	strDisplay = strDisplay + '<table cellspacing=0 width="100%">'
	strDisplay = strDisplay + '<tr><td class="gadgetheader">More News</td><td class="gadgetheaderend"></td></tr>'
	strDisplay = strDisplay + '<tr>'
	strDisplay = strDisplay + '<td colspan=2 class="gadgetbody">'
	
	strDisplay = strDisplay + '<table border=0 cellspacing=8 cellpadding=0>'
	
	for (var i = startNo; countNo < showNo; i++) {
	     
	     if (i <= this.numberEntries - 1){
	     
	        if (i != hideNo){        
		
	           var my = this.entries[i];                                      
	
		   strDisplay = strDisplay + '<tr>'
		   strDisplay = strDisplay + '<td class="articlelink" width=70 valign="top">'
		   
		   strDisplay = strDisplay + '<a class="articlelink" href="news.htm?article=' + i + '" target="_self">'		   
		   strDisplay = strDisplay + my.date
		   strDisplay = strDisplay + '</a>'
		   
		   strDisplay = strDisplay + '</td>'
		   strDisplay = strDisplay + '<td class="articlelink">'
		   strDisplay = strDisplay + '<a class="articlelink" href="news.htm?article=' + i + '" target="_self">'
		   strDisplay = strDisplay + '<b>'
		   strDisplay = strDisplay + my.title
		   strDisplay = strDisplay + '</b>'
		   strDisplay = strDisplay + '<div class="articlelink">'
		   strDisplay = strDisplay + my.caption
		   strDisplay = strDisplay + '</div>'		   
		   strDisplay = strDisplay +  '</a>'

		   strDisplay = strDisplay + '</td>'
		   strDisplay = strDisplay + '</tr>'
		   
		}
	     }	
	     
	     countNo++;
	     
	}

	
	strDisplay = strDisplay +'</table>'
	
	if (i <= this.numberEntries - 1) {
	    strDisplay = strDisplay + '<br>'
	    strDisplay = strDisplay + '<a class="photoslink" href="newsarchive.htm">'
	    strDisplay = strDisplay + 'View News Archive >>>'
	    strDisplay = strDisplay + '</a>'		
	}
	
	strDisplay = strDisplay +'</td>'
	strDisplay = strDisplay +'</tr>'
	strDisplay = strDisplay +'</table>'
	
	return strDisplay;
	
}

// Create an instance of the newspaper object
var Newspaper = new newspaper();
