var galleryArray = [
	['../images/foreword.main', ''],
	['../images/overview.main', 'Digging  for snails in a dried lake bed in Thailand.<br/>&copy; Werachai Wansamngan/UNEP/Still Pictures'],
	['../images/overview.box1', 'Leucadia Quispe harvests oca on her tiny plot in rural Botijlaca, Bolivia. She says there is less water for irrigation every year.<br/>&copy; Trygve Olfarnes/UNFPA'],
	['../images/overview.text1', 'Drought-stricken area of Kenya. Changes in rainfall patterns threaten food production in many parts of Africa and other regions.<br/>&copy; AFP/Getty Images'],
	['../images/ch1.main', 'Lightning streaks across the night sky in Hefei, China. Storms will become more frequent and intense as the earth’s atmosphere continues to warm.<br/>&copy; Xinhua/Xinhua Press/Corbis'],
	['../images/ch1.text1', 'The lake is all that remains of a glacier near the rural town of Botijlaca, Bolivia. Bolivia’s glaciers are melting rapidly, jeopardizing water supplies to rural and urban communities.&nbsp; &copy; Andi Gitow/UNTV'],
	['../images/ch1.box11', 'Anita Cano&nbsp; &copy; Trygve Olfarnes/UNFPA'],
	['../images/ch2.main', 'A hotel in Taiwan Province of China toppled into the sea after Typhoon Morakot lashed the shoreline in August 2009.&nbsp; &copy; Associated Press'],
	['../images/ch2.text0', 'Zimbabwean farmer Mabel Zevezanayi holds a dried corn cob in Bikita District, affected by drought.&nbsp; &copy; AFP/Getty Images'],
	['../images/ch2.text1', 'A woman works in her cornfield near a coking factory in Changzhi, Shanxi Province, China.&nbsp; &copy; Reuters'],
	['../images/ch2.text2', '&copy; Amanda Koster/Corbis'],
	['../images/ch3.main', 'An Indian villager carries her belongings through flood waters in the village of Sandeshkhali, 100 kilometres southeast of Kolkata.<br/>&copy; AFP/Getty Images'],
	['../images/ch3.box15', 'Oreba Obiin, 51, combats coastal erosion in Kiribati by planting mangrove seedlings.&nbsp; &copy; Reethu Arjun/UNPFA'],
	['../images/ch3.text1', 'Man runs for shelter from storm near Niamey, Niger.&nbsp; &copy; AFP/Getty Images'],
	['../images/ch4.main', 'Two women negotiate flood water in the Moroccan town of Souk Larbaa.&nbsp; &copy; AFP'],
	['../images/ch4.text1', 'A Bangladeshi woman plants gourds on the roof of her home. The rooftop garden provides food during floods, when waters destroy field crops.<br/>&copy; GMB Akash/Panos Pictures'],
	['../images/ch4.text2', 'Bangladeshi women now earn a living from salt-water fishing in areas that have become permanently flooded as a result of rising seas.<br/>&copy; GMB Akash/Panos Pictures'],
	['../images/ch4.box25', '&copy; UN Photo/Paulo Filgueiras'],
	['../images/ch5.main', 'Women in a flood-prone community in Gaibandha, Bangladesh, gather once a week to share ideas about how to adapt to worsening climate and rising seas.&nbsp; &copy; GMB Akash/Panos Pictures'],
	['../images/ch5.box26', '&copy; Mainichi Corporation'],
	['../images/ch5.text1', 'Women near Hyderabad plant crops adaptable to climate change in the bed of a dried-up lake as part of a national rural employment project that will benefit India’s environment.&nbsp; &copy; Reuters'],
	['../images/ch5.box27', '&copy; Global Environment Facility'],
	['../images/ch5.box28', '&copy; Climate Change Coordination Centre'],
	['../images/ch5.text2', 'A woman prepares to plant a seedling during the “Feast of the Forest” in Puerto Princesa, the Philippines. Participants attend the annual event to plant trees in deforested areas to help stem global warming.&nbsp; &copy; Reuters/John Javellana'],
	['../images/ch5.box30', '&copy; Courtesy of Centre for Social Markets (CSM)'],
	['../images/ch6.main', 'Children attend primary school in Gaibandha, Bangladesh, where the community built the school in an elevated area of the village so that the children could continue their studies even during flooding. Actions that empower girls and women may help limit climate change in the long run.<br/> &copy; GMB Akash/Panos Pictures'],
	['../images/ch6.text1', '&copy; Doug Murray/Reuters/Corbis'],
	['../images/ch6.text2', 'A family receives family planning advice at Kivunge Hospital, Zanzibar.<br/>&copy; Sala Lewis/UNFPA'],
	['../images/ch6.text3', 'A woman boils water in kettles heated by solar energy panels in Pengyang County, China.&nbsp; &copy; Reuters']
];

