/******************************************************************************/
/*                                                                            */
/*   Script: www.originalnidarky.cz global script                             */
/*   Author: Michal Kobelka                                                   */    
/*           michalkobelka@gmail.com                                          */
/*           EtosComp.eu                                                      */
/*                                                                            */
/******************************************************************************/


/*

  OS & Browser detection

*/
$(document).ready(function() {

  if ($.client.os == "Windows") {
  
    $(".mainmenu a").css('padding', '0px 27px');
    //alert($.client.os);
  
  } else if ($.client.os == "Linux") {
  
    $(".mainmenu a").css('padding', '0px 20px');
    //alert($.client.os);
  
  }

});



/*

  Function which sets the height of the productImage elements to the same value
  
*/
$(document).ready(function() {
  
  var height = 0;
  $(".productImage").each(function() { // Get height of all productImage elements
    
    var backup    = $(this).height();
    var newHeight = parseInt(backup);
    if(newHeight > height) height = newHeight; // Get the most high element
  
  });
  
  $(".productImage").each(function() {
    
    $(this).css("min-height",height); // Set the max value to all productImage elements
  
  });
  
});

/*

  Function which sets the height of the productBoxes to the same value
  
*/
$(document).ready(function() {
  
  var height = 0;
  $(".productBoxMiddle").each(function() { // Get height of all productImage elements
    
    var backup    = $(this).height();
    var newHeight = parseInt(backup);
    if(newHeight > height) height = newHeight; // Get the most high element
  
  });
 
  
  $(".productBoxMiddle").each(function() {
    
    $(this).css("min-height",height); // Set the max value to all productImage elements
  
  });
  
});


/*

  Payment disabling
  
*/

function selectPpl () {
    var a = $("#pay2").attr("checked");
    $(".payLabel1").css("background","url('" + baseUrl + "/images/pay1.png') no-repeat scroll 50% 0px");
    $(".payLabel1").css("color","#942E12");
    $(".payLabel1 span").css("color","#B9A271");
    if(a == false){
        $("#pay1").attr("checked","checked");
    }
    $("#pay1").removeAttr("disabled");
    
    $(".payLabel2").css("background","url('" + baseUrl + "/images/pay2.png') no-repeat scroll 50% 0px");
    $(".payLabel2").css("color","#942E12");
    $(".payLabel2 span").css("color","#B9A271");
    $("#pay2").removeAttr("disabled");

}

function selectPosta() {

    $(".payLabel1").css("background","url('" + baseUrl + "/images/pay1g.png') no-repeat scroll 50% 0px");
    $(".payLabel1").css("color","#999");
    $(".payLabel1 span").css("color","#999");
    $("#pay1").attr("checked","");
    $("#pay1").attr("disabled","disable");
    
    $(".payLabel2").css("background","url('" + baseUrl + "/images/pay2.png') no-repeat scroll 50% 0px");
    $(".payLabel2").css("color","#942E12");
    $(".payLabel2 span").css("color","#B9A271");
    $("#pay2").attr("checked","checked");
    $("#pay2").removeAttr("disabled");

}

function selectOsobne() {

    $(".payLabel1").css("background","url('" + baseUrl + "/images/pay1g.png') no-repeat scroll 50% 0px");
    $(".payLabel1").css("color","#999");
    $(".payLabel1 span").css("color","#999");
    $("#pay1").attr("checked","");
    $("#pay1").attr("disabled","disable");
    
    $(".payLabel2").css("background","url('" + baseUrl + "/images/pay2g.png') no-repeat scroll 50% 0px");
    $(".payLabel2").css("color","#999");
    $(".payLabel2 span").css("color","#999");
    $("#pay2").attr("checked","");
    $("#pay2").attr("disabled","disable");

}

$(document).ready(function() {



  //alert(orderDoprava);

  if(undefined != window.orderDoprava) {
    switch(orderDoprava) {
    
      case "BRNO": selectOsobne(); break;
      case "PRAHA": selectOsobne(); break;
      case "PPL": selectPpl(); break;
      case "POSTA": selectPosta(); break;
    
    }
  }

  // PPL
  $(".delLabel1, #del1").click(function() {
  
    selectPpl();
  
  });
  
  
  // Česká pošta
  $(".delLabel2, #del2").click(function() {
  
    selectPosta();
  
  });


  // Osobní odběr
  $(".delLabel3, #del3, #del4").click(function() {
    
    selectOsobne();
  
  });
  
});



$(document).ready(function() {


  $(".level1").hover(function() {
  
    $(this).css("background","url('" + baseUrl + "/images/active.png') no-repeat scroll 50% 0px");

  }, function() {
  
    $(this).css("background","none");
  
  });

  $(".level0:not(:has(ul))").hover(function() {
  
    $(this).css("background","url('" + baseUrl + "/images/active.png') no-repeat scroll 50% 0px");

  }, function() {
  
    $(this).css("background","none");
  
  });
  
  $(".level0>span>a").hover(function() {
  
    $(this).css("background","url('" + baseUrl + "/images/active.png') no-repeat scroll 50% 0px");

  }, function() {
  
    $(this).css("background","none");
  
  });

  
});

function ajaxChangeGift(productElement) {
    $('#ajaxInput').attr("name","prepocitat").attr("value","Přepočítat");
    $('#orderForm').submit();
    /*
    var quantity = $("#productsGift" + productElement).attr("checked");
    var id = $("#zboziId" + productElement).attr("value");
    $.post(baseUrl + '/order/ajaxgift' ,{"product": '{ "product" : "' + id + '", "checked" : "' + quantity + '"}'}, function(responseJson) {
      if(responseJson == 1) {
        var img=baseUrl + "/images/gift.png";
      } else {
        var img=baseUrl + "/images/giftG.png";
      }
      $("#giftImg" + productElement).attr("src",img);
    });
    return true;
    */
}

function ajaxChangeCart(doprava,uhrada) {
    
    $('#ajaxInput').attr("name","prepocitat").attr("value","Přepočítat");
     $('#orderForm').submit();
    /*
    var ajax = "{";
    if(doprava != "") {
         $("#"+doprava).css("color","red");
         $("#"+doprava).css("background-color","#FFFFEE");
         ajax = ajax + '"doprava" : "' + doprava + '"';
      
    }
    if(uhrada != "") {
      if(ajax !="{") {
        ajax = ajax + ", ";
      }
      $("#"+uhrada).css("color","red");
      $("#"+uhrada).css("background-color","#FFFFEE");
      ajax = ajax + '"uhrada" : "' + uhrada+ '"';
    }
    ajax = ajax + "}";
    $.post(baseUrl + '/order/ajaxcart' ,{"product": ajax}, function(responseJson) {
      if(doprava != "") {
         $("#"+doprava).css("color","#942E12");
         $("#"+doprava).css("background-color","#FFFFFF");
      }
      if(uhrada != "") {
        $("#"+uhrada).css("color","#942E12");
              $("#"+uhrada).css("background-color","#FFFFFF");
      }
    });
    return true;
    */
}