var options = { path: '/', expires: 10 };

$(document).ready(function() {
    
    $('#price_with_dph_akceptace').keyup(function(){
      //alert((1+ ($('#dph').val()/100)));
      $('#price_without_dph_akceptace').val(($(this).val()) / (1+ ($('#dph').val()/100)));
      $('#price_dph_akceptace').val(($(this).val()) - $('#price_without_dph_akceptace').val());
    });
    
    $('#hpgallery').find('a').each(function(){
      $(this).click(function(){
        $('#hpgallery').find('a').each(function(){
          $(this).find('.gallery-p').css('display','none');
          $(this).find('.gallery-p').css('width','0px');
          $(this).css('width','34px');
        });
      
        $(this).find('.gallery-p').css('display','block');
        $(this).find('.gallery-p').css('width','180px');
        $(this).css('width','223px');
        $(window).focus();
        
        return false;
      });
    
    $('.advrt-control-slide').find('li').each(function(){
      $(this).click(function(){
        //alert('#'+$(this).attr('id')+'-line');
        $('#'+$(this).attr('id')+'-line').click();
        $('.advrt-control-slide').find('li').each(function(){
          $(this).removeClass('ban-selected');
        });
        
        $(this).addClass('ban-selected');
      });
    });
    
    $('#hpgallery').find('a:first').click();
    $('.advrt-control-slide').find('li:first').addClass('ban-selected');
      
/*          function () {
            $(this).find('p').css('display','block');
            $(this).css('width','190px');
          }, 
          function () {
            $(this).find('p').css('display','none');
            $(this).css('width','34px');
            $('#hpgallery').find('a:first').each(function(){
              $(this).find('p').css('display','block');
              $(this).css('width','190px');
            });
          }*/
    });
    
    $('.odebrat-z-burzy').each(function(){
      $(this).click(function(){
        $(this).parent().find('#odebrat').val('1');
        $(this).parent().submit();
      });
    });
    
    $('.eshop-enter').click(function(){
      window.location.href = '/registrace/';
    });
    
    $('.btn-detail-inzerce').each(function(){
      $(this).click(function(){
        window.location.href = $(this).parent().parent().find('a').attr('href');
      });
    });
    
    $('#kosik').click(function(){
      window.location.href = '/kosik/';
    });
    
    $('.uschovat').click(function(){
      $('.uschovatRadio').each(function(){
        if ($(this).is(':checked')){
          $(this).attr('checked',''); 
        }else{
          $(this).attr('checked','checked');  
        }
      });
      $('#orderitem').submit();
    });
    
    $('#zrusit-objednavku').click(function(){
      window.location.href='?do=ok';
    });
    /*
    / zalozky v detailu zbozi
    */
    $('#tabs').find('a').each(function(){
      if ($(this).attr('href').indexOf('gallery') <= 0){
        $(this).click(function(){
           var obj = $(this);
           $.get('/detail.php'+$(this).attr('href')+'&j=1', function(data){
                $('#param-content').html(data);
           });
           $('#tabs').find('li').each(function(){
            $(this).removeClass('bm-active');
           });
           obj.parent().addClass('bm-active');
           return false;
        });
      };
    });
    
    
    $('#mainmenu').find('li').each(function(){
      if ($(this).attr('class') != 'menu-sep'){
        $(this).find('a').hover(
            function () {
              $(this).addClass('menu-selected');
              $(this).parent().find('span').addClass('span-selected');
            }, 
            function () {
              $(this).removeClass('menu-selected');
              $(this).parent().find('span').removeClass('span-selected');
            }
        );
      }
    });


    PopUpBox($('#question'),'/jquery/question.php?id='+$('#id').val(),505,420,'productQuestion');
    
    
    $('#container').css('visibility','visible');
    
    $('.product').each(function(){
      $(this).click(function(){
        window.location.href= $(this).find('a:first').attr('href');
      });      
    });
    $('.kosik').click(function(){
      //window.location.href='/kosik/';
    });
 
    $('#deliveryCheck').click(function(){
      if ($(this).is(':checked')){
      
        $('.deliveryAddressInputs').each(function(){
          //alert($(this).css('display'));
          //$(this).css('display','block');
          //$(this).css('display','table-row');
          $(this).removeClass('hideDelivery');
        }); 
      }else{
        $('.deliveryAddressInputs').each(function(){
          $(this).addClass('hideDelivery');
          $(this).find('input').each(function(){
            $(this).val('');
          });
        }); 
      }
    });
 
    $('.prepocitat-arrows').click(function(){
      
      $('#orderitem').submit();
    });
 
    $('.level0').find('span,a').each(function(){
      $(this).click(function(){
        if ($(this).getNodeName() == 'SPAN'){
          //alert($(this).parent().find('ul').css('display'));
          $(this).parent().addClass('selected');
          $(this).parent().parent().find('li').each(function(){
            $(this).removeClass('selected');
          });
          if ($(this).parent().find('ul').css('display') == 'none'){
            
            $(this).parent().parent().find('ul').each(function(){
              //alert($(this).html());
              $(this).css('display','none');
              //$(this).parent().removeClass('selected');  
              $(this).parent().removeClass('selected');
            });
            $(this).parent().addClass('selected');
            $(this).parent().find('ul').css('display','block');
          }else{
            $(this).parent().removeClass('selected');
            $(this).parent().find('ul').css('display','none');
          }
        }
        //alert($(this).type());
      });      
    });
 
    PopUpBox($('#loginLink'),'/jquery/login.php',858,443,'loginBox',0);      
    
    var errorMessage = $('#errorMessage').html();
    //if (errorMessage > ''){
      //ErrorMessages($('#errorMessage'),300,300,'loginBox'); 
    //} 
 
    var speed = $('#speed').val();
    var time = $('#time').val();
    jQuery('#mycarousel').jcarousel({
        auto: parseInt(time),
        rtl: true,
        wrap: 'circular',
        animation: parseInt(speed),
        initCallback: mycarousel_initCallback
    });

    jQuery('#mycarousel1').jcarousel({
        auto: parseInt(time),
        wrap: 'circular',
        animation: parseInt(speed),
        initCallback: mycarousel_initCallback
    });

    
    jQuery('#mycarousel2').jcarousel({
        auto: parseInt(time),
        wrap: 'circular',
        rtl: true,
        animation: parseInt(speed),
        initCallback: mycarousel_initCallback
    });

    $('.product').each(function(){
      $(this).hover(
          function () {
            $(this).addClass('selected');
          }, 
          function () {
            $(this).removeClass('selected');
          }
      );
    });

    $('#pol0').change(function(){
      $('#sorting-form').submit();      
    });
    $('#pol1').change(function(){
      $('#pol0').val($('#pol1').val());
      $('#sorting-form').submit();      
    });
/*
    $('.darekzdarmatitle').click(function(){
      if ($('.darekzdarmatitle').find('span').text() == '+'){
        $('.darekzdarmatitle').find('span').text('-');
        $('.darekzdarmaHidden').css('display','block');
      }else{
        $('.darekzdarmatitle').find('span').text('+');
        $('.darekzdarmaHidden').css('display','none');
      }
    });
*/
    $('.paymentList').each(function(){
      $(this).click(function(){
        if ($(this).val() == 9){
          $('.deliveryHide').css('display','none');
        }else{
          $('.deliveryHide').css('display','');
        }
      });
    });

/*
    $('.paymentList').each(function(){
      $(this).click(function(){
        //alert($(this).val());
        if ($(this).val() == 6){
          $('.delivery-list').find('input').each(function(){
            if ($(this).val() == 23){
              //alert($(this).val());
              $('.delivery-list').find('input').each(function(){
                //alert($(this).val());
                if ($(this).val() == 19){
                  $(this).attr('checked','checked');
                }
              });
              $(this).attr('disabled',true);
            }
          });
        }else{
          $('.delivery-list').find('input').each(function(){
            $(this).attr('disabled',false);
          });
        }
      });
    });
*/
/*
    $('.paymentList').each(function(){
      if (($(this).is(':checked'))&&($(this).val() == 6)){ // dobirak
        $('.delivery-list').find('input').each(function(){
          //alert($(this).val());
          if ($(this).val() == 23){
            $(this).attr('disabled','disabled');
          }
        });
      }
    });
*/
    $('.second').each(function(){
      $(this).click(function(){
        $('#produktyDarky').removeClass('prod-dar');
        $('#produktyDarky').addClass('dar-prod');
        $.cookie('darky', '1', options);
        $.get('/jquery/categorylist.php?sekce=1', function(data){
          $('#kategorie').html(data);          
        });
      });
      return false;       
    });
    $('.first').each(function(){
      $(this).click(function(){
        $('#produktyDarky').removeClass('dar-prod');
        $('#produktyDarky').addClass('prod-dar');
        $.cookie('darky', '', options);
        $.get('/jquery/categorylist.php?sekce=0', function(data){
          $('#kategorie').html(data);   
        });
      });
      return false;       
    });

    $('.ikonky li').hover(
        function () {
          $(this).find('div').slideDown();
        }, 
        function () {
          $(this).find('div').hide();
        }
    );

    $('#znateztv').hover(
        function () {
          $(this).attr('src','/img/znate-tv-on.png');
        }, 
        function () {
          $(this).attr('src','/img/znate-tv-off.png');
        }
    );

    $('#kvetoucicaje').hover(
        function () {
          $(this).attr('src','/img/kvetouci-caje-on.png');
        }, 
        function () {
          $(this).attr('src','/img/kvetouci-caje-off.png');
        }
    );

    
    
    var hideBuyDialog = setTimeout("hideDialog();",5000);
/*
    $('.delivery-list').each(function(){
      $(this).find('input').each(function(){
        if ($(this).attr('type') == 'radio'){
          var id = $(this).attr('id').replace('delivery','');
          if ($(this).is(':checked')){
            $('#deliveryPriceJS').val(parseInt($('#hiddenDeliveryPrice'+id).val()));
            SumFinalPrice();
          }
          $(this).click(function(){
            var id = $(this).attr('id').replace('delivery','');
            $('#deliveryPriceJS').val(parseInt($('#hiddenDeliveryPrice'+id).val()));
            SumFinalPrice();
          });
        }
      });
    });

    $('.paymentListDiv').each(function(){
      $(this).find('input').each(function(){
        if ($(this).attr('type') == 'radio'){
          var id = $(this).attr('id').replace('payment','');
          if ($(this).is(':checked')){
            //alert($('#hiddenPaymentPrice'+id).val());
            $('#paymentPriceJS').val(parseInt($('#hiddenPaymentPrice'+id).val()));
            SumFinalPrice();
          }
          $(this).click(function(){
            var id = $(this).attr('id').replace('payment','');
            $('#paymentPriceJS').val(parseInt($('#hiddenPaymentPrice'+id).val()));
            SumFinalPrice();
          });
        }
      });
    });*/

/*
    $('.delivery-list').each(function(){
      $(this).find('input').each(function(){
        if ($(this).attr('type') == 'radio'){
          var id = $(this).attr('id').replace('delivery','');
          if ($(this).is(':checked')){
            // pripoctu dopravu k cene
            $('#finalPrice').html((parseInt($('#pricewithdph').val()) + parseInt($('#hiddenDeliveryPrice'+id).val())) + ' ' + $('#mena').val());
          }
          //alert(id);
          $(this).click(function(){
            var id = $(this).attr('id').replace('delivery','');
            //alert(parseInt($('#hiddenDeliveryPrice'+id).val()));
            $('#finalPrice').html((parseInt($('#pricewithdph').val()) + parseInt($('#hiddenDeliveryPrice'+id).val())) + ' ' + $('#mena').val());
          });

        }
      });
    });
*/
    $('.nejnovejsi').click(function(){
      $('#sortby').val('d_date_insert');
      $('#sort-style').val('DESC');
      $('#sorting-form').submit();
    });
    $('.nejdrazsi').click(function(){
      $('#sortby').val('n_price_with_dph');
      $('#sort-style').val('ASC');
      $('#sorting-form').submit();
    });
    $('.nazvu').click(function(){
      $('#sortby').val('s_name');
      $('#sort-style').val('ASC');
      $('#sorting-form').submit();
    });
    
    $('#sortby2').change(function(){
      $('#sortby').val($(this).val());
    });

    $('.infolinka').find('a:first').each(function(){
      $(this).hover(
        function () {
          $('.submenu').slideDown();
        }, 
        function () {
          $('.submenu').hide();
        }
      );
    });
    $('.submenu').each(function(){
      $(this).hover(
        function () {
          $('.submenu').show();
        }, 
        function () {
          $('.submenu').hide('slow');
        }
      );
    });
  

    // popis dostupnosti
    $('.dostupnostPopUp').each(function(){
      $(this).hover(
        function () {
          $(this).parent().find('.dostupnostPopUpText').css('display','inline');
        }, 
        function () {
          $(this).parent().find('.dostupnostPopUpText').css('display','none');
        }
      );
    })


    // napoveda pro parametry
    $('.parametrHelp').each(function(){
      PopUpBox($(this),'/jquery/parameterhelp.php?param='+$(this).attr('param'),300,300,'napoveda');
    });
    


    // hodnoceni
    $('#ratingform .hodnoceni .stars').mousemove(function(e){
      var rating = $(this).offset();
      var x = (e.pageX + 1) - rating.left;
      var ratingValue = (x);
      
      if (ratingValue <= 20){
        $posunuti = "-80px";
        $('#hodnoceniValue').val('0');
        $('#ratingform .values').html('0% Nepoužitelný');
      }else if ((ratingValue <= 40)&&(ratingValue > 20)){
        $posunuti = "-60px";
        $('#hodnoceniValue').val('30');
        $('#ratingform .values').html('30% Špatný');
      }else if ((ratingValue <= 60)&&(ratingValue > 40)){
        $posunuti = "-40px";
        $('#hodnoceniValue').val('50');
        $('#ratingform .values').html('50% Průměrný');
      }else if ((ratingValue <= 80)&&(ratingValue > 60)){
        $posunuti = "-20px";
        $('#hodnoceniValue').val('80');
        $('#ratingform .values').html('80% Velmi dobrý');
      }else if ((ratingValue <= 100)&&(ratingValue > 80)){
        $posunuti = "-0px";
        $('#hodnoceniValue').val('100');
        $('#ratingform .values').html('100% Perfektní');
      }
      $('#ratingform .hodnoceni .stars').css('background-position',$posunuti + ' 0px');

    });

    $('#ratingform .hodnoceni .stars').click(function(){
      $('#values').html($('#hodnoceniValue').val());
      $('#ratingform').submit();
    });


    // hodnoceni v recenzi
    $('#recenze .hodnoceni .stars').mousemove(function(e){
      var rating = $(this).offset();
      var x = (e.pageX + 1) - rating.left;
      var ratingValue = (x);
      
      if (ratingValue <= 20){
        $posunuti = "-80px";
        $('#hodnoceniRecenze').val('0');
        $('#recenze .values').html('0% Nepoužitelný');
      }else if ((ratingValue <= 40)&&(ratingValue > 20)){
        $posunuti = "-60px";
        $('#hodnoceniRecenze').val('30');
        $('#recenze .values').html('30% Špatný');
      }else if ((ratingValue <= 60)&&(ratingValue > 40)){
        $posunuti = "-40px";
        $('#hodnoceniRecenze').val('50');
        $('#recenze .values').html('50% Průměrný');
      }else if ((ratingValue <= 80)&&(ratingValue > 60)){
        $posunuti = "-20px";
        $('#hodnoceniRecenze').val('80');
        $('#recenze .values').html('80% Velmi dobrý');
      }else if ((ratingValue <= 100)&&(ratingValue > 80)){
        $posunuti = "-0px";
        $('#hodnoceniRecenze').val('100');
        $('#recenze .values').html('100% Perfektní');
      }
      $('#recenze .hodnoceni .stars').css('background-position',$posunuti + ' 0px');

    });

    //$('#recenze .hodnoceni .stars').click(function(){
    //  $('#values').html($('#hodnoceniValue').val());
    //});

 /*
    if ($('#ratingclose').val() == 0){
      $('.ratline-mask').mousemove(function(e){
        var rating = $(this).offset();
        var x = (e.pageX + 1) - rating.left;
        var ratingValue = ((x) * 2);
        ratingValue = (ratingValue / 10) + 0.2;
        ratingValue = Math.round(ratingValue*10)/10;
        if ((ratingValue == '')||(ratingValue == '0.4')){
          ratingValue = '0.0';
        }
        if ((ratingValue == '1')||(ratingValue == '2')||(ratingValue == '3')||(ratingValue == '4')||(ratingValue == '5')||(ratingValue == '6')||(ratingValue == '7')||(ratingValue == '8')||(ratingValue == '9')){
          ratingValue = ratingValue + '.0';
        }
        $(this).parent().find('.dpr-red').css('width',((x) * 2)+'%');
        $('.rat-number').find('strong').html(ratingValue);
        $('#rating').val(ratingValue);
      });
      
      $('.ratline-mask').mouseout(function(){
        var defaultValue = $('#rating-load').val();
        setTimeout(function () {
          $('.rat-number').find('strong').html(defaultValue);
          $('#rating-width').css('width',defaultValue*10+'%');
        },3000);
      });
*/

    // chat
    $('.smileys').find('img').each(function(){
      $(this).click(function(){
        $('#chattext').val($('#chattext').val() + $(this).attr('alt'));
      });
    });

    // silencer
    $('#words').keyup(function() {
      if ($(this).val().length >= 2){
        $('#silencer').css('display','inline');
        $('#silencer').html("<img src='/img/loader.gif' alt='' />");
        //var sHtml = "<ul class='silencer'>";
        $.get('/jquery/silencer.php?srch='+$(this).val(), function(data){
          if (data > ''){ 
            $('#silencer').html(data);          
          }else{
            $('#silencer').css('display','none');
          }
        });

      }
    });


    // horozntal hover efekt
    $('.horizontal').find('li').each(function(){
      $(this).hover(
        function () {

          $(this).addClass('sel');
          obj = $(this);
          obj.find('.catPopUp').css('display','inline');
          
        }, 
        function () {
          $(this).removeClass('sel');
          obj = $(this);
          obj.parent().find('.catPopUp').css('display','none');
        }
      );
    });

    $('.horizontal').find('li:first').each(function(){
      $(this).hover(
        function () {
          $(this).addClass('sel-first');
          $(this).find('a:first').addClass('sel');
        }, 
        function () {
          $(this).removeClass('sel-first');
          $(this).find('a:first').removeClass('sel');
        }
      );
    });
    $('.horizontal').find('li.last').each(function(){
      $(this).hover(
        function () {
          $(this).addClass('sel-last');
          $(this).find('a:first').addClass('selected');
        }, 
        function () {
          $(this).removeClass('sel-last');
          $(this).find('a:first').removeClass('selected');
        }
      );
    });
    

    $('.category').find('li.level0').each(function(){
      $(this).hover(
        function () {
          $(this).addClass('sele');
        }, 
        function () {
          $(this).removeClass('sele');
        }
      );
    });

    $('.category').find('li.level1').each(function(){
      $(this).hover(
        function () {
          $(this).addClass('select');
        }, 
        function () {
          $(this).removeClass('select');
        }
      );
    });

    $('.category').find('li.level2').each(function(){
      $(this).hover(
        function () {
          $(this).addClass('select');
        }, 
        function () {
          $(this).removeClass('select');
        }
      );
    });


    /*
    / zalozky v detailu zbozi
    */
    $('.bookmarks li').find('a').each(function(){
      if ($(this).attr('href').indexOf('gallery') <= 0){
        $(this).click(function(){
           $('.bookmarks li').each(function(){
              $(this).removeClass('bm-active');
           });
           $(this).parent().attr('class','bm-active');
           $.get('/detail.php'+$(this).attr('href')+'&j=1', function(data){
                $('#param-content').html(data);
           });
           return false;
        });
      }
    });
    
    /*
    / odeslani emailu a dalsi formulare v detailu zbozi, provazani se zalozkama
    */
    
    $('.buttons').find('a').each(function(){
      
      $(this).click(function(){
         $('.bookmarks li').each(function(){
            $(this).removeClass('bm-active');
         });
         $.get('/detail.php'+$(this).attr('href')+'&j=1', function(data){
              $('#param-content').html(data);
         });
         return false;
      });
    });
    
    
    /*
    * pridani focus a blur na novinky emailem
    */    
    $("#mailnewsinput").focus(function () {
      if ($(this).val() == 'váš@e-mail'){
        $(this).val('');
      }
    });
    $("#mailnewsinput").blur(function () {
      if ($(this).val() == ''){
        $(this).val('váš@e-mail');
      }
    });

    /*
    * pridani focus a blur na pole hledani
    */    
    $("#words").focus(function () {
      if ($(this).val() == 'Hledat...'){
        $(this).val('');
      }
    });
    $("#words").blur(function () {
      if ($(this).val() == ''){
        $(this).val('Hledat...');
      }
    });


    /*
    * pridani focus a blur na logovaci formular
    */    
    /*$("#logininput").focus(function () {
      if ($(this).val() == 'Přihlašovací jméno'){
        $(this).val('');
      }
    });
    $("#logininput").blur(function () {
      if ($(this).val() == ''){
        $(this).val('Přihlašovací jméno');
      }
    });*/
    

    /*
    * pridani focus a blur na logovaci formular
    */    
    /*$("#passwordinput").focus(function () {
      if ($(this).val() == 'heslo'){
        $(this).val('');
      }
    });
    $("#passwordinput").blur(function () {
      if ($(this).val() == ''){
        $(this).val('heslo');
      }
    });*/


    /*$("#mesto").blur(function () {
      if (($(this).val() > '')&&($('#psc').val() == '')){
        $.get('/jquery/psc.php?mesto='+$(this).val(), function(data){
           $('#psc').val(data);
        });        
      }
    });
    $("#psc").blur(function () {
      if (($(this).val() > '')&&($('#mesto').val() == '')){
        $.get('/jquery/psc.php?psc='+$(this).val(), function(data){
           //alert(data);
           $('#mesto').val(data);
        });        
      }
    });*/


    $('.advrt-control').find('li').each(function(){
      if ($(this).attr('class') == 'counter'){
        $(this).click(function(){ 
        //alert(mainTimeoutmainimg);
          clearTimeout(mainTimeoutmainimg);
          counter = (parseInt($(this).attr('id').replace('dot-','')) );
          //alert(XMLID);
          //$.cookie('advert-last'+XMLID, counter, options);
          XMLBan(XMLFILE,XMLID,counter,XMLTIME,'1','mainTimeoutmainimg');
        });
      }
    });

   
});

