﻿$(function() {

    var scrollpane = $('#playlist .content').jScrollPane({
        scrollbarWidth: 20
    });

    // scroll to active item
    if (scrollpane[0] != null) {
        scrollpane[0].scrollTo($('#playlist .active').position().top);
    }

    // bottom search submit
    $('a.detail').click(function() { $(this).parents('form').submit(); });
    $('a.submit').click(function() { $(this).parents('form').submit(); });

    // contact-lightbox
    $('#open-contact-lightbox').attr('href', $('#open-contact-lightbox').attr('rev'))
        .fancybox({
            'scrolling': 'no',
            'autoDimensions': false,
            'width': 'auto',
            'height': 270,
            'hideOnOverlayClick': false
        });

    $('.contact-lightbox input.button').live('click', function() {
        var form = $('#contact-form');
        $(this).attr("disabled", true);
        $('.ajax-indicator', form).removeClass('invi');

        form.ajaxSubmit({
            success: function(responseText, statusText, xhr, form) {
                $('.contact-lightbox').parent().html(responseText);

                if ($('#contact-form input').length == 0) {
                    setTimeout(function() {
                        $.fancybox.close();
                    }, 5000);
                }
            }
        });

        return false;
    });

    // send-video-to-friend-lightbox
    if ($('#open-send-to-friend').length) {
        $('#open-send-to-friend').click(function() {
            xt_click(this, 'C', Xiti_Number, 'envoi_a_un_ami::' + Xiti_Title, 'A');

            $.fancybox({
                'href': $('#open-send-to-friend').attr('rev') + '?Video=' + $('#open-send-to-friend').attr('rel'),
                'scrolling': 'no',
                'autoDimensions': false,
                'width': 'auto',
                'height': 220,
                'hideOnOverlayClick': false
            });
        });

        $('.send-to-friend input.button').live('click', function() {
            var form = $('#send-to-friend-form');
            $(this).attr("disabled", true);
            $('.ajax-indicator', form).removeClass('invi');

            form.ajaxSubmit({
                success: function(responseText, statusText, xhr, form) {
                    $('.send-to-friend').parent().html(responseText);

                    if ($('#send-to-friend-form input').length == 0) {
                        setTimeout(function() {
                            $.fancybox.close();
                        }, 5000);
                    }
                }
            });

            return false;
        });
    }

    // attachments-lightbox
    if ($('#open-attachments').length) {
        $('#open-attachments').click(function() {
            xt_click(this, 'C', Xiti_Number, 'documents::' + Xiti_Title, 'A');
            $.fancybox({
                'href': $('#open-attachments').attr('rev'),
                'scrolling': 'no',
                'autoDimensions': false,
                'autoScale': true,
                'width': 300,
                'height': 100,
                'hideOnOverlayClick': false
            });
        });
    }

    // download button
    $('#download-video').click(function() {
        xt_click(this, 'C', Xiti_Number, 'telecharger::' + Xiti_Title, 'A');
    });
});
