function isTouchDevice() {
   var el = document.createElement('div');
   el.setAttribute('ongesturestart', 'return;');
   if(typeof el.ongesturestart == "function"){
      return true;
   }else {
      return false
   }
}
(function($) {

$.fn.dump = function() {
   return $.dump(this);
}

$.dump = function(object) {
   var recursion = function(obj, level) {
      if(!level) level = 0;
      var dump = '', p = '';
      for(i = 0; i < level; i++) p += "\t";
      
      t = type(obj);
      switch(t) {
         case "string":
            return '"' + obj + '"';
            break;
         case "number":
            return obj.toString();
            break;
         case "boolean":
            return obj ? 'true' : 'false';
         case "date":
            return "Date: " + obj.toLocaleString();
         case "array":
            dump += 'Array ( \n';
            $.each(obj, function(k,v) {
               dump += p +'\t' + k + ' => ' + recursion(v, level + 1) + '\n';
            });
            dump += p + ')';
            break;
         case "object":
            dump += 'Object { \n';
            $.each(obj, function(k,v) {
               dump += p + '\t' + k + ': ' + recursion(v, level + 1) + '\n';
            });
            dump += p + '}';
            break;
         case "jquery":
            dump += 'jQuery Object { \n';
            $.each(obj, function(k,v) {
               dump += p + '\t' + k + ' = ' + recursion(v, level + 1) + '\n';
            });
            dump += p + '}';
            break;
         case "regexp":
            return "RegExp: " + obj.toString();
         case "error":
            return obj.toString();
         case "document":
         case "domelement":
            dump += 'DOMElement [ \n'
                  + p + '\tnodeName: ' + obj.nodeName + '\n'
                  + p + '\tnodeValue: ' + obj.nodeValue + '\n'
                  + p + '\tinnerHTML: [ \n';
            $.each(obj.childNodes, function(k,v) {
               if(k < 1) var r = 0;
               if(type(v) == "string") {
                  if(v.textContent.match(/[^\s]/)) {
                     dump += p + '\t\t' + (k - (r||0)) + ' = String: ' + trim(v.textContent) + '\n';
                  } else {
                     r--;
                  }
               } else {
                  dump += p + '\t\t' + (k - (r||0)) + ' = ' + recursion(v, level + 2) + '\n';
               }
            });
            dump += p + '\t]\n'
                  + p + ']';
            break;
         case "function":
            var match = obj.toString().match(/^(.*)\(([^\)]*)\)/im);
            match[1] = trim(match[1].replace(new RegExp("[\\s]+", "g"), " "));
            match[2] = trim(match[2].replace(new RegExp("[\\s]+", "g"), " "));
            return match[1] + "(" + match[2] + ")";
         case "window":
         default:
            dump += 'N/A: ' + t;
            break;
      }
      
      return dump;
   }
   
   var type = function(obj) {
      var type = typeof(obj);
      
      if(type != "object") {
         return type;
      }
      
      switch(obj) {
         case null:
            return 'null';
         case window:
            return 'window';
         case document:
            return 'document';
         case window.event:
            return 'event';
         default:
            break;
      }
      
      if(obj.jquery) {
         return 'jquery';
      }
      
      switch(obj.constructor) {
         case Array:
            return 'array';
         case Boolean:
            return 'boolean';
         case Date:
            return 'date';
         case Object:
            return 'object';
         case RegExp:
            return 'regexp';
         case ReferenceError:
         case Error:
            return 'error';
         case null:
         default:
            break;
      }
      
      switch(obj.nodeType) {
         case 1:
            return 'domelement';
         case 3:
            return 'string';
         case null:
         default:
            break;
      }
      
      return 'Unknown';
   }
   
   return recursion(object);
}

function trim(str) {
   return ltrim(rtrim(str));
}

function ltrim(str) {
   return str.replace(new RegExp("^[\\s]+", "g"), "");
}

function rtrim(str) {
   return str.replace(new RegExp("[\\s]+$", "g"), "");
}

})(jQuery);
jQuery.fn.eachDelay = function(callback, speed){
	return jQuery.eachDelay( this, callback, speed)
}
jQuery.extend({
	eachDelay: function(object,callback, speed){ 
		var name, i = -1, length = object.length, $div = $('<div>'), id;
		if (length === undefined) { //not an array process as object
			var arr = [], x = -1;
			for (name in object) arr[++x] = name; 
			id = window.setInterval(function(){
			 if( ++i === arr.length || callback.call(object[ arr[i] ], arr[i], object[ arr[i] ]) === false) 
			 	 clearInterval(id);
			}, speed);	
		}
		else { //array-compatible element ie. [], jQuery Object
			id = window.setInterval(function(){ 
				if (++i === object.length || callback.call(object[i], i, object[i]) === false) 
					clearInterval(id);
			}, speed);
		}
		return object;
	}
});
var _images = ['images/face-logo-hover.png','images/word-logo-hover.png','images/twitter-logo-hover.png','images/youtube-logo-hover.png'];
 