/*
* parsovani XML s bannerama a stridani banneru po sekundach
*/
var counter = 0;
var name = "";
var url = "";
var img = "";
var blank = "";
var text = "";
var params = "";
var items = "";

var XMLFILE = "";
var XMLID = "";
var XMLCOUNTER = "";
var XMLTIME = "";


function XMLBan(file,id,counter,time, bannerControlBool,timeoutName){
  
  clearTimeout(timeoutName);
          
  var i = 1;
  if (bannerControlBool == '1'){
    XMLFILE = file;
    XMLID = id;
    XMLCOUNTER = counter;
    XMLTIME = time;
    XMLCONTROL = bannerControlBool;
  }
  $.ajax({
    url: file,
    cache: false,
    success: function(data) {
      $(data).find('banner').each(function(){
          name = $(this).find('name').text();
          url = $(this).find('url').text();
          img = $(this).find('img').text();
          blank = $(this).find('blank').text();
          text = $(this).find('text').text();
          params = $(this).find('params').text();
          items = $(this).find('count').text();
          if ((parseInt(counter)) > items){
            $.cookie('advert-last'+id, 1, options);
          }else{
            $.cookie('advert-last'+id, (parseInt(counter)), options);
          }
          if ((parseInt($.cookie('advert-last'+id))) == i){
            if (bannerControlBool == '1'){
              SelectDot((parseInt($.cookie('advert-last'+id))));
            }
            ShowBanner(id,img,(parseInt($.cookie('advert-last'+id))),file,items,time,name,url,bannerControlBool,timeoutName);
            return false;
          }
          i += 1; 
      });
    }
  });
  

}

