document.write('<script type="text/javascript" src="http://www.marsans.es/media/js/ajax/script.aculo.us/prototype.js"></script>');
var contador = 0;
var contador1 = 1;
var tiempo = 0;
var tempor = null;

function carruselActivo(){
	var actual = 0;
	for(j=0;j<fondoArr.length;j++){
	
		var img = fondoArr[j][0];
		var imgIni = document.getElementById('imgCarrusel').src;

		indexImg = img.indexOf("/media/");
		indexImgIni = imgIni.indexOf("/media/");

		lengthImg = img.length;
		lengthImgIni = imgIni.length;

		img = img.substring(indexImg,lengthImg);
		imgIni = imgIni.substring(indexImgIni,lengthImgIni);

		if(img == imgIni){actual  =j}
	
	}
	
	if(actual<(fondoArr.length-1)){		
		
		if(document.getElementById('li'+(actual+1))){
			nuevaImg((actual+1),document.getElementById('li'+(actual+1)).childNodes[0])
			if(actual!= 0 && actual%5==4){moveLi(1)}
		}
		else{reset();}
	}
	else{
		parar();
		reset();	
	}
}

function nuevaImg(itm,tim){
	var longTim = parseInt(tim.parentNode.parentNode.childNodes.length);
	document.images.imgCarrusel.src = eval('fondoArr['+itm+'][0]');
	//document.images.imgCarrusel.alt = eval('fondoArr['+itm+'][4]');
	document.images.imgCarrusel.parentNode.href = eval('fondoArr['+itm+'][1]');
	
	if(eval('fondoArr['+itm+'][5]!=""')){
		document.images.pxControl.src = eval('fondoArr['+itm+'][5]');
	}else{
		document.images.pxControl.src = '/media/images/es/general/V2/pt.gif';
	}
	
	
	document.getElementById('contentTextCarrusel').innerHTML = '<h3>'+eval("fondoArr["+itm+"][2]")+'</h3><p>'+eval("fondoArr["+itm+"][3]")+'</p><a href='+eval("fondoArr["+itm+"][1]")+'>Ir a la oferta</a>';
	for(a=0;a<longTim;a++){					
		if(tim.parentNode.parentNode.childNodes[a].tagName == 'LI'){
			tim.parentNode.parentNode.childNodes[a].className = 'contCarruselInctive';
		}
		tim.parentNode.className = 'contCarruselActive';
	}
	
}

function reset(){
	for(j=0;j<document.getElementsByClassName('contCarruselActive').length;j++){
		document.getElementsByClassName('contCarruselActive')[j].className = 'contCarruselInctive';
	}
	
	document.getElementById('li0').className = 'contCarruselActive';
	document.getElementById('contentNum').style.left = 0;
	contador = 0;
	contador1 =1;
	fin = false;

	document.getElementById('imgCarrusel').src = fondoArr[0][0];
	//document.images.imgCarrusel.alt = fondoArr[0][4];
	document.images.imgCarrusel.parentNode.href = fondoArr[0][1];
	document.getElementById('contentTextCarrusel').innerHTML = '<h3>'+fondoArr[0][2]+'</h3><p>'+fondoArr[0][3]+'</p><a href='+fondoArr[0][1]+'>Ir a la oferta</a>';
	
	if(fondoArr[0][5]!=""){
		document.images.pxControl.src = fondoArr[0][5];
	}else{
		document.images.pxControl.src = '/media/images/es/general/V2/pt.gif';
	}
	
	if(fondoArr.length>5){document.getElementById('flechaRightCarrusel').style.display = 'block';}
	else{document.getElementById('flechaRightCarrusel').style.display = 'none';}
	document.getElementById('flechaLeftCarrusel').style.display = 'none';
}

function automat(segd){
	var seg = 25000;
	tiempo = parseInt(seg);
	reset();
	//window.status="Pase automatico";
	if (isNaN(tiempo) || tiempo <= 0)   alert("Error en el tiempo")
	else tempor = setTimeout("pasar()", tiempo)
}

function parar(){
	clearTimeout(tempor);
}

function pasar(){
	carruselActivo(1);
	//if (contador < fondoArr.length-1)
		tempor = setTimeout("pasar()", tiempo)
		//contador++;
}

function moveLi(typ){
	
	if(fondoArr.length<5){
		document.getElementById('flechaLeftCarrusel').style.display = 'none';
		document.getElementById('flechaRightCarrusel').style.display = 'none';
	}
	
	var maxLong = (fondoArr.length/5)+1;
	var newLeft = document.getElementById('contentNum').offsetLeft;
	var increm = 0;
	
	contador1 = parseInt(contador1)+parseInt(typ);
	
	if(contador1<maxLong && contador1>=1){		
		if(fondoArr.length/(5*contador1)>=1){increm = 5*27}
		else{
			increm = (fondoArr.length%5)*27;
			if(typ==1){contador1++}
			else{contador1--}
		}
	}
	
	newMaxLong= parseInt(maxLong);	
	
	
	if(contador1<newMaxLong && fondoArr.length>4){document.getElementById('flechaRightCarrusel').style.display = 'block'}
	else{document.getElementById('flechaRightCarrusel').style.display = 'none'}
	
	if(contador1>=2){document.getElementById('flechaLeftCarrusel').style.display = 'block'}
	else{document.getElementById('flechaLeftCarrusel').style.display = 'none'}
		
	increm = increm*typ;
	
	if(IE){document.getElementById('contentNum').style.left = parseInt(document.getElementById('contentNum').offsetLeft-increm);}
	else {document.getElementById('contentNum').style.left = parseInt(document.getElementById('contentNum').offsetLeft-increm)+'px';}
}

//ROTACION DE BANNERS FOOTER

var timeRotation = 10000;
var index=0;
var rotativoArr = new Array();

function cambioImg(){
	if(index==rotativoArr.length){index=0;}
	document.getElementById("rotativoInferior").innerHTML=rotativoArr[index];			
	if(index==rotativoArr.length){index=0;}
	setTimeout("cambioImg()",timeRotation);
	index++;
}
							
function send(){
	if(valid()){
		var oFrm = document.getElementById("boletin");
		oFrm.show.value = false;
		oFrm.submit();
	}
}
		
function valid(){
	if(!ValidField('email','boletin',20,1,'mail',true,'Direccion e-mail')){
		return false;
	}
	return (true);
}
		
function selectAllEmail(object){
	object.focus();
	object.select();
}