$.support.cssProperty = (function() {
  function cssProperty(p, rp) {
    var b = document.body || document.documentElement,
    s = b.style;

    // No css support detected
    if(typeof s == 'undefined') { return false; }

    // Tests for standard prop
    if(typeof s[p] == 'string') { return rp ? p : true; }

    // Tests for vendor specific prop
    v = ['Moz', 'Webkit', 'Khtml', 'O', 'Ms'],
    p = p.charAt(0).toUpperCase() + p.substr(1);
    for(var i=0; i<v.length; i++) {
      if(typeof s[v[i] + p] == 'string') { return rp ? (v[i] + p) : true; }
    }
  }

  return cssProperty;
})();

$('document').ready(function(){	
	var pathname = window.location.pathname;
	if (pathname.match('/(.*)countries(.*)/')){
		$('#section-menu ul li.selected').addClass('opened');
		$('#section-menu ul li ul li.selected').addClass('opened');
		$("#section-menu ul li ul li.selected ul li a").corner("cc:#ebeced");
		$open='0';
		
		$("#section-menu ul li.africa").find("li").each(function(){
			if ($(this).hasClass("selected")){
				$open='1';
			}
		});
		
		if ($open=='0') {
			$("#section-menu ul li.selected.africa").removeClass("selected");
			$("#section-menu ul li.africa").children().css("display","none");
		}
		
		$open='0';
		$("#section-menu ul li.asia").find("li").each(function(){
			if ($(this).hasClass("selected")){
				$open='1';
			}
		});
		
		if ($open=='0') {
			$("#section-menu ul li.selected.asia").removeClass("selected");
			$("#section-menu ul li.asia").children().css("display","none");
		}
		
		$open='0';
		$("#section-menu ul li.eastern-europe").find("li").each(function(){
			if ($(this).hasClass("selected")){
				$open='1';
			}
		});
		
		if ($open=='0') {
			$("#section-menu ul li.selected.eastern-europe").removeClass("selected");
			$("#section-menu ul li.eastern-europe").children().css("display","none");
		}
		
		$open='0';
		$("#section-menu ul li.latin-america-and-the-caribbean").find("li").each(function(){
			if ($(this).hasClass("selected")){
				$open='1';
			}
		});
		
		if ($open=='0') {
			$("#section-menu ul li.selected.latin-america-and-the-caribbean").removeClass("selected");
			$("#section-menu ul li.latin-america-and-the-caribbean").children().css("display","none");
		}
		
		$("#section-menu ul li.africa a").css("display","block");
		$("#section-menu ul li.asia a").css("display","block");
		$("#section-menu ul li.eastern-europe a").css("display","block");
		$("#section-menu ul li.latin-america-and-the-caribbean a").css("display","block");
		
	} else {
		if ($('#section-menu ul').length) {
			$('#section-menu ul li.selected').addClass('opened');
			$("#section-menu ul li.selected ul li a").corner("cc:#ebeced");
		}
	}
	//addthis
	
	if ($.browser.msie && $.browser.version.substr(0,1)<7) {		
	} else {
		$('div.photo-right:first').append('<script type="text/javascript">\
											var addthis_config = {\
											pubid: "ra-4e5cd58d58d77917",\
				    						ui_language: "en",\
											services_compact: "facebook, twitter, linkedin, viadeo, email, google, myspace, delicious, digg, reddit, stumbleupon, more",\
											data_ga_property: "UA-11879400-1",\
									        data_track_clickback: true\
											}\
											</script>\
											<div class="addthis_toolbox addthis_default_style">\
											<div style="float:left;padding-right:5px;">Share this page: </div>\
											<a class="addthis_button_facebook"></a>\
											<a class="addthis_button_twitter"></a>\
											<a class="addthis_button_google_plusone" g:plusone:count="false" g:plusone:annotation="none"></a>\
											<a class="addthis_button_linkedin"></a>\
											<span class="addthis_separator">|</span>\
											<a href="http://addthis.com/bookmark.php?v=250" class="addthis_button_compact">More options</a>\
											</div>\
											<script>\
												var addthis_share = {\
												   templates: {\
													  twitter: "#VolunteerAbroad with @projectsabroadP . #Volunteer projects in developing countries for professionals: {{url}}"\
												   }\
												}\
											</script>\
											<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js"></script>');
		$('div.photo:first').append('<script type="text/javascript">\
										var addthis_config = {\
										pubid: "ra-4e5cd58d58d77917",\
				    					ui_language: "en",\
										services_compact: "facebook, twitter, linkedin, viadeo, email, google, myspace, delicious, digg, reddit, stumbleupon, more",\
										data_ga_property: "UA-11879400-1",\
										data_track_clickback: true\
										}\
										</script>\
										<div class="addthis_toolbox addthis_default_style">\
										<div style="float:left;padding-right:5px;">Share this page: </div>\
										<br clear="all" />\
										<a class="addthis_button_facebook"></a>\
										<a class="addthis_button_twitter"></a>\
										<a class="addthis_button_google_plusone" g:plusone:count="false" g:plusone:annotation="none"></a>\
										<a class="addthis_button_linkedin"></a>\
										<span class="addthis_separator">|</span>\
										<a href="http://addthis.com/bookmark.php?v=250" class="addthis_button_compact">More options</a>\
										</div>\
										<script>\
												var addthis_share = {\
												   templates: {\
													  twitter: "#VolunteerAbroad with @projectsabroadP . #Volunteer projects in developing countries for professionals: {{url}}"\
												   }\
												}\
										</script>\
										<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js"></script>');
	}
	
	//first-child-fix
	$(":first-child").addClass("first-child");
	//add ie shadows
	
	$(function () {
		if($.browser.msie){ //if text-shadow not supported
			//top menu
			
			//on selected
			$("#menu ul li a").each(function () {
				var myclass = $(this).attr("class");
				$(this).find("em").append("<span></span>");
				$(this).find("em").css("color","#333");
				$(this).each(function() { 
					var duplicate = $(this).text(); 
					$(this).find("span").text(duplicate); 
				});
				
				if (myclass == "first-child"){
					$(this).find("em").css("color","#fff");
					$(this).find("span").css("color","#333");
					$(this).find("span").css("top","10px");
				}
			 });
			//on hover
			$("#menu ul li a").hover(
			  function () {
				var myclass = $(this).attr("class");
				if (myclass == "first-child"){
					$(this).find("em").css("color","#333");
					$(this).find("span").css("color","#fff");
					$(this).find("span").css("top","12px");
				}
			  }, 
			  function () {				
				var myclass = $(this).attr("class");
				if (myclass == "first-child"){
					$(this).find("em").css("color","#fff");
					$(this).find("span").css("color","#333");
					$(this).find("span").css("top","10px");
				}
			  }
			);
			//lefthand menu
			$("#section-menu ul li a").each(function () {
				if ($(this).css("text-shadow") != "none"){
					$(this).append("<span></span>");
					if ($(this).parent().hasClass("selected")){
						$(this).find("span").css("color","#fff");
						$(this).css("color","#666");
					}
					if (!$(this).parent().hasClass("selected")){
						$(this).css("color","#ddd");
					}
					$(this).each(function() { 
						var duplicate = $(this).html(); 
						$(this).find("span").html(duplicate);
					});
				}
			 });
			
			$("#section-menu ul li a").hover(									 
			  function () {
				if ($(this).css("text-shadow") != "none" && !$(this).parent().hasClass("selected")){
					$(this).find("span").css("color","#fff");
					$(this).css("color","#333");
				}
			  }, 
			  function () {
			  	if ($(this).css("text-shadow") != "none" && !$(this).parent().hasClass("selected") && $(this).css("font-size") != "11px"){ //11px hardcoding for IE6
					$(this).find("span").css("color","#444");
					$(this).css("color","#ddd");
				}
			  }
			);
		}
		//gallery
		if (pathname.match('/(.*)photo-gallery(.*)/')){
			$("a[rel^='photos']").prettyPhoto({animationSpeed:'fast',theme:'facebook',slideshow:5000, autoplay_slideshow: true, show_title: false, overlay_gallery: false});
		}
		
		if (pathname.match('/(.*)staff-in-destinations(.*)/')){	
			$('a.anchor').css('display','none');
			var i = 0;
			//hide list
			$("ul#staff-items li").each(function () {
				if ($(location).attr('href').split('#')[1] == null) {										
					if (i != 0) {
						$(this).css("display","none");
					} else {
						i = 1;
					}
					
				} else {
					if (!$(this).hasClass($(location).attr('href').split('#')[1])) {
						$(this).css("display","none");
					}
				}
			});
			//click scroller
			$('ul#country-selector li a').click(function() {
			  	liClass = $(this).attr("href").split('#')[1];
				$("ul#staff-items li").each(function () {
						$(this).css("display","none");
				});
				$("ul#staff-items li." + liClass).css("display","inline");
				$('html, body').animate({scrollTop:0}, 'slow');
			});
			//click on left menu
			$('ul#section-menu-items li a[href^="#"]').click(function() {
			  	liClass = $(this).attr("href").split('#')[1];
				$("ul#staff-items li").each(function () {
						$(this).css("display","none");
				});
				$("ul#staff-items li." + liClass).css("display","inline");
				$('html, body').animate({scrollTop:0}, 'slow');
			});
			
			$('html, body').animate({scrollTop:0}, 'slow');
		}
		
		if (pathname.match('/(.*)prices(.*)/')){
			$('table.prices-box :last-child').addClass('last');
		}
		
		//projects abroad button
		
	}); //end domready
});
