﻿var STWD_actionId;
function STWD_Embed(actionId)
{
   STWD_actionId = actionId;
   if ($.cookie(COOKIE_NAME) == '1'){
        $('#wdheader').css('background-image', 'url(\'http://wenus.stanuschtechnologies.pl/players/player3/express/img/zkl_otw.png\')');
        $('#wdheader').attr("title","Otwórz wirtualnego doradcę");
        $("#wdwrapper").show();	
        STWD_OpenWd(actionId);
   }else{
        $('#wdheader').css('background-image', 'url(\'http://wenus.stanuschtechnologies.pl/players/player3/express/img/zkl_zam.png\')');
        $('#wdheader').attr("title","Zamknij wirtualnego doradcę");
        $("#wdwrapper").hide();
        STWD_CloseWd();
   }
}

function STWD_actionInvoked(actionId)
{
	try {document.getElementById("wd").answerQuestion(actionId);}
	catch (e) {}
}

function STWD_OpenWd(actionId)
{
    if(!actionId) actionId = "";
    //element do zast�pienia przez wd
    $('#wdwrapper').append("<div id='wdcontent'><p>You need Flash Player 9 or greater: <a href='http://get.adobe.com/flashplayer/?promoid=DAFYL'>http://get.adobe.com</a></p></div>");
    $('#wdst').css('width', '265px');//IE6
    var flashvars = {
	    skin: "http://wenus.stanuschtechnologies.pl/players/player3/express/avatar.swf",
	    configfile: "http://wenus.stanuschtechnologies.pl/players/player3/express/avatar.xml",
		engine: "http://wenus.stanuschtechnologies.pl/players/player3/Common/engine.swf",
		startQuestion: actionId
    };
    var params = {
        menu: "false",
        wmode: "window",
        allowScriptAccess: "always"
    };
    var attributes = {
        id: "wd",
        name: "wd"
    };
    swfobject.embedSWF("http://wenus.stanuschtechnologies.pl/players/player3/express/loader.swf", "wdcontent", "220", "450", "9","http://preprod.stanusch.com/players/player3/Common/expressInstall.swf", flashvars, params, attributes);
}

function STWD_CloseWd()
{
    $('#wdst').css('width', 'auto'); //IE6
    swfobject.removeSWF("wd");
    
}

function STWD_OpenData(data)
{
	if (data.toString().indexOf('product://') != -1)
	{
		var productId = data.substr(10 ,data.length - 10)
		var urlStr = '/produkt,' + productId + ',p';
		window.open(urlStr,"_self");
	}
	else
	{
		window.open(data,"_self");
	}
}

function STWD_AnswerQuestion(question) {
	try {document.getElementById("wd").answerQuestion(question);}
	catch (e) {alert(e);}
}

var COOKIE_NAME = 'wd_empik_isopen';

$(document).ready(function () 
{
    //$('body').append("<!--[if gte IE 5.5]><![if lt IE 7]><style type=\"text/css\">div#wdst {right: auto; bottom: auto;left: expression( ( 0 - wdst.offsetWidth + ( document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth ) + ( ignoreMe2 = document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ) ) + 'px' );top: expression( ( - 27 - wdst.offsetHeight + ( document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight ) + ( ignoreMe = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ) ) + 'px' );}</style><![endif]><![endif]-->");
    $('body').append("<div id='wdst'><div id='wdheader'></div><div id='wdwrapper'></div></div>");
    
    $("#wdheader").click(function(){
        if ($.cookie(COOKIE_NAME) == '1'){
            $('#wdheader').css('background-image', 'url(\'http://wenus.stanuschtechnologies.pl/players/player3/express/img/zkl_zam.png\')');
            $('#wdheader').attr("title","Otwórz wirtualnego doradcę");
            $("#wdwrapper").hide();
            STWD_CloseWd();
            $.cookie(COOKIE_NAME, '0', null);
        }else{
            $('#wdheader').css('background-image', 'url(\'http://wenus.stanuschtechnologies.pl/players/player3/express/img/zkl_otw.png\')');
            $('#wdheader').attr("title","Zamknij wirtualnego doradcę");
            $("#wdwrapper").show();
            STWD_OpenWd(STWD_actionId);
            $.cookie(COOKIE_NAME, '1', null);
        }
    });
});