function ShowBanner(id,img,counter,file,items,time,name,url,bannerControlBool,timeoutName){
  if (img.indexOf('.swf') > 0){
    $('#'+id).hide();
    $("object").remove();
    $("<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0' width='1180' height='359' id='blade' align='middle'><param name='allowScriptAccess' value='sameDomain' /><param name='allowFullScreen' value='false' /><param name='movie' value='"+img+"' /><param name='quality' value='high' /><param name='bgcolor' value='#ffffff' /><embed src='"+img+"' quality='high' bgcolor='#ffffff' width='1180' height='359' name='blade' align='middle' allowScriptAccess='sameDomain' allowFullScreen='false' type='application/x-shockwave-flash' pluginspage='http://www.adobe.com/go/getflashplayer' /></object>").insertBefore($('#'+id));
  }else{
    $("object").remove();
    $('#'+id).show();
    $('#'+id).attr('src',img);
    $('#'+id).attr('alt',name);
    $('#'+id).attr('title',name);
    $('#'+id).parent().attr('href',url);
    $('#'+id).parent().attr('alt',name);
    $('#'+id).parent().attr('title',name);
  }
  Show(document.getElementById(id), 0);
  if ((parseInt(counter)) > items){
    counter = 1;
  }else{
    counter = parseInt(counter) + 1;
  }
  if (bannerControlBool){
    mainTimeoutmainimg = setTimeout(function () {XMLBan(file,id,counter,time,bannerControlBool,'mainTimeoutmainimg')},time);
  }else{
    timeoutName = setTimeout(function () {XMLBan(file,id,counter,time,bannerControlBool,timeoutName)},time);
  }
}

