function showCart() {
	var flip = $('#supperAjaxCart');

	flip.fadeIn('slow', function() {
		flip.css('display','inline');
	});

}
function hideCart() {

	var flip = $('#supperAjaxCart');
	
	flip.fadeOut('slow', function() {
		flip.css('display','none');	
	});

}


$(document).ready(function(){

	/* Слушаем клики */	
	$('.tipVisible').bind('click',function(){
		var tip = $(this).parent();
		
		if(tip.is(':animated'))
			return false;
					
		if(tip.find('.slideOutContent').css('display') == 'none')
		{				
			tip.trigger('slideOut');
			
			showCart();
			
			$.cookie("shopos_ajaxcart_is_opened", 1);
		}else{ 
			hideCart();	
			
			tip.trigger('slideIn');
			
			$.cookie("shopos_ajaxcart_is_opened", null);
		}

	});
	
	$('.slideOutTip').bind('slideOut',function(){

		var tip = $(this);
		var slideOut = tip.find('.slideOutContent');
		
		$('.slideOutTip.isOpened').trigger('slideIn');
		
		if(!tip.data('dataIsSet'))
		{
			tip	.data('origWidth',tip.width())
				.data('origHeight',tip.height())
				.data('dataIsSet',true);
			
			if(tip.hasClass('openTop'))
			{				
				tip.css({
					bottom	: tip.parent().height()-(tip.position().top+tip.outerHeight()),
					top		: 'auto'
				});
				
				tip.find('.tipVisible').css({position:'absolute',bottom:5});
				tip.find('.slideOutContent').remove().prependTo(tip);
			}
			
			if(tip.hasClass('openLeft'))
			{
				tip.css({
					right	: Math.abs(tip.parent().outerWidth()-(tip.position().left+tip.outerWidth())),
					left	: 'auto'
				});
				
				tip.find('.tipVisible').css({position:'absolute',right:10});
			}
		}
				
		tip.addClass('isOpened').animate({
			width	: Math.max($('body').width() - 10,tip.data('origWidth')),
			height	: slideOut.outerHeight()+tip.data('origHeight') - 30
		},function(){
			slideOut.fadeIn();
		});

	}).bind('slideIn',function(){
		var tip = $(this);
		
		tip.find('.slideOutContent').fadeOut('fast',function(){
			tip.animate({
				width	: tip.data('origWidth'),
				height	: tip.data('origHeight')
			},function(){
				tip.removeClass('isOpened');
			});
		});

	});
	
		/* Выполняется при загрузке страницы */
	$('.slideOutTip').each(function(){
		var $is_open = $.cookie("shopos_ajaxcart_is_opened");
		if($is_open != null){
			$('.tipVisible').trigger('click');
		}else{
			$(this).width(35+$(this).find('.tipTitle').width());
		}
	});
});
