document.write('<style type="text/css">.hide-from-js{display:none}</style>');

function shopGoodsImgDetail(href) {
  return window.open(href,"shopGoodsImgDetail","scrollbars=no,resizable=yes,height=330,width=350,left=10,top=10");  
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;if(!d) d=document;if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document;n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n];for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n);return x;
}

function setCookie(cookieName, cookieValue, expires, path, domain, secure) {
  if (!expires) {
  	var dnes = new Date();
  	var expires = new Date(dnes.getTime() + 1000 * 60 * 60 * 24); // za 24 hodin
  }
	document.cookie =
		escape(cookieName) + '=' + escape(cookieValue)
		+ (expires ? '; expires=' + expires.toGMTString() : '')
		+ (path ? '; path=' + path : '; path=/')
		+ (domain ? '; domain=' + domain : '')
		+ (secure ? '; secure' : '');
	//alert(document.cookie)
}
function getCookie(cookieName) {
	var cookieValue = '';
	var posName = document.cookie.indexOf(escape(cookieName) + '=');
	if (posName != -1) {
		var posValue = posName + (escape(cookieName) + '=').length;
		var endPos = document.cookie.indexOf(';', posValue);
		if (endPos != -1) cookieValue = unescape(document.cookie.substring(posValue, endPos));
		else cookieValue = unescape(document.cookie.substring(posValue));
	}
	return (cookieValue);
}


//prepinani menu na titulce
$(document).ready(function (){
  $('#category.hp .item').bind('mouseover',function(){
    $('#category .item').removeClass('selected');
    $('#category .item').removeClass('selected2');
    $('#category-detail').removeClass('dnone');
    $(this).addClass('selected');
  });
  
  $('.information').bind('mouseover',function(){
    $('#category .item').removeClass('selected');
    $('#category .item').removeClass('selected2');
    $('#category-detail').addClass('dnone');
  });
  
  $('#hp-banner').bind('mouseover',function(){
    $('#category .item').removeClass('selected');
    $('#category .item').removeClass('selected2');
    $('#category-detail').addClass('dnone');
  });
  
  /*$('#category-detail').bind('mouseover',function(){
    console.debug('over');
  });*/
});

//prepinani tabu v detailu
$(document).ready(function (){
  $('#tabs .tab').bind('click',function(){
    $('#tabs .tab').parent().removeClass('selected');
    $(this).parent().addClass('selected');
    $('.tab-box').hide();
    $($(this).attr('href')).show();
    return false;
  });
});

//prepocet ceny v kosiku
$(document).ready(function (){
  $('.JS_delivery').bind('change',function(){
    var iDeliveryId = $(this).val();
    var iTotalPriceVat = iBasketPriceVat;
    var iTotalPrice = iBasketPrice;
    var iTotalPriceonlyVat = iBasketPriceVat-iBasketPrice;
    
    
    if (aDeliveryTerms[iDeliveryId]['price']>0)
    {
      iTotalPrice = Math.round(iTotalPrice+aDeliveryTerms[iDeliveryId]['price']);
      iTotalPriceVat = Math.round(iTotalPriceVat+aDeliveryTerms[iDeliveryId]['price_vat']);
      iTotalPriceonlyVat = Math.round(iTotalPriceVat-iTotalPrice);
    }
    if (aDeliveryTerms[iDeliveryId]['delivery_percentage_discount']>0)
    {
      iDiscountVat = iTotalPriceVat / 100 * aDeliveryTerms[iDeliveryId]['delivery_percentage_discount'];
      iDiscount = iTotalPrice / 100 * aDeliveryTerms[iDeliveryId]['delivery_percentage_discount'];
      
      iTotalPrice -= iDiscount;//(iTotalPrice/((aDeliveryTerms[iDeliveryId]['delivery_percentage_discount']/100)+1));
      iTotalPriceVat -= iDiscountVat;//(iTotalPriceVat/((aDeliveryTerms[iDeliveryId]['delivery_percentage_discount']/100)+1));
      iTotalPriceonlyVat = (iTotalPriceVat-iTotalPrice);
    }
    if (aDeliveryTerms[iDeliveryId]['payment_percentage_discount']>0)
    {
      iDiscountVat = iTotalPriceVat / 100 * aDeliveryTerms[iDeliveryId]['payment_percentage_discount'];
      iDiscount = iTotalPrice / 100 * aDeliveryTerms[iDeliveryId]['payment_percentage_discount'];
      
      iTotalPrice -= iDiscount;// (iTotalPrice/((aDeliveryTerms[iDeliveryId]['payment_percentage_discount']/100)+1));
      iTotalPriceVat -= iDiscountVat;//(iTotalPriceVat/((aDeliveryTerms[iDeliveryId]['payment_percentage_discount']/100)+1));
      iTotalPriceonlyVat = (iTotalPriceVat-iTotalPrice);
    }
    
    $('#JS_total_price_vat').html(addCommas(Math.round(iTotalPriceVat))+'<small class="nowrap"> Kč</small>');
    $('#JS_total_price').html(addCommas(Math.round(iTotalPrice))+'<small class="nowrap"> Kč</small>');
    $('#JS_total_price_only_vat').html(addCommas(Math.round(iTotalPriceonlyVat))+'<small class="nowrap"> Kč</small>');
  });
});

//doplnujici obrazky
$(function() {
    $('.other-image-in').jCarouselLite({
        btnNext: '.next',
        btnPrev: '.prev',
        visible: 3
        //circular: false
    });
});

function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ' ' + '$2');
	}
	return x1 + x2;
}
