
function SkryjZobraz(id)
    {
       var prvek;
     
       if (prvek = document.getElementById(id)){
          
           if (prvek.style.display=="none"){ 	
    	     prvek.style.display="block";
    	     }
       else {     
          prvek.style.display="none";
          } 
      }   
	 }

// "javascript bez javascriptu" - otevirani odkazu v novem okne - v html pro odkaz pouzijeme class="popup"

function aktualizujOdkazy() {
  if(!document.getElementsByTagName) return false;
  var links = document.getElementsByTagName("a");
  for (var i=0; i < links.length; i++) {
    if(links[i].className.match("noveokno")) {
      links[i].onclick = function () {
        return !window.open(this.href);
      }
    }
  }
}
window.onload=aktualizujOdkazy;

// natahovaci sirka webu  
function resizeFunction(){
         
    var body = $("body").width();
    //var window = $(window).width();// je zde jen pro debug rozliseni 1024
//    alert (body);
    var hp_banner = $(".bannerProVituAVercu").width();
    obsahAuto = body - 235;
      
    if ($("body").width() > 1250) {
    
      $(".obsah").css("width", 1020); // 1250 - 220 (sirka menu)
      $("body").css("overflow-x", "hidden");
      
    }
    
    else if ($("body").width() < 994) {
    
      $(".obsah").css("width", 758); // 994 - 220 - 16 (rezerva) (sirka menu)
      $("body").css("width", 994);
      $("#head").css("width", 994);
      $("body").css("overflow-x", "auto");
    
    }
    
    else if ($("body").width() > 994 && $("body").width() < 1250){
    
      $(".obsah").css("width", obsahAuto);
    
    }
    
    var obsah = $(".obsah").width();
    productWidth = ((obsah / 2) - 30);
    
    $(".product").css("width", productWidth);
    
    // posouvani banneru na uvodni strane
    
    var divObsah = $(".obsah").width();
    var posunBanneru = (divObsah / 2) - ( hp_banner / 2);
    var posunBanneruPresne = Math.floor(posunBanneru)
    $(".bannerProVituAVercu").css("margin-left", posunBanneruPresne+"px");

    $(".bannerProVituAVercu, .bannerProVituAVercu *").mouseover(function () {
      $('#changing').cycle('pause');  
    });
    
    $(".bannerProVituAVercu, .bannerProVituAVercu *").mouseout(function () {
      $('#changing').cycle('resume');  
    });
    
    // uprava pri rozliseni mensim nez je 1024px
    
    if (body < 1100 && body > 994){
      $("div.similar, div.detail").addClass("wide");
    }
    //alert (body);
    
  
}

function setSizeSel()
{
  var $sizeSel = $("#size-select");
  var selected = $sizeSel.find("option:selected").first();
  
  if (!selected)
  {
    selected = $sizeSel.find("option").first();
  }
  
  $("#size-label").text( selected.text() );
  if ($("#size-table tbody tr:visible").size() > 0)
  {
    $("#size-table tbody tr:visible").fadeOut('fast', function() { $("." + selected.val()).fadeIn('fast'); } );
  } else {
    $("." + selected.val()).fadeIn('fast');
  }
}

function translateCategory( cat )
{
    switch(cat)
    {
        case 'product':
            return 'Produkty';
        case 'manufacturer':
            return 'Značky';
        case 'category':
            return 'Kategorie';
    }
    
    return '';
}

$.widget("custom.catcomplete", $.ui.autocomplete, {
        _renderMenu: function( ul, items ) {
            var self = this,
            currentCategory = "";
            currentTerm = $('#search-field').val();
            lcTerm = currentTerm.toLowerCase();
            $.each( items, function( index, item ) {
                if ( item.category != currentCategory ) {
                    ul.append( "<li class='ui-autocomplete-category'>" + translateCategory(item.category) + "</li>" );
                    currentCategory = item.category;
                }
                label = item.label;
                lcLabel = label.toLowerCase();
                i = lcLabel.indexOf(lcTerm);
                if (i >= 0)
                {
                    item.label = label.substring(0, i) + '<strong>' + label.substr(i, currentTerm.length) + '</strong>' + label.substring(i + currentTerm.length);
                }
                self._renderItem( ul, item );
            });
        }
    });


$(document).ready(function(){
   
    $('#search-field').catcomplete({
        minLength: 3,
        focus: function(event, ui) { return false; },
        select: function(event, ui) {
            if (ui.item.url)
            { 
                $(location).attr('href',urlRoot + ui.item.url);
            }
            return false; 
        },
        source: urlRoot + "autocomplete.php"
    });
    
  $("#size-select").change( setSizeSel );
  setSizeSel();
  /** zaskrnuti prvni barvy pytle **/
	
	$("input[name='antaresbarva']:first").attr('checked', 'checked');
  
  // uvodni strana parfemu
  
//  $(".showAllParfumes").click(function () {
  
      $("#parfemy-hp-nejprodavanejsi").hide();
      $("#parfemy-hp-vsechny").show();
       
//    });
    
    
    // resize detail banner - parfumes advertisement
    
    var sirkaBanneru = $(".detail_banner a img").width();
    if (sirkaBanneru > 971){
      $(".detail_banner a img").css("width", "971px");
    }
  
    resizeFunction();
    

/**
 *  Resize obrázků v rozcestníku kategorie - THE NEW CROSSWAY
 */


var images = $('#crossway img');


$.each(images, function(i, img){
    $(img).ready(function(){
        var width = $(img).width();
    	var height = $(img).height();
        if ( width > 130){
            $(img).css( 'width', "130px" );
        }
        else {

            if ( height > 130){
              $(img).css( 'height', "130px" );
            }
            else {
        	  $(img).css( 'height', "auto" );
            }

            $(img).css( 'width', "auto" );

        }
    });
});


/**
 *  Klikatelny banner s pomoci jedineho odkazu
 */ 
 
  var bannerExists = $('.bannerProVituAVercu').height();
  if(bannerExists > 0){
     
      $('.bannerProVituAVercu, .bannerProVituAVercu > *').click(function () {
        var url = $("a.bannerodkaz").attr("href");
        if (url) {
          window.location = url;
        }
      });
      
      
    /**
     *  Changing the background on the home page
     */
     
      $("#changing").css("display", "block");
      $("#changing").css("visibility", "visible");
       
      $("#changing").cycle({
          fx:    'turnUp',
          timeout: 6000
      });

  } else {
    $("#changing").hide();
  }
   
   
  /**
   *  Odeslani formul??e ONCHANGE
   */     
   
  $("#znackyForm, #sortByForm").change(function(){
    this.submit();
  });
  
  $("#rozmery tr").hover(function(){
      $(this).addClass("hover");
  }, function(){
    $(this).removeClass("hover");
  });

  var product2Width = $(".product2").width();
  if (product2Width)
  {
    $(".product-img").css("width", product2Width+"px");
  }

  /**
   *  POCET PRODUKTU NA RADEK - PRODUKT2
   */
   
   var obsah = $(".obsah").width();
   
  if (obsah <= 1020 && obsah >= 940){
      var product2 = ((obsah/4)-10);
//      alert (product2);
      $(".product2").css("width", product2+"px");
      $(".product2").css("margin-right", "5px");
  }
  if (obsah < 940 && obsah >= 758){
      var product2 = ((obsah/3)-10);
//      alert (product2);
      $(".product2").css("width", product2+"px");
      $(".product2").css("margin-right", "5px");
  } 
  
  
});


$(window).resize(function(){

    resizeFunction();
  
});
 
 
  




