var $j = jQuery.noConflict();

$j(document).ready(function () {
    if ($j('a.product-video').length > 0) {
        $j('a.product-video').click(function () {
            var vidPath = $j(this).attr('href');
            var vidTitle = $j(this).attr('name');
            $j.ajax({
                url: '/store/os/product_video.aspx',
                cache: false,
                success: function (html) {
                    $j('#video-popup').html(html);
                    initPopup('#video-popup', '#video-popup .top a');
                    $j('.jp-playlist ul li').html(vidTitle);
                    initVideo(vidPath);
                },
                error: function (e) {
                    alert(e.responseText);
                }
            });
            return false;
        });
    }
    render_cart_header("CartItemsLBGet", "CartTotalLBGet");
});

function initPopup(obj, close) {
    $j('.overlay').show();
    $j('.wrapper').height($j(document).height());
    $j('.wrapper').width($j(window).width());
    $j('.wrapper, ' + obj).show();
    $j(close + ', .wrapper').click(function () {
        $j('.overlay').hide();
        $j('#video-popup').hide();
        $j("#jplayer").jPlayer("clearMedia");
    });

}

function initVideo(vidPath) {
    $j("#jplayer").jPlayer({
        ready: function () {
            $j(this).jPlayer("setMedia", {
                m4v: vidPath
            }).jPlayer("play");
        },
        supplied: "m4v",
        solution: "html, flash",
        swfPath: "/store/os/images/",
        wmode: "transparent",
        backgroundColor: "#fff"
    });

}
