/*
*** 
*/ 
   
   
var timerCarrinho = '';
$(function(){

	$(window).scroll(function(){
        var wtop	 	= $(this).scrollTop();
		var carrinho 	= $('#carrinho-top');
		//var container	= $('#ofertas');
		var cheight 	= $(carrinho).height();
        if( wtop > ( cheight / 2 ) )
        {

            
            $('.logo_off').show();
            $('.busca_off').show();
            $('#carrinho_topo').css({margin: '3px 0px'});
            $(carrinho)
				.css({
                    position: 'fixed',top: '0px',left:'0',display: 'block',background: "url('../imagens/topo/bg_topo_over.gif') no-repeat top right transparent",
                    padding: '10px',color: '#FFF',width: '100%', height: '40px'
                })
				.animate({
					marginTop:  '0px'
				});
                
        }
        else
        {

            $('.logo_off').hide();
            $('.busca_off').hide();   
            $('#carrinho_topo').css({margin: '20px 0px'});				            
            $(carrinho)
				.stop(true, true)
				.css({
                    position: 'relative',
					marginTop: 0,
                    background: 'transparent',
                    color: '#000',
                    width: '200px',
                    border: "none"
                    
                }).removeClass('white');
        }
    });
    

	$('#produtos  li div').draggable({
        scroll: false,
        appendTo: "body",
		helper: 'clone',
        cursor: "pointer",
		start: function()
		{
			clearTimeout( timerCarrinho );
            getItens('');
			$('#carrinho-container').show();
		}
	});

	$('#carrinho-produtos').droppable({
		hoverClass: 'ui-state-hover',
		accept: '.produto-dd',
       
		drop: function( event, ui )
		{
		     
			$(this).find('.adicione').remove();
			var cod = ui.draggable.attr('produto_id')//find('.produto-id').val();
            //alert(cod);
            getItens(cod);
            getItens(cod);

		}
	});

	$('#carrinho-container').mouseenter(function(){
		clearTimeout( timerCarrinho );
	});

	$('#carrinho-container').mouseleave(function(){
		var carrinho = $(this);
		timerCarrinho = setTimeout( function(){
			$(carrinho).slideUp();
		}, 300 );
	});
    
});
