var baners;
var ban=0;
var numNov=0;
var nov=1;
var movent=false;

window.onload=function() {
	
	if ($("map_canvas")) {
		initializeMap();
	}
	if($('map')){
		map();
	}
	var movil=$('movilNovedades');
	if(movil){
		numNov=$('contadorNov').value
		var anchura=$('contadorNov').value*464;
		//movil.style.width=ancura+'px';
		$('movilNovedades').style.width= anchura+"px";
		//animarNov();
		
	}
	var nov=$('nov1');
	if(nov){
		$('visorNovedades').style.height=nov.getHeight()+"px";
		
	}
}

function enviar() {
	
	if (($('nombre').value=="") || ($('apellidos').value=="") || ($('telefono').value=="") || ($('mail').value=="") || ($('mensaje').value=="") || ($('asunto').value=="")) {
		alert('tiene que rellenar todos los campos');
		return;
	}
	var url="../xml/mail.php";
	var params="nombre="+encodeURI($('nombre').value)+"&ape="+encodeURI($('apellidos').value)+"&telefono="+encodeURI($('telefono').value)+"&mail="+encodeURI($('mail').value)+"&mensaje="+encodeURI($('mensaje').value)+"&asunto="+encodeURI($('asunto').value+"&donde="+$('donde').value);
	var ajax=new Ajax.Request ( url, {
		method: 'post',
		postBody: params,
		onLoading: function() {
					//buida($('msg'));
					//var t=document.createTextNode(unescape(iditextos[1]));
					//$('msg').style.visibility='visible';
					//$('msg').appendChild(t);
				},
		onComplete:function(reply) {
					if (reply.responseText=="Err") {
						var txt="Ha ocurrido un error.";
					} else {
						var txt="Mensaje enviado satisfactoriamente";
					}
					
					alert(txt);
					
					if (reply.responseText=="Ok") {
						
						location.href = "index.php";
						
					}
			}
		});	
}

function abrirsubcat(cod){
	window.location="productosCat.php?codSub="+cod;
}

function abrirproductos(cod){
	window.location="productos.php?cod="+cod
	
}


function buscarArt(){
	var texte=$('texte').value
	window.location="buscar.php?texte="+texte;
}


function comollegar(){
	$('map').style.display="none";
	$('textMaps').style.display="block";
	$('textComollegar').style.display="none";
	$('comollegar').style.display="block";
}

function googleMaps(){
	$('textComollegar').style.display="block";
	$('textMaps').style.display="none";
	$('map').style.display="block";
	$('comollegar').style.display="none";
}


function novedadmas(){
	
	if(movent==false){

			
			if(numNov>nov){
				movent=true;
				new Effect.Move("movilNovedades", { mode: 'relative', duration: 1.5 , x:-464, afterFinish: function(){
					movent=false;
					
					$('visorNovedades').style.height=$('nov'+nov).getHeight()+"px";
					
					


				} });
				nov++;
			}
		
	}
}
function novedadmenos(){
	if(movent==false){
		
		if(nov>1){
			movent=true;
			new Effect.Move("movilNovedades", { mode: 'relative', duration: 1.5 , x:464, afterFinish: function(){
				movent=false;
				$('visorNovedades').style.height=$('nov'+nov).getHeight()+"px";
			} });
			nov--;
		}
	}
}

function animarNov(){
	//alert("num: "+numNov+" nov: "+nov);
	if(nov<=numNov){
		if(nov==numNov){
			animaInvNov();
		}else{
		new Effect.Move("movilNovedades", { mode: 'relative', duration: 2.0, x:-464 , afterFinish:function(){			
				nov++;
				$('visorNovedades').style.height=$('nov'+nov).getHeight()+"px";
				setTimeout("animarNov();",4000);
			
			
		}});
		}
	}
	
}
function animaInvNov(){
	if(nov>1){
		new Effect.Move("movilNovedades", { mode: 'relative', duration: 2.0, x:464 , afterFinish:function(){
			nov--;
			$('visorNovedades').style.height=$('nov'+nov).getHeight()+"px";
			setTimeout("animaInvNov();",4000);
			
		}});
	}
	
}