function SelectDot(counter){
  //alert(counter);
  $('.advrt-control').find('li').each(function(){
    //if ($(this).attr('class') == 'ban-selected'){
      $(this).removeClass('ban-selected');
      //return false;
    //  $(this).find('img').attr('src','/img/banner-dot.png');
    //}
  });
  $('#dot-'+counter).addClass('ban-selected');
  $('#dot-'+counter).find('img').attr('src','/img/banner-dot-sel.png');
}

function setOpacity (obj, opacity) {
	opacity = (opacity == 100)?99.999:opacity;
	obj.style.filter = "alpha(opacity:"+opacity+")"; 
	obj.style.KHTMLOpacity = opacity/100;  
	obj.style.MozOpacity = opacity/101; 
	obj.style.opacity = opacity/100; 
}

function Show(obj, opacity) {
	if (opacity <= 100 && obj) {
		setOpacity(obj, opacity);
		opacity += 10;
		setTimeout(function () { Show(obj, opacity) }, 30); // rekurze na tuto funkci, k provedení dalšího stupně změny průhlednosti
	}
}

function Hide(obj, opacity, img) {
	if (opacity >= 0 && obj) {
		setOpacity(obj, opacity);
		opacity -= 10;
		setTimeout(function () { Hide(obj, opacity, img) }, 30); // rekurze na tuto funkci, k provedení dalšího stupně změny průhlednosti
  	
	}//else{
	// obj.src = img;
	// Show(obj, 0);
	//}
}


