
$SY = {
    replace_embed: function(embd) {

        if (embd.getAttribute('name') != 'ASP_sct0323_p') {
            var rplc;
            if (embd.outerHTML) {
                var html = embd.outerHTML;
                if (html.match(/wmode\s*=\s*('|")[a-zA-Z]+('|")/i))
                    rplc = html.replace(/wmode\s*=\s*('|")window('|")/i, "wmode='opaque'");
                else rplc = html.replace(/<embed\s/i, "<embed wmode='opaque' ");
                embd.insertAdjacentHTML('beforeBegin', rplc);
                embd.parentNode.removeChild(embd);
            } else {
                rplc = embd.cloneNode(true);
                if (!rplc.getAttribute('wmode') || rplc.getAttribute('wmode') == 'Window')
                    rplc.setAttribute('wmode', 'opaque');
                embd.parentNode.replaceChild(rplc, embd);
            }
        }
    }
    , replace_objct: function(objct) {

        if (objct.getAttribute('name') != 'ASP_sct0323_p') {
            var rplc;
            if (objct.outerHTML) {
                var html = objct.outerHTML;
                if (html.match(/<param\s+name\s*=\s*('|")wmode('|")\s+value\s*=\s*('|")[a-zA-Z]+('|")\s*\/?\>/i))
                    rplc = html.replace(/<param\s+name\s*=\s*('|")wmode('|")\s+value\s*=\s*('|")window('|")\s*\/?\>/i, "<param name='wmode' value='opaque' />");
                else rplc = html.replace(/<\/object\>/i, "<param name='wmode' value='opaque' />\n</object>");
                var chldrn = objct.childNodes;
                for (n = 0; n < chldrn.length; n++) {
                    if (chldrn[n].getAttribute('name').match(/flashvars/i)) {
                        rplc = html.replace(/<param\s+name\s*=\s*('|")flashvars('|")\s+value\s*=\s*('|")[^'"]*('|")\s*\/?\>/i, "<param name='flashvars' value='" + chldrn[n].getAttribute('value') + "' />");
                    }
                }
                objct.insertAdjacentHTML('beforeBegin', rplc);
                objct.parentNode.removeChild(objct);
            }
        }
    }
    , add_event: function(objct, type, fnctn) {
        if (objct.addEventListener) {
            objct.addEventListener(type, fnctn, false); return true;
        } else if (objct.attachEvent) {
            var rtrn = objct.attachEvent('on' + type, fnctn); return rtrn;
        } else {
            objct.onclick = fnctn;
        }
    }
	,
    hash: new Array()
	,
    getkey: function(obj) {
        var k = obj.getAttribute('id');
        if (!k)
            k = obj.getAttribute('name');
        if (!k)
            k = obj.getAttribute('src');
        if (!k)
            return '';
        return k;
    }
    , start: function() {
        var embds = document.getElementsByTagName('embed');

        for (i = 0; i < embds.length; i++) {
            if ($SY.hash[$SY.getkey(embds[i])])
                continue;
            $SY.hash[$SY.getkey(embds[i])] = 1;
            if (embds[i].getAttribute('Q_wmode_exception') != 'true') {
                $SY.replace_embed(embds[i]);
            }
        }
        var objcts = document.getElementsByTagName('object');
        for (i = 0; i < objcts.length; i++) {
            if ($SY.hash[$SY.getkey(objcts[i])])
                continue;
            $SY.hash[$SY.getkey(objcts[i])] = 1;
            if (objcts[i].getAttribute('Q_wmode_exception') != 'true') {
                $SY.replace_objct(objcts[i]);
            }
        }
    }
    , attach: function() {
        //$SY.add_event(window, 'load', $SY.start);
        //setTimeout(function() { $SY.start(); }, 10);
    },
    getCookie: function(check_name) {
        var a_all_cookies = document.cookie.split(';');
        var a_temp_cookie = '';
        var cookie_name = '';
        var cookie_value = '';
        var b_cookie_found = false; // set boolean t/f default f
        for (i = 0; i < a_all_cookies.length; i++) {
            a_temp_cookie = a_all_cookies[i].split('=');
            cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
            if (cookie_name == check_name) {
                b_cookie_found = true;
                if (a_temp_cookie.length > 1) {
                    cookie_value = unescape(a_temp_cookie[1].replace(/^\s+|\s+$/g, ''));
                }
                return cookie_value;
                break;
            }
            a_temp_cookie = false;
            cookie_name = '';
        }
        if (!b_cookie_found) {
            return false;
        }
    },
    getBrowserWidth: function() {
        var winW = 630, winH = 460;

        if (parseInt(navigator.appVersion) > 3) {
            if (navigator.appName == "Netscape") {
                winW = window.innerWidth;
                winH = window.innerHeight;
            }
            if (navigator.appName.indexOf("Microsoft") != -1) {
                winW = document.body.offsetWidth;
                winH = document.body.offsetHeight;
            }
        }
        return winW;
    },
    insertCode: function(tag, str, parent) {
        var div;
        if (parent)
            div = parent;
        else
            div = document.body;
        var element = document.createElement(tag);
        element.innerHTML = str;
        div.appendChild(element);
    },
    progressDiv: null,
    widgetDiv: null,
    getSYUrl1: "http://www.stickeryou.com/widgets/minicliplink.ashx?step=2",
    getSYUrl2: "http://www.stickeryou.com/widgets/miniclip/miniClipMain.aspx",
    baseSYUrl: "www.stickeryou.com",
    getSessionId: function() {
        return $SY.getCookie("PHPSESSID");
    },
    step1: function() {
        //$SY.start();
        var divEditor = document.getElementById("profileEdit");
        divEditor.style.visibility = "hidden";

        divid = "progressIndicator_SY";
        $SY.progressDiv = document.createElement("div");
        $SY.progressDiv.setAttribute("id", divid);
        $SY.progressDiv.style.position = "absolute";
        $SY.progressDiv.style.backgroundColor = "white";
        $SY.progressDiv.style.width = "610px";
        $SY.progressDiv.style.height = "413px";
        $SY.progressDiv.style.border = "medium none";
        $SY.progressDiv.style.padding = "0px";
        $SY.progressDiv.style.overflow = "hidden";
        $SY.progressDiv.style.left = "5px";
        $SY.progressDiv.style.top = "10px";
        $SY.progressDiv.style.display = "block";
        $SY.progressDiv.style.textAlign = "center";
        $SY.progressDiv.style.zIndex = "999999";
        $SY.progressDiv.innerHTML =
            '<div style="position: relative; top: 0px; left: 0px;z-index: 1;">' +
		    '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="610" height="413" id="FlashID" title="loading"' +
            'type="application/x-shockwave-flash" style="z-index:999999;"  codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0">' +
            '<param name="movie" value="http://' + $SY.baseSYUrl + '/widgets/Libs/loading.swf" />' +
            '<param name="wmode" value="opaque" />' +
            '<param name="swfversion" value="9.0.0.0" />' +
            '<embed width="610" height="413" wmode="opaque" menu="false" type="application/x-shockwave-flash" wmode="transparent" src="http://' + $SY.baseSYUrl + '/widgets/Libs/loading.swf"/>' +
            '</object></div>' +
            '<div style="position: relative; float: right; top: -413px; left: 0px;z-index: 200;"><a href="javascript:$SY.closeIntro(); "><img src="http://www.stickeryou.com/widgets/images/close.png" /></a></div>';

        var wrapper = document.getElementById("profiles");
        if (wrapper)
            wrapper.appendChild($SY.progressDiv);
        else
            document.body.appendChild($SY.progressDiv);

        var divid = "syins" + Math.floor(Math.random() * 9999999);
        var div = document.createElement("script");
        div.setAttribute("id", divid);
        div.setAttribute("src", $SY.getSYUrl1 + "&session=" + $SY.getSessionId() + "&rnd=" + Math.floor(Math.random() * 9999999));
        document.body.appendChild(div);
    },
    closeIntro: function() {
        try {
            if ($SY.progressDiv)
                $SY.progressDiv.parentNode.removeChild($SY.progressDiv);
            if ($SY.widgetDiv)
                $SY.widgetDiv.parentNode.removeChild($SY.widgetDiv);
        } catch (e) { }
        
        var divEditor = document.getElementById("profileEdit");
        divEditor.style.visibility = "visible";
    },
    step2: function(itemIds) {
        if ($SY.progressDiv)
            $SY.progressDiv.parentNode.removeChild($SY.progressDiv);
        width = 602;
        // create a popup with iframe and redirect to the url2
        var html = "<div style='background-color:#ffffff; height: 431px; overflow: hidden;'>" +
                 "<iframe style='border:0;overflow:hidden;width:100%; height:100%;background-position:right;' frameborder=0 " +
                 " src='" + $SY.getSYUrl2 + "?itemids=" + itemIds + "&_parentUrl=" + encodeURIComponent(window.location) + "' id='__syWidgetIF' >" +
                 "</iframe>";
+"</div>";
        var divid = "syins" + Math.floor(Math.random() * 9999999);
        $SY.widgetDiv = document.createElement("div");
        $SY.widgetDiv.setAttribute("id", divid);
        $SY.widgetDiv.style.overflow = "hidden";
        $SY.widgetDiv.style.left = "0px";
        $SY.widgetDiv.style.top = "0px";
        $SY.widgetDiv.style.width = width + "px";
        $SY.widgetDiv.style.height = "406px";
        $SY.widgetDiv.style.padding = "10px";
        $SY.widgetDiv.style.display = "block";
        $SY.widgetDiv.style.position = "absolute";
        $SY.widgetDiv.style.backgroundImage = "url(http://" + $SY.baseSYUrl + "/widgets/images/miniclip_popupbg.png)";
        $SY.widgetDiv.style.border = "none";
        $SY.widgetDiv.style.zIndex = "999999";
        var w = $SY.getBrowserWidth() - width;
        w /= 2;
        //div.style.left = w + "px";
        html = html.replace("#pid#", divid);
        $SY.widgetDiv.innerHTML = html;

        var wrapper = document.getElementById("profiles");
        if (wrapper)
            wrapper.appendChild($SY.widgetDiv);
        else
            document.body.appendChild($SY.widgetDiv);
        setTimeout(function() { $SY.iframeChecker(); }, 100);
    },
    iframeChecker: function() {
        iframe = document.getElementById("__syWidgetIF");
        var cmd = window.location.hash;

        if (cmd.length > 1) {
            cmd = cmd.substr(1);
            window.location.hash = "";
        }

        if (cmd == "closeWidget") {
            $SY.widgetDiv.parentNode.removeChild($SY.widgetDiv);
            var divEditor = document.getElementById("profileEdit");
            divEditor.style.visibility = "visible";
        }
        else {
            setTimeout(function() { $SY.iframeChecker(); }, 500);
        }
    }
};
var SY = $SY;
$SY.attach();
//--s_step1