( function($) {
    // we can now rely on $ within the safety of our ?bodyguard? function
    $(document).ready( function() { 

     jQuery('#page-nav li:last-child').css('border','none');

		// Slider 
        var panels_amount = jQuery('.produtoHome').length;

        var panel_width		= 245 ;
        var panels_width	=   ((panels_amount *  panel_width) * -1) + (panel_width * 4);
        var panels_shift	=    (panel_width * 3)*-1;
        var current_shift	= 0;
        
		jQuery('.seta_dir').animate({
                        opacity: 1
                     },1500,'easeInOutSine');
        
        if(panels_amount > 4){
        if(current_shift == 0){
                jQuery('.carousel-nav .back').animate({
                    opacity:0 
                },1000,'easeInOutSine')
         }

        jQuery('.seta_dir').click(function(){
           
            if( current_shift + panels_shift < panels_width  ) //End
            {
                 current_shift =  panels_width;
                 jQuery(this).animate({
                    opacity: 1
                 },500,'easeInOutSine')
                 jQuery('.seta_esq').animate({
                    opacity:1
                },500,'easeInOutSine')
                  //alert('1');                
            }     
            else{
                   current_shift = current_shift +  panels_shift;
                   jQuery(this).animate({
                        opacity: 1
                     },1500,'easeInOutSine');
                jQuery('.seta_esq').animate({
                    opacity:1 
                },1000,'easeInOutSine');
                //alert('2');
            }
        jQuery('#categories-slider').animate({ marginLeft: current_shift}, 800); //Action

        });
        
        jQuery('.seta_esq').click(function(){
        
           if( current_shift - panels_shift > 0){
                    current_shift = 0;
                    
                jQuery(this).animate({
                    opacity:1 
                },500,'easeInOutSine')   
             jQuery('.seta_dir').animate({
                    opacity:1 
                },500,'easeInOutSine')
                    
                    //alert('3'); 
            }
               else{
                   current_shift = current_shift -  panels_shift;
               jQuery('.seta_dir').animate({
                    opacity:1 
                },500,'easeInOutSine')
               
            if(current_shift == 0){
            
                jQuery(this).animate({
                    opacity:1
                },500,'easeInOutSine') 
         }
                   //alert('4'); 
            } 

       jQuery('#categories-slider').animate({ marginLeft: (current_shift) }, 400,'easeInOutSine'); //Action

        });
        }  
        else {
             jQuery('.carousel-nav').hide();
        }     

} ) 
} ) ( jQuery );
