$(document).ready(function() {

    if($("#player1").length) var myPlayer = VideoJS.setup("player1");

    $('#player1').bind('play',function(){
        $(this).parent('div').expose({
            loadSpeed: 'fast',
            color: '#000',
            opacity: 0.7
        });
    });
    $('#player1,#player2').bind('pause',function(){
        $.mask.close();
    });


    /* cufon */
    Cufon($('.header .menu a'), {
        hover: {
            color: '#333333'
        },
        fontFamily: 'Gotham Black'
    });
    Cufon.replace($('h2'), {
        fontFamily: 'Gotham Black'
    });
    
    Cufon.replace($('.cite'), {
        fontFamily: 'font-normal'
    });

    /* fancybox */
    /*$("a.group, .gallery a").fancybox();*/


    /* eventy gallery */
    var picturesPerSlide = 4;
    var slideWidth = '240px';
    var picturesCount = $('.product-gallery .img').size();
    var slidesCount = Math.ceil( picturesCount / picturesPerSlide );
    var filmBox = $('.product-gallery .wrapper');
    var actualSlide = 1;

    if ( picturesCount > picturesPerSlide ) $('.product-gallery .navigation > div').show();

    $('.product-gallery .next').bind('click', function(){
        if (actualSlide < slidesCount){
            $(filmBox).animate({
                'left': '-=' + slideWidth
            }, 'slow');
            actualSlide++;
        }
    })

    $('.product-gallery .prev').bind('click', function(){
        if (actualSlide > 1){
            $(filmBox).animate({
                'left': '+=' + slideWidth
            }, 'slow');
            actualSlide--;
        }
    })

    var max_news_height = null;
    $(".home_news .item").each(function(){
        var object = $(this);

        if(max_news_height < object.height())
        {
            max_news_height = object.height();
        }
    })
    $(".home_news .item").height(max_news_height);
    $(".home_news:not(.nohover) .item,.news .item:not(.nohover)").hover(
        function(){
            $(this).addClass('item-hover');
        },function(){
            $(this).removeClass('item-hover');
        })

    initExpose($);
    initCycle($);
    initFancy($);
    
});



function initExpose($) {
    var th = $("#video1,#video2");
    if (th.length == 0) return;
    $.getScript('http://cdn.jquerytools.org/1.2.5/all/jquery.tools.min.js', function() {

        });
}

function initCycle($) {
    var th = $(".rotate");
    if (th.length == 0) return;
    $.getScript('uploads/files/js/jquery.cycle.min.js', function() {
        th.cycle({
                    
            });
    });
}



function initFancy($) {
    var th = $(".fancy");
    if (th.length == 0) return;
    var fancyboxShowsUp = true;
    $("#fancybox-footer").hide();
    $.getScript('uploads/files/js/jquery.fancybox.js', function() {



        th.fancybox({
            'padding' 				: 0,
            'transitionIn'			: 'none',
            'transitionOut'			: 'none',
            'overlayOpacity'                    : 0.9,
            'overlayColor'                      : '#000',
            'centerOnScroll'                    : false,
            'autoScale'                         : true,
            'titlePosition'                     : 'inside',
            'hideOnOverlayClick'                : false,
            'showNavArrows'			: true,
            'autoDimensions'                    : true,
            'scrolling'                         : 'no',
            'cyclic'                            : true   ,
            'titleFormat'			: function(title, currentArray, currentIndex, currentOpts)
            {
                return '<span id="fancybox-title-over">' + (title.length ? ' &nbsp; ' + title : '') + '</span>';
            },

            'onStart'               : function(selectedArray, selectedIndex, selectedOpts)
            {
                $("#fancybox-footer").fadeIn();
                $("#fancybox-footer-counter").html((selectedIndex + 1) + ' / ' + selectedArray.length);
                fancyboxShowsUp = false;
            },

            'onClosed'              : function ()
            {
                $("#fancybox-footer").hide();
                fancyboxShowsUp = true;
            }
        });
    });

}
