function hideAll(){
	document.getElementById('box_popis').style.display = 'none';
	document.getElementById('box_obsah-baleni').style.display = 'none';
	document.getElementById('box_tech-udaje').style.display = 'none';
	document.getElementById('box_upozorneni').style.display = 'none';
	document.getElementById('box_galerie').style.display = 'none';
}

function hideAllExcPopis(){
	document.getElementById('box_obsah-baleni').style.display = 'none';
	document.getElementById('box_tech-udaje').style.display = 'none';
	document.getElementById('box_upozorneni').style.display = 'none';
	document.getElementById('box_galerie').style.display = 'none';
}

function showPopis(){
  hideAll();
  document.getElementById('box_popis').style.display = 'block';
}

function showObsah(){
  hideAll();
  document.getElementById('box_obsah-baleni').style.display = 'block';
}

function showTech(){
  hideAll();
  document.getElementById('box_tech-udaje').style.display = 'block';
}

function showUpozorneni(){
  hideAll();
  document.getElementById('box_upozorneni').style.display = 'block';
}

function showGalerie(){
  hideAll();
  document.getElementById('box_galerie').style.display = 'block';
}

function setListeners(){
  document.getElementById("switch_popis").addEventListener("click", function() {showPopis();},false);
  document.getElementById("switch_obsah-baleni").addEventListener("click", function() {showObsah();},false);
  document.getElementById("switch_tech-udaje").addEventListener("click", function() {showTech();},false);
  document.getElementById("switch_upozorneni").addEventListener("click", function() {showUpozorneni();},false);
  document.getElementById("switch_galerie").addEventListener("click", function() {showGalerie();},false);
}

function setAttachEvents(){
  document.getElementById("switch_popis").attachEvent("onclick", function() {showPopis();} );
  document.getElementById("switch_obsah-baleni").attachEvent("onclick", function() {showObsah();} );
  document.getElementById("switch_tech-udaje").attachEvent("onclick", function() {showTech();} );
  document.getElementById("switch_upozorneni").attachEvent("onclick", function() {showUpozorneni();} );
  document.getElementById("switch_galerie").attachEvent("onclick", function() {showGalerie();} );
}

if (typeof window.addEventListener != "undefined") {
  window.addEventListener("load",function() {hideAll();} ,true);
  window.addEventListener("load",function() {showPopis();} ,true);
  window.addEventListener("load",function() {setListeners();} ,true);
}
else {
  window.attachEvent("onload",function() {hideAllExcPopis();} );
/*  window.attachEvent("onload",function() {showPopis();} ); */
  window.attachEvent("onload",function() {setAttachEvents();} );
}


/* dostupnost skladem / jiny termin (zmena barvy textu) pro vypis (product-list) - id -> class*/

document.getElementsByClassName = function(clsName){
    var retVal = new Array();
    var elements = document.getElementsByTagName("*");
    for(var i = 0;i < elements.length;i++){
        if(elements[i].className.indexOf(" ") >= 0){
            var classes = elements[i].className.split(" ");
            for(var j = 0;j < classes.length;j++){
                if(classes[j] == clsName)
                    retVal.push(elements[i]);
            }
        }
        else if(elements[i].className == clsName)
            retVal.push(elements[i]);
    }
    return retVal;
}

$(function() {

  var availcheck2 = document.getElementsByClassName("availability_value");

  for (i=0; i<availcheck2.length; i++)
  {

    if (availcheck2[i].innerHTML.substring(0,7) == 'skladem') {
      availcheck2[i].style.color = "#00CC00";
    }
    else {
      availcheck2[i].style.color = "#CC0000";
      //availcheck2[i].innerHTML = '<a href="#" style="color: red; text-decoration: underline">'+availcheck2[i].innerHTML+'</a>'; 
    }
  }
});

// funkce pro odstraneni diakritiky

sdiak = "áäčďéěíĺľňóô öŕšťúů üýřžÁÄČĎÉĚÍĹĽŇÓÔ ÖŔŠŤÚŮ ÜÝŘŽ"; 
bdiak = "aacdeeillnoo orstuu uyrzAACDEEILLNOO ORSTUU UYRZ"; 
function bezdiak(txt) 
{ 
  tx = ""; 
  for(p = 0; p < txt.length; p++) 
  { 
    if (sdiak.indexOf(txt.charAt(p)) != -1) 
    { 
      tx += bdiak.charAt(sdiak.indexOf(txt.charAt(p))); 
    } 
    else tx += txt.charAt(p); 
  } 
  return tx; 
}

/* dostupnost skladem / jiny termin (zmena barvy textu) */



$(function() {
  var availcheck = document.getElementById("availability_value").innerHTML;
  if (availcheck == 'skladem') {
    $("#availability_value").css("color","#00CC00");
  }
  else {
    $("#availability_value").css("color","#CC0000");
    
    // dotaz na dostupnost mailem
    var mail_subject = 'Dotaz na produkt '+$("#primary_block h2").html();
    var mail_body = 'Dobrý den,%0D%0A%0D%0Achtěl(a) bych se dotázat na dostupnost produktu '
      +$("#primary_block h2").html()+'%0D%0A%0D%0A';
    
    $("#availability_value").html('<a href="mailto:obchod@compexbrno.cz?subject='+bezdiak(mail_subject)+
      '&body='+bezdiak(mail_body)+'" style="color: red">'+$("#availability_value").html()+'</a>');
  }

});

// coolipo twin banner

$(function() {

  var backgrounds = new Array(
    'url(http://www.elektrocoleti.cz/img/banner/banner-coolipo-2.jpg)',
    'url(http://www.elektrocoleti.cz/img/banner/banner-coolipo-1.jpg)'
  );

  var poradi = -1;

  function bgchange() {
    poradi++;
    if (poradi >= backgrounds.length) poradi = 0;
    return backgrounds[poradi];
  };

  setInterval(function() {
    $('div.coolipo-banner').find('a').fadeOut(500);
  }, 10000);

  setTimeout(function() {
    setInterval(function() {
      $('div.coolipo-banner').find('a').css('background-image',bgchange());
      $('div.coolipo-banner').find('a').fadeIn(500);
    }, 10000);
  }, 500);

});

$(function() {
  var price = document.getElementById("our_price_display").innerHTML;
  price = price.replace(' ','');
  price = parseInt(price)
  if (price > 2000){
    //alert('>100');
    $("div.dopravazdarma").find('img').attr('src', "http://www.elektrocoleti.cz/img/banner/dopravazdarma-2.jpg");
    }
  

});



