// JavaScript Document - Slider © 2011 Ailon Webs

numCapas = 6;
var enl = new Array(numCapas);
enl[0] = "android-mobile-applications/my-wines.php";
enl[1] = "android-mobile-applications/breathe.php";
enl[2] = "android-mobile-applications/natural-notes.php";
enl[3] = "android-mobile-applications/natural-notes-plus.php";
enl[4] = "android-mobile-applications/nlistas.php";
enl[5] = "android-mobile-applications/nlistas-plus.php";
var temp;
var automatico = true;
var anchoSlide = 830; // para mover slide con javascript = navegadores sin css3
time = 8000; // t en ms
function veo(quien){
		automatico = false;
		clearTimeout(temp);
		paso(quien);
}

// Devuelve true si un navegador no soporta las transiciones del css3 
function soyAntiguo() {
	if (!Modernizr.cssanimations || !Mondernizr.csstransitions) {
		//alert("no tengo cssanimations o csstransitions");
		return true;
	} else {
		return false;
	} 
}

function paso(quien) {
	
//	alert(quien);
	for(i=1;i<=numCapas;i++) {
		document.getElementById(i).style.display = "none";
		document.getElementById('slideBot'+i ).className = "";
	}
	
	document.getElementById(quien).style.display = "";
	document.getElementById('slideBot'+quien).className = "enSlide";
	
	
	if (soyAntiguo()) {
		var muevoA = document.getElementById(quien); 
		clearInterval(muevoA.animationTimer);
		muevoA.style.left = "830px";
		//elementID, newLeft, newTop, newWidth, newHeight, time, callback
		animate(quien,0,0,null,null,time/10,null);
	} 
}

function enQueSlideEstoy() {
	if (document.getElementsByClassName) {
		botSeleccionado = document.getElementsByClassName("enSlide")[0].id;
	} else { //ie
		i = 0;
  		a = document.getElementsByTagName("li");
  		while (element = a[i++]) {
			if (element.className == "enSlide") {
				botSeleccionado = element.id;
			}
		}
	}
	numSlide = parseInt(botSeleccionado.charAt(8));
	return numSlide;
}

function antS() {
	numSlide = enQueSlideEstoy();
	if(numSlide==1) {
		numSlide=numCapas;
	} else {
		numSlide = numSlide-1;
	}
	veo(numSlide);
}
function sigS() {
	numSlide = enQueSlideEstoy();
	if(numSlide==numCapas) {
		numSlide=1;
	} else {
		numSlide = numSlide+1;
	}
	veo(numSlide);
}
function autoSig() {
	if(enQueSlideEstoy()==numCapas) {
		quien=1;
	} else {
		quien = numSlide+1;
	}
	if (automatico) {
		temp=setTimeout("autoSig()",time);
	}
	paso(quien);
	
}
function abro() {
	window.location = enl[enQueSlideEstoy()-1];
}
if (automatico = true) {
temp = setTimeout("autoSig()",time);
}

//////////////////////////// funciones para mover los slides con javascript ////////////////////////////////////////

function animate(elementID, newLeft, newTop, newWidth, newHeight, time, callback)
{
	if (typeof(animacion) != 'undefined') {
		clearTimeout(animacion);
	}
  var el = document.getElementById(elementID);
  if(el == null)
    return;
 
  var cLeft = parseInt(el.style.left);
  var cTop = parseInt(el.style.top);
  var cWidth = parseInt(el.style.width);
  var cHeight = parseInt(el.style.height);
  
  if (newWidth == null) {
	  newWidth = cWidth;
  }
  if (newHeight == null) {
	  newHeight = cHeight;
  }
  
  var totalFrames = 1;
  if(time > 0)
    totalFrames = time/40;

  var fLeft = newLeft - cLeft;
  if(fLeft != 0)
    fLeft /= totalFrames;
  
  var fTop = newTop - cTop;
  if(fTop != 0)
    fTop /= totalFrames;
  
  var fWidth = newWidth - cWidth;
  if(fWidth != 0)
    fWidth /= totalFrames;
  
  var fHeight = newHeight - cHeight;
  if(fHeight != 0)
    fHeight /= totalFrames;
    
  doFrame(elementID, cLeft, newLeft, fLeft, cTop, newTop, fTop, 
      cWidth, newWidth, fWidth, cHeight, newHeight, fHeight, callback);
}

function doFrame(eID, cLeft, nLeft, fLeft, cTop, nTop, fTop, 
    cWidth, nWidth, fWidth, cHeight, nHeight, fHeight, callback)
{
  var el = document.getElementById(eID);
  if(el == null)
    return;

  cLeft = moveSingleVal(cLeft, nLeft, fLeft);
  cTop = moveSingleVal(cTop, nTop, fTop);
  cWidth = moveSingleVal(cWidth, nWidth, fWidth);
  cHeight = moveSingleVal(cHeight, nHeight, fHeight);

  el.style.left = Math.round(cLeft) + 'px';
  el.style.top = Math.round(cTop) + 'px';
  el.style.width = Math.round(cWidth) + 'px';
  el.style.height = Math.round(cHeight) + 'px';
  
  if(cLeft == nLeft && cTop == nTop && cHeight == nHeight 
    && cWidth == nWidth)
  {
    if(callback != null)
      callback();
    return;
  }
    
  animacion = setTimeout( 'doFrame("'+eID+'",'+cLeft+','+nLeft+','+fLeft+','+cTop+','
      +nTop+','+fTop+','+cWidth+','+nWidth+','+fWidth+','+cHeight+','
      +nHeight+','+fHeight+','+callback+')', 40);
}

function moveSingleVal(currentVal, finalVal, frameAmt)
{
  if(frameAmt == 0 || currentVal == finalVal)
    return finalVal;
  
  currentVal += frameAmt;
  if((frameAmt > 0 && currentVal >= finalVal) 
      || (frameAmt < 0 && currentVal <= finalVal))
  {
    return finalVal;
  }
  return currentVal;
}

