jQuery(document).ready(function($) {
	
	$('#home-slider').nivoSlider({
		effect:'fade', //sliceDown,sliceDownLeft,sliceUp,sliceUpLeft,slideUpDown,slideUpDownLeft,fold,fade,random
		animSpeed:500,
		pauseTime:10000,
		controlNav:false,
		directionNav:false,
		slices:15,
		pauseOnHover:false,
		afterChange:function() {
		 		var src = $('#home-slider div').first().css('background-image');
		 		src = src.split('/');
		 		src = src[src.length - 1];
		 		src = src.split('.');
		 		src = src[0];
        
        switch (src) {
          case 'home_destinations': //destinations reached
            var t = '175px';
            var l = '385px';
            break;
          case 'home_savings': //exceptional savings
            var t = '165px';
            var l = '265px';
            break;
          case 'home_service': //exceptional service
            var t = '166px';
            var l = '265px';
            break;
          case 'home_tech': //exception technology
            var t = '166px';
            var l = '267px';
            break;
        }		 		
		 		
		 		$(".nivo-hover").css({
		 		  top: t,
		 		  left: l
		 		});

		}
	});

  //the home page tabs
	$('#home-content #info').tabs();
		
  //the home page accordion
	$("#accordion").accordion({
      collapsible: true,
      active:false,
      'autoHeight':false
	});
  
	//clear these input fields when we click on them.
	$('input, textarea').not('.submit-button').focus(function() {
		var id = $(this).attr('id');
		var label = $('label[for="' + id + '"]').text();
				
		if ($(this).val().toLowerCase() == label.toLowerCase()) {
	    $(this).val('');
		}		
		$(this).css('text-transform','none');

		$(this).blur(function() {
			if ($(this).val() == '') {
				$(this).css('text-transform','uppercase');
				var id = $(this).attr('id');
				var label = $('label[for="' + id + '"]').text();
				$(this).val(label);
			}
		});
	});
	
	//clears all of the default values from the form when we submit
	$('form').submit(function() {
	  $('input,textarea').each(function(){
      var id = $(this).attr('id');
  		var label = $('label[for="' + id + '"]').text();		
  		if ($(this).val().toLowerCase() == label.toLowerCase()) {
  	   $(this).val('');
  		}
	  });
	});
	
	//add the labels back into the fields if they're blank
	$('input, textarea').not('.submit-button').each(function() {
		var id = $(this).attr('id');
		var label = $('label[for="' + id + '"]').text();

		if ($(this).val() == '' ) {
		  $(this).val(label);
		}	  	  
  
	});
		
  //adjust the height of the left and right columns to be the same
  var l = $('#left').height();
  var r = $('#right').height();
  if (l > r) {  
    $('#right').height(l);
  } else {
     $('#left').height(r);   
  }

  //open all links with rel="external" in a new window
  $('a[rel|="external"]').attr("target", "_blank");

  // Open all external links in new window (even if they don't have rel="external")
  $('a[href^="http"]').not('a[href*="' + window.location.host + '"]').attr("target", "_blank");

  $('a.fancy-box').fancybox({	
    transitionIn	:	'elastic',
		transitionOut	:	'elastic',
		speedIn		:	200, 
		speedOut		:	200, 
		overlayShow	:	true,
		autoScale : false
	});
	
	//show and hide the global office locations
	$('#office-locations a.show').toggle(function() {
	  $('#office-locations #global-offices').slideDown('slow');
	},function() {
	  $('#office-locations #global-offices').slideUp('slow');	  
	});
	
	//give every radio button element a class of 'radio'
	$('input[type="radio"]').addClass('radio');	
	
	$('input[type="checkbox"]').addClass('checkbox');	

});