var galleryIdx = 0;
var numLinksShown = 5;
 
function GalleryView()
{
		$("#new").attr("src", galleryArray[galleryIdx][0] + ".gallery.jpg");
		var fade = $("div.fade div");
		if (fade.is(":animated"))
			fade.stop().fadeTo(250, 1);
		else
			fade.fadeIn(250, PutInFront);
			
		$('a[rel=galleryViewerLink]').attr("title", galleryArray[galleryIdx][1]).attr("href", galleryArray[galleryIdx][0] + ".big.jpg");
		
		$('a.numLink').css("background", "none").css("color", "#f89831");
		$($('a.numLink')[galleryIdx]).css("background", "#f89831").css("color", "#fff");
}

function PutInFront()
{
	$("#current").attr("src", $("#new").attr("src"));
	$("div.fade div").fadeOut("fast");
}

function NextPhoto()
{
	if (galleryIdx < galleryArray.length - 1)
	{
		galleryIdx++;
		GalleryView();
		if ($($("a.numLink")[galleryIdx]).css("display") == "none")
		{
			$($("a.numLink")[galleryIdx]).css("display", "block");
			if (galleryIdx >= numLinksShown && $($("a.numLink")[galleryIdx-numLinksShown]).css("display") == "block")
				$($("a.numLink")[galleryIdx-numLinksShown]).css("display", "none");
		}
	}
}
function PrevPhoto()
{
	if (galleryIdx > 0)
	{
		galleryIdx--;
		GalleryView();
		if ($($("a.numLink")[galleryIdx]).css("display") == "none")
		{
			$($("a.numLink")[galleryIdx]).css("display", "block");
			if (galleryIdx <= galleryArray.length - numLinksShown && $($("a.numLink")[galleryIdx+numLinksShown]).css("display") == "block")
				$($("a.numLink")[galleryIdx+numLinksShown]).css("display", "none");
		}
	}
}
function ViewPhoto(picIdx)
{
	if (picIdx >= 0 && picIdx < galleryArray.length)
	{
		galleryIdx = picIdx;
		GalleryView();
	}
}

function HideArticle()
{
	if (document.getElementById)
	{
		document.getElementById('theRest').style.display = 'none';
		document.getElementById('readLink').style.display = 'block';
		document.getElementById('topLink').style.display = 'none';
	}
}
function ContinueReading()
{
	if (document.getElementById)
	{
		document.getElementById('theRest').style.display = 'block';
		document.getElementById('readLink').style.display = 'none';
		document.getElementById('topLink').style.display = 'block';
	}
	return false;					
}
$(document).ready(function() {

	$('a[rel=gallery]').lightBox({

		imageLoading: '../images/lightbox-ico-loading.gif',
		imageBtnClose: '../images/lightbox-btn-close.gif',
		imageBtnPrev: '../images/lightbox-btn-prev.gif',
		imageBtnNext: '../images/lightbox-btn-next.gif',
		containerResizeSpeed: 350,
		txtImage: 'Image',
		txtOf: 'of'
	});
				
	$('a[rel=charts]').lightBox({

		imageLoading: '../images/lightbox-ico-loading.gif',
		imageBtnClose: '../images/lightbox-btn-close.gif',
		imageBtnPrev: '../images/lightbox-btn-prev.gif',
		imageBtnNext: '../images/lightbox-btn-next.gif',
		containerResizeSpeed: 350,
		txtImage: 'Image',
		txtOf: 'of'
	});
	$('a[rel=galleryViewerLink]').lightBox({

		imageLoading: '../images/lightbox-ico-loading.gif',
		imageBtnClose: '../images/lightbox-btn-close.gif',
		imageBtnPrev: '../images/lightbox-btn-prev.gif',
		imageBtnNext: '../images/lightbox-btn-next.gif',
		containerResizeSpeed: 350,
		txtImage: 'Image',
		txtOf: 'of'
	});
	  
	$("a.numLink").click(function() {
		var i = $("a.numLink").index(this);
		$($("a.numLink")[i]).attr("href", galleryArray[i][0] + ".big.jpg");
		ViewPhoto(i);
		return false;
	});
	$($('a.numLink')[0]).css("background", "#f89831").css("color", "#fff");
	
	if ($.browser.safari)
		$("ul.pag").css("width", 210);
	//for (var i = 0; i < $("ul.pag li").length; i++)
	//	$($("ul.pag li")[i]).find("a").click(function() { alert("hi "+i);ViewPhoto[i];return false; });
});

