$(function() {
	
	// 
	$('.GeoLocationTextBox')
		.geo_autocomplete(
			{
				geocoder_region : 'uk',
	    		mapheight       : 0,
				mapwidth        : 0,
				width           : 178
			}
		);
  
  /*
   * External Links
   */
  $('a[rel=external]')
    .click(
      function(e) {
        open(this.href);
        e.preventDefault();
      }
    )
    .attr('title', 'Opens in a new window');
    
  /*
   * Useful Stuff
   */
  $('li:last-child').addClass('last-item');
  
  $('input, select, textarea')
    .blur(
      function() {
        $(this).removeClass('focus');
      }
    )
    .focus(
      function() {
        $(this).addClass('focus');
      }
    )
    .hover(
      function() {
        $(this).addClass('hover');
      },
      function() {
        $(this).removeClass('hover');
      }
    );
    
  $('input.default')
    .focus(
      function() {
            if ($(this).val() == $(this)[0].title) {
          $(this).val('');
        }
      }
    )
    .blur(
      function() {
            if ($(this).val() == '') {
          $(this).val($(this)[0].title);
        }
      }
    )
    .blur();
    
  /*
   * Manipulate Umbraco's image alignment
   */
  $('#content img')
    .each(
      function(e) {
        if ($(this).css('float') == 'left') {
          $(this).addClass('left');  
        }
        else if ($(this).css('float') == 'right') {
          $(this).addClass('right');
        }
      }
    );
    
  /*
   * S3Slider
   */
  $('#content .banner .animation ul').append('<li />');
  
  $('#content .banner .animation')
    .s3Slider({
      timeOut : 4000
    });
    
  /*
   * ToolTip
   */
  var xOffset = 05,
    yOffset = 35;
  
  $('a.tooltip')
    .hover(
      function(e) {
        this.t = this.title;
        this.title = '';
        $('body').append('<p id="tooltip">' + this.t + '</p>');
        $('#tooltip').css({left : (e.pageX + xOffset) + 'px', top : (e.pageY - yOffset) + 'px'}).fadeTo(400, 0.8);
      },
      function(e) {
        this.title = this.t;
        $("#tooltip").remove();
      }
    )
    .mousemove(
      function(e) {
        $('#tooltip').css({left : (e.pageX + xOffset) + 'px', top : (e.pageY - yOffset) + 'px'});
      }
    );
    
  /*
   * Fancybox
   */
  $('ul.people li a')
    .click(
      function(e) {
        $.fancybox({
          autoScale      : false,
//          href           : this.href.replace('.html', '_single.html'),
          href           : this.href.replace('.aspx', '/OurTeamMember.aspx'),
          height         : 300,
          overlayColor   : '#000',
          padding        : 20,
          titleShow      : false,
          transitionIn   : 'elastic',
          transitionOut  : 'elastic',
          type           : 'iframe',
          width          : 600
        });
        
        e.preventDefault();
      }
    ); 
    
	/* 
	* Range Slider
	*/
	var minSalaryVal, maximumSalaryVal;
	if ($.query.get('minimumSalary') != '') {
	    minSalaryVal = $.query.get('minimumSalary');
	} else {
	    minSalaryVal = '10000';
	}
	if ($.query.get('maximumSalary') != '') {
	    maximumSalaryVal = $.query.get('maximumSalary');
	} else {
	    maximumSalaryVal = '250000';
	}
			
	if ($('#slider-salary').length) {
		$('#slider-salary' )
			.slider(
				{
					min	: 10000,
					max	: 250000,
					range  : true,
					slide  : function(event, ui) { $('.textSalary').val('\u00A3' + ui.values[0] + ' - \u00A3' + ui.values[1]) },
					values: [minSalaryVal, maximumSalaryVal]
				}
			);
			
		$('.textSalary').val('\u00A3' + $('#slider-salary').slider('values', 0) + ' - \u00A3' + $('#slider-salary').slider('values', 1));
	}
  
});
