//KM 06 12 11 12:56

var STWD_GLOBAL_URL = "http://mars.stanuschtechnologies.pl/aio/bots/player3/";
var STWD_CATALOG = "multimedialny/";
var STWD_CONFIGFILE = "";
var STWD_AVATAR = "";
var STWD_AVATAR_WIDTH = 700;
var STWD_AVATAR_HEIGHT = 540;

function STWD_Embed(htmelement, config, avatar) {
	if (!config) STWD_CONFIGFILE = STWD_GLOBAL_URL + STWD_CATALOG + "avatar.xml";
    else STWD_CONFIGFILE = config;
	
	if (!avatar) STWD_AVATAR = STWD_GLOBAL_URL + STWD_CATALOG + "avatar.swf";
    else STWD_AVATAR = avatar;
	
    var flashvars = {
        configfile: STWD_CONFIGFILE,
        skin: STWD_AVATAR,
        engine: STWD_GLOBAL_URL + "Common/engine.swf",
        playerId: window.location.href
    };
    var params = {
        menu: "false",
        wmode: "opaque",
        allowScriptAccess: "always"
    };
    var attributes = {
        id: "wd",
        name: "wd"
    };
    swfobject.embedSWF(STWD_GLOBAL_URL + STWD_CATALOG + "loader.swf", htmelement, STWD_AVATAR_WIDTH, STWD_AVATAR_HEIGHT, "9", STWD_GLOBAL_URL + "/Common/expressInstall.swf", flashvars, params, attributes);
}

function STWD_Baner(htmelement, banerswfurl) {
    var flashvars = {
    };
    var params = {
        menu: "false",
        wmode: "opaque"
    };
    var attributes = {
        id: "baner",
        name: "baner"
    };
    swfobject.embedSWF(banerswfurl, htmelement, "234", "505", "9", "", flashvars, params, attributes);
}

function STWD_CloseWd() {
    swfobject.removeSWF("wd");
    $("#avatarwrapper").hide();
}

function STWD_OpenData(param) {
    window.open(param, "wdOpener");
}

function STWD_AnswerQuestion(question) {
    try { document.getElementById("wd").answerQuestion(question); }
    catch (e) { alert(e); }
}

function STWD_ShowPic(url) {
    //$("#avatarwrapper").css("visibility", "hidden");
    //hide2();
    jQuery.slimbox(url);
}

function showAvatar(configFile, avatar, color) {
    if (!color) {
        color = "#000000";
    }
    $('#avatarwrapper').show();
    $('#avatarwrapper').html('<div id="closebtn">X</div><div id="avatar"></div>');
    $('#avatarwrapper').css('z-index', '1000');
    $("#closebtn").css('visibility', 'hidden');

    STWD_Embed("avatar", configFile, avatar);

    //wycentruj
    var bodyWidth = $('body').width();
    var left = parseInt(bodyWidth / 2 - STWD_AVATAR_WIDTH / 2);
    $('#avatarwrapper').css("left", left + "px");
    
    $('#closebtn').css("color", color);

    //$('#avatarwrapper').css("top", "100px");
}

function showCloseBtn() {
    $("#closebtn").hide();
    $("#closebtn").css('visibility', 'visible');
    $("#closebtn").fadeIn('slow');
}

$(function () {
    $('body').prepend('<table><tr><td><div id="avatarwrapper"></div></td></tr></table>');

    $("#avatarwrapper").hide();
    $("#closebtn").live('click', function (event) {
        STWD_CloseWd()

    });
});
