﻿String.IsNullOrEmpty = function (value) {
    var isNullOrEmpty = true;
    if (value) {
        if (typeof (value) == 'string') {
            if (value.length > 0)
                isNullOrEmpty = false;
        }
    }
    return isNullOrEmpty;
}

$(document).ready(function () {
    swflinks = $('div.flash-file');
    swflinks.each(function () {
        content = createSwf($(this));
        $(this).replaceWith(content);
    });
});

function createSwf(swf) {
    width = getWidth(swf.attr("class"));
    height = getHeight(swf.attr("class"));
    file = swf.attr("title");
    if (String.IsNullOrEmpty(file)) return "<strong>flash-file div tags require an title<strong>";
    s = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' width='" + width + "' height='" + height + "'><param NAME='wmode' VALUE='opaque'><param name='movie' value='" + file + "' /><!--[if !IE]>--><object type='application/x-shockwave-flash' data='" + file + "' width='" + width + "' height='" + height + "'  wmode='opaque'><!--<![endif]--><p>Alternative content</p><!--[if !IE]>--></object><!--<![endif]--></object>";

    return s;
}

function getWidth(classString) {
    param = "width"
    classes = classString.split(" ");
    for (i = 0; i < classes.length; i++) {
        clazz = classes[i];
        if (clazz.slice(0, param.length) == param) { // starts with
            return clazz.slice(param.length);
        }
    }
    return "979"; // default
}

function getHeight(classString) {
    param = "height"
    classes = classString.split(" ");
    for (i = 0; i < classes.length; i++) {
        clazz = classes[i];
        if (clazz.slice(0, param.length) == param) { // starts with
            return clazz.slice(param.length);
        }
    }
    return "330"; // default
}

