function makeOver(){
    var list = $(".over");
    var lengthList = list.length;
    //
    for(var i=0; i<lengthList; i++){
        var btn = $(list[i]);
        //
        btn.mouseenter(function(e){
            var btnThis = $(this);
            var over = $("#"+btnThis.attr("over"));
            var align = btnThis.attr("align");
            var pos = btnThis.position().left + btnThis.parent().position().left;
            //
            over.show();
            if(align){
                switch(align){
                    case "carousel":
                        if(pos > 240 && pos < 860){
                            over.addClass("tipInverse");
                            pixels = 1;
                        }else{
                            over.removeClass("tipInverse");
                            pixels = 1;
                        }
                        //$(".scroll-content li img").fadeTo(0, 0.5);
                        //btnThis.find("img").fadeTo(0, 1);
                        btnThis.css({
                            zIndex:500
                        });
                        //
                        btnThis.find(".tipClose").click(function(){
                            over.hide();
                        });
                        break;
                    case "category":
                        btnThis.css({
                            zIndex:100
                        });	
                        btnThis.find(".btnFechar").click(function(){
                            $(this).parent().hide();
                        });						
                        break;						
                }	
            }

        });
        btn.mouseleave(function(e){
            var btnThis = $(this);
            var over = $("#"+btnThis.attr("over"));
            var align = btnThis.attr("align");
            //
            over.hide();
            if(align){
                switch(align){
                    case "carousel":
                        //$(".scroll-content li img").fadeTo(0, 1);
                        btnThis.css({
                            zIndex:0
                        });		
                        break;
                    case "category":
                        btnThis.css({
                            zIndex:0
                        });					
                        break;						
                }	
            }

        });
    }
}


var width = 0;
var width_li = 0;
var para  = 0;
var lado = 'left';
var clique_prev = 0;
var clique_next = 0;
var pixels = 1;

function carousel()
{	
    total = $(".scroll-content").css('left');
    total = total.replace("px", "");
    if(para != 1)
    {
        if(-($(".scroll-content").width()-$(".scroll-pane").width()) >= total)
        {
            lado = 'right';
            clique_prev = 0;
            clique_next = 1;
            pixels = 1;
            $(".scroll-content").css('left','-'+($(".scroll-content").width()-$(".scroll-pane").width()-1+'px'));
        }
        else if(total >= 0)
        {
            lado = 'left';
            clique_next = 0;
            clique_prev = 1;
            pixels = 1;
            $(".scroll-content").css('left','-1px');
        }
        else
        {
            if(lado == 'left')
            {
                total -= pixels;
            }
            else
            {
                total = Number(total) + pixels;
            }

            $(".scroll-content").css('left',total+'px');
        }

    }

    setTimeout("carousel()",10);
}
$(document).ready(function(){	
    var list = $(".over");
    var lengthList = list.length;
    width = lengthList * $('.scroll-content li').first().width();	
    width_li = $('.scroll-content li').first().width();
    $(".scroll-content").css('width',width);
    makeOver();
    carousel();



    $(".scroll-pane").hover(
        function () {
            para = 1;
        },
        function () {
            para = 0;
        }
        );

    $(".carPrev").click(function () { 
        lado = 'right';		
        if(clique_prev == 1)
        {
            pixels++;
            if(total >= 0)
            {
                total = 0;	
            }	
            $(".scroll-content").css('left',total+'px');
        }
        else
        {
            clique_prev = 1;
            clique_next = 0;
            pixels = 1;
        }
    });
    $(".carNext").click(function () { 
        lado = 'left';

        if(clique_next == 1)
        {
            pixels++;

            if(-($(".scroll-content").width()-$(".scroll-pane").width()) >= total)
            {
                total = $(".scroll-content").width()-$(".scroll-pane").width();	
            }	

            $(".scroll-content").css('left',total+'px');
        }
        else
        {

            clique_prev = 0;
            clique_next = 1;
            pixels = 1;
        }
    });
});
