var mdgFacts = 
   [{title: 'Goal 1. Eradicate Extreme Poverty and Hunger', 
		li: ['The World Bank\'s latest estimates show that 1.4 billion people in developing countries were living in extreme poverty in 2005.<br />Recent increases in the price of food have had a direct and adverse effect on the poor and are expected to push many more people - an estimated 100 million - into absolute poverty.', 
			'The proportion of children under five who are undernourished declined from 33 per cent in 1990 to 26 per cent in 2006. However, by 2006, the number of children in developing countries who were underweight still exceeded 140 million.']},
						  
	{title: 'Goal 2. Achieve Universal Primary Education', 
		li: ['Globally, 570 million children are enrolled in school. The number of children of primary school age who were out of school fell from 103 million in 1999 to 73 million in 2006. In that year, primary school enrolment in developing countries reached 88 per cent on average, up from 83 per cent in 2000.', 
			'In sub-Saharan Africa, the net primary school enrolment  ratio has only recently reached 71 per cent, even after a significant jump in enrolment that began in 2000. Around 38 million children of primary school age in this region are still out of school.',
			'In Southern Asia, the enrolment ratio has climbed above 90 per cent, yet more than 18 million children of primary school age are not enrolled.']},
						  						 
	{title: 'Goal 3. Promote Gender Equality and Empower Women', 
		li: ['Of the 113 countries that failed to achieve gender parity in primary and secondary school enrolment by the target date of 2005, only 18 are likely to achieve the goal by 2015.', 
			'Girls account for 55 per cent of the out-of-school population.',
			'Since 2000, the proportion of seats for women in parliaments only increased from 13.5 to 17.9 per cent.Women occupy at least 30 per cent of parliamentary seats in 20 countries, although none of these countries are in Asia.']},

	{title: 'Goal 4. Reduce Child Mortality', 
		li: ['Worldwide, deaths of children under five years of age declined from 93 to 72 deaths per 1,000 live births between 1990 and 2006.', 
			'A child born in a developing country is over 13 times more likely to die within the first five years of life than a child born in an industrialized country. Sub-Saharan Africa accounts for about half the deaths of children under five in the developing world',
			'Between 1990 and 2006, about 27 countries - the large majority in sub-Saharan Africa - made no progress in reducing childhood deaths.']},

	{title: 'Goal 5. Improve Maternal Health', 
		li: ['Estimates for 2005 show that, every minute, a woman  dies of complications related to pregnancy and childbirth. This adds up to more than 500,000 women annually and 10 million over a generation. Almost all of these women -99 per cent - live and die in developing countries.', 
			'Maternal mortality shows the greatest disparity among countries: in sub-Saharan Africa, a woman\'s risk of dying from treatable or preventable complications of pregnancy and childbirth over the course of her lifetime is 1 in 22, compared to 1 in 7,300 in developed regions. The risk of a woman dying from pregnancy-related causes during her lifetime is about 1 in 7 in Niger compared to 1 in 17,400 in Sweden.',
			'Every year, more than 1 million children are left motherless and vulnerable because of maternal death. Children who have lost their mothers are up to 10 times more likely to die prematurely than those who have not.']},

	{title: 'Goal 6. Combat HIV/AIDS, Malaria and other Diseases', 
		li: ['Every day, nearly 7,500 people are infected with HIV and 5,500 die from AIDS. Globally, an estimated 33 million people were living with HIV/AIDS in 2007', 
			'The number of people living with HIV rose from an estimated 29.5 million in 2001 to 33 million in 2007. The vast majority of those living with HIV are in sub-Saharan Africa, where about 60 per cent of adults living with HIV in 2007 were women.',
			'Malaria kills over 1 million people annually, 80 per cent of whom are children under five in sub-Saharan Africa. There continue to be between 350 million and 500 million cases of malaria worldwide each year.',
			'An estimated 250 million anti-malaria insecticide-treated bed nets are required to reach 80 per cent coverage in sub-Saharan Africa. To date, the funds committed will provide only 100 million nets - less than one half of the requirement.']},

	{title: 'Goal 7. Ensure Environmental Sustainability', 
		li: ['Some 1.6 billion people have gained access to safe drinking water since 1990. At this rate, the world is expected to meet the MDG target on drinking water.', 
			'But about 1 billion people still do not have access to safe drinking water, and 2.5 billion lack access to basic sanitation services.',
			'Currently, only 22 per cent of the world\'s fisheries are sustainable, compared to 40 per cent in 1975. Despite their importance to the sustainability of fish stocks and coastal livelihoods, only 0.7 per cent of the world\'s oceans - about 2 million square kilometres - were put under protection.',
			'Some 2.4 billion people live without access to modern cooking and heating services, and 1.6 billion have no access to electricity.']},

	{title: 'Goal 8. Develop a Global Partnership for Development', 
		li: ['Official development assistance (ODA) continued to drop from an all-time high of $107.1 billion in 2005, to $103.7 billion in 2007. Aid flows need to increase by $18 billion per year to meet the promise made by the G8 in 2005 of doubling aid by 2010 - an additional $50 billion annually in global aid, of which $25 billion would be for Africa.', 
			'For the average developing country, the burden of servicing external debt fell from almost 13 per cent of export earnings in 2000 to 7 per cent in 2006, creating a more favourable environment for investment and allowing them to allocate more resources to reducing poverty.',
			'In developed countries, 58 per cent of people used the Internet in 2006, compared to 11 per cent in developing countries and 1 per cent in the least developed countries.']}
];
var mdgQuotes={ title:'Quotes', li:['"The Millennium Development Goals are owned by the people." - Eveline Herfkens, former Executive Coordinator for the Millennium Development Goals Campaign, Special Advisor to the UNDP Director.', 'The Millennium Campaign: "Additional (financial) resources must be delivered free of harmful conditionalities and without causing another downward spiral of debt."', '<a target="_blank" href="http://mdgachievers.com/main/quotes">More &raquo;</a>']};			
var mdgVideos = {scroll:0, names:['ReRx12QUv54','XmDsHw8Ekcs','m_7Ryry4vX0','6loLgqgXAhI','0JtxWEiy6ss','vddX4n30sXY','UkzM3uyAD4A','JN81oCYXP3Y','NSHClXW7KJA']};

