/**
 * @author blazsak
 */
$(document).ready(function(){
   
  //  $("a[rel^='prettyPhoto']").prettyPhoto({
  //    theme: 'light_rounded',
  //    showTitle: false
  //  });
    $("a.fancy").fancybox();
  
    
    $(".textswap").focus(function(){
      //alert('focus');
      var f = $(this);
      var val = f.val();
      if(val == '- wpisz szukaną frazę -') f.val('');
      
    }).blur(function(){
      var f = $(this);
      var val = f.val();
      if(val == '') f.val('- wpisz szukaną frazę -');
    });
    
    $("img[align='right']").css('float', 'right');
    $("img[align='left']").css('float', 'left');
   
   
    $('input[name=dane[shipment]]').change(function(){
        var value = $('input[name=dane[shipment]]:checked').val();
        //alert(value);
        $('.payC').attr('disabled', true);
        if (value) {
          var s1 = value.split('c');
          var s2 = s1[1].split(',');
          for (var x = 0; x < s2.length; x++) {
            if (s2[x]) {
              $('.payC'+s2[x]).removeAttr('disabled');
            }
          }
        }
      
      }).change(); 
    
  
    /**
     * DEBUG
     */
    $("#debug ul.tabs").tabs(".debug-pane-item", {tabs: 'a'});
    $("#debug  a.debug-init").toggle(function(){ $(this).addClass('on'); $('.debug-pane-item-' + $(this).attr('rel')).addClass('on');$('.debug-instance-' + $(this).attr('rel')).show();},function(){ $(this).removeClass('on'); $('.debug-pane-item-' + $(this).attr('rel')).removeClass('on'); $('.debug-instance-' + $(this).attr('rel')).hide();});
    
    
    $('#przelicz').change(function(){przelicz()}).keyup(function(){przelicz()});
    
    
    function przelicz(){
      var ile = parseInt($('#przelicz').val());
      var price = parseFloat($('#p1').val().replace(',','.'));
      var price2 = parseFloat($('#p2').val().replace(',','.'));
      if (isNaN(ile)) 
        ile = 1;
      else {
        if(ile > 999) ile = 999; 
        
        $('#przelicz').val(ile);
      }
      
      if(price2){
        var new_price2 = Math.round(price2 * ile * 100) / 100;
        var new_price = Math.round(price * ile * 100) / 100;
        $('.my-price').html(new_price2.toFixed(2).replace('.',',') + ' zł');
        $('.old-price').html(new_price.toFixed(2).replace('.',',') + ' zł');
        
      }else{
        var new_price = Math.round(price * ile * 100) / 100;
        $('.my-price').html(new_price.toFixed(2).replace('.',',') + ' zł');
      }
  //alert(ile);
  
  
  
    }
    
});

function fontSize(size){
  $('div.page,.el-title,.box-price,.box-title,.box-opis,.product-tabs,.katalog-lista,.price-show,.polecane-product,.polecane-info,.polecane-price').css('font-size',size + 'em');
  
}

function printPage(href){
  window.open(href, '', 'resizable=yes,status=no,location=no,toolbar=no,menubar=no,fullscreen=no,scrollbars=yes,dependent=no,width=700,height=500');
}