/*
* kontrola formularu
*/
function ControlForm(form){
  var errorMessage = '';
  var errorMessageUdaje = '';
  var errorMessageCaptcha = '';
  $('#'+form).find('input').each(function(){
    if ($(this).attr('mandatory') > ''){
      
      if (($(this).attr('type') == 'text')||($(this).attr('type') == 'password')){
      
        if ($(this).val() == ''){
          if ($(this).attr('name').search('mail') != -1){
            if(!EmailControl($(this).val())){
              if ((form == 'finalordform')||(form == 'regform')){
                $(this).css('border','2px solid #a53820');
                $(this).focus(function () {
                  $(this).css('border-left','1px solid #919191');
                  $(this).css('border-top','1px solid #919191');
                  $(this).css('border-right','1px solid #e7e7e7');
                  $(this).css('border-bottom','1px solid #e7e7e7');
                });
              }
              errorMessage = errorMessage + $(this).attr('mandatory') + '<br />';
            }
          }else{
              if ((form == 'finalordform')||(form == 'regform')){
                $(this).css('border','2px solid #a53820');
                $(this).focus(function () {
                  $(this).css('border-left','1px solid #919191');
                  $(this).css('border-top','1px solid #919191');
                  $(this).css('border-right','1px solid #e7e7e7');
                  $(this).css('border-bottom','1px solid #e7e7e7');
                });
              }
              if (($(this).attr('id') == 'email')||($(this).attr('id') == 'telefon')||($(this).attr('id') == 'jmeno')||($(this).attr('id') == 'prijmeni')||($(this).attr('id') == 'ulice')||($(this).attr('id') == 'mesto')||($(this).attr('id') == 'psc')||($(this).attr('id') == 'cp')){
                if (errorMessage == ''){
                  errorMessage = '<strong>Fakturační adresa:</strong><br />' + $(this).attr('mandatory') + '<br />';
                }else{
                  errorMessage = errorMessage + $(this).attr('mandatory') + '<br />';
                }
              }else if (($(this).attr('id') == 'slogin')||($(this).attr('id') == 'spassword')){
                if (errorMessageUdaje == ''){
                  errorMessageUdaje = '<br /><strong>Přihlašovací údaje:</strong><br />' + $(this).attr('mandatory') + '<br />';
                }else{
                  errorMessageUdaje = errorMessageUdaje + $(this).attr('mandatory') + '<br />';
                }
              }else if (($(this).attr('id') == 'captchakod')){
                if (errorMessageCaptcha == ''){
                  errorMessageCaptcha = '<br /><strong>Kontrolní údaj:</strong><br />' + $(this).attr('mandatory') + '<br />';
                }else{
                  errorMessageCaptcha = errorMessageCaptcha + $(this).attr('mandatory') + '<br />';
                }
              }else{
                errorMessage = errorMessage + $(this).attr('mandatory') + '<br />';
              }
          }
        } 
      }else if ($(this).attr('type') == 'checkbox'){
        if (!$(this).is(':checked')){
          if ((form == 'finalordform')||(form == 'regform')){
            $(this).css('border','2px solid #a53820');
            $(this).focus(function () {
                  $(this).css('border-left','1px solid #919191');
                  $(this).css('border-top','1px solid #919191');
                  $(this).css('border-right','1px solid #e7e7e7');
                  $(this).css('border-bottom','1px solid #e7e7e7');
            });
          }
          errorMessage = errorMessage + $(this).attr('mandatory') + '<br />';
        } 
      }  
    }
  });
  
  errorMessageDod = "";
  if ($('#deliveryCheck').is(':checked')){
    
    $('#'+form).find('input').each(function(){
      if ($(this).attr('man') > ''){
        if (($(this).attr('type') == 'text')&&($(this).attr('id').indexOf('-dod') > 0)){
          if ($(this).val() == ''){
              if ((form == 'finalordform')||(form == 'regform')){
                $(this).css('border','2px solid #a53820');
                $(this).focus(function () {
                  $(this).css('border-left','1px solid #919191');
                  $(this).css('border-top','1px solid #919191');
                  $(this).css('border-right','1px solid #e7e7e7');
                  $(this).css('border-bottom','1px solid #e7e7e7');
                });
              }
              if (errorMessageDod == ''){
                errorMessageDod = '<br /><strong>Dodací adresa:</strong><br />' + $(this).attr('man') + '<br />';
              }else{
                errorMessageDod = errorMessageDod + $(this).attr('man') + '<br />';
              }
          }
        }
      }
    });
    
  }
  
  
  $('#'+form).find('textarea').each(function(){
    if ($(this).attr('mandatory') > ''){
      if ($(this).val() == ''){
        if ((form == 'finalordform')||(form == 'regform')){
          $(this).css('border','2px solid #a53820');
          $(this).focus(function () {
            $(this).css('border-left','1px solid #919191');
            $(this).css('border-top','1px solid #919191');
            $(this).css('border-right','1px solid #e7e7e7');
            $(this).css('border-bottom','1px solid #e7e7e7');
          });
        }
        errorMessage = errorMessage + $(this).attr('mandatory') + '<br />';
      } 
    }
  });

  
  if ((errorMessage > '')||(errorMessageDod > '')||(errorMessageCaptcha > '')||(errorMessageUdaje > '')){
    errorMessage = "<br /><br /><br /><div class='messages'>" + errorMessage + errorMessageUdaje + errorMessageDod + errorMessageCaptcha +"</div>"; 
    
    PopupMessages(errorMessage,300,200,'errorMessages');
    return false;
  }else{
    return true;
  }
}