$.each(_images,function(e) {
$(new Image()).load(function() {
}).attr('src',this);
});

$(document).ready(function() {
	$('.pagina').focus(function () {
	if ($(this).val() == $(this).attr("title")) {
		$(this).val("");
	}
}).blur(function () {
	if ($(this).val() == "") {
		$(this).val($(this).attr("title"));
	}
});
	if(('.cuadro-dob-promo').length){
	$('.cuadro-dob-promo, .cuadro-sim-promo').hover(function(){
		$(".morado-185", this).stop().animate({top:'146px'},{queue:false,duration:160});
	}, function() {
		$(".morado-185", this).stop().animate({top:'157px'},{queue:false,duration:160});
	});
	$('.cuadro-publi, .cuadro-tv').hover(function(){
		$(".morado-93", this).stop().animate({top:'-10px'},{queue:false,duration:160});
	}, function() {
		$(".morado-93", this).stop().animate({top:'0px'},{queue:false,duration:160});
	});
	}
	if($("#noticias").length){
	$("#noticias").jCarouselLite({
		vertical: true,
		hoverPause:true,
		visible: 5,
		auto:1000,
		speed:1000
	});
	}
	
	

	 $('.boton')
		.css( {backgroundPosition: "0px 30px"} )
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(0px 0px)"}, {duration:100})
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(0px 30px)"}, {duration:100, complete:function(){
				$(this).css({backgroundPosition: "0px 30px"})
			}})
		});
		 $('.botonsub')
		.css( {backgroundPosition: "0px 27px"} )
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(0px 0px)"}, {duration:100})
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(0px 27px)"}, {duration:100, complete:function(){
				$(this).css({backgroundPosition: "0px 27px"})
			}})
		});
});
$(window).load(function() {
	if($("#contacto").length){
		$("#contacto").validate();
		}
	if($(".flex").length){
		$(".flex").elastic();
		}
	if($('#slider').length){
		$('#slider').nivoSlider({
			effect:'fade',
		 directionNav:false, 
      	 controlNav:false
		});} 
		if($('.slider183').length){
	$('.slider183').eachDelay(function(){ 
		  $(this).nivoSlider({
					  effect:'fade',
					  directionNav:true, 
					  controlNav:false,
					  pauseTime:4500});
		   }, 600);
	}
	if($('.colorbox').length){
	$('.colorbox').colorbox();
	}
	if($('.newsletterb').length){
	$('.newsletterb').colorbox({width:"40%", inline:true, href:"#newsletter",onLoad:function(){
		newsletter($('#email').val());
		},onClosed:function(){
			$("#newsletter").hide();
			$('#email').val('');
			}});
	}
	$(".boton").hoverIntent({
		timeout:800,
		over:function(){
				$(this).children("div.sub").stop(true,true).fadeIn(300).css("z-index","1000");
	
		},
		out:function(){
				$(this).children("div.sub").stop(true,true).fadeOut(300).css("z-index","0");;
		}
	});
});
function newsletter(email){
	 
	if(validateEmail(email)){
		$.ajax({
			   type: "POST",
			   url: "info.php",
			   data: "what=newsletter&email="+email,
			   success: function(msg){
				 $.fn.colorbox({html:msg, open:true, onClosed:function(){$('#email').val('')}});
			   }
			 });
		
		}else{
			$.fn.colorbox({html:"<div class='newsresponse'>Introduzca un email correcto.</div>", open:true, onClosed:function(){$('#email').val('')}});
			}
	}
function newsletter2(email,nombre){
	 
	if(validateEmail(email)){
		$.ajax({
			   type: "POST",
			   url: "info.php",
			   data: "what=newsletter2&email="+email+"&nombre="+nombre,
			   success: function(msg){
				 $.fn.colorbox({html:msg, open:true, onClosed:function(){$('#email').val('')}});
			   }
			 });
		
		}else{
			$.fn.colorbox({html:"<div class='newsresponse'>Introduzca un email correcto.</div>", open:true, onClosed:function(){$('#email').val('')}});
			}
	}
