(function($) {
    $.video = {
        id: "jQueryVideo",
        flashid: "jQueryFlash",
        loadPlayer: false,
        width: 0,
        height: 0,
        backgroundcolor: "",
        opacity: "",
        fadeSpeed: 0
    },
    $.video.initialize = function(options) {
        if (options) {
            for (var propertyName in options) {
                if (typeof ($.video[propertyName]).toString().toLowerCase() != "undefined" && propertyName != "id")
                    $.video[propertyName] = options[propertyName];
            }
        }
    },
    $.video.show = function(videopath, options, flashvarArray) {
        $.video.initialize({
            loadPlayer: false,
            width: 640,
            height: 504,
            backgroundcolor: "#ffffff",
            opacity: "0.7",
            fadeSpeed: 500
        });
        if (options) $.video.initialize(options);
        var intra = (window.location.href.toLowerCase().indexOf("intranet") > 0 ? "/intranet" : "");
        if ($("#" + $.video.id).length == 0) {
            var msgbox = '<table cellpadding="0" cellspacing="0" id="' + $.video.id + '" style="display:none; position:absolute">' +
		        '<tr>' +
			        '<td><img src="' + intra + '/skins/aos2/resources/flashplayer/top_left_graphic.gif" /></td>' +
			        '<td style="background-image: url(\'' + intra + '/skins/aos2/resources/flashplayer/topbar.gif\'); background-repeat: repeat-x;"></td>' +
			        '<td id="' + $.video.id + 'close">' +
			            '<img src="' + intra + '/skins/aos2/resources/flashplayer/button_close.png" style="position: absolute; margin: -11px 0 0 -5px"/>' +
			        '</td>' +
		        '</tr>' +
		        '<tr>' +
			        '<td style="background-image: url(\'' + intra + '/skins/aos2/resources/flashplayer/leftbar.gif\'); background-repeat: repeat-y"></td>' +
			        '<td id="' + $.video.id + 'container"></td>' +
			        '<td style="background-image: url(\'' + intra + '/skins/aos2/resources/flashplayer/leftbar.gif\'); background-repeat: repeat-y"></td>' +
		        '</tr>' +
		        '<tr>' +
			        '<td><img src="' + intra + '/skins/aos2/resources/flashplayer/bottom_left_graphic.gif" /></td>' +
			        '<td style="background-image: url(\'' + intra + '/skins/aos2/resources/flashplayer/bottombar.gif\'); background-repeat: repeat-x;"></td>' +
			        '<td><img src="' + intra + '/skins/aos2/resources/flashplayer/bottom_right_graphic.gif"/></td>' +
		        '</tr>' +
	        '</table>';

            $(msgbox).appendTo($(document.body));
        }
        $("#" + $.video.id + "container").empty();
        $("#" + $.video.id + "container").css({
            backgroundColor: $.video.backgroundcolor
        });
        $("#" + $.video.id + "close").css({
            cursor: "pointer"
        });

        $("#" + $.video.id + "close").click(function() {
            $.video.hide();
        });

        var s1 = new SWFObject(
            !$.video.loadPlayer ? videopath : intra + "/skins/aos2/resources/flashplayer/player.swf",
            "ply",
            $.video.width,
            $.video.height,
            "9",
            $.video.backgroundcolor);
        s1.addParam("allowfullscreen", "true");
        s1.addParam("allowscriptaccess", "always");
        s1.addParam("wmode", "transparent");
        var flashVar = null;
        if (flashvarArray) {
            for (var i = 0; i < flashvarArray.length; i++) {
                flashVar += "&" + flashvarArray[i].Key + "=" + flashvarArray[i].Value;
            }
            flashVar = flashVar.substr(1);
        }
        if ($.video.loadPlayer)
            s1.addParam("flashvars", "file=" + videopath + "&type=video&autostart=true&screencolor=" + $.video.backgroundcolor + "&" + flashVar);
        else
            s1.addParam("flashvars", flashVar);
            
        s1.write($.video.id + "container");

        $("#" + $.video.id).width($.video.width);
        $("#" + $.video.id).height($.video.height);

        $.modal.show($("#" + $.video.id),
            {
                opacity: $.video.opacity,
                fadeSpeed: $.video.fadeSpeed
            }
        );
    },
    $.video.hide = function() {
        $("#" + $.video.id + "container").empty();
        $.modal.hide($("#" + $.video.id));
    }
})(jQuery);