


jQuery.noConflict(); //  kvuli konfliktu motools a jquery ( potřeba nahradit všechny $ -> jQuery )

jQuery(document).ready(function(){
jQuery( "#tabs" ).tabs();
});

jQuery(document).ready(function()
{
     var termTemplate = "<span class='ui-autocomplete-term'>%s</span>";
     //Autocomplete
     jQuery("#search").autocomplete(
     {
          //source:["c++", "java", "php", "coldfusion", "javascript", "asp", "ruby", "python", "c", "scala", "groovy", "haskell", "pearl"],
          source: "../zbozi_all.php",
          //source: [{"value":"Some Name"},{"value":"Some Othername"}]
          dataType: "json",
          minChars:2,
          width:400,
          matchContains:true,
          highlight:true,
          selectFirst:false,
          select: function(event, ui)
          {
             if(ui.item.adr!="")
             {          
                window.location.href = "/"+ui.item.adr;
             }
             else
             {
                window.location.href = "/hledej?term=" + ui.item.value;
             }

             
          },
          open: function(e,ui) {
            var
                acData = jQuery(this).data('autocomplete'),
                styledTerm = termTemplate.replace('%s', acData.term);

            acData
                .menu
                .element
                .find('a')
                .each(function() {
                  var me = jQuery(this);
                  var regex = new RegExp(acData.term, "gi");
                  me.html( me.text().replace(regex, function (matched) {
                     return termTemplate.replace('%s', matched);
                  }) );
               });

         }
     });
});

jQuery(document).ready(function(){
jQuery('#rating').raty();
});


jQuery(document).ready(function(){
jQuery("#hornimenu ul li").bind("mouseenter", function() {
jQuery(this).children("ul").css("top", "30").slideDown("slow");
});

jQuery("#hornimenu ul li").bind("mouseleave", function() {
jQuery(this).children("ul").stop(true, true).slideUp();
});
});


//facebook fbs_click
function fbs_click()
{
   u=location.href;t=document.title;
   window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&amp;t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
   return false;
}
//konec facebook

function check()
{
     var res;
     res = false;

     for(i=0; i < document.form.elements.length; i++)
      {
          var alertText = ""
          if(document.form.elements[i].type == "select-one")
          {
              if (document.form.elements[i].options[document.form.elements[i].selectedIndex].value == '0')
              {
                alertText += ('Vyberte prosím volitelné parametry výrobku');
              }

              if (alertText != "")
              {
              alert(alertText);
              return false;
              }
          }
      }
      

    for (i = 0; i < document.form.do_darek.length; i++) {
    res = res || document.form.do_darek[i].checked;
    }
    if(document.form.do_darek.length==undefined)
    {
       res = res || document.form.do_darek[i].checked;
    }
    if (!res) {
        pokracovat = confirm('Nevybrali jste si dárek! Zvolte OK pokud chcete přesto pokračovat, Storno, pokud si chcete dárek vybrat');
       if (pokracovat)
          {
             window.location.href = 'kos_insert';
             return true;
          }
       else
       {
          window.location.href = '#do_darek';
          return false;
       }
    }

      

  return true;
}

jQuery(document).ready(function(){ gapi.plusone.render("medium", {"size": "medium", "count":"false"});});


var TINY={};

function T$(i){return document.getElementById(i)}
function T$$(e,p){return p.getElementsByTagName(e)}

TINY.dropdown=function(){
	var p={fade:1,slide:1,active:0,timeout:200}, init=function(n,o){
		for(s in o){p[s]=o[s]} p.n=n; this.build()
	};
	init.prototype.build=function(){
		this.h=[]; this.c=[]; this.z=1000;
		var s=T$$('ul',T$(p.id)), l=s.length, i=0; p.speed=p.speed?p.speed*.1:.5;
		for(i;i<l;i++){
			var h=s[i].parentNode; this.h[i]=h; this.c[i]=s[i];
			h.onmouseover=new Function(p.n+'.show('+i+',1)');
			h.onmouseout=new Function(p.n+'.show('+i+')')
		}
	};
	init.prototype.show=function(x,d){
		var c=this.c[x], h=this.h[x];
		clearInterval(c.t); clearInterval(c.i); c.style.overflow='hidden';
		if(d){
			if(p.active&&h.className.indexOf(p.active)==-1){h.className+=' '+p.active}
			if(p.fade||p.slide){
				c.style.display='block';
				if(!c.m){
					if(p.slide){
						c.style.visibility='hidden'; c.m=c.offsetHeight; c.style.height='0'; c.style.visibility=''
					}else{
						c.m=100; c.style.opacity=0; c.style.filter='alpha(opacity=0)'
					}
					c.v=0
				}
				if(p.slide){
					if(c.m==c.v){
						c.style.overflow='visible'
					}else{
						c.style.zIndex=this.z; this.z++; c.i=setInterval(function(){slide(c,c.m,1)},20)
					}
				}else{
					c.style.zIndex=this.z; this.z++; c.i=setInterval(function(){slide(c,c.m,1)},20)
				}
			}else{
				c.style.zIndex=this.z; c.style.display='block'
			}
		}else{
			c.t=setTimeout(function(){hide(c,p.fade||p.slide?1:0,h,p.active)},p.timeout)
		}
	};
	function hide(c,t,h,s){
		if(s){h.className=h.className.replace(s,'')}
		if(t){c.i=setInterval(function(){slide(c,0,-1)},20)}else{c.style.display='none'}
	}
	function slide(c,t,d){
		if(c.v==t){
			clearInterval(c.i); c.i=0;
			if(d==1){
				if(p.fade){c.style.filter=''; c.style.opacity=1}
				c.style.overflow='visible'
			}
		}else{
			c.v=(t-Math.floor(Math.abs(t-c.v)*p.speed)*d);
			if(p.slide){c.style.height=c.v+'px'}
			if(p.fade){var o=c.v/c.m; c.style.opacity=o; c.style.filter='alpha(opacity='+(o*100)+')'}
		}
	}
	return{init:init}
}();
