$(function() {

    /**
     * Zmiana obrazków po kliknięciu
     *
     */
    $('.product_image').click(
    function() {
        url = $(this).attr('src');
        url1 = url.replace('_1.', '_0.');
        $('#product_main_image').attr('src', url1);
        
        url2 = url.replace('_1.', '_2.');
        $('#block_ui_product_main_image').attr('src', url2);
    });

    $("#items_to_add").change(function() {
		$("#wishlist_quantity").attr("value",$(this).val());
	});


    /**
     * Zmiana obrazków w wyskakujacym okienku
     *
     */
    $('.block_ui_product_image').click(
    function() {
        url = $(this).attr('src');
        url = url.replace('_1.', '_2.');
        $('#block_ui_product_main_image').attr('src', url);
    });
    
$('#product_main_image').click(function() { 
    $.blockUI(
            
            { 
    // message displayed when blocking (use null for no message) 
    message:  $('#block_ui_images'), 
     
    // styles for the message when blocking; if you wish to disable 
    // these and use an external stylesheet then do this in your code: 
    // $.blockUI.defaults.css = {}; 
    css: {  
        width:          '100%',  
        top:            '5%',
        left:           '0',  
        backgroundColor:'transparent', 
		position:		'absolute',
		'text-align': 	'center',
		margin: '0',
		padding: '0'
    }, 
         
    // z-index for the blocking overlay 
    baseZ: 1000, 
     
    // set these to true to have the message automatically centered 
    centerX: true, // <-- only effects element blocking (page block controlled via css above) 
    centerY: false, 
     
    // allow body element to be stetched in ie6; this makes blocking look better 
    // on "short" pages.  disable if you wish to prevent changes to the body height 
    allowBodyStretch: true, 
     
    // be default blockUI will supress tab navigation from leaving blocking content; 
    constrainTabKey: true, 
     
    // fadeOut time in millis; set to 0 to disable fadeout on unblock 
    fadeOut:  400, 
     
    // suppresses the use of overlay styles on FF/Linux (due to significant performance issues with opacity) 
    applyPlatformOpacityRules: true 

            
            }); 
            
		$('.blockUI').click(function() { 
            $.unblockUI(); 
        });            
		$('#block_ui_images').click(function() { 
            return false;
        });
		
		
        }); 
        
        
    $('#unblock_trigger').click(function() { 
            $.unblockUI(); 
        }); 


	var _avail_form_text = $('#prod_avail_email').val();
	$('#prod_avail_email').click(function (){
		if ($(this).val() == _avail_form_text) {
			$(this).val('');$(this).css('color','#000000');
		}
	});
	$('#prod_avail_email').blur(function (){
		if (!$(this).val()) {
			$(this).val(_avail_form_text);
			$(this).css('color', '#CCCCCC');
		}
	});


});


     function show_product_list(collection_id) {
//        var html = '<img src="images/loader/ajax-loader.gif">';
//        $("#other_from_category").append(html);
        $("#coll_trigger").css("display", "none");
        $.get(
            'default/store_products/ajax-show-product-list',
            {collection_id: collection_id},
            function(response) {
                $('#other_from_category').html(response.html);
            },
            'json'
        );
     }
	  
function quantityPlus(_obj){
	var quantity_obj = $(_obj).parent().find('.quantity-input');
	$(quantity_obj).val(parseInt($(quantity_obj).val()) + 1);
}

function quantityMinus(_obj){
	var quantity_obj = $(_obj).parent().find('.quantity-input');
	if (parseInt($(quantity_obj).val()) > 1)
		$(quantity_obj).val(parseInt($(quantity_obj).val()) - 1);
}

function quantityValid(_obj){
	if (isNaN(parseInt($(_obj).val())))
		$(_obj).val(1);
	$(_obj).val(parseInt($(_obj).val()));
	
}

