document.write('<style type="text/css">.hide-from-js{display:none}</style>');


// fill in captcha code
$(document).ready(function () {
  if ($('#captchaCode').length) {
    $.get(HTTP_PATH+'/inc/securImage/AJAX_captcha.php', function (data) {
      $('#captchaCode').val(data);
      //alert(data);
    });
  }
});


// prettyPopin
$(document).ready(function(){
  $("a[rel^='prettyPopin']").bind('click', function(){$('.flash-banner').hide()});
  $("a[rel^='prettyPopin']").prettyPopin({
    width:800,
    callback: function(){$('.flash-banner').show();},
    height:600
  });
});


// fancybox
$(document).ready(function () {
  $("#play-multimedia").fancybox({
    frameWidth:800,
    onStart: function(){$('.flash-banner').hide();},
    onClosed: function(){$('.flash-banner').show();},
    frameHeight:600}); //
});


// fotogalerie
$(document).ready(function() {
  $("a.fotogalery").fancybox({
    'overlayOpacity':0.7,
    onStart: function(){$('.flash-banner').hide();},
    onClosed: function(){$('.flash-banner').show();}
  });
});


function myScrollTo(elm)
{
  var srcName; var target; var offset; var top;
  srcName = $(elm).attr('href');
  srcName = srcName.substring(1);

  target = $('#'+srcName+'');

  offset = $(target).offset();
  top = offset.top;


  $('html,body').animate({scrollTop: top}, 1000);
  return true;
}

function shopGoodsImgDetail(href) {
  return window.open(href,"shopGoodsImgDetail","scrollbars=yes,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);
}



  window.onload = function(){
  if(document.all && navigator.appVersion.indexOf("MSIE")>-1 && navigator.appVersion.indexOf("Windows")>-1)
  {
    var a = document.getElementsByTagName("label");
    for(var i=0,j=a.length;i<j;i++){
      if(a[i].hasChildNodes && a[i].childNodes.item(0).tagName == "IMG")
      {
        a[i].childNodes.item(0).forid = a[i].htmlFor;
        a[i].childNodes.item(0).onclick = function(){
          var e = document.getElementById(this.forid);
          switch(e.type){
            case "radio": e.checked|=1;break;
            case "checkbox": e.checked=!e.checked;break;
            case "text": case "password": case "textarea": e.focus(); break;
          }
        }
      }
    }
  }
}

$(document).ready(function () {
  $('#JSadvanceFilterButton').bind('click', function () {
    $(this).hide();
    $('#footer-producers').css('opacity', '0')
    $('#footer-producers').show()
    $('#footer-producers').animate({
    opacity: '1'
    }, 500);
    $('#JSadvanceFilterButtonHide').show();
    return false;
  });
  $('#JSadvanceFilterButtonHide').bind('click', function () {
    $('#footer-producers').animate({
    opacity: '0'
    }, 500, function () {
      $('#JSadvanceFilterButton').show();
      $('#footer-producers').hide();
    });
    return false;
  });

  $('#footer-producers label a').each(function () {
    text = $(this).text();
    $(this).parent().append(text);
    $(this).remove();
  });
});

//prace s kraji
$(document).ready(function() {
  $('.send_to_shop').bind('change', function(){
    $('#send_to_shop').show('slow');
  });
  $('.normal_delivery').bind('change', function(){
    $('#send_to_shop').hide('slow');
  });
  $('.hide-js').hide();

  $('.link_on_region').bind('click', function(){
    var sRegion = $(this).attr('href');
    $('#region_shops').show('slow');
    $('.region_shops').hide('slow');
    $(sRegion).show('slow');
    initializeGoogleMap();
  });
});


//Spodni lista s produkty
$(function() {
    $('#goods-galery-in').jCarouselLite({
        btnNext: '.next',
        btnPrev: '.prev',
        visible: 4,
        circular: true
    });
});


$(function() {
    $('#news-next-images-in').jCarouselLite({
        btnNext: '.next',
        btnPrev: '.prev',
        visible: 2,
        circular: false
    });
});


//prevzeti fakturacnich udaju z dodacich v kosiku
$(document).ready(function(){
  copyDeliveryAddress($('#copyDeliveryAdress'));
  $('#form1 input').bind('keyup', function(){
    copyDeliveryAddress($('#copyDeliveryAdress'));
  });

  $('#copyDeliveryAdress').bind('change', function(){
    copyDeliveryAddress($(this));
  });
});

//prevzeti fakturacnich udaju z dodacich v registraci
$(document).ready(function(){
  copyDeliveryAddressRegistration($('#copyDeliveryAdress'));
  $('#form-delivery input').bind('keyup', function(){
    copyDeliveryAddressRegistration($('#copyDeliveryAdress'));
  });

  $('#copyDeliveryAdress').bind('change', function(){
    copyDeliveryAddressRegistration($(this));
  });
});

$(document).ready(function () {
   $('.overPicture').live('mouseover', function () {
     if ($(this).attr('href') && $(this).attr('href') != '')
       overlib('<img src="' + this.href + '" alt="' + this.href + '" />');
     else
       overlib('<img src="' + $(this).find('input[name=overPictureHref]').val() + '" alt="' + $(this).find('input[name=overPictureHref]').val() + '" />');
   });
   $('.overPicture').live('mouseout', function () {
     nd();
   }); 
});


function copyDeliveryAddress(checkbox)
{
  if(checkbox.attr('checked'))
  {
    $('#form2 input[name=name_invoice]').val($('#form1 input[name=name]').val());
    $('#form2 input[name=street_invoice]').val($('#form1 input[name=street]').val());
    $('#form2 input[name=zip_invoice]').val($('#form1 input[name=zip]').val());
    $('#form2 input[name=town_invoice]').val($('#form1 input[name=town]').val());
    $('#form2 input[name=country_invoice]').val($('#form1 input[name=country]').val());
  }
  else
  {
    $('#form2 input[name=name_invoice]').val('');
    $('#form2 input[name=street_invoice]').val('');
    $('#form2 input[name=zip_invoice]').val('');
    $('#form2 input[name=town_invoice]').val('');
    $('#form2 input[name=country_invoice]').val('');
  }
}

function copyDeliveryAddressRegistration(checkbox)
{
  if(checkbox.attr('checked'))
  {
    $('#form-invoice input[name=_country_invoice]').val($('#form-delivery input[name=_country]').val());
    $('#form-invoice input[name=_street_invoice]').val($('#form-delivery input[name=_street]').val());
    $('#form-invoice input[name=_zip_invoice]').val($('#form-delivery input[name=_zip]').val());
    $('#form-invoice input[name=_town_invoice]').val($('#form-delivery input[name=_town]').val());
  }
  else
  {
    $('#form-invoice input[name=_country_invoice]').val('');
    $('#form-invoice input[name=_street_invoice]').val('');
    $('#form-invoice input[name=_zip_invoice]').val('');
    $('#form-invoice input[name=_town_invoice]').val('');
  }
}
