// Copyright Pierre Saslawsky 2006 - pierre(at@)photobiker(dot.)com


//-----------------------------------------------------------------------
//
//-----------------------------------------------------------------------

var ITEMS_PER_NEWS_ENTRY = 6;
var INDEX_NEWS_DATE			= 0;
var INDEX_NEWS_HOMEPAGELINE	= 1;
var INDEX_NEWS_TEXT			= 2;
var INDEX_NEWS_IMAGEURL		= 3;
var INDEX_NEWS_IMAGESIZE	= 4;
var INDEX_NEWS_IMAGELINK	= 5;


var gNewsList = new Array(
	"May 15th, 2010",
	"<a href='http://photos.merrittgrooms.com' style='color:#cc4530; border:3px double; padding:2px; text-decoration:none;'>Click here for the coverage of the San Francisco EMMY Awards 2010</a>",
	"Only one thing can take me out of maternity leave: the San Francisco Emmy Awards, of course! The pictures are now available at <a style='color:#cc4530' href='http://photos.merrittgrooms.com'>photos.merrittgrooms.com</a>",
	"news/emmys2010.jpg", 67, "http://photos.merrittgrooms.com",

	"May 16th, 2009",
	"Coverage of the <a href='http://photos.merrittgrooms.com' style='color:#cc4530'>San Francisco Emmy Awards</a>",
	"I'm on a roll: my third year at the San Francisco Emmy Awards! The pictures are now available at <a href='http://photos.merrittgrooms.com'>photos.merrittgrooms.com</a>",
	"news/emmys2009.jpg", 67, "http://photos.merrittgrooms.com",

	"May 10th, 2008",
	"Coverage of the <a href='http://photos.merrittgrooms.com' style='color:#cc4530'>San Francisco Emmy Awards</a>",
	"My second year at the San Francisco Emmy Awards. It was so much fun last year, I came back for more. The pictures can be found at <a href='http://photos.merrittgrooms.com'>photos.merrittgrooms.com</a>",
	"news/emmys2008.jpg", 67, "http://photos.merrittgrooms.com",

	"May 12th, 2007",
	"Coverage of the <a href='http://photos.merrittgrooms.com' style='color:#cc4530'>San Francisco Emmy Awards</a>",
	"Big event today: I covered the San Francisco / Northern California Emmy Awards ceremony. You can view and purchase the pictures at <a href='http://photos.merrittgrooms.com'>photos.merrittgrooms.com</a>",
	"news/emmys.jpg", 69, "http://photos.merrittgrooms.com",

	"January 30th, 2007",
	"New images from Thailand and India",
	"New images from Thailand and India... I'm back in town after 2 1/2 months in two of the most dissimilar cultures: the delicate kindness of Thailand and the harsh intensity of India.",
	"news/indiakid.jpg", 120, "photos.html?cat=3",

	"September 3rd, 2006",
	"New images in Portraits and Design",
	"New images in Portraits and Design... It was a fantastic experience shooting Fredy & Celina. She was 8-month pregnant and I thought nothing was more appropriate than showing up at their home with 30 lbs of fruit.",
	"news/fredycelina.jpg", 120, "photos.html?cat=1",

	"July 20th, 2006",
	"The new web site is online.",
	"The new web site is online, with tons of new pictures and a revamped look. The News page is here, and more things will come soon.",
	"news/060720frontpage.jpg", 120, "index.html",

	"July 15th 2006",
	"Vacation in France in August.",
	"I'm going to France on vacation for 2 or 3 weeks in August. Pierre misses his mom, and you know how moms are sacred in France. Au revoir, &agrave; bient&ocirc;t!",
	/*"http://www.reluctantgourmet.com/images/cheese.jpg"*/"news/zidane3.gif", 120, "",

	"July 7th, 2006",
	"Two new galleries: Design and Still Life.",
	"The <a href='photos.html?cat=5'>Design</a> and <a href='photos.html?cat=6'>Still Life</a> galleries were added, as well as several pictures in the Fashion gallery",
	"photos/design/icon.jpg", 0, "photos.html?cat=5",

	"June 2nd, 2006",
	"Thank you to all the models from the Portraits gallery",
	"Party time! All the models from the <a href='photos.html?cat=1'>Portraits</a> gallery have received their autographed prints.",
	"photos/portraits/icon.jpg", 0, "photos.html?cat=1",

	"May 2006",
	"Graduation party of the Portraiture class",
	"I graduated from an Advanced Lighting and Portraiture class, my first class in almost 20 years. My boyfriend Pierre's reaction when looking at the class Final projects was: \"You kicked ass, Dear!\" Thank you, Pierre.",
	"news/graduation.jpg", 60, "",

	"April 2006",
	"Merritt is on the front page of the San Francisco Bay Guardian",
	"Our article about the perception of the United States in foreign countries is on the front page of the San Francisco Bay Guardian. A copy can be found on <a href='http://www.photobiker.com'>photobiker.com</a>.",
	"http://www.photobiker.com/smallimages/sfbayguardian.jpg", 120, "http://www.photobiker.com",

	"March 2006",
	"Merritt is exposed in 4 art galleries in San Francisco.",
	"With the addition of <a href='http://www.artist-xchange.com/'>Artist-Xchange</a> this month, and after <a href='http://sanfrancisco.citysearch.com/profile/11522079/'>Paxton Gate</a>, <a href='http://www.sfstation.com/swallowtail-b5712'>Swallowtail</a> and <a href='http://www.sfonlinearts.com/index.htm'>Larry Warnock</a>, it's now a total of 4 galleries that are showing my art in the city.",
	"pix/iconscorpio.jpg", 80, ""
	);


