$(document).ready(function() {
    (function($) {
        $.fn.extend({
            sui_video: function() {
                this.each(function() {
                    var t = $(this);
                    t.sui_hover().sui_press()
                    .click(function() {
                        var z = $("#sui_video_template").clone();
                        z.removeAttr("id");
                        z.find(".sui_video_header_title").html(t.attr("alt"));
                        var r = /#.*vid:(.+);/.exec(t.attr("href"))[1];
                        /*var m = z.find("param[name='movie']");
                        for (i = 0; i < m.get(0).attributes.length; i++) {
                            if (m.get(0).attributes[i].nodeName == "value") {
                                alert(m.get(0).attributes[i].nodeValue);
                            }
                        }
                        var r = /#.*vid:(.+);/.exec(t.attr("href"))[1];
                        if (m.length > 0) {
                            m.attr("value", m.attr("value").replace(/{VIDEOID}/, r));
                        }*/
                        var m = z.find("embed");
                        if (m.length > 0) {
                            m.attr("src", m.attr("src").replace(/{VIDEOID}/, r));
                        }
                        z.show().sui_moveable({handle_selector:".sui_video_header"}).find(".sui_video_header_close").click(function(){z.sui_moveable("remove");sui.shader.remove_and_hide(".sui_video")});
                        z.removeAttr("id").sui_shader_load({offset_x: "center", offset_y: "center"});
                    });
                });
                return $(this);
            }
        });
    })(jQuery);
    $(".sui_video_thumbnail").sui_video();
    var r = /#.*vid:(.+);/.exec(window.location.hash);
    if (r && r.length == 2) {
        $(".sui_video_thumbnail[href]").each(function() {
            var t = $(this);
            var z = /#.*vid:(.+);/.exec(t.attr("href"));
            if (z && z.length == 2 && z[1] == r[1]) {
                t.triggerHandler("click");
                return false;
            }
            return true;
        });
    }
});