function validateEmail(id) 
{ 
var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,4}$/; 
return emailPattern.test(id); 

}
function filtrarPromo(){
	$('#lol').show();
	$('#lol2').hide();
	var idcategoria=$("#idcategoria").val();
	var idmarca=$("#idmarca").val();
	var fecha=$("#fecha").val();
	
	
		$.ajax({  		
		url: "info.php",		
		type: "POST",  		
		data: "what=filtroPromo&idmarca="+idmarca+"&idcategoria="+idcategoria+"&fecha="+fecha,  		
		dataType: "json",		
		cache: "false",  		
		success: function(jsonarray){
					var paginas=jsonarray[0];
					var content=jsonarray[1]
					 $("#paginacion").html(content);
					 if(paginas>0){
					 if($('#paginador').length){
							$("#paginador").paginate({
										count 		: paginas,
										start 		: 1,
										display     : 4,
										border					: false,
										text_color  			: '#888',
										background_color    	: '#EEE',	
										text_hover_color  		: 'black',
										background_hover_color	: '#CFCFCF',
										mouse					: 'press',
										onChange     			: function(page){
																	$('._current','#paginacion').removeClass('_current').hide();
																	$('#p'+page).addClass('_current').show();
																  }
									});
							$("#paginador").css('left',($("#paginador").width()-($(".jPag-control-front").position().left + $(".jPag-control-front").width())) / 2);
					}
					$('.colorbox').colorbox();
					 }else{
						$("#paginador").css({left:'0px',padding:'0px'}).html("No se han encontrado resultados."); 
						 }
					$('#lol').hide();
					$('#lol2').show();
		   }, error: function(xhr, textStatus, errorThrown){
    alert(errorThrown);
  }
		 });
		
		
	
}
function area(pts) {
   var area=0;
   var nmenosuno = pts.length-1;
   var p1; var p2;

   for (var i=0;i<nmenosuno;i++) {
      p1=pts[i]; p2=pts[i+1];
      var alo=(p1[0]*p2[1]);
      var alo2=(p1[1]*p2[0]);
	  area+=(alo-alo2);
   }
   area=area/2;
   return Math.abs(area);
}

