$(document).ready( function(){ 
	
	//When page loads...
	$(".panel").hide(); //Hide all content
	$("ul.tabbedContentNav li:first").addClass("active").show(); //Activate first tab
	$(".panel:first").show(); //Show first tab content
	$("p.mission a").addClass("clickToSeeMore");
	$("div.highlightLink a").addClass("clickToSeeMore");
	$("div.highlightLink p a").addClass("clickToSeeMore");
	$("p.highlightLink p a").addClass("clickToSeeMore");
	$("p.highlightLink a").addClass("clickToSeeMore");
	$("div#splashButtonLink a").addClass("splashLink");
	$("div#givingSplashButtonLink a").addClass("givingSplashLink");
	$("ul#breadcrumbs li:last-child a").addClass("noBg");
	$(".videoLink1").replaceWith("<a rel=\"shadowbox;height=" + $("#video").height() + ";width=" +  $("#video").width() + "\" href=\"#video\" class=\"videoLink1\">" + $(".videoLink1").html() + "</a>");
	$(".videoLink2").replaceWith("<a rel=\"shadowbox;height=" + $("#video2").height() + ";width=" +  $("#video2").width() + "\" href=\"#video2\" class=\"videoLink2\">" + $(".videoLink2").html() + "</a>");
	$(".videoLink3").replaceWith("<a rel=\"shadowbox;height=" + $("#video3").height() + ";width=" +  $("#video3").width() + "\" href=\"#video3\" class=\"videoLink3\">" + $(".videoLink3").html() + "</a>");
	$(".panel2").hide(); 
	$("ul.tabbedContentNav2 li:first").addClass("active2").show(); //Activate first tab
	$(".panel2:first").show(); //Show first tab content
	$(".panel3").hide(); 
	$("ul.tabbedContentNav3 li:first").addClass("active3").show(); //Activate first tab
	$(".panel3:first").show(); //Show first tab content
	$("ul#pressList li:last-child div").removeClass("hr");
	$(".answer").hide();
	$(".correct").hide();
	$(".directions").hide();
	
	// Photo Credit
	$(".photoCredit").hover(
	function() { $(this).contents("span:last-child").css({ display: "block" }); },
	function() { $(this).contents("span:last-child").css({ display: "none" }); }
	);
	
	
	$("a.popup").attr("rel", "shadowbox;width=640;height=390");	
	// Pagination 	
	var show_per_page = 10;
	var number_of_items = $('#pressList').children().size();
	var number_of_pages = Math.ceil(number_of_items/show_per_page);
	$('#current_page').val(0);
	$('#show_per_page').val(show_per_page);
	var navigation_html = '<a class="previous_link clickToSeePrev" href="javascript:previous();">Previous</a>|';
	var current_link = 0;
	while(number_of_pages > current_link){
		navigation_html += '<a class="page_link" href="javascript:go_to_page(' + current_link +')" longdesc="' + 
current_link +'">'+ (current_link + 1) +'</a>|';
		current_link++;
	}
	navigation_html += '<a class="next_link clickToSeeMore" href="javascript:next();">Next</a>';
	$('#page_navigation').html(navigation_html);
	$('#page_navigation .page_link:first').addClass('active_page');
	$('#pressList').children().css('display', 'none');
	$('#pressList').children().slice(0, show_per_page).css('display', 'block');
	
	var newText = $(".pressDate").text().split(" ").join("</span> <span>");
  	//newText = "<span>" + newText + "</span>";
  	//$(".pressDate").html(newText);
   
	//On Click Events
	
	$("#siteSearch").click(function() {
		$("#searchForm").submit();
	});
	$("#viewGive").click(function() {
		$("#waysToGive ul").css('display', 'block');
	});
	$("#languages").click(function() {
		$("#languages").toggleClass("languageClose");
		$("#languageList ul").toggle();	
	});
	$("a.vawtgClose").click(function() {
		$("#waysToGive ul").css('display', 'none');
	});
	$("#explorePlacesBox").click(function() {
		$("#explorePlaces ul").css('display', 'block');
	});
	$("a.exploreClose").click(function() {
		$("#explorePlaces ul").css('display', 'none');
	});
	$("ul.tabbedContentNav li").click(function() {
		$("ul.tabbedContentNav li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".panel").hide(); //Hide all tab content
		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active ID content
		return false;
	});	
	$("ul.tabbedContentNav2 li").click(function() {
		$("ul.tabbedContentNav2 li").removeClass("active2"); //Remove any "active" class
		$(this).addClass("active2"); //Add "active" class to selected tab
		$(".panel2").hide(); //Hide all tab content
		var activeTab2 = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab2).fadeIn(); //Fade in the active ID content
		return false;
	});
	$("ul.tabbedContentNav3 li").click(function() {
		$("ul.tabbedContentNav3 li").removeClass("active3"); //Remove any "active" class
		$(this).addClass("active3"); //Add "active" class to selected tab
		$(".panel3").hide(); //Hide all tab content
		var activeTab3 = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab3).fadeIn(); //Fade in the active ID content
		return false;
	});
	$(".visit").click(function() {
		$("ul.tabbedContentNav li:first").removeClass("active"); 
		$(".visitTab").addClass("active"); 
		$(".panel").hide(); 
		var activeTab = $("#preserveTab3"); 
		$(activeTab).fadeIn(); 
		document.location='#thingsToDo';
		$(".preserveMap").load(location.href + " .preserveMap > *");
		return false;
	});	
	$(".visitTab h4 a").click(function() {	
	$(".preserveMap").load(location.href + " .preserveMap > *");	
	});
	$(".mapTab h4 a").click(function() {	
	$(".featureMap").load(location.href + " .featureMap > *");	
	});
	$(".fullBio").click(function() {
		$("ul.tabbedContentNav2 li").removeClass("active2"); 
		$(".bioTab").addClass("active2"); 
		$(".panel2").hide(); 
		var activeTab2 = $("#bioTab5"); 
		$(activeTab2).fadeIn(); 
		return false;
	});	
	$(".initiativesClose").click(function() {
		$("#initiativesAfricaMenu").hide();
		$("#initiativesAsiaMenu").hide();
		$("#initiativesCaribbeanMenu").hide();
		$("#initiativesCAmericaMenu").hide();
		$("#initiativesNAmericaMenu").hide();
		$("#initiativesSAmericaMenu").hide();
		$("#initiativesAfricaButton a").removeClass("on");
		$("#initiativesAsiaButton a").removeClass("on");
		$("#initiativesCaribbeanButton a").removeClass("on");
		$("#initiativesCAmericaButton a").removeClass("on");
		$("#initiativesNAmericaButton a").removeClass("on");
		$("#initiativesSAmericaButton a").removeClass("on");
	});
	
                    	
	
                                                                	                                                           	                    
});

function previous(){
	new_page = parseInt($('#current_page').val()) - 1;
	//if there is an item before the current active link run the function
	if($('.active_page').prev('.page_link').length==true){
		go_to_page(new_page);
	}
}
function next(){
	new_page = parseInt($('#current_page').val()) + 1;
	//if there is an item after the current active link run the function
	if($('.active_page').next('.page_link').length==true){
		go_to_page(new_page);
	}
}
function go_to_page(page_num){
	//get the number of items shown per page
	var show_per_page = parseInt($('#show_per_page').val());
	//get the element number where to start the slice from
	start_from = page_num * show_per_page;
	//get the element number where to end the slice
	end_on = start_from + show_per_page;
	//hide all children elements of content div, get specific items and show them
	$('#pressList').children().css('display', 'none').slice(start_from, end_on).css('display', 'block');
	/*get the page link that has longdesc attribute of the current page and add active_page class to it
	and remove that class from previously active page link*/
	$('.page_link[longdesc=' + page_num 
+']').addClass('active_page').siblings('.active_page').removeClass('active_page');
	//update the current page input field
	$('#current_page').val(page_num);
}
var url = location.href;
var url_parts = url.split('?');
var main_url = url_parts[0];	
