﻿
$(document).ready(function(){    
    
    $(window).load(function(){
    
       
        
        $('.try-to-email-me').click(function(){
            se();
            
        });
    });
    
    
    
    
    
   
    
    

    if(window.location.href.indexOf('?churrasco1')!=-1)
    {
        animateAnchor('churrasco1');
    }
    

    // listeners big fields
    var bigFields = $('.big-field');
    bigFields
        .click(function(){
            $(this).select();
        })
        .blur(function(){
            $(this).val($.trim($(this).val()));
            
            if(isNaN($(this).val()) || $(this).val()=='')
            {
                $(this).val('0');
            }
            else $(this).val(parseInt($(this).val()));
        });
    
   
      
    
    // custom checkboxes    
    $('.itens-table input:checkbox').each(function(){
    
        var src;
        if($(this).is(':checked'))
        {
            src = 'on';
        }
        else
        {
            src = 'off';
        }
        
        $(this).hide();
        
        $(this).parent().append('<img src="chk-' + src + '.png">');
        
        $(this).parent().find('img').click(function(){
            
            checkItem($(this));
            
        });
        
    });
    
    // produto - check/uncheck
    
    $('.produto').each(function(){
        
        $(this).click(function(){
            
            checkItem($(this).parent().find('.chk img'));
            
        });
        
    });

});



function checkItem(item)
{
    var chk = item.parent().find('input:checkbox');
    if(chk.is(':checked'))
    {
        chk.removeAttr('checked');
        item.attr('src','chk-off.png');
    }
    else
    {
        chk.attr('checked','checked');
        item.attr('src','chk-on.png');
    }
}

function churrasco()
{
    var tot = 0;
    $('.big-field').each(function(){
        tot += parseInt($(this).val());
    });
    
    if(tot > 0)
    {
        $('#content').submit();
    }
    else
    {
        alert('Para efetuar o cálculo, você precisa inserir o número de pessoas para o churrasco.');
        animateAnchor('step-1');
    }
};


function marcaDesmarcaTodos(grp,act)
{
    var container = $('#' + grp + '-table td.chk');
    var chks = container.find('input:checkbox');
    var imgs = container.find('img');
    
    if(act == 'select')
    {
        chks.attr('checked','checked');
        imgs.attr('src','chk-on.png');
    }
    else
    {
        chks.removeAttr('checked');
        imgs.attr('src','chk-off.png');
    }
    
    
}







function animateAnchor(anchor) {
    
    var uri = "#" + anchor;
    
    anchor = $('#' + anchor);    
    var destination = anchor.offset().top;    

    $("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, 1100 );
    
    setTimeout(function()
    {
        window.location.href = uri;
    },1200);

    return false;
};



//var _actualContent = null;
//function showContent(who, ref)
//{

	//var container = $('#content-box');
    //who = $('#' + who);
    
   // var pos = {};
    //pos.left = $(ref).offset().left - 160;
    //pos.top = $(ref).offset().top + 23;
    
  //  container.find('.content').html(who.html());
   // container.css({top: pos.top, left: pos.left});
    

   // if(container.is(':hidden')) container.fadeIn();
    //else
   // {
     //   if(_actualContent==who.attr('id'))
       // {
      //      container.fadeOut();
        //}
    //}
    
    //_actualContent = who.attr('id');
    
    //setLinks();
//};

//function hideContentBox()
//{
//    var container = $('#content-box');
//    container.fadeOut();
//};