function centroid(pts) {
    var nmenosuno = pts.length-1;
   var ekis=0; var ye=0; 
   var p1; var p2;

   for (var i=0;i<nmenosuno;i++) {
      p1=pts[i]; p2=pts[i+1];
      var f=(p1[0]*p2[1]-p2[0]*p1[1])*(p1[0]+p2[0]);
	  var g=(p1[0]*p2[1]-p2[0]*p1[1])*(p1[1]+p2[1]);
	  
      ekis+=f;
      ye+=g;
	  f=0;
	  g=0;
   }
   var loco=area(pts)*6;
   var ekisf=(ekis/loco);
   var yef=(ye/loco);
   
   return [Math.abs(ekisf.toFixed(0)),Math.abs(yef.toFixed(0))];
}
function info(clave){
	$("#listado").hide();
	$("#section").css({background:"#FFF url(images/loadingwhite.gif) no-repeat 50% 50%"});
	$.ajax({
		   type: "POST",
		   url: "info.php",
		   data: "what=infoLocal&clave="+clave,
		   success: function(msg){
			   $("#section").css({background:"#FFF"});
			   $("#desc").html(msg).show();
			   $("#listado").hide();
			   }
	});
}
function listados(tipo){
	$("#listado").hide();
	$("#desc").hide();
	$("#section").css({background:"#FFF url(images/loadingwhite.gif) no-repeat 50% 50%"});
	$.ajax({
		   type: "POST",
		   url: "info.php",
		   data: "what=listados&tipo="+tipo,
		   success: function(msg){
			   $("#section").css({background:"#FFF"});
			   $("#listado").html(msg);
			   $("#listado").show();
			   if(isTouchDevice()==true){
$("#directorio").css({height:"332px",display:"block",height:" 100%","-webkit-perspective": "1000","-webkit-backface-visibility": "hidden"});
$("#section").css({height:"332px","overflow-y":"auto",display:"block"});
$('#directorio').touchScroll(); }else{
	if($('#directorio').length){
	$('#directorio').hoverscroll({
		vertical:true,
		width:    208,  
		height:   332,
		arrows:   true
	});
	}
	}
				$('.mata').click(function(){
		var level=$(this).attr('href');
		var pla=$(this).attr('rel');
		var lol=pla.split('-');
		var lol2=pla.split('-');
		var ekis=lol[1]-317;
		var ye=lol2[2]-222;
		var ide=$(this).attr('name');
		var bot="boton-n"+level;
		$(".muere").children().hide();
		$("."+bot).children().show();
		if(level==nivel){
			}else{
				$(".mapa").html("").css({background:"#FFF url(images/loadingwhite.gif) no-repeat 50% 50%"});
				$.ajax({
			   type: "POST",
			   url: "info.php",
			   data: "what=mapa&boton="+bot,
			   success: function(msg){
				 $("#changer").html(msg);
				 $('.mapa').mobilymap({
					position: ekis+" "+ye,
					markerClass: 'punto',
					popup: false,
					cookies: false,
					caption: false,
					setCenter: true,
					navigation: true,
					navSpeed: 1000,
					outsideButtons: '.popo a',
					onMarkerClick: function(){
						setAreaOut(document.getElementById(anterior),'gmipam_0_canvas',0,0);
						var idcual=$(this).children().html();
						setAreaOver(document.getElementById(idcual),'gmipam_0_canvas','0,0,255','0,0,0','0.33',0,0,0);
						actual=idcual;
						if(anterior==""){anterior=idcual;}else{anterior=actual;}
						},
						onPopupClose: function(){},
						onMapLoad: function(){
							addMapper();
							setAreaOver(document.getElementById(ide),'gmipam_0_canvas','0,0,255','0,0,0','0.33',0,0,0);
							actual=ide;
							nivel=level;
							}
				});
			   }
		});
				
				}
		info(ide);		
		return false;
		});
			   }
	});
}
function lista(tipo,id){
	$("#listado").hide();
	$("#desc").hide();
	$("#section").css({background:"#FFF url(images/loadingwhite.gif) no-repeat 50% 50%"});
	nivel="";
	$.ajax({
		   type: "POST",
		   url: "info.php",
		   data: "what=lista&tipo="+tipo+"&id="+id,
		   success: function(msg){
			   $("#section").css({background:"#FFF"});
			   $("#listado").html(msg);
			   $("#listado").show();
			   if(isTouchDevice()==true){
$("#directorio").css({height:"332px",display:"block",height:" 100%","-webkit-perspective": "1000","-webkit-backface-visibility": "hidden"});
$("#section").css({height:"332px","overflow-y":"auto",display:"block"});
$('#directorio').touchScroll(); }else{
	if($('#directorio').length){
	$('#directorio').hoverscroll({
		vertical:true,
		width:    208,  
		height:   332,
		arrows:   true
	});
	}
	}
				$('.mata').click(function(){
		var level=$(this).attr('href');
		var pla=$(this).attr('rel');
		var lol=pla.split('-');
		var lol2=pla.split('-');
		var ekis=lol[1]-317;
		var ye=lol2[2]-222;
		var ide=$(this).attr('name');
		var bot="boton-n"+level;
		$(".muere").children().hide();
		$("."+bot).children().show();
		if(level==nivel){
			}else{
				$(".mapa").html("").css({background:"#FFF url(images/loadingwhite.gif) no-repeat 50% 50%"});
				$.ajax({
			   type: "POST",
			   url: "info.php",
			   data: "what=mapa&boton="+bot,
			   success: function(msg){
				 $("#changer").html(msg);
				 $('.mapa').mobilymap({
					position: ekis+" "+ye,
					markerClass: 'punto',
					popup: false,
					cookies: false,
					caption: false,
					setCenter: true,
					navigation: true,
					navSpeed: 1000,
					outsideButtons: '.popo a',
					onMarkerClick: function(){
						setAreaOut(document.getElementById(anterior),'gmipam_0_canvas',0,0);
						var idcual=$(this).children().html();
						setAreaOver(document.getElementById(idcual),'gmipam_0_canvas','0,0,255','0,0,0','0.33',0,0,0);
						actual=idcual;
						if(anterior==""){anterior=idcual;}else{anterior=actual;}
						},
						onPopupClose: function(){},
						onMapLoad: function(){
							addMapper();
							setAreaOver(document.getElementById(ide),'gmipam_0_canvas','0,0,255','0,0,0','0.33',0,0,0);
							actual=ide;
							nivel=level;
							}
				});
			   }
		});
				
				}
		info(ide);		
		return false;
		});
			   }
	});
}
function busqueda(str){
	$("#listado").hide();
	$("#desc").hide();
	$("#section").css({background:"#FFF url(images/loadingwhite.gif) no-repeat 50% 50%"});
	nivel="";
	$.ajax({
			   type: "POST",
			   url: "info.php",
			   data: "what=search&str="+str,
			   success: function(msg){
				$("#section").css({background:"#FFF"});
			   $("#listado").html(msg);
			   $("#listado").show();
			   if(isTouchDevice()==true){
$("#directorio").css({height:"332px",display:"block",height:" 100%","-webkit-perspective": "1000","-webkit-backface-visibility": "hidden"});
$("#section").css({height:"332px","overflow-y":"auto",display:"block"});
$('#directorio').touchScroll(); }else{
	if($('#directorio').length){
	$('#directorio').hoverscroll({
		vertical:true,
		width:    208,  
		height:   332,
		arrows:   true
	});
	}
	}
				$('.mata').click(function(){
		var level=$(this).attr('href');
		var pla=$(this).attr('rel');
		var lol=pla.split('-');
		var lol2=pla.split('-');
		var ekis=lol[1]-317;
		var ye=lol2[2]-222;
		var ide=$(this).attr('name');
		var bot="boton-n"+level;
		$(".muere").children().hide();
		$("."+bot).children().show();
		if(level==nivel){
			}else{
				$(".mapa").html("").css({background:"#FFF url(images/loadingwhite.gif) no-repeat 50% 50%"});
				$.ajax({
			   type: "POST",
			   url: "info.php",
			   data: "what=mapa&boton="+bot,
			   success: function(msg){
				 $("#changer").html(msg);
				 $('.mapa').mobilymap({
					position: ekis+" "+ye,
					markerClass: 'punto',
					popup: false,
					cookies: false,
					caption: false,
					setCenter: true,
					navigation: true,
					navSpeed: 1000,
					outsideButtons: '.popo a',
					onMarkerClick: function(){
						setAreaOut(document.getElementById(anterior),'gmipam_0_canvas',0,0);
						var idcual=$(this).children().html();
						setAreaOver(document.getElementById(idcual),'gmipam_0_canvas','0,0,255','0,0,0','0.33',0,0,0);
						actual=idcual;
						if(anterior==""){anterior=idcual;}else{anterior=actual;}
						},
						onPopupClose: function(){},
						onMapLoad: function(){
							addMapper();
							setAreaOver(document.getElementById(ide),'gmipam_0_canvas','0,0,255','0,0,0','0.33',0,0,0);
							actual=ide;
							nivel=level;
							}
				});
			   }
		});
				
				}
		info(ide);		
		return false;
		});
				$("#lola").val("");
				$("#go").focus();   
				   }
	});
	}
