//<![CDATA[
jQuery.noConflict();

function addToCart(product_id, wait_msg, ok_msg, error_msg, oos_msg){
	jQuery.blockUI({css: {border: 'none',padding: '15px',backgroundColor: '#000','-webkit-border-radius': '10px','-moz-border-radius': '10px',opacity: '.5',color: '#fff'}, message:'<h3>'+wait_msg+'<\/h3>'});

	jQuery.post(SITE_URL+"/add2cart.php",{ product: product_id, quantity:jQuery('#qty').val() },
		function(data){
      if(data=='ok') {
        jQuery.blockUI({ css: {border: 'none',padding: '15px',backgroundColor: '#000','-webkit-border-radius': '10px','-moz-border-radius': '10px',opacity: '.5',color: '#fff'}, message:'<h3>'+ok_msg+'<\/h3>', timeout: 2000 }); 

        jQuery.get(SITE_URL+"/shortcartinfo.php", 
          function(data) {
            var price = jQuery(data).find('price').text();
            var items = jQuery(data).find('items').text();
            
            jQuery('#c_items span').text(items);
            jQuery('#c_price span').text(price);
          },
          'xml');
        
      } else if (data=='OOS') {
        jQuery.blockUI({ css: {border: 'none',padding: '15px',backgroundColor: '#000','-webkit-border-radius': '10px','-moz-border-radius': '10px',opacity: '.5',color: '#fff'}, message:'<h3>'+oos_msg+'<\/h3>', timeout: 2000 });
      } else {
        jQuery.blockUI({ css: {border: 'none',padding: '15px',backgroundColor: '#000','-webkit-border-radius': '10px','-moz-border-radius': '10px',opacity: '.5',color: '#fff'}, message:'<h3>'+error_msg+'<\/h3>', timeout: 2000 });
      }
  });
}

function CartOperations(operation, id, wait_msg, empty_msg){
	jQuery.blockUI({ 
		css: {border: 'none',padding: '15px',backgroundColor: '#000','-webkit-border-radius': '10px','-moz-border-radius': '10px',opacity: '.5',color: '#fff'},
		message:'<h3>'+wait_msg+'<\/h3>',
		timeout: 1500 
	}); 
	
	jQuery.post(SITE_URL+"/cart_operations.php",{
	 operation: operation,
	 id: id,
   qty: jQuery('#qty'+id).val()
	 } ,function(data){
	 	jQuery.post(SITE_URL+"/shortcartinfo.php", { id: id, operation: operation, qty: jQuery('#qty'+id).val() },
      function(data) {
        var price = jQuery(data).find('price').text();
        var items = jQuery(data).find('items').text();
        var qty_x = jQuery(data).find('qty').text();
        var operation_x = jQuery(data).find('operation').text();
        var product_id = jQuery(data).find('product_id').text();
        var product_price = jQuery(data).find('product_price').text();
        var product_price_sub = jQuery(data).find('product_price_sub').text();
        var product_price_vat = jQuery(data).find('product_price_vat').text();
        
        jQuery('#c_items span').text(items);
        jQuery('#c_price span').text(price);
        
        if (qty_x == 0) {operation_x = 'remove'}
        
        if (operation_x == 'remove') {
          jQuery('#pr'+product_id).remove();
        }
        
        if (operation_x == 'update') {
          jQuery('#qty'+product_id).val(qty_x);
          jQuery('#prp'+product_id).text(product_price);
          jQuery('#prs'+product_id).text(product_price_sub);
          jQuery('#prv'+product_id).text(product_price_vat);
          jQuery('#subtotal').text(price);
        }
        
        if (jQuery("table tr").length < 3)
        {
          jQuery('.total').remove();
          jQuery("#s_cart").last().append('<tr><td colspan="7"><strong>'+empty_msg+'</strong></td></tr>');

          jQuery('.c_btn1').hide();
        }
      },
      'xml');
		});
}

jQuery(document).ready(function() {
  jQuery('ul.sf-menu').superfish({
    delay: 1000,
    animation: {opacity:'show',height:'show'},
    speed: 'fast',
    autoArrows: false,
    dropShadows: false
  });
  
  jQuery('#pthumbs a').click(function() {
    var img = jQuery(this).attr('href');
    
    jQuery("#pimage img").fadeOut('slow', function() { 
      jQuery(this).load(function() { jQuery(this).fadeIn(); }); 
      jQuery(this).attr("src", img); 
    }); 
    
    return false;
  });
  
  jQuery('#sb').click(function () {
    if (jQuery('#sb').is(':checked')) {
      jQuery('#shipping_form').slideUp();
    } else {
      jQuery('#shipping_form').slideDown();
    }
  });
  
  jQuery('#isfirm0').click(function () {
    if (jQuery('#isfirm0').is(':checked')) {
      jQuery('#f_form').slideUp();
    }
  });
  
  jQuery('#isfirm1').click(function () {
    if (jQuery('#isfirm1').is(':checked')) {
      jQuery('#f_form').slideDown();
    }
  });
  
  jQuery("#newsletter").validate({
    rules: {
			email: { email: true, required: true }
		}
	});
  
  jQuery("#cf").validate({
    rules: {
      name: {required: true },
      tel: {required: true },
      message: {required: true },
			email: { email: true, required: true }
		}
	});
  
});
//]]>

