
$(document).ready(function(){

/* Clear form input field onfocus */
$.fn.search = function() {
	return this.focus(function() {
		if( this.value == this.defaultValue ) {
			this.value = "";
		}
	}).blur(function() {
		if( !this.value.length ) {
			this.value = this.defaultValue;
		}
	});
};
$("#site-search").search(); /* global search */
$("#name").search(); /* name field, contact us page */



/* Add span for arrow on staff perspective page  */
$(".name")
		.append("<span class='arrow'></span>");


/* Add class .arrow-on to a.name on staff perspective page (swap png bg image) */
$(".name").hover( 
  function () {
    $(this).addClass("arrow-on");
  },
  function () {
    $(this).removeClass("arrow-on");
  }
);

/* Add class .promo-hover to div.promo on Relocation & Support and Jobs to style div as required */
$("#relocation .promo, #jobs .promo").hover( 
  function () {
    $(this).addClass("promo-hover");
  },
  function () {
    $(this).removeClass("promo-hover");
  }
);

/* Find last link URL in div and apply link to entire div  */
$('#relocation .promo, #jobs .promo').click(function() {
  window.location = $('a:last', this).attr('href');
});


/* Hide submit button and automatically submit form in Jobs section */ if ( $("#locationform") ) {
    $("#locationform").change( function() {
        $("#locationform").submit();
    });
    $("#locationform input").hide();
}

			/* Set up faux combobox */
			
			$('#country-nav div.ul').hide();
			$('#country-nav p').bind('click', function() {
							$('#country-nav div.ul').toggle();
							return false;
			});
			$(document).click(function() {
							$('#country-nav div.ul').hide();
			});

			/* Add class to div.ul to manipulate li.selected (done in CSS) */
			
			$("#country-nav div.ul").hover( 
					function () {
							$(this).addClass("ul-hover");
					},
					function () {
							$(this).removeClass("ul-hover");
					}
			);
			
			
			/* Find URL with with attribute rel="external" and open in new window */
			$('A[rel="external"]').click( function() {
        window.open( $(this).attr('href') );
        return false;
    });


});