function ControlLoginForm(form){
  var errorMessage = '';
  var errorMessageUdaje = '';
  var errorMessageCaptcha = '';
  $('#'+form).find('input').each(function(){
    if ($(this).attr('man') > ''){
      
      if (($(this).attr('type') == 'text')||($(this).attr('type') == 'password')){
      
        if ($(this).val() == ''){
          //alert($(this).attr('id'));
          if (($(this).attr('id') == 'logininputOrder')||($(this).attr('id') == 'passwordinputOrder')){
            if (errorMessageUdaje == ''){
              errorMessageUdaje = '<br /><strong>Přihlašovací údaje:</strong><br />' + $(this).attr('man') + '<br />';
            }else{
              errorMessageUdaje = errorMessageUdaje + $(this).attr('man') + '<br />';
            }
          }
        } 
      } 
    }
  });
  if (errorMessageUdaje > ''){
    errorMessageUdaje = "<h1>Chyba!</h1><p>Musíte vyplnit všechny povinné pole.<br />Chybně vyplněné pole jsou: </p><div class='messages'>" + errorMessageUdaje + "</div>"; 
    PopupMessages(errorMessageUdaje,300,100,'errorMessages');
    return false;
  }else{
    return true;
  }
}

function EmailControl(f){
    if ((f=='' || f=='vas@email.cz') || f.indexOf('..') != -1 || f.indexOf('.@') != -1 || f.indexOf('@.') != -1 || (f.indexOf('@') < 1 || f.indexOf('@') != f.lastIndexOf('@') || f.lastIndexOf('.') < f.lastIndexOf('@')+2  || f.lastIndexOf('.') > (f.length-3) || f.lastIndexOf('.') < (f.length-4))){
       return false;
      }
    if ((f.indexOf('ř') > -1) || (f.indexOf('ě') > -1) || (f.indexOf('š') > -1) || (f.indexOf('č') > -1) || (f.indexOf('ž') > -1) || (f.indexOf('ý') > -1) || (f.indexOf('á') > -1) || (f.indexOf('í') > -1) || (f.indexOf('é') > -1) || (f.indexOf('ů') > -1) || (f.indexOf('ú') > -1)){
       return false;
    }
    return true;
}

