
/*

JavaScript
FrameWork - Jquery
NOVEMBRO S.L.
2009/01/22

SIMELEC SL
partes.js

Hace la peticion del buscador y del mapa web

*/


var host = 'http://simelec.es';



$(document).ready(function() {
	
	// LENGUAJE
	var lg = $('meta[name="language"]').attr('content');
	if (lg == '') {lg = 'es'};
	
	var href = null;
	var ACPath = host+'/library/ajax/__index.php';
	
	//paginator
	var paginatorStyle = 3;
	var paginatorPosition = 'both';
	
	// EL MAPA WEB
	$('#mapaweb').live('click', function(event) {
		
		href = '?mapaweb=true&texto=0&lg='+lg;
		Peticion(href);
		return false;
	});
	
	$('.mapaweb a').live('click', function() {
		return this;
		});
	
	
	// EL BUSCADOR POR EL BOTON
	$('#buscador').live('click', function(event) {
		
		var texto = $('#input-buscador').attr('value');
		href = '?texto='+texto+'&mapaweb=0';
		
		//jQuery.facebox(href);
		if (texto) Peticion(href);
		else  $('#input-buscador').attr({'value':'introducir un valor'})
		
		
		
		return false;
	
	});
	
	// EL BUSCADOR ENTRANDO DIRECTAMENTE EN EL INPUT
	$('#input-buscador').keypress(function (e) {
		
		if (e.which == 13) {
			var texto = $(this).attr('value');
			href = '?buscador=0&lg='+lg+'&texto='+texto
			
			if (texto) Peticion(href);
			else  $('#input-buscador').attr({'value':'introducir un valor'})
			
			};
		});
	
	
	
	// ####################################################
	// FUNCIONES EXTRAS
	// ####################################################
	
	function Peticion (href) {
		
		$.fancybox.showActivity();

		$.ajax({
			url: ACPath,
			type: 'GET',
			cache: false,
			dataType: 'html',
			data: href.replace('?','&'),

			error: function(){
				$.fancybox('Ha ocurrido un error en la petici&oacute;n.');
				},

			success: function(data){
				$.fancybox(
					data,{
						onComplete: function() {
   							$('#Js-paginar').pagination();
 							$('.js-columnize').columnize({columns: 3, balance: true, minHeight:150});
							}
						}
					
					)
				}
			});

		return false;
		
		}; // fin ajax
		
	
	function bloquear (remove) {
		if (remove == 1){
			$('#bloquear').remove();
		} else {
			if (document.body.scrollHeight>$(document).height()) var h = document.body.scrollHeight
			else var h = $(document).height();
			
			var w = $(window).width();

			$('body').append('<div id="bloquear"/>');
			$('#bloquear').height(h);
			$('#bloquear').width(w);
			};
		
		}; // bloquear


});

