jQuery(document).ready(function() {
	
// tar

	// set up accordion for tool list in main page
	if (jQuery('#ToolList')) {
		jQuery('#ToolList').accordion({autoHeight: false,  header: '.head'});
	};
	
	if (jQuery('#PhotoCredit')) {
		jQuery('#PhotoCredit').addClass('hidden');
		jQuery('#PhotoCredit span').css("display", "none");
		jQuery('#PhotoCredit a').css("display", "none");
		
		
		jQuery('#PhotoCredit.hidden').livequery('click', function() {
				jQuery(this).animate({opacity:"1"}).css("background-color","#333").toggleClass("hidden").toggleClass("shown");
				jQuery('#PhotoCredit span').fadeIn();
				jQuery('#PhotoCredit a').fadeIn(); 
				jQuery('#PhotoCredit h4').text("Hide photo credit");
			}
		);

		jQuery('#PhotoCredit.shown').livequery('click', function() {
				jQuery(this).animate({opacity:"0.7"}).toggleClass("hidden").toggleClass("shown");
				jQuery('#PhotoCredit span').fadeOut();
				jQuery('#PhotoCredit a').fadeOut(); 
				jQuery('#PhotoCredit h4').text("Photo credit");
				jQuery(this).css("background","none")
			}
		);
		
	};
	

	
	/* Homepage countries toggler */
	
	jQuery('#CountriesToggler').addClass('hide');
	jQuery('#CountriesToggler a').text("Hide ASEAN countries");
	
	
	jQuery('#CountriesToggler.hide a').livequery('click', function() {
	 	jQuery('#CountriesBox').slideToggle();
	 	jQuery('#CountriesToggler a').text("Show ASEAN countries");
		jQuery('#CountriesToggler').removeClass('hide').addClass('show');
		return false;
	});
	
	jQuery('#CountriesToggler.show a').livequery('click', function() {
	 	jQuery('#CountriesBox').slideToggle();
	 	jQuery('#CountriesToggler a').text("Hide ASEAN countries");
		jQuery('#CountriesToggler').removeClass('show').addClass('hide');
		return false;
	});
	


	
	/* Set up FAQ Page */
	jQuery('#FAQList li.FAQ .FAQContent').hide();
	jQuery('#FAQList .FAQ').addClass('closed');
	
	jQuery('#FAQList .closed .FAQTitle').livequery('click', function() {
		all = jQuery('#FAQList .expanded .FAQTitle');
		all.next().slideUp();
		all.find(".toggler").html("");
		all.parent().removeClass('expanded');
		all.parent().addClass('closed');
		
		parental = jQuery(this).parent();
		parental.removeClass('closed');
		parental.find(".toggler").html("Click to Hide");
		parental.addClass('expanded');
		jQuery(this).next().slideDown();

		return false;
	});
	
	jQuery('#FAQList .expanded .FAQTitle').livequery('click', function() {
		parental = jQuery(this).parent();
		parental.removeClass('expanded');
		parental.find(".toggler").html("");

		parental.addClass('closed');
		parental.find("p.FAQTitle").css("cursor", "pointer");
		jQuery(this).next().slideUp();
		
		return false;
	});
	/* end of Set up FAQ Page */

	
	/* end of Meeting planner */
	
	/* Milestone page */
	switchToIndex(jQuery("#MilestoneIndex #Index1 a"), 1);
	jQuery("#MilestoneIndex #Index1 a").click(function() {
		switchToIndex(this, 1);
		return false;
	});
	jQuery("#MilestoneIndex #Index2 a").click(function(e, obj) {
		switchToIndex(this, 2);
		return false;
	});
	jQuery("#MilestoneIndex #Index3 a").click(function(e, obj) {
		switchToIndex(this, 3);
		return false;
	});
	function switchToIndex(obj, index) {
		jQuery("#MilestoneContent li.nav").hide();
		jQuery("#MilestoneIndex li a").removeClass('current');
		jQuery(obj).addClass('current');
		jQuery("#Content" + index + " p:first").addClass('first');
		jQuery("#MilestoneContent #Content" + index).fadeIn();
	}
	/* end of Milestone page */
	
	
	/* remove search box text on focus */
	
	var swap_text_boxes = [];

	function init_swap_text_boxes(){
	  //Store the default value for each box
	  jQuery('.SearchBox input[type=text][value]').each(function() {
	    swap_text_boxes[jQuery(this).attr('id')] = jQuery(this).attr('value');
	  });
	  //Add focus and blur events to set or clear the value
	  jQuery('.SearchBox input[type=text][value]').bind('focus', function() {
	    if(jQuery(this).val() == swap_text_boxes[jQuery(this).attr('id')]) {
	      jQuery(this).val('');
	    }
	  });
	  jQuery('.SearchBox input[type=text][value]').bind('blur', function() {
	    if(jQuery(this).val() == '') {
	      jQuery(this).val(swap_text_boxes[jQuery(this).attr('id')]);
	    }
	  });
	}

	init_swap_text_boxes();
	
});