mdgRelativeUrl = $('base').attr('href');
if (mdgRelativeUrl[mdgRelativeUrl.length-1] != '/') mdgRelativeUrl += '/';
//mdgRelativeUrl = 'http://localhost/mdg1/html'; //hack dirty

$(document).ready(function() {
	//$('.mdg-home-main-menu-item').click( function(){
	$('.mdg-home-main-menu-item').click( function(){
		$('.mdg-home-contents').css('display', 'none'); //hide all contents
		$('#mdg-home-content-'+this.title).css('display', 'block');//show clicked/picked content		  
		$('.mdg-home-main-menu-item').removeClass('selected');
		$('#mdg-home-second-menu-additional').css('display','none'); //hide square :0
		$(this).addClass('selected');
		if (this.title == 'goals'){
			$('#mdg-home-second-menu').css('display', 'block');
			$('ul#mdg-home-second-menu').css('paddingLeft','75px');		  			
			$('.mdg-home-second-menu-item').each( function(i){
		 		$(this).click( function(){
					$('#mdg-home-content-goals').html('<img src="'+mdgRelativeUrl+'images/goals/mp_goal'+(i+1)+'.jpg" width="360" />');
					return false;
				});
			});
		}		  
		else if ( this.title == 'videos' )
		{
			$('#mdg-home-second-menu').css('display', 'none');
			mdgSet4Video();
			$('.mdg-home-content-videos-link:first').click(); //show first youtube
			$('#scrollVideosLeft').find('a').click( function(){
				if ( --mdgVideos.scroll <= 0 )
				{
					mdgVideos.scroll = 0;
					$(this).addClass('notshow');
				}
				$('#scrollVideosRight').find('a').removeClass('notshow');
				mdgSet4Video();
				return false;
			});
			$('#scrollVideosRight').find('a').click( function(){
				if ( ++mdgVideos.scroll >= mdgVideos.names.length - 4)
				{ 
					mdgVideos.scroll = mdgVideos.names.length - 4;
					$(this).addClass('notshow');
				}
				$('#scrollVideosLeft').find('a').removeClass('notshow');
				mdgSet4Video();
				return false;
			 });
		 }
		 else if ( this.title == 'slideshow' )
		 {
			 $('#mdg-home-second-menu').css('display', 'none');
			 $('#mdg-home-content-slideshow').css('display', 'block' );
			 $('#mdg-home-second-menu').click( function(){} ); //r
		 }
		 else if ( this.title == 'facts' )
		 {
			 $('#mdg-home-second-menu').css('display', 'block');
			 $('ul#mdg-home-second-menu').css('paddingLeft','53px');	
			 $('#mdg-home-second-menu-additional').css('display','block'); //hide square :0
			 $('.mdg-home-second-menu-item').each( function(i){
				$(this).click( function(){
					tmp = '<h3 class="mdg-home-header">'+mdgFacts[i].title+'</h3><ul class="mdg-home-list">';
					for (j=0;j<mdgFacts[i].li.length;++j)
						tmp += '<li>'+mdgFacts[i].li[j]+'</li>';
					tmp += '<ul>';	
					$('#mdg-home-content-facts').html(tmp);					
					return false;
				});
			 });
		 	 $('.mdg-home-second-menu-item:first').click();
		 }
		 else if ( this.title == 'quotes' )
		 {
			 $('#mdg-home-second-menu').css('display', 'none');	
			 tmp = '<h3 class="mdg-home-header">'+mdgQuotes.title+'</h3><ul class="mdg-home-list">';
			 for (j=0;j<mdgQuotes.li.length;++j)
				tmp += '<li>'+mdgQuotes.li[j]+'</li>';
			 tmp += '<ul>';	
			 $('#mdg-home-content-quotes').html(tmp);					
		 }
		 else //achievers
		 {		  
			 ach = $('#mdg-home-content-achievers');
			 $('#mdg-home-second-menu').css('display', 'none');
			 $.ajax({ type:'GET', dataType:'html',
				error: function (xhr, desc, exceptionobj){ ach.html('<p>Something goes wrong</p>'); },
				success:function (data, textStatus){ ach.html(textStatus == 'success' ? data : data) },
				beforeSend:function(XMLHttpRequest){ ach.html('<p>Requesting content...</p>')},
				url: mdgRelativeUrl+'main/achievers' });
		 }
		 return false;
	});
	$('#mdg-home-main-menu li a').each( function(i){
		if (i==1) $(this).click(); // like we click on goals menu
	});
});

function mdgSet4Video(){
	$('.mdg-home-content-videos-link').each( function(i){
		$(this).click( function(){
		  nm = mdgVideos.names[mdgVideos.scroll+i];
		  $('#mdg-home-content-videos-video').html(
			'<object width="420" height="300">'+
			'<param name="movie" value="http://www.youtube.com/v/'+nm+'&hl=en&fs=1">'+
			'</param>'+
			'<param name="allowFullScreen" value="true"></param>'+
			'<param name="allowscriptaccess" value="always"></param>'+
			'<embed src="http://www.youtube.com/v/'+nm+'&hl=en&fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="420" height="300"></embed>'+
			'</object>'
			);
		  return false;	
		});
		$(this).find('img').attr('src', 'http://i2.ytimg.com/vi/'+mdgVideos.names[mdgVideos.scroll+i]+'/default.jpg');
	});
}