var NEWS = gNewsList.length / ITEMS_PER_NEWS_ENTRY;

var NEWS_PER_PAGE = 3;
var PAGES = Math.floor(NEWS/NEWS_PER_PAGE) + 1;

function GetNewsDate(news)			{ return gNewsList[news*ITEMS_PER_NEWS_ENTRY + INDEX_NEWS_DATE]; }
function GetNewsHomePageLine(news)	{ return gNewsList[news*ITEMS_PER_NEWS_ENTRY + INDEX_NEWS_HOMEPAGELINE]; }
function GetNewsText(news)			{ return gNewsList[news*ITEMS_PER_NEWS_ENTRY + INDEX_NEWS_TEXT]; }
function GetNewsImageUrl(news)		{ return gNewsList[news*ITEMS_PER_NEWS_ENTRY + INDEX_NEWS_IMAGEURL]; }
function GetNewsImageSize(news)		{ return gNewsList[news*ITEMS_PER_NEWS_ENTRY + INDEX_NEWS_IMAGESIZE]; }
function GetNewsImageLink(news)		{ return gNewsList[news*ITEMS_PER_NEWS_ENTRY + INDEX_NEWS_IMAGELINK]; }


//-----------------------------------------------------------------------
// Runs on load
//-----------------------------------------------------------------------

var gCurrentPage = paramVal("page");
if (gCurrentPage.length == 0)
	gCurrentPage = 0;


//-----------------------------------------------------------------------
// Display page
//-----------------------------------------------------------------------

function DisplayPreviousPage() {
	if (gCurrentPage <= 0)
		return;
	DisplayNewsPage(--gCurrentPage);
}

function DisplayNextPage() {
	if (gCurrentPage >= (PAGES - 1))
		return;
	DisplayNewsPage(++gCurrentPage);
}

function UpdateArrowButtons() {
	var leftArrow = document.getElementById('leftArrow');
	var rightArrow = document.getElementById('rightArrow');
	if (!leftArrow || !rightArrow)
		return;

	var disabledButton;

	if (gCurrentPage == 0) {
		disabledButton = leftArrow;
	}
	else
	if (gCurrentPage >= (PAGES - 1)) {
		disabledButton = rightArrow;
	}

	leftArrow.className = "";
	rightArrow.className = "";
	if (disabledButton != undefined) {
		disabledButton.className = "disabled";
	}

	// the code below isn't necessary: it's just nice to see updated links in the status bar
	// when hovering above the arrow buttons
	var leftArrowLink = document.getElementById('leftArrowLink');
	var rightArrowLink = document.getElementById('rightArrowLink');
	if (!leftArrowLink || !rightArrowLink)
		return;

	var previousPage = gCurrentPage - 1;
	if (previousPage < 0)
		previousPage = 0;
	leftArrowLink.href = "news.html?page=" + previousPage;

	var nextPage = gCurrentPage + 1;
	if (nextPage >= (PAGES - 1))
		nextPage = PAGES - 1;
	rightArrowLink.href = "news.html?page=" + nextPage;
}

function DisplayNewsPage(page) {
	gCurrentPage = page;
	UpdateArrowButtons();

	for (var i=0; i < NEWS_PER_PAGE; i++) {
		var newsIndex = page*NEWS_PER_PAGE + i;
		var newsText = GetNewsText(newsIndex);
		var imageUrl = GetNewsImageUrl(newsIndex);
		var imageSize = GetNewsImageSize(newsIndex);
		var imageLink = GetNewsImageLink(newsIndex);

		var elt = document.getElementById('news' + i);
		if (!elt) return;

		if (newsText == undefined) {
			elt.innerHTML = "";
		}
		else {
			var tag = "";
			tag += '<div class="date">' + GetNewsDate(newsIndex) + '</div><br>';
			tag += newsText;
			tag += '<div class="newsImage">';
			if (imageUrl.length > 0) {
				if (imageLink.length > 0)
					tag += '<a href="' + imageLink + '">';
	
				var sizeTag = "";
				if (imageSize > 0) {
					sizeTag = ' width="' + imageSize + '"';
				}
				
				tag += '<img src="' + imageUrl + '"' + sizeTag + '>';
	
				if (imageLink.length > 0)
					tag += '</a>';
			}
			elt.innerHTML = tag;
		}

	}
}