function initializeMap() {
  if (GBrowserIsCompatible()) {
    var map = new GMap2(document.getElementById("map_canvas"));
    map.setCenter(new GLatLng(39.596215,2.631279), 17);
    map.addControl(new GSmallMapControl());
    map.addControl(new GMapTypeControl());
    map.setMapType(G_HYBRID_MAP);
    map.openInfoWindow(map.getCenter(),
                       "<div style='font-size:7pt;'><b>SILLERO:</b><br />Asegra, 5<br />07011 Pol. Can Valero<br />Palma de Mallorca<br />Tel: 971 20 77 03<br />FAX: 971 20 51 02</div>");
  }
}

function map(){
	if (GBrowserIsCompatible()) { 
			map = new GMap2(document.getElementById("map")); 
			map.setCenter(new GLatLng(39.60150544017119, 2.629058361053467), 17); 
			map.addControl(new GSmallMapControl()); 
			map.addControl(new GMapTypeControl()); 
			map.setMapType(G_HYBRID_MAP); 
			map.openInfoWindow(map.getCenter(), 
				"<div id='menmapa'><div id='iconomapa' style='float: left; margin-right: 23px;'><img src=../img/ico.png style='width:48px;'></div><div id='titulomapa' style='color: rgb(0, 152, 219); font-weight: bold; font-size: 15px;'>Gispert</div><div id='dirmapa' style='color:#0098DB; font-size:12px;'>Josep Antoni de Cabanyes 12 - 07011 Polígono Cals Enagistes</div><div id='telmapa' style='color:#0098DB; font-size:12px;'> Tel 971 75 15 25 / Fax 971 75 21 23</div></div>"); 
			 
			
			/*GEvent.addListener(map,"click", function(overlay,latlng) {      
		      if (latlng) {    
		        //var myHtml = "The GLatLng value is: " + map.fromLatLngToDivPixel(latlng) + " at zoom level " + map.getZoom(); 
		        var myHtml = "The GLatLng value is: " + latlng + " at zoom level " + map.getZoom(); 
		        map.openInfoWindow(latlng, myHtml); 
		      } 
	    });*/
	    
	}
}



function fora(d) {
	d.firstChild.style.backgroundImage="url('../img/btngrislateral1.png')";
	d.childNodes[2].style.backgroundImage="url('../img/btngrislateral2.png')";
	d.childNodes[1].style.backgroundImage="url('../img/btngrisfondo.png')";
}

function sobre(d) {
	d.firstChild.style.backgroundImage="url('../img/btnazullateral1.png')";
	d.childNodes[2].style.backgroundImage="url('../img/btnazullateral2.png')";
	d.childNodes[1].style.backgroundImage="url('../img/btnazulfondo.png')";
}



function validar() {
	$('log1').hide();
	$('log2').hide();
	$('log1').show();
	var usu=$('usu').value;
	var pass=hex_md5($('pass').value);
	var url="../xml/validaUsu.php";
	var params="usu="+usu+"&pass="+pass;
	var ajax=new Ajax.Request( url, {
		method: 'post',
		postBody: params,
		onComplete: function (reply) {
			if (reply.responseText=="ok") {
				window.location.reload();
			} else {
				$('log1').hide();
				$('log2').show();
			}
		}
	});
}

function cambiafondo(opc){
	if(opc==2){
		$('oferta').style.backgroundColor='#57AAD8';
	}else{
		$('oferta').style.backgroundColor='#B0022B';
	}

}

function cambiarfondo(d,opc){
	if(opc==1){
		d.style.backgroundImage='url(../img/itemmenusup2.jpg)'
	}else{
		d.style.backgroundImage='url(../img/itemmenusup.jpg)'
	}
	
}




