$(document).ready(function(){
    
    var webroot = $('.webroot').attr('id');

    $('.topo .content ul.menu ul').css({ 'display': 'none', 'visibility': 'hidden' });

    $('.topo .content ul.menu').superfish();

    $('div#step').stepy({
        backLabel:      '< Anterior',
        nextLabel:      'Próximo >',
        titleClick:     true,
        finishButton: false
    });

    $('.getState').change(function(){
        $('.loadCity').load(webroot + 'cities/get_cities/' + $(this).val());
    });

    $('.loadCity').change(function(){
        $('.showRepresentantes').hide();
        $('.showRepresentantes').fadeIn();
        $('.showRepresentantes').load(webroot + 'representatives/load/' + $(this).val());
    });

    $('h4.accordio').live('click', function(){
        $('div.accordio').slideUp('normal');
        $(this).next().slideDown('normal');
        return false;
    });
    $('div.accordio').hide();

    $('.data').setMask({
        mask: '99/99/9999'
    });
    $('.fone').setMask({
        mask: '(99) 9999.9999'
    });
    $('.cep').setMask({
        mask: '99999-999'
    });

    /*$('.big-img a').lightBox({
        overlayBgColor: '#000',
        overlayOpacity: 0.6,
        imageLoading: webroot + 'img/site/loading.gif',
        imageBtnClose: webroot + 'img/site/close.gif',
        imageBtnPrev: webroot + 'img/site/prev.gif',
        imageBtnNext: webroot + '/img/site/next.gif',
        containerResizeSpeed: 350,
        txtImage: 'Imagem',
        txtOf: 'de'
    });*/

    $('.slideView a, table.tabela tbody tr a, .content-receita a').fancybox({
        'titlePosition' 	: 'over',
        'titleFormat'       : function(title, currentArray, currentIndex, currentOpts) {
            return '<span id="fancybox-title-over">Imagem ' +  (currentIndex + 1) + ' / ' + currentArray.length + '</span>';
        }
    });

    $(".video").click(function() {
        $.fancybox({
            'padding'		: 0,
            'autoScale'		: false,
            'transitionIn'	: 'none',
            'transitionOut'	: 'none',
            'title'			: this.title,
            'width'		: 680,
            'height'		: 495,
            'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
            'type'			: 'swf',
            'swf'			: {
                'wmode'		: 'transparent',
                'allowfullscreen'	: 'true'
            }
        });

        return false;
    });

    $('.geral ul.chamada li .fabrica, .geral ul.chamada li .multimidia').fadeTo('fast', 0.7);

    $('.geral ul.chamada li .fabrica, .geral ul.chamada li .multimidia').hover(function(){
        $(this).fadeTo('fast', 1.0).css({
            'cursor' : 'pointer'
        });
    },function(){
        $(this).fadeTo('fast', 0.7).css({
            'cursor' : 'pointer'
        });
    });

    var pausePlay = $('a.control').live('click', function(){
        var paused = slider.is(':paused');
        slider.cycle(paused ? 'resume' : 'pause', true);
    });

    var slider = $('.topo .bg-topo .slider-home').cycle({
        fx: 'fade',
        pause: true,
        paused: function(cont, opts, byHover){
            !byHover && pausePlay.html('Resume');
            $('a.control').css({
                'background': 'url("' + webroot + 'img/site/navegacao.png") no-repeat top center'
            }).attr({
                'title': 'Continuar'
            });
        },
        resumed: function(cont, opts, byHover){
            !byHover && pausePlay.html('Pause');
            $('a.control').css({
                'background': 'url("' + webroot + 'img/site/navegacao.png") no-repeat top right'
            }).attr({
                'title': 'Pause'
            });
        },
        timeout: 8000,
        pager: '.navegacao'
    });

    $('.navegacao').append('<a class="control" title="Pause">control</a>');

    $('.topo .bg-topo .slider-home .bg .content .img-produto').reflect({
        height: 0.165
    });

    /*$('.geral .content .slider-produto .img-produto').reflect({
        height: 0.165
    });*/

    $("#slider-produtos").featureCarousel({
        // include options like this:
        // (use quotes only for string values, and no trailing comma after last option)
        // option: value,
        // option: value
        autoPlay: 0,
        trackerIndividual: false,
        trackerSummation: false
    });

    //$('#slider-produto, #thumb-produtos').jcarousel();

    /*$('#slider-produto, #thumb-produtos').movingBoxes({
        startPanel   : 2,      // start with this panel
        width        : 800,    // overall width of movingBoxes (not including navigation arrows)
        panelWidth   : .45,     // current panel width adjusted to 70% of overall width
        buildNav     : true,
        fixedHeight  : true,// if true, navigation links will be added
        navFormatter : function(){
            return "&#9679;";
        } // function which returns the navigation text for each panel
    });*/

    $(".thumbs").carousel({
        vertical: false,
        scrollNext: ".next",
        scrollPrev: ".prev",
        scrollNum: 3,
        circular: false,
        scrollVisible: 3,
        itemHeight: 100,
        itemWidth: 105,
        scrollSpeed : 1000
    });

    $('img[rel^=lightbox]').click(function(){
        $(this).attr('src', function(i, u){
            $(' img.foto-click').attr('src', u).fadeIn();
            $('a[rel^=lightbox]').attr('href', $(this).attr('photo'));
        //alert(u);
        });
        return false;
    });

    $('.espelho').reflect({
        height: 0.165
    });

    $('.geral .content .receitas-relacionadas ul.lista-receitas-relacionadas li:first').css('margin', '0 18px 0 0');
    $('.geral .content .receitas-relacionadas ul.lista-receitas-relacionadas li:last').css('margin', '0 0 0 18px');

    $('.geral .content .bread li:first').css('list-style-image', 'none');
    $('.geral .content .bread li:last a').css({
        'color' : '#cc1419',
        'font-weight' : 'bold',
        'text-decoration' : 'none'
    });

    $('#slideshow').slideView(/*{
        loop: true
    }*/);

    $('.showExtranet').hover(function(){
        $('.link-extranet').fadeIn();
    },function(){
        $('.link-extranet').fadeOut();
    });

    $('.link-extranet').hover(function(){
        $(this).fadeIn();
        //$(this).css({'display': 'block'});
    }, function(){
        $(this).fadeOut();
    });

});