function DelCountBasket(ID){
  document[ID].count.value = 0;
  document[ID].submit();
}

function printDetail(url){
  window.open(url);
  //alert(url);
}

function ControlNumber(){
     if ((event.keyCode <48) || (event.keyCode >57)) event.returnValue = false;
}

function OpenWindow(sUrl,sParam){
  window.open(sUrl,"_blank",sParam);
}	


/*
* lightbox 
*/    

function PopUpBox(obj,sUrl,nWidth,nHeight,sClass){
    obj.click(function(){
       var screens = "";

       var viewportwidth;
       var viewportheight;
       
 
       if (typeof window.innerWidth != 'undefined'){
         viewportwidth = window.innerWidth,
         viewportheight = window.innerHeight
       }else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0){
         viewportwidth = document.documentElement.clientWidth,
         viewportheight = document.documentElement.clientHeight
       }else{
         viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
         viewportheight = document.getElementsByTagName('body')[0].clientHeight
       }

      var height = viewportheight;
      var width = viewportwidth;  

      var scrolledX = document.body.scrollLeft || document.documentElement.scrollLeft || self.pageXOffset || 0; 
      var scrolledY = document.body.scrollTop || document.documentElement.scrollTop || self.pageYOffset || 0;  
      var screenWidth = document.body.clientWidth || document.documentElement.clientWidth || self.innerWidth; 
      //var screenWidth = width;
      var screenHeight = document.body.clientHeight || document.documentElement.clientHeight || self.innerHeight;
      //var screenHeight = height; 


      
      // get the size information on the modal div 
      var divHeight = nHeight; 
      var divWidth = nWidth;       
      
      var left = scrolledX + (screenWidth - nWidth)/2; 
      var top = scrolledY + (height - nHeight)/2; 

  

      // prekryti cernou barvou
      $("<div class='overlay' style='filter: alpha(opacity=75); ZOOM: 1; height: "+document.body.scrollHeight+"px;'></div>").appendTo('body');
      htmlData = "";
      //$.get(sUrl, function(data){
      //  htmlData = data;

        // vytvoreni boxu pro formular
        sHtml = "<div class='"+sClass+"' style='width: "+nWidth+"px; display: block; top: "+top+"px; left: "+left+"px; height:"+nHeight+"px;'>"+
            		"  <div class='content'>"+
            		"     <iframe class='"+sClass+"' src='"+sUrl+"' MARGINWIDTH='0' MARGINHEIGHT='0' frameborder='0' style='width: "+nWidth+"px;height:"+(nHeight)+"px;'></iframe>"+
                "  </div>"+
                "</div>";
    
    
        // priradim html k telu stranky
        //$('html, body').animate({scrollTop:0}, 'slow'); 
        $(sHtml).appendTo('body');
        
        // akce pro tlacitko zavrit
        $('#close-form,#ok-form').click(function(){
          $('.'+sClass, window.parent.document).remove();
          $('.overlay').remove();
          return false;
        });
        $('.overlay').click(function(){
          $('.'+sClass).remove();
          $('.overlay').remove();
        });

      //});


      return false;
    });    
}

