function copyInput(){
      // copy input title content into value only if value is empty (allows for fields to be pre-populated e.g. from php)
  $("#enquiry,#cont-text").find('input[title], textarea[title]').each(function() {
    var el = $(this);

    function sticky() {
      if (el.attr('value').length == 0) {
        el.attr('value', el.attr('title'));
        el.addClass('inactive');
      }
    }

    // reset on mouse out
    $(this).blur(function() {
      sticky();
    });

    // clear on mouse in
    $(this).focus(function() {
      if (el.attr('title') == el.attr('value')) {
        el.attr('value', '');
        el.removeClass('inactive');
      }
    });


  });

}


function copyInput2(){
    	// copy input title content into value only if value is empty (allows for fields to be pre-populated e.g. from php)
	$("#enquiry2").find('input[title], textarea[title]').each(function() {
		var el = $(this);

		function sticky() {
			if (el.attr('value').length == 0) {
				el.attr('value', el.attr('title'));
				el.addClass('inactive');
			}
		}

		// reset on mouse out
		$(this).blur(function() {
			sticky();
		});

		// clear on mouse in
		$(this).focus(function() {
			if (el.attr('title') == el.attr('value')) {
				el.attr('value', '');
				el.removeClass('inactive');
			}
		});


	});
}



$(document).ready(function() {
	copyInput();
  copyInput2();
  $("ul:not(:has(li))").remove();

	// external links
	$('a.external').click(function() {
	    window.open($(this).attr('href'), 'blank');
	    return false;
	});

	// clean junk on form submit
	$('form').submit(function() {
		$(this).find('input[title], textarea[title]').each(function() {
			if ($(this).attr('title') == $(this).attr('value')) $(this).attr('value', '');
		});
	});

	// google map
	if ($('#map').length > 0) {
		load();
	}

	// Expanding menu
	$('#left-column li:has(ul)').each(function() {
		$(this).find('a:eq(0)').click(function() {
			// toggle display
			$('#left-column li:not(.active) ul:visible').slideUp('slow');
			$(this).parent().find('ul').slideDown('slow');

			// disable link clicks on expansion items
			return false;
		});
	});

	$('#left-column li:not(.active) ul').hide();

	// IE6 fixing
	if ($.browser.msie && ~$.browser.version < 7) {
		// width issues
		$('ul.black-bar li, div.testimonial, div.testimonial *, div.dual-content').each(function() {
			$(this).width($(this).width());
		});

		jQuery.ifixpng(url + 'images/blank.gif');
		jQuery('img[src$=.png], .bg-png').ifixpng();

		// fix for the fix applied to pngs
		$('#left-column ul.navigation li a').css({
			'position': 'relative',
			'z-index': 999
		});
	}

	// validation
	$("#enquiry,#cont-text").validate({
		invalidHandler:function(){
			copyInput();
		}
	});

  $("#enquiry2").validate({
    invalidHandler:function(){
      copyInput2();
    }
  });

	if ($.cookie('admin')){
	    $('li#edit-link').css('display','block');
	}

	$('#pmi p:first, #healtcare p:first, #mortgage p:first, #pi p:first').css('margin-top', '0px');

	function addMega(){
	    $(this).find("#drop").slideDown('fast');
		$(this).find("#droppi").slideDown('fast');
	}

	function removeMega(){
	    $(this).find("#drop").slideUp('fast');
		$(this).find("#droppi").slideUp('fast');
	}

	var megaConfig = {
	    interval: 200,
	    sensitivity: 7,
	    over: addMega,
	    timeout: 500,
	    out: removeMega
	};
	$('#drop-me').hoverIntent(megaConfig);
	$('#droppi-me').hoverIntent(megaConfig);


	$('#tabcontent div').hide();
	$('#tabcontent div:first').show();
	$('#hometabs2 div:first').addClass('active');
	$('#hometabs2 ul li div a').mouseover(function(){ //When any link is clicked
		$('#hometabs2 div').removeClass('active');//$(this).parent('div').siblings().removeClass('active'); // Remove active class from Previous Link or All Links
		$(this).parent('div').addClass('active'); //Set parent (just before element of It like content-filter.html) of clicked link class to active
		var currentTab = '#' + $(this).attr('class'); // Set variable currentTab to value of class attribute of clicked link
		$(currentTab).siblings().hide();//.fadeOut()	$('#news-mid div').hide(); // Hide all divs with in tab id
		$(currentTab).show(); //.fadeIn() Show div with id equal to variable currentTab
		return false;
	});

	var origHeight = $('#qualify.lpqualify .jq-mid').height();

	$('#qualify:not(.lpqualify|.carehome) .jq-mid').hide();

	$('#qualify.lpqualify .jq-mid').animate({
	  height:"0px"
	});

  $('#qualify.lpqualify h2,#qualify.lpqualify #hide-blob a.show').click(function(){
    if(parseInt($('#qualify.lpqualify .jq-mid').height()) == 0){
      $('#qualify.lpqualify .jq-mid').animate({
        height: origHeight
      });
    }else{
      $('#qualify.lpqualify .jq-mid').stop().animate({
        height:"0px"
      });
    }

    $('#hide-blob a').toggleClass("show-active");
    return false;
  });

  setTimeout("$('#qualify.open #hide-blob a.show').trigger('click')", 500);

	$('#qualify:not(.lpqualify) h2,#qualify:not(.lpqualify) #hide-blob a.show').click(function(){
		$('.jq-mid').slideToggle();
		$('#hide-blob a').toggleClass("show-active");
		return false;
	});

	$('.jq-mid input[type="text"], textarea').focus(function(){
		if($(this).val() == this.defaultValue ){
			$(this).val('');
		}
		$(this).addClass('jq-active');
	}).blur(function(){
		if($(this).val() == ''){
			$(this).val(this.defaultValue);
		}
		$(this).removeClass('jq-active');
	});

	$('.a').hide();
	$('.q').click(function(){
		$(this).next('.a').slideToggle('fast').siblings('.a').hide();
		$(this).toggleClass('active').siblings('.q').removeClass('active');
	});

	$('#cont-text input[type="text"], textarea').hover(function(){
		$(this).addClass('jq-active');
	},function(){
		$(this).removeClass('jq-active')
	});

	$('#cont-text input[type="text"], textarea').focus(function(){
		if($(this).val() == this.defaultValue){
			$(this).val('');
		}
		$(this).addClass('jq-active');
	}).blur(function(){
		if($(this).val() == ''){
			$(this).val(this.defaultValue);
			}
		$(this).removeClass('jq-active');
	});


	$('#watch-me ul').innerfade({
		speed: 500,
		timeout: 5000
	});

	// Expandable read more
	$('.expandable').each(function() {
		$(this).find('.content:first').hide();

		$(this).find('.toggle:first').click(function(e) {
			e.preventDefault();

			$(this).parent().find('.content:first').slideToggle();
		});
	});
});