function ameni(ami){
	var level=nivel;
	if(level==""){level="0";}
	$(".mapa").html("").css({background:"#FFF url(images/loadingwhite.gif) no-repeat 50% 50%"});
		//lista('niv',level);
		$.ajax({
			   type: "POST",
			   url: "info.php",
			   data: "what=ameni&nivel="+level+"&amenidad="+ami,
			   success: function(msg){
				 $("#changer").html(msg);
				 $('.mapa').mobilymap({
					position: 'center',
					markerClass: 'punto',
					popup: false,
					cookies: false,
					caption: false,
					setCenter: true,
					navigation: true,
					navSpeed: 1000,
					outsideButtons: '.popo a',
					onMarkerClick: function(){
						
						setAreaOut(document.getElementById(anterior),'gmipam_0_canvas',0,0);
						var idcual=$(this).children().html();
						setAreaOver(document.getElementById(idcual),'gmipam_0_canvas','0,0,255','0,0,0','0.33',0,0,0);
						actual=idcual;
						if(anterior==""){anterior=idcual;}else{anterior=actual;}
						
						},
						onPopupClose: function(){},
						onMapLoad: function(){
							addMapper();
							nivel=level;
							}
				});
			   }
		});
	
	}
function changeList(ca){
	if(ca=="listado"){
		$("#desc").hide();
		$("#listado").show();
		}else{
		$("#desc").show();
		$("#listado").hide();
		}
}
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-11152742-24']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
