$(function() {

    if ($.browser.msie && ($.browser.version < 7)) {

	$('img[src$=.png]').ifixpng();
	$('div#site-icons a:not(.active) img').hover(
	    function(){
		$(this).css('margin-top', '0');
	    }
	    ,
	    function(){
		$(this).css('margin-top', '-17px');
	    }
	    );
    }

    $('img#stat-btn').click(function(){
	$('div#stat-body').slideToggle('fast');
    });

});

function myTrim(_str) {
    return _str.replace(/^\s+|\s+$/g, '');
}

function isDefined(_var) {
    if (typeof(_var) == 'undefined') {
	return false;
    }
    return true;
}

function updateShoppingCart(iPId, iPCount) {
/*	$.post('/shoppingcart/add/', { id: iPId, count: iPCount }, function(data) {
		$('div#shopping-cart-wrapper').html(data);
	}, 'html'); /**/
}

(function($) {

    $.fn.ourParquetCallBack = function(options) {

	// build main options before element iteration
	var opts = $.extend({}, $.fn.ourParquetCallBack.defaults, options);

	if(this.length > 0) {

	    $this = $(this[0]);
	    var o = $.meta ? $.extend({}, opts, $this.data()) : opts;

	    if(o.url != null) {

		$this.click(function(e){
		    e.preventDefault();
		    $.get(o.url, function(data){
			$.facebox(data);
		    });
		});

		jQuery('#backCallWrapper form').live('submit', function(e){
		    e.preventDefault();
		    var $formEl = jQuery(this);
		    jQuery.ajax({
			url: o.url,
			type: 'post',
			data: jQuery(this).serialize(),
			dataType: 'json',
			success: function(data) {

			    if(data.status == 'error') {
				var $el = $formEl.find('.errorBox').hide().empty();
				jQuery.each(data.data, function(index, value){
				    $el.append('<div>'+value+'</div>');
				});
				$el.show();
			    }

			    if (data.status == 'success') {
				$formEl
				.parent()
				.empty()
				.append('<h2>'+data.msg+'</h2><a href="#" onclick="jQuery(document).trigger(\'close.facebox\');return false;" title="Закрыть">Закрыть&nbsp;[x]</a>');
			    }
			}
		    });
		});
	    }
	}

	return this;
    };

    $.fn.ourParquetCallBack.defaults = {
	url: null
    };

})(jQuery);
