/**
 * lh.js
 * @author Lewis Howles
 *
 * Default Niceties.
 */

var lh = {
	
	/*
	 * Set default text for inputs (title attribute)
	 */
	setInputTexts : function(){
	   $("input[type=text], textarea").each(
		   function(){
			   $(this).val($(this).attr('title'));
		   }
	   );
	},
	
	/*
	 * Show / hide text from inputs
	 */
	inputText : function(){
	   $("input, textarea").focus(function(event){
		   if($(this).val() === $(this).attr('title'))
			   $(this).val("");
	   }).blur(function(event){
		   if($(this).val() === "")
			   $(this).val($(this).attr('title'));
	   });
	},
	
	/*
	 * Set target blank on external links
	 */
	externalLinks : function(){
		$('a[rel="external"]')
			.attr('target', '_blank')
	}
}

$(function() {
	lh.setInputTexts();
	lh.inputText();
	lh.externalLinks();
	
	$varLocation = $.getUrlVar('location');
	if ($varLocation) {
		$('.cms_form #location').val($.getUrlVar('location').replace('+', ' ').replace('%20', ' '));
	}
	
	$.fn.maphilight.defaults = {
		fill: true,
		fillColor: '6e191e',
		fillOpacity: 1,
		stroke: false,
		strokeColor: '5e090e',
		strokeOpacity: 1,
		strokeWidth: 1,
		fade: true,
		alwaysOn: false,
		neverOn: false,
		groupBy: false
	}
	
	$('.map').maphilight();
	
	$('#testimonial-fader').innerfade({'timeout' : 10000});
});

// Get URL Parameters
$.extend({
  getUrlVars: function(){
	var vars = [], hash;
	var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
	for(var i = 0; i < hashes.length; i++)
	{
	  hash = hashes[i].split('=');
	  vars.push(hash[0]);
	  vars[hash[0]] = hash[1];
	}
	return vars;
  },
  getUrlVar: function(name){
	return $.getUrlVars()[name];
  }
});
