/* 

Example Javascript Animation Techniques by Hesido.com;
4 different, reusable examples

*/

function initAnims(objId) {
  //try{
   switch(scheme){
     case 1 : defColor = new Array(161,162,166); finColor = new Array(100,100,102); break;
     case 2 : defColor = new Array(61,59,63); finColor = new Array(102,102,102); break;
     case 3 : defColor = new Array(233,233,233); finColor = new Array(204,204,204); break;
     case 4 : defColor = new Array(61,59,63); finColor = new Array(102,102,102); break;
     default : defColor = new Array(61,59,63); finColor = new Array(102,102,102);
   }
		
	//	Init fade animation with memory, both directions
		var animElements = getObj(objId).getElementsByTagName("a");
		for(var i=0; i<animElements.length; i++) {
		  if(animElements[i].className != 'author')
			animElements[i].onmouseover = fadeBGColMem;
			animElements[i].onmouseout = fadeBGColRestore;
			}

		function fadeBGColMem() {
			if (!this.currentbgRGB) this.currentbgRGB = defColor; //if no mem is set, set it first;
			doBGFadeMem(this,this.currentbgRGB,finColor,2,10,1);
			}

		function fadeBGColRestore() {
			if (!this.currentbgRGB) return;	//avoid error if mouseout an element occurs before the mosueover
												//(e.g. the pointer already in the object when onload)
			doBGFadeMem(this,this.currentbgRGB,defColor,12,20,1);
			}		
	 // }
	//  catch(e){}
  }

//*******************

function doBGFade(elem,startRGB,endRGB,finalColor,steps,intervals,powr) {
//BG Fader by www.hesido.com
	if (elem.bgFadeInt) window.clearInterval(elem.bgFadeInt);
	var actStep = 0;
	elem.bgFadeInt = window.setInterval(
		function() {
			elem.style.backgroundColor = "rgb("+
				easeInOut(startRGB[0],endRGB[0],steps,actStep,powr)+","+
				easeInOut(startRGB[1],endRGB[1],steps,actStep,powr)+","+
				easeInOut(startRGB[2],endRGB[2],steps,actStep,powr)+")";
			actStep++;
			if (actStep > steps) {
			elem.style.backgroundColor = finalColor;
			window.clearInterval(elem.bgFadeInt);
			}
		}
		,intervals)
}


//*******************

function doBGFadeMem(elem,startRGB,endRGB,steps,intervals,powr) {
//BG Fader with Memory by www.hesido.com
	if (elem.bgFadeMemInt) window.clearInterval(elem.bgFadeMemInt);
	var actStep = 0;
	elem.bgFadeMemInt = window.setInterval(
		function() {
			elem.currentbgRGB = [
				easeInOut(startRGB[0],endRGB[0],steps,actStep,powr),
				easeInOut(startRGB[1],endRGB[1],steps,actStep,powr),
				easeInOut(startRGB[2],endRGB[2],steps,actStep,powr)
				];
			elem.style.backgroundColor = "rgb("+
				elem.currentbgRGB[0]+","+
				elem.currentbgRGB[1]+","+
				elem.currentbgRGB[2]+")";
			actStep++;
			if (actStep > steps) window.clearInterval(elem.bgFadeMemInt);
		}
		,intervals)
}

//*******************

function doWidthChangeMem(elem,startWidth,endWidth,steps,intervals,powr) {
//Width changer with Memory by www.hesido.com
	if (elem.widthChangeMemInt) window.clearInterval(elem.widthChangeMemInt);
	var actStep = 0;
	elem.widthChangeMemInt = window.setInterval(
		function() {
			elem.currentWidth = easeInOut(startWidth,endWidth,steps,actStep,powr);
			elem.style.width = elem.currentWidth+"px";
			actStep++;
			if (actStep > steps) window.clearInterval(elem.widthChangeMemInt);
		}
		,intervals)

}

//*******************

function doPosChangeMem(elem,startPos,endPos,steps,intervals,powr) {
//Position changer with Memory by www.hesido.com
	if (elem.posChangeMemInt) window.clearInterval(elem.posChangeMemInt);
	var actStep = 0;
	elem.posChangeMemInt = window.setInterval(
		function() {
			elem.currentPos = [
				easeInOut(startPos[0],endPos[0],steps,actStep,powr),
				easeInOut(startPos[1],endPos[1],steps,actStep,powr)
				];
			elem.style.left = elem.currentPos[0]+"px";
			elem.style.top = elem.currentPos[1]+"px";
			actStep++;
			if (actStep > steps) window.clearInterval(elem.posChangeMemInt);
		}
		,intervals)

}

//*******************

function easeInOut(minValue,maxValue,totalSteps,actualStep,powr) {
//Generic Animation Step Value Generator By www.hesido.com
	var delta = maxValue - minValue;
	var stepp = minValue+(Math.pow(((1 / totalSteps)*actualStep),powr)*delta);
	return Math.ceil(stepp)
}



//-----------------------------------------------------------------------------
// prepnuti obrazku

var timer;

function switchPhoto(path, alt){
  var mainPic = getObj('picture');
  setOpacity(mainPic, 0);
  mainPic.src = path;
  mainPic.alt = alt;
  fadeIn(mainPic, 0);
  return false;
}


//-----------------------------------------------------------------------------
// fade-In efekt

function fadeIn(obj, opacity){
  if(opacity < 1){
    opacity += 0.10;
    setOpacity(obj, opacity);
    timer = setTimeout(function(){fadeIn(obj, opacity);}, 30);
  }
  else{
   clearTimeout(timer);
   setOpacity(obj, 1);
  }
}

// ----------------------------------------------------------------------------
// funkce nastavi pruhlednost danemu elementu

function setOpacity(obj, level) {
  obj.style.opacity = level;
  obj.style.MozOpacity = level;
  obj.style.KhtmlOpacity = level;
  obj.style.filter = "alpha(opacity=" + (level * 100) + ");";
  obj.alpha = level;
}



function wrong_mail_address(adresa){
  var re = /^[_a-zA-Z0-9\.\-]+@[_a-zA-Z0-9\.\-]+\.[a-zA-Z]{2,4}$/;
  return re.test(adresa) == 0;
}

function getObj(id){
   if(Boolean(document.getElementById))
      return document.getElementById(id);
   else if(Boolean(document.all))
      return eval('document.all.'+id);
   else
      return eval('document.'+id);
}


//------------------------------------------------------------------------------
// vrati mailovku ve spravnem tvaru

function healMail(revMail){
  revMail = revMail.substr(7,100);
  var mail = '';
  for (var i = revMail.length-1; i >=0; i--){
    mail += revMail.substr(i,1);
  }
  location.href = 'mailto:' + mail;
  return false;
}

