// FancyPlayer.js - A spicy mix of FancyBox and Flowplayer

function notReady() {

    $(document).ready(function() {

        //if (Modernizr.video.h264 && $.query.get('page') != 'Home' && $.query.get('page') != ""  && $.query.get('page') != 'Catalog' && $.query.get('page') != 'Catalog/Mesh') {

        videoclip = '';
        var player = '';

        

        $(".videoAnchor").hover(function() {
            videoclip = $(this).attr('href');
            $(this).attr({ "href": "#video_box" });
            //$(this).removeAttr("target");

        },

	function() {
	    $(this).attr({ "href": "" + videoclip + "" });
	});

        $(".videoAnchor").fancybox({
            'hideOnContentClick': false,
            'overlayOpacity': .6,
            'zoomSpeedIn': 400,
            'zoomSpeedOut': 400,
            'easingIn': 'easeOutBack',
            'easingOut': 'easeInBack',
            'callbackOnShow': function() {
                player = $f("fancy_div", "../js/flowplayer-3.1.1.swf", {
                    play: { opacity: 0 },
                    clip: {
                        autoPlay: true,
                        autoBuffering: false,
                        url: videoclip,
                        onStart: function(clip) {
                            var wrap = jQuery(this.getParent());
                            var clipwidth = clip.metaData.width;
                            var clipheight = clip.metaData.height;
                            var pos = $.fn.fancybox.getViewport();
                            $("#fancy_outer").css({ width: clipwidth, height: clipheight });
                            $("#fancy_outer").css('left', ((clipwidth + 36) > pos[0] ? pos[2] : pos[2] + Math.round((pos[0] - clipwidth - 36) / 2)));
                            $("#fancy_outer").css('top', ((clipheight + 50) > pos[1] ? pos[3] : pos[3] + Math.round((pos[1] - clipheight - 50) / 2)));
                        },
                        onFinish: function() {
                            $('#fancy_close').trigger('click');
                        }
                    }
                });
                player.load();
                $('#fancy_close').click(function() {
                    $("#fancy_div_api").remove();
                });
            },
            'callbackOnClose': function() {
                $("#fancy_div_api").remove();
            }
        });

        // }
    });

}