$(function() {
		// a workaround for a flaw in the demo system (http://dev.jqueryui.com/ticket/4375), ignore!
		//$( "#dialog:ui-dialog" ).dialog( "destroy" );
	
	 
		$( "#modal-dialog-click").click(function(){
      $('.dostupnostPopUpText').dialog({
  			width: 600,
  			height: 300,
  			modal: true
  		});
    });

});
function hideDialog(){
  $('#addbuy').hide('slow');
}
function SumFinalPrice(){
  $('#finalPrice').html((parseInt($('#pricewithdph').val()) + parseInt($('#deliveryPriceJS').val())  + parseInt($('#paymentPriceJS').val()) ) + ' ' + $('#mena').val());  
}

function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        //carousel.startAuto(0);
        carousel.startAuto();
    });

    carousel.buttonNext.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
 
    carousel.buttonPrev.bind('click', function() {
        //carousel.startAuto(0);
        carousel.startAuto();
    });
 
    carousel.buttonPrev.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
 

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

function PopupMessages(text,nWidth,nHeight,sClass){
      var screens = "";

var viewportwidth;
 var viewportheight;
 
 // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
 
       if (typeof window.innerWidth != 'undefined'){
         viewportwidth = window.innerWidth,
         viewportheight = window.innerHeight
       }else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0){
         viewportwidth = document.documentElement.clientWidth,
         viewportheight = document.documentElement.clientHeight
       }else{
         viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
         viewportheight = document.getElementsByTagName('body')[0].clientHeight
       }

      var height = viewportheight;
      var width = viewportwidth;  

      var scrolledX = document.body.scrollLeft || document.documentElement.scrollLeft || self.pageXOffset || 0; 
      var scrolledY = document.body.scrollTop || document.documentElement.scrollTop || self.pageYOffset || 0;  
      var screenWidth = document.body.clientWidth || document.documentElement.clientWidth || self.innerWidth; 
      //var screenWidth = width;
      var screenHeight = document.body.clientHeight || document.documentElement.clientHeight || self.innerHeight;
      //var screenHeight = height; 


      
      // get the size information on the modal div 
      var divHeight = nHeight; 
      var divWidth = nWidth;       
      
      var left = scrolledX + (screenWidth - nWidth)/2; 
      var top = scrolledY + (height - nHeight)/2; 
      //$('#modal').css('top', top); $('#modal').css('left', left); 
      // prekryti cernou barvou
      $("<div class='overlay' style='filter: alpha(opacity=75); ZOOM: 1; height: "+document.body.scrollHeight+"px;'></div>").appendTo('body');
      htmlData = text;

        // vytvoreni boxu pro formular
        sHtml = "<div class='"+sClass+"' style='width: "+divWidth+"px; display: block; top: "+top+"px; left: "+left+"px; min-height:"+divHeight+"px;'>"+
            		"  <div class='content'>"+
            		"     <img src='/img/close.png' id='close-form' alt='' />"+
                "     "+htmlData+ ""+
                "     <div class='align-center'><img src='/img/ok.png' id='ok-form' alt='' border='0'/></div>"+
                "  </div>"+
                "</div>";
    
    
        // priradim html k telu stranky
        //$('html, body').animate({scrollTop:0}, 'slow'); 
        $(sHtml).appendTo('body');
        
        // akce pro tlacitko zavrit
        $('#close-form,#ok-form').click(function(){
          $('.'+sClass).remove();
          $('.overlay').remove();
        });
        $('.overlay').click(function(){
          $('.'+sClass).remove();
          $('.overlay').remove();
        });
      return false;
}

$.fn.getNodeName = function() {
  // returns the nodeName of the first matched element, or ""   
  return this[0] ? this[0].nodeName : ""; 
}; 


