
//////////// Slideshow /////////
//Author:     Ondrej Jaura
//Date:       15. Feb 2009
//Version:    1.0
//Prototype:  v1.6+
//Please leave this note here 
///////////////////////////////////////
function callall(){
  new Slideshow();  
setInterval('blinkIt()',500);
  //menu6open(num); 
}



var J = jQuery.noConflict();

function menu6open(num) {
  J("#li_"+num).closest("li").siblings("li").find("ul").slideUp();
  J("#li_"+num).closest("li").find("ul").slideDown();
}


function pridajEmail() {
  var email=J("#nlemail").val();
  var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
  if (reg.test(email)) {
    J.post("/php/pridajEmail.php", {e: email},
    function(data){
     alert("Váš email bol pridaný do našej databázy.");});
  } else alert("Email nieje správne zadaný.");
}

function add_cart(item_id){
  J.get("/php/addCart.php?g="+item_id,function(data){
  alert("polozka bola pridaná do košíka");
  document.getElementById("kosik").style.display="none";
  document.getElementById("kosik_blink").style.display="";
 });
}

function SetCol(Element, Col) {
  if (Element.style)
    Element.style.backgroundColor = Col;
}

function galeryFoto(n,f,name,dir) {
  myLightWindow.activateWindow({href:'/pages/galery_foto.php?n='+n+'&f='+f+'&dir='+dir,width:'500px',height:'450px',type:'page',title:name});
}

function slideFoto(f) {
  myLightWindow.activateWindow({href:'/pages/slide_foto.php?f='+f,width:'500px',height:'450px',type:'page',title:'Slideshow Galéria'});
}


function dieloDetail(n,name){
  myLightWindow.activateWindow({href:'/pages/dielo_detail.php?n='+n,type:'page',title:name});
}

function galleryScroll(file_names,button,cesta){
  names=file_names;
  pole=names.split(";");
  poc = document.getElementById('pocitadlo');
  pom = document.getElementById('referencia_foto');
  obrazok_casti = pom.src.split("p=");
  //obrazok = nazov suboru
  obrazok = obrazok_casti[obrazok_casti.length - 1];
  obrazok = obrazok.replace("%20", " ");
  
  //najdi poradovnik nacitaneho obrazka v poli suborov
  for (i=0;i<pole.length;i++){
    if (pole[i] == obrazok){
    num = i;
    } 
  } 
  
  //ak button previous
  if(button==0 && num > 0){
    pom.src = cesta + "photo.php?p=" + pole[num - 1];
    poc.innerHTML = (num) + '/' + pole.length;
  }
  
  //ak button next
  if(button==1 && num < pole.length - 1){
    pom.src = cesta + "photo.php?p=" + pole[num + 1];
    poc.innerHTML = (num + 2) + '/' + pole.length;
  } 
}

var Slideshow = Class.create({
  initialize: function(options) {
    this.div=$("slideshow");
    this.li=this.div.childElements();
    for (var i=0;i<this.li.length;i++) {
      this.li[i].setStyle({
        position: 'absolute',
        top: '0px',
        left: (i*120)+'px'
      });
      this.li[i].observe('mouseover',this.startScroll.bindAsEventListener(this));
      this.li[i].observe('mouseout',this.stopScroll.bindAsEventListener(this));
    }
    this.first=0;
    this.loop=0;
    this.step=1;
    this.delay=0.00;
    //this.scrolling=this.scroll.bind(this).delay(this.delay);
  },
  scroll: function() {
    if (this.loop>=120) {
      this.loop=this.step;
      var left=parseInt(this.li[this.first].style.left);
      this.li[this.first].style.left=(left+this.li.length*120)+'px';
      this.first=(this.first+1<this.li.length)?this.first+1:0;
    }
    else {this.loop+=this.step;} 
    for (var i=0;i<this.li.length;i++) {
      this.li[i].style.left=(parseInt(this.li[i].style.left)-this.step)+'px';
    }
    this.scrolling=this.scroll.bind(this).delay(this.delay);
  },
  stopScroll: function() {
    window.clearTimeout(this.scrolling);
  },
  startScroll: function() {
    this.scrolling=this.scroll.bind(this).delay(0.0);
  }
});

//FUNKCIE PRE FORMULARE

function isEkvivalentPasswd(elem1,elem2, helperMsg){
  if(elem1.value != elem2.value){
    alert(helperMsg);
    elem2.focus();
    return false;
  }
  return true;
}

function notEmpty(elem, helperMsg){
	if(elem.value.length == 0){
		alert(helperMsg);
		elem.focus(); // set the focus to this input
		return false;
	}
	return true;
}

function isNumeric(elem, helperMsg){
	var numericExpression = /^[0-9]+$/;
	if(elem.value.match(numericExpression)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isAlphabet(elem, helperMsg){
	var alphaExp = /^[a-zA-Z]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isAlphanumeric(elem, helperMsg){
	var alphaExp = /^[0-9a-zA-Z]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function lengthRestriction(elem, min, max, helperMsg){
	var uInput = elem.value;
	if(uInput.length >= min && uInput.length <= max){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function lengthMin(elem, min, helperMsg){
	var uInput = elem.value;
	if(uInput.length >= min){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function madeSelection(elem, helperMsg){
	if(elem.value == "Please Choose"){
		alert(helperMsg);
		elem.focus();
		return false;
	}else{
		return true;
	}
}

function emailValidator(elem, helperMsg){
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(elem.value.match(emailExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isChecked(elem, helperMsg){
	if(elem.checked == true){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function blinkIt() {
if (!document.all) return;
else {
for(i=0;i<document.all.tags('blink').length;i++){
s=document.all.tags('blink')[i];
s.style.visibility=(s.style.visibility=='visible') ?'hidden':'visible';
}
}
}





