$(function(){
    $( "#video_tabs_wrapper").css({
        height:'0',
        width: '0',
        overflow:'hidden'
    });

    video1_count = $('#video_gallery1 img').length;
    video1_show = (video1_count <= 3)?video1_count:3;
    video1_wrap = (video1_count <= 3)?'null':'circular';
    video1_buttons = (video1_count <= 3)?null:'<div></div>';

    video2_count = $('#video_gallery2 img').length;
    video2_show = (video2_count <= 3)?video2_count:3;
    video2_wrap = (video2_count <= 3)?'null':'circular';
    video2_buttons = (video2_count <= 3)?null:'<div></div>';

    $('#video_gallery1').jcarousel({
        scroll: 1,
        wrap: video1_wrap,
        visible: video1_show,
        buttonNextHTML: video1_buttons,
        buttonPrevHTML: video1_buttons,
        initCallback: function(){
            if($('#video_gallery1 img:first-child').attr('src')) {
                $('#video_gallery1 :first-child img:first-child').css('opacity', '1');
            }

            $('#video_gallery1 img').click(function(){
                var thumb = $(this);
                $('#video_gallery1 img').animate({
                    'opacity': '0.5'
                },'fast',function(){
                    thumb.animate({
                        'opacity': '1'
                    },'fast');
                });
                playVideo1(thumb.attr('name'));
            });
        }
    });
    $('#video_gallery2').jcarousel({
        scroll: 1,
        wrap: video2_wrap,
        visible: video2_show,
        buttonNextHTML: video2_buttons,
        buttonPrevHTML: video2_buttons,
        initCallback: function(){
            if($('#video_gallery2 img:first-child').attr('src')) {
                $('#video_gallery2 :first-child img:first-child').css('opacity', '1');
            }

            $('#video_gallery2 img').click(function(){
                var thumb = $(this);
                $('#video_gallery2 img').animate({
                    'opacity': '0.5'
                },'fast',function(){
                    thumb.animate({
                        'opacity': '1'
                    },'fast');
                });
                playVideo2(thumb.attr('name'));
            });
        },
        itemLoadCallback: function(){
            $( "#video_tabs_wrapper").css({
                height:'auto',
                width: 'auto',
                overflow:'auto'
            });
            $( "#video_tabs" ).tabs();
        }
    });
});
