//Script para limpiar los inputs cuando se hace focus
$(function() {
	$.fn.clearInput = function() {
		return this.focus(function() {
			if( this.value == this.defaultValue ) {
				this.value = "";
			}
		}).blur(function() {
			if( !this.value.length ) {
				this.value = this.defaultValue;
			}
		});
	};
	$(".clearField").clearInput();
});

function js_urlencode (clearString) {
  var output = '';
  var x = 0;
  clearString = clearString.toString();
  var regex = /(^[a-zA-Z0-9_.]*)/;
  while (x < clearString.length) {
    var match = regex.exec(clearString.substr(x));
    if (match != null && match.length > 1 && match[1] != '') {
    	output += match[1];
      x += match[1].length;
    } else {
      if (clearString[x] == ' ')
        output += '+';
      else {
        var charCode = clearString.charCodeAt(x);
        var hexVal = charCode.toString(16);
        output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
      }
      x++;
    }
  }
  return output;
}

// Script para crear los tooltips
$(document).ready(function() 
{	
	
   // By suppling no content attribute, the library uses each elements title attribute by default
   $('.tTip[title], .topCont img[title], span[title]').qtip({
	  content: {
		 text: false // Use each elements title attribute
	  },
		style: {
			fontSize: 17,
			tip: true,
			tip: 'topLeft',
			name: 'blue' // Inherit the rest of the attributes from the preset blue style
		  }
   });

	//When page loads... crea los tabs
	$(".tab_content").hide(); //Hide all content
	$("ul.tabUl li:first").addClass("active").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content

	//On Click Event
	$("ul.tabUl li").click(function() {

		$("ul.tabUl li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content

		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab).show(); //Fade in the active ID content
		return false;
	});
});


// Slide panel de wineries

$(document).ready(function() {
    //$("div#panelWineries").hide();
    
    $("a.author-message").click(function(){ 

		$('input#messageToName').val( "" + $(this).html() + "" ) ;
		$('input#messageToEmail').val( "" + $(this).attr('rel') + "" );
    }); 
    
    $("div.panel_button").click(function(){ 
		
		$("div#panelWineries").slideDown();
		$("div.panel_button").toggle();
   
    }); 
	
	$("div#hide_button").click(function(){
        $("div#panelWineries").slideUp(); 
    });       
});


// Slide panel de tourism

$(document).ready(function() {
    
 
    $("div.panel_button2").click(function(){ 
	
		$("div#panelTourism").slideToggle();
		$("div.panel_button2").toggle();
   
   }); 
	
	$("div#hide_button2").click(function(){
        $("div#panelTourism").hide(); 
    });       
});





// Columnas del mismo alto
function equalHeight(group) {
    var tallest = 0;
    group.each(function() {
        var thisHeight = $(this).height();
        if(thisHeight > tallest) {
            tallest = thisHeight;
        }
    });
    group.height(tallest);
}

$(document).ready(function() {
	$('.igualar1 img').imgpreload(function(){
		equalHeight($(".igualar1"));
	});
	$('.igualar2 img').imgpreload(function(){
		equalHeight($(".igualar2"));
	});
	$('.igualar3 img').imgpreload(function(){
		equalHeight($(".igualar3"));
	});
	$('.igualar4 img').imgpreload(function(){
		equalHeight($(".igualar4"));
	});
	$('.igualar5 img').imgpreload(function(){
		equalHeight($(".igualar5"));
	});
	$('.igualar6 img').imgpreload(function(){
		equalHeight($(".igualar6"));
	});
	$('.igualar7 img').imgpreload(function(){
		equalHeight($(".igualar7"));
	});
	$('.igualar8 img').imgpreload(function(){
		equalHeight($(".igualar8"));
	});
	$('.igualar9 img').imgpreload(function(){
		equalHeight($(".igualar9"));
	});
	$('.igualar10 img').imgpreload(function(){
		equalHeight($(".igualar10"));
	});
	$('.igualar11 img').imgpreload(function(){
		equalHeight($(".igualar11"));
	});
	$('.igualar12 img').imgpreload(function(){
		equalHeight($(".igualar12"));
	});
	$('.igualar13 img').imgpreload(function(){
		equalHeight($(".igualar13"));
	});
	$('.igualar14 img').imgpreload(function(){
		equalHeight($(".igualar14"));
	});
	$('.igualar15 img').imgpreload(function(){
		equalHeight($(".igualar15"));
	});

});

