jQuery(document).ready(function($) {
	var clearMePrevious = '';

	$('#google-cse-search').attr('autocomplete', 'off');
	
	// clear input on focus
	$('#google-cse-search').focus(function() {
		if ($(this).val() == 'Realiza tu búsqueda') {
			clearMePrevious = $(this).val();
			$(this).val('');
		}
	});

	// if field is empty afterward, add text again
	$('#google-cse-search').blur(function()	{
		if ($(this).val() == '') {
			$(this).val(clearMePrevious);
		}
	});
	
	//Dropdown menu
	$('#menu-quebuscas').hover(function () {
		$('#dropdown-menu-quebuscas').show();
	},
	function () {
		$('#dropdown-menu-quebuscas').hide();
	});

	$('#menu-informacion').hover(function () {
		$('#dropdown-menu-informacion').show();
	},
	function () {
		$('#dropdown-menu-informacion').hide();
	});	
	
	$('#menu-saladeprensa').hover(function () {
		$('#dropdown-menu-saladeprensa').show();
	},
	function () {
		$('#dropdown-menu-saladeprensa').hide();
	});		
	
	//Target _blank
	$(function() {
	  $('.external').attr('target','_blank');
	});

});

google.load( 'search', '1', {style: google.loader.themes.MINIMALIST});

// Run this once the Google search JavaScript has loaded
google.setOnLoadCallback( function() {
	// This makes your input field support autocomplete
	// The first parameter
	// The second parameter is the DOM element of your search input field, which you could also grab with jQuery
	// The third parameter is the ID of your search form, not the actual DOM element. This is required so that when a user clicks on a search suggestion, the form gets submitted automatically
	google.search.CustomSearchControl.attachAutoCompletion(
		'004048340443839250538:dfow09ev1wu',
		document.getElementById( 'google-cse-search' ),
		'search-form' );
});
