// JavaScript Document
$(document).ready(function(){
						   
	$("#stars").stars({   
		oneVoteOnly: true, 
		split:2,
		callback: function(ui, type, value){
        	calificacion();
    	}
	});
	
	function red(){
		alto_c = $('.contenido').height();
		alto_m = $('.col-izq').height();
		
		if(alto_c >= alto_m){
			$('.main').css('height', (alto_c+$('.cabezal').height()+2)+'px');
			$('.col-izq').css('height', $('.contenido').height()+'px');
	
		} else {
			$('.main').css('height', (alto_m+$('.cabezal').height()+2)+'px');	
			
	
			
		}
			
		clearInterval(red);
	}
	red = setInterval(red, 100);
	
	//alert(alto_c + '+' + $('.cabezal').height() + '=' + (alto_c+$('.cabezal').height()+2)+'px');
	$('.col-izq').css('height', $('.contenido').height()+'px');
	
	if($('input[name=fase]:hidden').val() == 1){
		function redimImgfase(){
		$('.banner-comun img').attr('width', $('.banner-comun').width());
		$('.banner-comun img').attr('height', $('.banner-comun').height());
		
		$('.banner-grande img').attr('width', $('.banner-grande').width());
		$('.banner-grande img').attr('height', $('.banner-grande').height());
		
		$('.banner-ancho-2 img').attr('width', $('.banner-ancho-2').width());
		$('.banner-ancho-2 img').attr('height', $('.banner-ancho-2').height());
		}
		redimImgfase();
		
		$('.b_boton_').click(function(){
			
			var nombre = $('input[name=name-b]:text').val();
			var zona = $('select[name=zona-b]').val();
			var email = $('input[name=email-b]').val();
			var pz = $('input[name=pz]').val();
			var bm = $('input[name=bm]').val();
			var ie = $('input[name=ie]').val();
			
			if(nombre == ''){
				$('input[name=name-b]:text').css('background', '#D6A800');
				return;
			} else {
				$('input[name=name-b]:text').css('background', '#FFF');	
			}
			
			if(email == ''){
				$('input[name=email-b]:text').css('background', '#D6A800');
				return;
			} else {
				$('input[name=email-b]:text').css('background', '#FFF');
			}
			
			if(pz != 'on' && bm != 'on' && ie != 'on'){
				return;
			}
			if(pz == 'on'){
				pz = 1;	
			}
			if(bm == 'on'){
				bm = 1;	
			}
			if(ie == 'on'){
				ie = 1;	
			}
			$.get('includes/index_fns.php', {a : "subscripcion", n : nombre, z : zona, e : email, p : pz, b : bm, i : ie,}, function(data){
						cuadros = data;
						$('.boletin').html(cuadros);	
						resize_4();
						for(k=0;k<$("div.flash").size();k++){
							id = $("div.flash:eq("+k+") input[name=dir]:hidden").val();
							$("div.flash:eq("+k+")").flashembed(id);
						}
			});

		});
		
	}
	
	if($('input[name=fase]:hidden').val() == 2){
		function redimImgfase(){
			$('.banner-comun img').attr('width', $('.banner-comun').width());
			$('.banner-comun img').attr('height', $('.banner-comun').height());
			
			$('.banner-comun-3 img').attr('width', $('.banner-comun-3').width());
			$('.banner-comun-3 img').attr('height', $('.banner-comun-3').height());
			
			$('.banner-ancho-2 img').attr('width', $('.banner-ancho-2').width());
			$('.banner-ancho-2 img').attr('height', $('.banner-ancho-2').height());
		}
		redimImgfase();
		$('.boton-b').click(function(){
			if($('select[name=giro]').val() != 0){
			window.location.href = 'index.php?z=' + $('input[name=zona]:hidden').val() + '&t=' + $('select[name=giro]').val()+'&b='+$('input[name=calle]:text').val();							 
			}
		});
		
		
		
	}
	if($('input[name=fase]:hidden').val() == 3){
		function resize_3(){
			$('.banner-comun-5 img').attr('width', $('.banner-comun-5').width());
			$('.banner-comun-5 img').attr('height', $('.banner-comun-5').height());
		}
		function redimImgfase(){
			$('.banner-comun-5 img').attr('width', $('.banner-comun-5').width());
			$('.banner-comun-5 img').attr('height', $('.banner-comun-5').height());
		}
		resize_3();
		function paguinar_f3(paguina){
			var calle = '';
			calle = $('input[name=calle]:hidden').val();
			$.post('includes/index_fns.php', {a : "paguinar_f3", p : paguina, z : $('input[name=zona]:hidden').val(), g : $('input[name=guiro]:hidden').val(), c : calle}, function(data){
						cuadros = data;
						$('.imagenes').html(cuadros);
						resize_3();
						for(k=0;k<$("div.flash").size();k++){
							id = $("div.flash:eq("+k+") input[name=dir]:hidden").val();
							$("div.flash:eq("+k+")").flashembed(id);
						}
			});
			
		
		}
		paguinar_f3(0);
		
		$('.pag').click(function(){
			p = parseInt($(this).text());
			if(p != 1){
				if(p <= parseInt($('input[name=t_p]:hidden').val())){
					$('.pag:eq(0)').html(p - 1);
					$('.pag:eq(1)').html(p);
					$('.pag:eq(2)').html(p + 1);
					
					paguinar_f3(p-1);
				
				}
			} else {
				paguinar_f3(p-1);
			}

		});
		
		t_p = parseInt($('input[name=t_p]:hidden').val());
		if(t_p < 3){
			if(t_p == 1){
				$('.pag:eq(0)').hide();
				$('.pag:eq(1)').hide();
				$('.pag:eq(2)').hide();	
			} else if(t_p == 2){
				$('.pag:eq(2)').hide();
			}
		}
		
		
		
	}
	
	if($('input[name=fase]:hidden').val() == 4){
		function resize_4(){
		$('.banner-comun-5 img').attr('width', $('.banner-comun-5').width());
		$('.banner-comun-5 img').attr('height', $('.banner-comun-5').height());
		}
		function redimImgfase(){
			$('.banner-comun-5 img').attr('width', $('.banner-comun-5').width());
			$('.banner-comun-5 img').attr('height', $('.banner-comun-5').height());
		}
		function paguinar_f4(paguina){
			var filtro = '0';
			filtro = $('input[name=filtro]:hidden').val();
			$.get('includes/index_fns.php', {a : "paguinar", p : paguina, z : $('input[name=zona]:hidden').val(), g : $('input[name=guiro]:hidden').val(), t : $('input[name=tipo]:hidden').val(), f : filtro}, function(data){
						cuadros = data;
						$('.imagenes').html(cuadros);	
						resize_4();
						for(k=0;k<$("div.flash").size();k++){
							id = $("div.flash:eq("+k+") input[name=dir]:hidden").val();
							$("div.flash:eq("+k+")").flashembed(id);
						}
			});
		}
		
		flt = false;
		$('.filtro').toggle(function(){
			$('.filtro').fadeOut('fast');
			$(this).fadeIn().css('color', '#D6A800');
			id = $(this).attr('id');
			$('input[name=filtro]:hidden').val(id);
			paguinar_f4(0);
			//alert($('input[name=filtro]:hidden').val());
		 }, function(){
			$(this).css('color', '#AA4700');
			$('.filtro').fadeIn();
			id = $(this).attr('id');
			$('input[name=filtro]:hidden').val('');
			paguinar_f4(0);
			//alert($('input[name=filtro]:hidden').val());
		 });
		
		paguinar_f4(0);
		
		$('.pag').click(function(){
			p = parseInt($(this).text());
			if(p != 1){
				if(p <= parseInt($('input[name=t_p]:hidden').val())){
					$('.pag:eq(0)').html(p - 1);
					$('.pag:eq(1)').html(p);
					$('.pag:eq(2)').html(p + 1);
					
					paguinar_f4(p-1);
				
				}
			} else {
				paguinar_f4(p-1);
			}

		});
		
		var t_p = parseInt($('input[name=t_p]:hidden').val());
		if(t_p < 3){
			if(t_p == 1){
				$('.pag:eq(0)').hide();
				$('.pag:eq(1)').hide();
				$('.pag:eq(2)').hide();	
			} else if(t_p == 2){
				$('.pag:eq(2)').hide();
			}
		}
		
		
		
	}
	
	if($('input[name=fase]:hidden').val() == 5){
		$('.imagen-d img').attr('width', $('.imagen-d').width());
		$('.imagenes-d img').attr('height', $('.imagenes-d').height());
		$('.imagenes-d img').click(function(){
			src = $(this).attr('src');									
			$('.imagen-d img').attr('src', src);
			$('.imagen-d img').attr('width', $('.imagen-d').width());
			$('.imagenes-d img').attr('height', $('.imagenes-d').height());
		});
		
		function calificacion(){
			v = $('input[name=newrate]:hidden').val();
			$.post('includes/index_fns.php', {a : "calificacion", c : v, id : $('input[name=id_e]:hidden').val()}, function(data){
						respuesta = data;
						alert(respuesta);
						
			});														 
		};
		
		$('.descripcion').toggle(function(){
			/*$('.imagen-d').fadeOut(function(){*/
				$('.descripcion').animate({height:'550'}, 'slow');							
			/*});*/
			
											 
		}, function(){
			$('.descripcion').animate({height:'252'}, 'slow');
										 
		});
		
	}
	
	
	
});