﻿/*
* wdscript2 v2.1
* http://www.stanusch.com/
*
* Stanusch Technologies S.A.
*
* Date: 28-04-2011
* Author: Kamil Muichalik
*
* Wymagane skrypty: 1) SWFObject v2.2 - http://code.google.com/p/swfobject 
*                   2) jQuery 1.3.x lub wyższy http://jquery.com/ - gdy isMovable == true
*/
var stwd_adviser = {
    loader: "http://wenus.stanuschtechnologies.pl/players/player3/funduszhipoteczny/loader.swf",
    expressInstall: "http://wenus.stanuschtechnologies.pl/players/player3/Common/expressInstall.swf",
    skin: "http://wenus.stanuschtechnologies.pl/players/player3/funduszhipoteczny/avatar.swf",
    configFile: "http://wenus.stanuschtechnologies.pl/players/player3/funduszhipoteczny/avatar.xml",
    engine: "http://wenus.stanuschtechnologies.pl/players/player3/Common/engine.swf",
    actionId: "",
    currentPage: "",
    playerId: "",
    partitionName: "",
    cookieName: "swtd_cookie_12342",
    wmode: "window",
    width: "276",
    height: "259",
    conatiner: "wdContentOnSite",
    uid: "stwduid",
    isMovable: false, //requeired jQuery 1.3.X
    isOpen: true,
    top: "10%",
    dynamicContainerId: "stwd_dynamic_container_12342",
    wdContainerFormMoving: "wdst",
    wdWrapperForMoving: "wdwrapper",
    wdHeaderForMoving: "wdheader",
    buttonOnImage: "img/button.png",
    buttonOffImage: "img/button.png",
    buttonWidth: "31px",
    buttonHeight: "188px",
    float: "right",
    bcgColor: "#d4dadb",
    saveState: false,
    borderColor: "#d4dadb",
    borderStyle: "solid",
    borderWidth: 1,
    noFlashInfo: "<p>Wymagany Flash Player 9 lub nowszy: <a href='http://get.adobe.com/flashplayer/?promoid=DAFYL'>http://get.adobe.com</a></p>",
    embed: function (actionId) {
        if (actionId) this.actionId = actionId;
        if (this.browserDetect.browser == "Firefox" && parseFloat(this.browserDetect.version) >= 4) {
            // FF4 doesn't support transparent wmode, "transparent" couse Alt key up flash problem, polish signs bug exists
            this.wmode = "window";
        }
        this.flashvars = {
            skin: this.skin,
            configfile: this.configFile,
            engine: this.engine,
            startQuestion: "www_"+this.actionId,
            currentpage: this.currentPage,
            playerId: this.playerId,
            partitionName: this.partitionName
        };
        this.params = {
            menu: "false",
            wmode: this.wmode,
            allowScriptAccess: "always"
        };
        this.attributes = {
            id: this.uid,
            name: this.uid
        };

        if (this.isMovable) {
            if (this.float == 'left')
                $('body').append("<div id='" + stwd_adviser.wdContainerFormMoving + "'><div id='" + this.wdWrapperForMoving + "'></div><div id='" + stwd_adviser.wdHeaderForMoving + "'></div></div>"); //tylko raz!!uwaga funckaja rmove()
            else
                $('body').append("<div id='" + stwd_adviser.wdContainerFormMoving + "'><div id='" + stwd_adviser.wdHeaderForMoving + "'></div><div id='" + this.wdWrapperForMoving + "'></div></div>"); //tylko raz!!uwaga funckaja rmove()
            document.getElementById(this.wdWrapperForMoving).innerHTML = "<div id='" + this.dynamicContainerId + "'>" + stwd_adviser.noFlashInfo + "</div>";

            //state saved in cookie
            if (this.saveState) {
                this.isOpen = (this.cookie() == '1') ? true : false;
            }

            var bcgStr = this.isOpen ? "url(\'" + this.buttonOnImage + "\')" : "url(\'" + this.buttonOffImage + "\')";
            $('#' + stwd_adviser.wdHeaderForMoving).css('background-image', bcgStr);
            $('#' + stwd_adviser.wdHeaderForMoving).css('background-repeat', "no-repeat");
            $('#' + stwd_adviser.wdHeaderForMoving).css('background-color', this.bcgColor);
            $('#' + stwd_adviser.wdWrapperForMoving).css('background-color', this.bcgColor);
            $('#' + stwd_adviser.wdWrapperForMoving).css('border', this.borderWidth + "px  " + this.borderStyle + " " + this.borderColor);
            $('#' + stwd_adviser.wdHeaderForMoving).css('border', this.borderWidth + "px  " + this.borderStyle + " " + this.borderColor);

            $('#' + stwd_adviser.wdHeaderForMoving).css('cursor', "pointer");
            $('#' + stwd_adviser.wdHeaderForMoving).css('width', this.buttonWidth);
            $('#' + stwd_adviser.wdHeaderForMoving).css('height', this.buttonHeight);
            $('#' + this.wdContainerFormMoving).css("width", "auto");
            $('#' + this.wdContainerFormMoving).css("top", this.top);

            //for animate
            $('#' + this.wdWrapperForMoving).css("width", this.width + "px");
            $('#' + this.wdWrapperForMoving).css("height", this.height + "px");

            var tmpWidth = parseInt(this.width) + parseInt(this.borderWidth) * 2;
            if (this.float == 'left') {
                $('#' + stwd_adviser.wdHeaderForMoving).css('border-left-style', "none");
                if (!this.isOpen) {
                    $('#' + this.wdContainerFormMoving).css("left", "-" + tmpWidth + "px");
                }
                else
                    $('#' + this.wdContainerFormMoving).css("left", "0");
                $('#' + this.wdHeaderForMoving).css("float", "left");
                $('#' + this.wdWrapperForMoving).css("float", "left");

            }
            else {
                $('#' + stwd_adviser.wdHeaderForMoving).css('border-right-style', "none");
                if (!this.isOpen)
                    $('#' + this.wdContainerFormMoving).css("right", "-" + tmpWidth + "px");
                else
                    $('#' + this.wdContainerFormMoving).css("right", "0");
                $('#' + this.wdWrapperForMoving).css("float", "left");
                $('#' + this.wdHeaderForMoving).css("float", "left");
            }

            if (!this.isOpen) {
                this.cookie('0', null);
            }
            else {
                this.cookie('1', null);
                this.show();
            }

            if (document.all && !window.opera && !window.XMLHttpRequest) {
                $('#' + this.wdContainerFormMoving).css("position", "absolute");
            }
            else {

                $('#' + this.wdContainerFormMoving).css("position", "fixed");
            }

            swfobject.embedSWF(this.loader, this.dynamicContainerId, this.width, this.height, "9", this.expressInstall, this.flashvars, this.params, this.attributes);

            $("#wdheader").live("click", function () {
                stwd_adviser.toggle();
            });
        }
        else {
            document.getElementById(this.conatiner).innerHTML = "<div id='" + this.dynamicContainerId + "'>" + this.noFlashInfo + "</div>";
            swfobject.embedSWF(this.loader, this.dynamicContainerId, this.width, this.height, "9", this.expressInstall, this.flashvars, this.params, this.attributes);
        }
    },
	showDebugInfo: function(debugContent)
	{
		//alert(debugContent);
	},
    hide: function () {
        this.isOpen = false;
        $('#' + this.wdHeaderForMoving).css('background-image', "url(\'" + this.buttonOffImage + "\')");
        $('#' + this.wdHeaderForMoving).attr("title", "Otwórz");
        $('#' + this.wdWrapperForMoving).css("width", this.width + "px");
        $('#' + this.wdWrapperForMoving).css("height", this.height + "px");
        var tmpWidth = parseInt(this.width) + parseInt(this.borderWidth) * 2;

        if (this.float == 'left') {
            $("#" + this.wdWrapperForMoving).parent().stop().animate({ left: '-' + tmpWidth + 'px' }, function () {
                stwd_adviser.remove();
            });
        }
        else {
            $("#" + this.wdWrapperForMoving).parent().stop().animate({ right: '-' + tmpWidth + 'px' }, function () {
                stwd_adviser.remove();
            });
        }

        //set cookie
        this.cookie('0', null);
    },
    show: function () {
        this.isOpen = true;
        document.getElementById(this.wdWrapperForMoving).innerHTML = "<div id='" + this.dynamicContainerId + "'></div>";

        $('#' + this.wdHeaderForMoving).css('background-image', "url(\'" + this.buttonOnImage + "\')");

        $('#' + stwd_adviser.wdHeaderForMoving).css('background-color', this.bcgColor);
        $('#' + stwd_adviser.wdWrapperForMoving).css('background-color', this.bcgColor);
        $('#' + this.wdHeaderForMoving).attr("title", "Zamknij");
        $('#' + this.wdWrapperForMoving).css("width", this.width + "px");
        $('#' + this.wdWrapperForMoving).css("height", this.height + "px");

        if (this.float == 'left') {
            $("#" + this.wdWrapperForMoving).parent().stop().animate({ left: '0' }, 'slow', function () {
                stwd_adviser.open();
            });
        }
        else {
            $("#" + this.wdWrapperForMoving).parent().stop().animate({ right: '0' }, 'slow', function () {
                stwd_adviser.open();
            });
        }

        //set cookie
        this.cookie('1', null);
    },
    toggle: function () {
        if (this.isOpen) {
            this.hide();
        }
        else {
            this.show();
        }
    },
    close: function () {
    },
    open: function () {
        swfobject.embedSWF(this.loader, this.dynamicContainerId, this.width, this.height, "9", this.expressInstall, this.flashvars, this.params, this.attributes);
    },
    answerQuestion: function (actionId) {
        try { document.getElementById(this.uid).answerQuestion(actionId); }
        catch (e) { }
    },
    remove: function () {
        swfobject.removeSWF(this.uid);
    },
    openData: function (data) {
        window.open(data, "_self");
    },
    cookie: function (value, options) {
        var key = this.cookieName;
        // key and value given, set cookie...
        if (arguments.length > 1 && (value === null || typeof value !== "object")) {
            options = jQuery.extend({}, options);

            if (value === null) {
                options.expires = -1;
            }

            if (typeof options.expires === 'number') {
                var days = options.expires, t = options.expires = new Date();
                t.setDate(t.getDate() + days);
            }

            return (document.cookie = [
                encodeURIComponent(key), '=',
                options.raw ? String(value) : encodeURIComponent(String(value)),
                options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
                options.path ? '; path=' + options.path : '',
                options.domain ? '; domain=' + options.domain : '',
                options.secure ? '; secure' : ''
            ].join(''));
        }

        // key and possibly options given, get cookie...
        options = value || {};
        var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
        return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
    },
    browserDetect: {
        getBrowserName: function () {
            return this.browser;
        },
        getBrowserVersion: function () {
            return this.version;
        },
        getOS: function () {
            return this.OS;
        },
        init: function () {
            this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
            this.version = this.searchVersion(navigator.userAgent)
			    || this.searchVersion(navigator.appVersion)
			    || "an unknown version";
            this.OS = this.searchString(this.dataOS) || "an unknown OS";
        },
        searchString: function (data) {
            for (var i = 0; i < data.length; i++) {
                var dataString = data[i].string;
                var dataProp = data[i].prop;
                this.versionSearchString = data[i].versionSearch || data[i].identity;
                if (dataString) {
                    if (dataString.indexOf(data[i].subString) != -1)
                        return data[i].identity;
                }
                else if (dataProp)
                    return data[i].identity;
            }
        },
        searchVersion: function (dataString) {
            var index = dataString.indexOf(this.versionSearchString);
            if (index == -1) return;
            return parseFloat(dataString.substring(index + this.versionSearchString.length + 1));
        },
        dataBrowser: [
		    {
		        string: navigator.userAgent,
		        subString: "Chrome",
		        identity: "Chrome"
		    },
		    { string: navigator.userAgent,
		        subString: "OmniWeb",
		        versionSearch: "OmniWeb/",
		        identity: "OmniWeb"
		    },
		    {
		        string: navigator.vendor,
		        subString: "Apple",
		        identity: "Safari",
		        versionSearch: "Version"
		    },
		    {
		        prop: window.opera,
		        identity: "Opera"
		    },
		    {
		        string: navigator.vendor,
		        subString: "iCab",
		        identity: "iCab"
		    },
		    {
		        string: navigator.vendor,
		        subString: "KDE",
		        identity: "Konqueror"
		    },
		    {
		        string: navigator.userAgent,
		        subString: "Firefox",
		        identity: "Firefox"
		    },
		    {
		        string: navigator.vendor,
		        subString: "Camino",
		        identity: "Camino"
		    },
		    {		// for newer Netscapes (6+)
		        string: navigator.userAgent,
		        subString: "Netscape",
		        identity: "Netscape"
		    },
		    {
		        string: navigator.userAgent,
		        subString: "MSIE",
		        identity: "Explorer",
		        versionSearch: "MSIE"
		    },
		    {
		        string: navigator.userAgent,
		        subString: "Gecko",
		        identity: "Mozilla",
		        versionSearch: "rv"
		    },
		    { 		// for older Netscapes (4-)
		        string: navigator.userAgent,
		        subString: "Mozilla",
		        identity: "Netscape",
		        versionSearch: "Mozilla"
		    }
	    ],
        dataOS: [
		    {
		        string: navigator.platform,
		        subString: "Win",
		        identity: "Windows"
		    },
		    {
		        string: navigator.platform,
		        subString: "Mac",
		        identity: "Mac"
		    },
		    {
		        string: navigator.userAgent,
		        subString: "iPhone",
		        identity: "iPhone/iPod"
		    },
		    {
		        string: navigator.platform,
		        subString: "Linux",
		        identity: "Linux"
		    }
	    ]

    }

}
stwd_adviser.browserDetect.init();

