$(document).ready(function(){

    var pic_start = 1;
    var pic_end   = 24;
    var current_pic = 1;
    var start_stop = 1;
    var direction = 1;
    $("#thumb1").css("border", "solid 3px #d40000");

    function slide_left(){
        if(current_pic > pic_start){
            var shift;
            shift = (current_pic - 1) * 940 * (-1);
            $("#display-carpet").animate({
                left: shift
            })
        }
    }
    function slide_right(){
        if(current_pic <= pic_end){
            var shift;
            shift = (current_pic - 1) * 940 * (-1);
            $("#display-carpet").animate({
                left: shift
            });
        }
    }

    $("#display-left").click(function(){
        if(current_pic > 1)
            current_pic--;
        slide_right();
        $(".pic-selector").css("border", "solid 3px #000");
        $("#thumb"+current_pic).css("border", "solid 3px #d40000");
    });
    $("#display-right").click(function(){
        if(current_pic < 24)
            current_pic++;
        slide_right();
        $(".pic-selector").css("border", "solid 3px #000");
        $("#thumb"+current_pic).css("border", "solid 3px #d40000");
    });

    var slider_animate = 0;

    $(document).everyTime(5000, function(){
        if(slider_animate == 1){
        if(start_stop > 0 && current_pic < 24 && direction == 1){
            if(current_pic > 14){
                $("#thumbs_slider").stop().animate({
                    left: -600
                }, 3000)
            }
            if(current_pic < 24)
                current_pic++;
            slide_right();
            $(".pic-selector").css("border", "solid 3px #000");
            $("#thumb"+current_pic).css("border", "solid 3px #d40000");       
        }else if(start_stop > 0 && current_pic > 1 && direction == 0){
            if(current_pic < 11){
                $("#thumbs_slider").stop().animate({
                    left: 20
                }, 3000)
            }
            if(current_pic > 1)
                current_pic--;
            slide_right();
            $(".pic-selector").css("border", "solid 3px #000");
            $("#thumb"+current_pic).css("border", "solid 3px #d40000");
        }
        if(current_pic == 24)
            direction = 0;
        else if(current_pic == 1)
            direction = 1;
        }
    });

    $("body").mouseover(function(){
        slider_animate = 1;
    })
    $("body").mouseout(function(){
        slider_animate = 2;
    })

    $("#display, .pic-selector, #display-left ,#display-right").mouseover(function(){
        start_stop = -1;
    })
    $("#display, .pic-selector ,#display-left, #display-right").mouseout(function(){
        start_stop = 1;
    })

    $(".pic-selector").click(function(){
       current_pic = parseInt($(this).attr("picN"));
       slide_right();
       $(".pic-selector").css("border", "solid 3px #000");
       $("#thumb"+current_pic).css("border", "solid 3px #d40000");
    })

    $(".menu-btn").click(function(){

        $(".sub-menu").animate({height:0},500)
        $(this).next().next().animate({
            height: $(this).next().next().next().html() * 16
        },500)
        
    })

    $("#display").mouseover(function(){
        $(".pic-description").stop().animate({
            top: 249
        })
    })
    $("#display").mouseout(function(){
        $(".pic-description").stop().animate({
            top: 339
        })
    })

    $(".pic-selector").mouseover(function(){
        $(this).css("z-index", 1000);
        $(this).stop().animate({
            width: 90,
            height: 56,
            top: -14,
            left: -22            
        })
    })
    
    $(".pic-selector").mouseout(function(){
        $(this).css("z-index", 0);
        $(this).stop().animate({
            width: 45,
            height: 28,
            top: 0,
            left: 0
        })
    })

    $(".photo_frame").mouseover(function(){
        $(this).css("border", "solid 1px orange");
    })
    $(".photo_frame").mouseout(function(){
        $(this).css("border", "solid 1px #ccc");
    })

    $('#gallery a').lightBox();

    $(function(){
        if($("#content-display").height() < $("#content-menu").height())
            $("#content-display").height($("#content-menu").height());        
    })

    $(function(){
        if($("#content-display").height() > $("#content-menu").height())
            $("#content-menu").height($("#content-menu").height());
    })

   $("#thumbs-left").mouseover(function(){
       $("#thumbs_slider").stop().animate({
           left: 20
       }, 3000)
   })
   $("#thumbs-right").mouseover(function(){
       $("#thumbs_slider").stop().animate({
           left: -600
       }, 3000)
   })

   /*$("#products-menu a").css("opacity", 0.6);
   $(".menu-titles").css("opacity", 1);

   $("#products-menu a").mouseover(function(){
       $(this).stop().animate({opacity: 1}, 300)
   })
   $("#products-menu a").mouseout(function(){
       $(this).stop().animate({opacity: 0.6}, 1000)
   })
   $(".menu-titles").mouseout(function(){
       $(this).stop().animate({opacity: 1}, 1)
   })*/

   $("#display").click(function(){
       location.href = $("#link"+current_pic).attr("lnk");
   })

   $("#english").click(function(){

       window.alert("The english version of this website is not yet completed, for more info please contact us at info@ciessesistemi.com");

   })
   
})
