//TOOLTIP PARA TODO QUE TENGA EL ESTILO TOOLTIP
this.tooltip = function(){	
	/* CONFIG */		
		xOffset = 10;
		yOffset = 20;		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result		
	/* END CONFIG */		
	$("a.tooltip").hover(function(e){											  
		this.t = this.title;
		this.title = "";									  
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
    },
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
    });	
	$("a.tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};


//TABS			
			$(function() {
                $('#search> ul').tabs();
            });

//PARA ESCOGER FECHAS
$(document).ready(function(){
   $("#keys").datepicker({ 
    showOn: "both", 
	firstDay: 1,
	numberOfMonths: 2, 
	dateFormat: "dd/mm/yy", 
    buttonImage: "/images/icons/calendar.gif", 
    buttonImageOnly: true 
	});
	$("#keys2").datepicker({ 
    showOn: "both", 
	firstDay: 1,
	numberOfMonths: 2, 
	dateFormat: "dd/mm/yy", 
    buttonImage: "/images/icons/calendar.gif", 
    buttonImageOnly: true 
	});
	$("#keys3").datepicker({ 
    showOn: "both", 
	firstDay: 1,
	numberOfMonths: 2, 
	dateFormat: "dd/mm/yy", 
    buttonImage: "/images/icons/calendar.gif", 
    buttonImageOnly: true 
	});
	$("#keys4").datepicker({ 
    showOn: "both", 
	firstDay: 1,
	numberOfMonths: 2, 
	dateFormat: "dd/mm/yy", 
    buttonImage: "/images/icons/calendar.gif", 
    buttonImageOnly: true 
	});
	$("#keys5").datepicker({ 
    showOn: "both", 
	firstDay: 1,
	numberOfMonths: 1, 
	dateFormat: "dd/mm/yy", 
    buttonImage: "/images/icons/calendar.gif", 
    buttonImageOnly: true 
	});
	$("#keys6").datepicker({ 
    showOn: "both", 
	firstDay: 1,
	numberOfMonths: 1, 
	dateFormat: "dd/mm/yy", 
    buttonImage: "/images/icons/calendar.gif", 
    buttonImageOnly: true 
	});
	$("#keys7").datepicker({ 
    showOn: "both", 
	firstDay: 1,
	numberOfMonths: 1, 
	dateFormat: "dd/mm/yy", 
    buttonImage: "/images/icons/calendar.gif", 
    buttonImageOnly: true 
	});
	$("#keys8").datepicker({ 
    showOn: "both", 
	firstDay: 1,
	numberOfMonths: 1, 
	dateFormat: "dd/mm/yy", 
    buttonImage: "/images/icons/calendar.gif", 
    buttonImageOnly: true 
	});
	$("#keys9").datepicker({ 
    showOn: "both", 
	firstDay: 1,
	numberOfMonths: 1, 
	dateFormat: "dd/mm/yy", 
    buttonImage: "/images/icons/calendar.gif", 
    buttonImageOnly: true 
	});
	
	$("a#masCourse").click( function() {
        	$("div#courseZona").show("fast");
			$("div#masCourseDiv").hide();
			$("div#menosCourseDiv").show();
    	}
	);
	$("a#menosCourse").click( function() {
        	$("div#courseZona").hide("fast");
			$("div#masCourseDiv").show();
			$("div#menosCourseDiv").hide();
    	}
	);
	
	$("a#masCH").click( function() {
        	$("div#carZona").show("fast");
			$("div#masCHDiv").hide();
			$("div#menosCHDiv").show();
    	}
	);
	$("a#menosCH").click( function() {
        	$("div#carZona").hide("fast");
			$("div#masCHDiv").show();
			$("div#menosCHDiv").hide();
    	}
	);
	
	$("a#masA").click( function() {
        	$("div#accZona").show("fast");
			$("div#masADiv").hide();
			$("div#menosADiv").show();
    	}
	);
	$("a#menosA").click( function() {
        	$("div#accZona").hide("fast");
			$("div#masADiv").show();
			$("div#menosADiv").hide();
    	}
	);
	
  });




function sendForm(f) {
		f.submit();
}


//FUNCIONES PARA HACER EL ANIDADO DE CIUDADES, REGIONES Y CAMPOS
var ajax = new Array();

function listaCiudades(sel)
{
	var codigoProv = sel.options[sel.selectedIndex].value;
	document.getElementById('ciudad').options.length = 0;	// Empty city select box
	document.getElementById('campo').options.length = 0;	// Empty city select box
	if(codigoProv.length>0){
		var index = ajax.length;
		ajax[index] = new sack();

		ajax[index].requestFile = 'php/ciudades.php?zona='+codigoProv;	// Specifying which file to get
		ajax[index].onCompletion = function(){ creaCiudades(index) };	// Specify function that will be executed after file has been found
		ajax[index].runAJAX();		// Execute AJAX function
	}
}


function listaCiudades2(sel)
{
	var codigoProv = sel.options[sel.selectedIndex].value;
	document.getElementById('ciudad').options.length = 0;	// Empty city select box
	if(codigoProv.length>0){
		var index = ajax.length;
		ajax[index] = new sack();

		ajax[index].requestFile = 'php/ciudades2.php?zona='+codigoProv;	// Specifying which file to get
		ajax[index].onCompletion = function(){ creaCiudades2(index) };	// Specify function that will be executed after file has been found
		ajax[index].runAJAX();		// Execute AJAX function
	}
}


function listaCampos(sel)
{
	var codigoProv = sel.options[sel.selectedIndex].value;
	document.getElementById('campo').options.length = 0;	// Empty city select box
	if(codigoProv.length>0){
		var index = ajax.length;
		ajax[index] = new sack();

		ajax[index].requestFile = 'php/campos.php?zona='+codigoProv;	// Specifying which file to get
		ajax[index].onCompletion = function(){
										creaCampos(index);
									 };	// Specify function that will be executed after file has been found
		ajax[index].runAJAX();		// Execute AJAX function
	}
}

function listaCamposZona(sel)
{
	var codigoProv = sel.options[sel.selectedIndex].value;
	document.getElementById('campocart').options.length = 0;	// Empty city select box
	if(codigoProv.length>0){
		var index = ajax.length;
		ajax[index] = new sack();

		ajax[index].requestFile = 'php/campos2.php?zona='+codigoProv;	// Specifying which file to get
		ajax[index].onCompletion = function(){
										creaCampos2(index);
									 };	// Specify function that will be executed after file has been found
		ajax[index].runAJAX();		// Execute AJAX function
	}
}

function listaAccZona(sel)
{
	var codigoProv = sel.options[sel.selectedIndex].value;
	document.getElementById('acc').options.length = 0;	// Empty city select box
	if(codigoProv.length>0){
		var index = ajax.length;
		ajax[index] = new sack();

		ajax[index].requestFile = 'php/alojamiento-golf.php?zona='+codigoProv;	// Specifying which file to get
		ajax[index].onCompletion = function(){
										creaAcc(index);
									 };	// Specify function that will be executed after file has been found
		ajax[index].runAJAX();		// Execute AJAX function
	}
}

function creaCiudades(index)
{
	var obj = document.getElementById('ciudad');
	var obj2 = document.getElementById('campo');
	eval(ajax[index].response);	// Executing the response from Ajax as Javascript code	
}

function creaCiudades2(index)
{
	var obj = document.getElementById('ciudad');
	eval(ajax[index].response);	// Executing the response from Ajax as Javascript code	
}


function creaCampos(index)
{
	var obj2 = document.getElementById('campo');
	eval(ajax[index].response);	// Executing the response from Ajax as Javascript code	
}
function creaCampos2(index)
{
	var obj3 = document.getElementById('campocart');
	eval(ajax[index].response);	// Executing the response from Ajax as Javascript code	
}

function creaAcc(index)
{
	var obj3 = document.getElementById('acc');
	eval(ajax[index].response);	// Executing the response from Ajax as Javascript code	
}


//VENTANA EMERGENTE QUE ESTÁ ABAJO PARA MOSTRAR CAMPOS, NOTICIAS Y NAVIGATE
$(function () {
  $('.bubbleInfo').each(function () {
    // options
    var distance = 10;
    var time = 250;
    var hideDelay = 0;

    var hideDelayTimer = null;

    // tracker
    var beingShown = false;
    var shown = false;
    
    var trigger = $('.trigger', this);
    var popup = $('.popup', this).css('opacity', 0);

    // set the mouseover and mouseout on both element
    $([trigger.get(0), popup.get(0)]).mouseover(function () {
      // stops the hide event if we move from the trigger to the popup element
      if (hideDelayTimer) clearTimeout(hideDelayTimer);

      // don't trigger the animation again if we're being shown, or already visible
      if (beingShown || shown) {
        return;
      } else {
        beingShown = true;

        // reset position of popup box
        popup.css({
          bottom: 0,
          right: 0,
          display: 'block' // brings the popup back in to view
        })

        // (we're using chaining on the popup) now animate it's opacity and position
        .animate({
          top: '-=' + distance + 'px',
          opacity: 1
        }, time, 'swing', function() {
          // once the animation is complete, set the tracker variables
          beingShown = false;
          shown = true;
        });
      }
    }).mouseout(function () {
      // reset the timer if we get fired again - avoids double animations
      if (hideDelayTimer) clearTimeout(hideDelayTimer);
      
      // store the timer so that it can be cleared in the mouseover if required
      hideDelayTimer = setTimeout(function () {
        hideDelayTimer = null;
        popup.animate({
          top: '-=' + distance + 'px',
          opacity: 0
        }, time, 'swing', function () {
          // once the animate is complete, set the tracker variables
          shown = false;
          // hide the popup entirely after the effect (opacity alone doesn't do the job)
          popup.css('display', 'none');
        });
      }, hideDelay);
    });
  });
});