/*
// Drop down de menu
$(document).ready(function(){

	$("ul.topMenu li a").hover(function() { //When trigger is clicked...

		var original = $(this).parent();
		//$(this).parent().addClass("current_page_item");
		//Following events are applied to the subnav itself (moving subnav up and down)
		$(this).parent().find("ul.subNav").stop().slideDown('fast').show('slow', function(){
			$(this).height("auto");
			//original.addClass("current_page_item");
		}); //Drop down the subNav on click

		$(this).parent().hover(function() {
		}, function(){
			$(this).parent().find("ul.subNav").slideUp('slow'); //When the mouse hovers out of the subNav, move it back up
			//original.removeClass("current_page_item");
		});

		//Following events are applied to the trigger (Hover events for the trigger)
		}).hover(function() {
			$(this).addClass("subhover"); //On hover over, add class "subhover"
		}, function(){	//On Hover Out
			$(this).removeClass("subhover"); //On hover out, remove class "subhover"
	});

});
*/

// Agrandar y achicar la letra

$(document).ready(function(){
	$('#fontsizer').jfontsizer({
		applyTo: '.content .entry p, .content ul li, .postBodega p, #enologoFicha p, .agrandar p',
		expire: 30
	});
});


/*
// Create a self-invoking anonymous function. That way, 
// we're free to use the jQuery dollar symbol anywhere within.
(function($) {

// We name our plugin "newscroll". When creating our function, 
// we'll allow the user to pass in a couple of parameters.
$.fn.newsScroll = function(options) {
	
	// For each item in the wrapped set, perform the following. 
	return this.each(function() {	
	  
		var
		  // Caches this - or the ul widget(s) that was passed in.
		  //  Saves time and improves performance.
		  $this = $(this), 
		  
		  // If the user doesn't pass in parameters, we'll use this object. 
		  defaults = {
		  	speed: 400, // How quickly should the items scroll?
		  	delay: 3000, // How long a rest between transitions?
		  	list_item_height: $this.children('li').outerHeight() // How tall is each list item? If this parameter isn't passed in, jQuery will grab it.
	     },
	      // Create a new object that merges the defaults and the 
	      // user's "options".  The latter takes precedence.
		  settings = $.extend({}, defaults, options);
		 
	  // This sets an interval that will be called continuously.
	  setInterval(function() {
	  	    // Get the very first list item in the wrapped set.
	  	    $this.children('li:first')
	  	    		// Animate it
	  	    		.animate({ 
	  	    			marginTop : '-' + settings.list_item_height, // Shift this first item upwards.
	  	    		   opacity: 'hide' }, // Fade the li out.
	  	    		   
	  	    		   // Over the course of however long is 
	  	    		   // passed in. (settings.speed)
	  	    		   settings.speed, 
	  	    		   
	  	    		   // When complete, run a callback function.
	  	    		   function() {
	  	    		   	
	  	    		   	// Get that first list item again. 
	  	 					$this.children('li:first')
	  	 					     .appendTo($this) // Move it the very bottom of the ul.
	  	 					     
	  	 					     // Reset its margin top back to 0. Otherwise, 
	  	 					     // it will still contain the negative value that we set earlier.
	  	 					     .css('marginTop', 0) 
	  	 					     .fadeIn(300); // Fade in back in.
  		 			  }
 	 			  ); // end animate
 	  }, settings.delay); // end setInterval
	  });
}

})(jQuery);
*/

function check_all( elem )
{
	var checked_status = elem.checked;
	$("input[name="+elem.value+"[]]").each(function(){
		this.checked = checked_status;
	});
}
