//// animar los menus
function animaBanners (){
	$('.promo-peq, .promo-gde').innerfade({
		animationtype: 'fade',
		speed: 'slow',
		timeout: '5000',
		type: 'sequence',
		containerheight: '180px'					
	})
}

$(function(){
	var del=300;
	$('#buscador select').hover(function(){
		del=2000;	
	}, function(){
		del=300;	
	})
	$('#links li').hover(function(){
		$(this).find('ul').stop('false','true').fadeIn();
	},function(){
		$(this).find('ul').stop('false','true').delay(del).fadeOut();
	})
	
	/*$( "#slider-precio" ).slider({
			range: true,
			min: 150,
			max: 2000,
			values: [ 200, 600 ],
			slide: function( event, ui ) {
				$( "#precio" ).val( "Bs" + addPuntos(ui.values[ 0 ]) + " - Bs" + addPuntos(ui.values[ 1 ]));
			}
		});
		$( "#precio" ).val( "Bs" + addPuntos($( "#slider-precio" ).slider( "values", 0 )) +
			" - Bs" + addPuntos($( "#slider-precio" ).slider( "values", 1 )));*/
	$("#ubicacion").val("3");

	$('#sidebar a[title=Lista numeros]').click(function(){
		window.open("numeros-emergencia.html","","toolbar=no, status=no, menubar=yes, scrollbars=no, resizable=no, copyhistory=yes, width=400, height=530");
		return false;
	})
    
    $('#sidebar a[title=Lista numeros]').attr("href", "#");
    
	
	ponerTipoTarifa();

})

function addPuntos(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + '.' + '$2');
	}
	return x1 + x2;
}


// JavaScript Document

function addToFavorites(){
	var ns = "Para agregar esta web a tu lista de marcadores, pulsa Ctrl + D";
	var op = "Para agregar esta web a tus Marcadores de Opera, pulsa Ctrl + D";
	var ie = "Para agregar esta web a tus favoritos, pulsa Ctrl + D";


		if (typeof(document.body.style.maxHeight) != "undefined") {
		   alert(ie);
		} else {
			if (window.external){
			   window.external.AddFavorite('http://www.sitours.com','Vacaciones con SI Tours C.A.');	
			} else {
				alert(ns);
			}	
		}
}

//Esta funcion verifica si un campo es requerido antes de poder enviarse
function isRequired(Objeto, Campos_Requeridos) {
	var Cadena = new String();
	Cadena = Campos_Requeridos;
	var Campo = "[" + Objeto.name + "]";
	Cadena = Campos_Requeridos;
	if (Cadena.indexOf(Campo) != -1){
		return true;
	}
	return false;
}

function FormularioValido(Formulario, Campos_Requeridos){
	var cantidad = Formulario.length;
	for (i=0; i<cantidad; i++){
		if ( isRequired(Formulario.elements[i], Campos_Requeridos) == true && Formulario.elements[i].value == ''){
				cancelar = true;
				window.alert('Por favor especifique: "' + Formulario.elements[i].id + '"');
				Formulario.elements[i].focus();
				return false;
		}
	}
	return true;
}

function consultaBorrar(url) {
	if ( window.prompt('Si borrar este elemento, se borrará de forma definitiva. ¿Seguro desea borrarlo?') ) 
	     location.href = url;
}

//poner los centimos chiquitos

function acomodarCentimos(){
	$('.precio:contains(.00)').each(function(){
		var str= $(this).html();
		str = str.replace('.00','<span class="centimos">.00</span>');
		$(this).html(str);
	})	
}
// crea lista de hoteles en tarifas

function crearListaHoteles(){
	var lista='';
	$('#cuadrosTarifas h3').each(function(index, element) {
    	
		lista = lista + '<li><a href="#' + index + '">' + $(this).text() + '</li>';
		$(this).prepend('<a name="'+ index +'"></a>');
		if(index>0){
			$(this).append('<a class="subir" href="#top">Subir</a>');	    
		}
	});
	lista = '<ul class="lista-hoteles">' + lista + '</ul>';
	$('#cuadrosTarifas p:eq(0)').after(lista);
	//alert(lista);
}

function ponerTipoTarifa(){
	var titulo='<p class="estilo-2">Tarifas de Paquetes</p>';
	$('.tarifa-paquete:eq(0)').before(titulo);
	var titulo='<p class="estilo-2">Tarifas Regulares</p>';
	$('.tarifa-hotel:eq(0)').before(titulo);
}

function intro(){

//hoteles
	var hoteles= $('.promo-hotel');
	$('.hoteles-cont').empty();
	
	var paquetes = $('.paquete');
	$('.paquete').remove();
	
	
	var maxPgrupo=2;
	var columnas=3;
	var nHoteles=hoteles.length;	
	var filas=Math.ceil(nHoteles/(columnas*maxPgrupo));
	var grupos = filas * columnas;
	var grupoHTML= $('<div class="grupo-hoteles">');
	
	//alert(filas +' : ' + nHoteles);
	
	for (var i=1; i<= grupos ; i++){
		//alert(Math.round((i)/3)+':'+i/3);
		m= Math.round(i/3) == i/3;
		if (m){
			grupoHTML.addClass('no-margin');
		}else{
			grupoHTML.removeClass('no-margin');
		}
		grupoHTML.clone().appendTo($('.hoteles-cont'))	
	};
	
	var i=0;
	hoteles.each(function(index, element) {
		if (i>=$('.grupo-hoteles').length){
			i=0;
				
		}
		//alert($('.grupo-hoteles').length);
		$(element).appendTo('.grupo-hoteles:eq('+ i +')')
		i++;
    });
	
	$('.grupo-hoteles').divSlideShow({
		width:240,
		height:210,
		delay:5000,
		loop:20000,
		arrow:'none',
		controlClass:'selector-thumb',
		controlActiveClass:'activo',
		controlHoverClass:'hover',
		leftArrowClass:'flecha',
		rightArrowClass:'flecha'	
	});

///paquetes


	
	var j=0;
	
	var htmlPaquete = '<div class="grupo-paquetes">';
	paquetes.each(function(i) {
		if (j<3){
			htmlPaquete = htmlPaquete + '<div class="paquete slide">' + $(this).html() + '</div>';
			j++;
		}else{
			htmlPaquete = htmlPaquete + '</div><div class="grupo-paquetes"><div class="paquete slide">' + $(this).html() + '</div>';
			j=0;
		}
    });

	
	htmlPaquete = htmlPaquete + '</div>';
	//alert(htmlPaquete);
	$('h2.titulo-intro:eq(1)').after(htmlPaquete);
	//
		
	$('.grupo-paquetes').divSlideShow({
		width:740,
		height:210,
		delay:5000,
		loop:20000,
		arrow:'none',
		controlClass:'selector-thumb',
		controlActiveClass:'activo',
		controlHoverClass:'hover',
		leftArrowClass:'flecha',
		rightArrowClass:'flecha'	
	});
	$('.dssControlContainer').css({height:'10px'});
	//$('.selector-thumb:has(span)').hide();
	$('.precio:contains(.00)').each(function(){
		var str= $(this).html();
		str = str.replace('.00','<span class="centimos">.00</span>');
		$(this).html(str);
	})	
}
