// initialize values
function initSTTAF() {
    STTAF.closeButtonUrl = "http://nautanki.tv/site_media/img/delete_org.png";
    STTAF.tafLogo = new Image().src = STTAF.widgetHostUrl + "/common/" + "20080917" + "/themes/" + STTAF.cssTheme + "/images/tafLogo.png";
    STTAF.themeShade = new Image().src = STTAF.widgetHostUrl + "/common/" + "20080917" + "/themes/" + STTAF.cssTheme + "/images/themeShade.png";
    STTAF.tafSpriteImage = new Image().src = STTAF.widgetHostUrl + "/common/" + "20080917" + "/themes/" + STTAF.cssTheme + "/images/tafSpriteImage.png";
    STTAF.headerBg = new Image().src = STTAF.widgetHostUrl + "/common/" + "20080917" + "/themes/" + STTAF.cssTheme + "/images/headerBg.gif";

    STTAF.hig = new Image();
    STTAF.hig.src = STTAF.widgetUrl + "/" + "20080917" + "/images/SPIcons.png";
    STTAF.hih = new Image();
    STTAF.hih.src = STTAF.widgetUrl + "/" + "20080917" + "/images/SPIconsHover.png";
    STTAF.hib = new Image();
    STTAF.hib.src = STTAF.widgetUrl + "/" + "20080917" + "/css/chBG.gif";

    STTAF.hH = 5 + (STTAF.isBlogSelected ? 20 : 0) + (STTAF.isEmailSelected ? 20 : 0) + (STTAF.isIMSelected ? 20 : 0) + (STTAF.isSNSSelected ? 20 : 0);
}

function setT() {
    STTAF.to = setTimeout(function() {checkAndHide(this)}, 500);
}

// function which shows the expandable button hover map
function showHoverMap(obj, id, l, t) {

    // clear time outs if present
    if (STTAF.to) {
        clearTimeout(STTAF.to);
    }

	// setting this property to trigger that the button image is now in focus
	obj.hasFocus = true;

	if (STTAF.isButtonExpandable) {

	// making this for the hover div
	var divIdName = 'hoverDiv';

	// if a hoverDiv is present, then just return and don't do anything
	// this will prevent any multiple hover divs
	var hd = document.getElementById(divIdName);

	// get the x/y position for the hover
    var getPos = getHoverPos(obj);

    // assign the id, link and title
	STTAF.userid = id;

	l = l.toString();
    if (l.indexOf('http%3A%2F%2F') == 0 || l.indexOf('https%3A%2F%2F') == 0) {
        // nothing;
    } else {
        l = encodeURIComponent(l);
    }

    t = t.toString();
	if (STTAF.isEscaped && STTAF.isEscaped == "true") {
	    // nothing
    } else {
        if (STTAF.isEscaped && STTAF.isEscaped == "false") {
            t = escape(t);
        } else {
            // nothing
        }
    }

    if (document.getElementById('st-st-holder')) {
       document.getElementById('st-t-holder').innerHTML = t;
       document.getElementById('st-l-holder').innerHTML = l;
    } else {
        var holderDiv = document.createElement('div');
        holderDiv.setAttribute('id', 'st-st-holder');
        holderDiv.style.display = "none";
        document.body.insertBefore(holderDiv, document.body.firstChild);

        var tHolder = document.createElement('div');
        tHolder.setAttribute('id', 'st-t-holder');
        tHolder.innerHTML = t;

        var lHolder = document.createElement('div');
        lHolder.setAttribute('id', 'st-l-holder');
        lHolder.innerHTML = l;

        holderDiv.appendChild(tHolder);
        holderDiv.appendChild(lHolder);
    }

    // if the div is already present, but hidden (from a previous call)
    // then just show the div at the coordinates
	if (hd && hd.style.display != 'block') {
	    hd.style.display = 'block';
	    hd.style.top = getPos[0];
        hd.style.left = getPos[1];
        return false;
    }

    // if the div is already present and is currently on display,
    // just destroy it
    if (hd && hd.style.display == 'block') {
        hd.parentNode.removeChild(hd);
    }

    // now create the div which will hold the widget
	var cRef = document.createElement('div');
	cRef.setAttribute('id', divIdName);
    var cs = cRef.style;

	cs.margin = '0px';
	cs.padding = '0px';
	cs.border = 0;

    // holds the hover div code in an array
    var tmpArr = [];
    tmpArr.push("<div onmouseover='if (STTAF.to) clearTimeout(STTAF.to); this.hasFocus=true' onmouseout='setT(); this.hasFocus=false' id='hoverDivDiv' style='position: absolute; border:none; width:192px; margin:0; padding:0; background-color: #fff;'><div style='background:url(" + STTAF.widgetUrl + "/css/chBG.gif) repeat-x top; border: 1px solid gray;'><table cellpadding='0' cellspacing='0' style='width:100%;height:100%;margin:0;padding:0;'>");

    if (STTAF.isEmailSelected) {
        tmpArr.push("<tr><td style='padding:0px 4px;font-family:Arial;font-weight:bold;font-size:11px;text-align:left;height:22px;color:#000000;'>Email</td><td style='padding:0px 4px;height:22px;'><div title='Gmail' onclick='setAndFire(document.getElementById(\"st-t-holder\").innerHTML, document.getElementById(\"st-l-holder\").innerHTML ,this,\"email\",\"gmail\");' onmouseover='chgImage(this);' onmouseout='chgImageBack(this);' style='width:24px;height:22px;background:url(" + STTAF.hig.src + ") no-repeat;background-position:-1px -1px;margin:0;padding:0;'></div></td><td style='padding:0px 4px;height:22px;'><div title='MSN / Hotmail / Live' onclick='setAndFire(document.getElementById(\"st-t-holder\").innerHTML, document.getElementById(\"st-l-holder\").innerHTML ,this,\"email\",\"msn\");' onmouseover='chgImage(this);' onmouseout='chgImageBack(this);' style='width:24px;height:22px;background:url(" + STTAF.hig.src + ") no-repeat;background-position:-37px -1px;margin:0;padding:0;'></div></td><td style='padding:0px 4px;height:22px;'><div title='Yahoo Mail' onclick='setAndFire(document.getElementById(\"st-t-holder\").innerHTML, document.getElementById(\"st-l-holder\").innerHTML ,this,\"email\",\"yahoo\");' onmouseover='chgImage(this);' onmouseout='chgImageBack(this);' style='width:24px;height:22px;background:url(" + STTAF.hig.src + ") no-repeat;background-position:-78px -1px;margin:0;padding:0;'></div></td><td style='padding:0px 4px;height:22px;'><div title='Type in addresses' onclick='setAndFire(document.getElementById(\"st-t-holder\").innerHTML, document.getElementById(\"st-l-holder\").innerHTML ,this,\"email\",\"email\");' onmouseover='chgImage(this);' onmouseout='chgImageBack(this);' style='width:24px;height:22px;background:url(" + STTAF.hig.src + ") no-repeat;background-position:-113px -1px;margin:0;padding:0;'></div></td></tr>");
    }

    if (STTAF.isIMSelected) {
        tmpArr.push("<tr><td style='padding:0px 4px;font-family:Arial;font-weight:bold;font-size:11px;text-align:left;height:22px;color:#000000;'>IM</td><td style='padding:0px 4px;height:22px;'><div title='Google Talk' onclick='setAndFire(document.getElementById(\"st-t-holder\").innerHTML, document.getElementById(\"st-l-holder\").innerHTML ,this,\"im\",\"gtalk\");' onmouseover='chgImage(this);' onmouseout='chgImageBack(this);' style='width:24px;height:22px;background:url(" + STTAF.hig.src + ") no-repeat;background-position:-1px -28px;margin:0;padding:0;'></div></td><td style='padding:0px 4px;height:22px;'><div title='MSN / Live Messenger' onclick='setAndFire(document.getElementById(\"st-t-holder\").innerHTML, document.getElementById(\"st-l-holder\").innerHTML ,this,\"im\",\"msn\");' onmouseover='chgImage(this);' onmouseout='chgImageBack(this);' style='width:24px;height:22px;background:url(" + STTAF.hig.src + ") no-repeat;background-position:-37px -28px;margin:0;padding:0;'></div></td><td style='padding:0px 4px;height:22px;'><div title='Yahoo Messenger' onclick='setAndFire(document.getElementById(\"st-t-holder\").innerHTML, document.getElementById(\"st-l-holder\").innerHTML ,this,\"im\",\"yahoo\");' onmouseover='chgImage(this);' onmouseout='chgImageBack(this);' style='width:24px;height:22px;background:url(" + STTAF.hig.src + ") no-repeat;background-position:-78px -28px;margin:0;padding:0;'></div></td><td style='padding:0px 4px;height:22px;'><div title='AOL Instant Messenger' onclick='setAndFire(document.getElementById(\"st-t-holder\").innerHTML, document.getElementById(\"st-l-holder\").innerHTML ,this,\"im\",\"aim\");' onmouseover='chgImage(this);' onmouseout='chgImageBack(this);' style='width:24px;height:22px;background:url(" + STTAF.hig.src + ") no-repeat;background-position:-113px -28px;margin:0;padding:0;'></div></td></tr>");
    }

    if (STTAF.isBlogSelected) {
        tmpArr.push("<tr><td style='padding:0px 4px;font-family:Arial;font-weight:bold;font-size:11px;text-align:left;height:22px;color:#000000;'>Blog</td><td style='padding:0px 4px;height:22px;'><div title='Wordpress' onclick='setAndFire(document.getElementById(\"st-t-holder\").innerHTML, document.getElementById(\"st-l-holder\").innerHTML ,this,\"blog\",\"wordpress\");' onmouseover='chgImage(this);' onmouseout='chgImageBack(this);' style='width:24px;height:22px;background:url(" + STTAF.hig.src + ") no-repeat;background-position:-1px -60px;margin:0;padding:0;'></div></td><td style='padding:0px 4px;height:22px;'><div title='Blogger' onclick='setAndFire(document.getElementById(\"st-t-holder\").innerHTML, document.getElementById(\"st-l-holder\").innerHTML ,this,\"blog\",\"blogger\");' onmouseover='chgImage(this);' onmouseout='chgImageBack(this);' style='width:24px;height:22px;background:url(" + STTAF.hig.src + ") no-repeat;background-position:-37px -60px;margin:0;padding:0;'></div></td><td style='padding:0px 4px;height:22px;'><div title='Live Journal - Coming soon' style='width:24px;height:22px;background:url(" + STTAF.hig.src + ") no-repeat;background-position:-78px -60px;margin:0;padding:0;'></div></td><td style='padding:0px 4px;height:22px;'>&nbsp;</td></tr>");
    }

    if (STTAF.isSNSSelected) {
        tmpArr.push("<tr><td style='padding:0px 4px;font-family:Arial;font-weight:bold;font-size:11px;text-align:left;height:22px;color:#000000;'>Social</td><td style='padding:0px 4px;height:22px;'><div title='Facebook' onclick='setAndFire(document.getElementById(\"st-t-holder\").innerHTML, document.getElementById(\"st-l-holder\").innerHTML ,this,\"sns\",\"fb\");'  onmouseover='chgImage(this);' onmouseout='chgImageBack(this);' style='width:24px;height:22px;background:url(" + STTAF.hig.src + ") no-repeat;background-position:-1px -88px;margin:0;padding:0;'></div></td><td style='padding:0px 4px;height:22px;'><div title='Twitter' onclick='setAndFire(document.getElementById(\"st-t-holder\").innerHTML, document.getElementById(\"st-l-holder\").innerHTML ,this,\"sns\",\"twitter\");' onmouseover='chgImage(this);' onmouseout='chgImageBack(this);' style='width:24px;height:22px;background:url(" + STTAF.hig.src + ") no-repeat;background-position:-37px -88px;margin:0;padding:0;'></div></td><td style='padding:0px 4px;height:22px;'><div style='width:24px;height:22px;background:url(" + STTAF.hig.src + ") no-repeat;background-position:-78px -88px;margin:0;padding:0;'></div></td><td style='padding:0px 4px;height:22px;'><div style='width:24px;height:22px;background:url(" + STTAF.hig.src + ") no-repeat;background-position:-113px -88px;margin:0;padding:0;'></div></td></tr>");
    }

    tmpArr.push("</table></div></div>");

	// this is the hover div code. join used to boost performance in IE
	var text =  tmpArr.join('');

	// assign the hover div code to the hoverDiv and append it to the image as a sibling
	cRef.innerHTML = text;

	cs.zIndex = 2000;
	cs.display = 'block';

    // the hover div needs to be absolutely positioned so that no jumping occurs
    cs.position = 'absolute';

    // and set the hover div to come 1 px below the button
    cs.top = getPos[0];
    cs.left = getPos[1];

    // IE7 fix for jumping
    if (document.getElementById('st-root-div-set')) {
        document.getElementById('st-root-div-set').appendChild(cRef);
    } else {
        var cMain = document.createElement('div');
        cMain.setAttribute('id', 'st-root-div-set');
        cMain.appendChild(cRef);
        document.body.insertBefore(cMain, document.body.firstChild);
    }

	} else {
		return;
	}

}

function getHoverPos(obj) {
    // if absolute location is given, we need the hover div to come up just below the button
    // so get the image height and width
    var iH = obj.offsetHeight;
    var iW = obj.offsetWidth;

    // and the image top and left location
    var iT = obj.offsetTop;
    var iL = obj.offsetLeft;

    // accumulate the total offset top and offset left to get the fixed
    // position
    var parentObj = obj.offsetParent;
    while(parentObj) {
        iT += parentObj.offsetTop || 0;
        iL += parentObj.offsetLeft || 0;
        parentObj = parentObj.offsetParent;
    }

    // get the scroll x/y and window x/y
    var sxy = scrollXY();
    var wxy = windowXY();

    // tricky part here. we need to position the hover map such that
    // if the div goes beyond the browser limits, we reposition it
    // to come right/bottom justified and within the browser
    if ((iT - sxy[1] + STTAF.hH) > wxy[1]) {
        iT = iT - (iH + STTAF.hH);
    }
    if ((iL - sxy[0] + 192) > wxy[0]) {
        iL = iL - (103);
    }

    // and set the hover div location dimensions
    topVal = iT + iH;
    leftVal = iL;

    return [topVal + 'px', leftVal + 'px'];
}

// browser independent method to get the window dimensions
function windowXY(){
    var x = 0;
    var y = 0;
    if (typeof (window.innerWidth) == "number") {
        x = window.innerWidth;
        y = window.innerHeight;
    } else {
        if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
            x = document.documentElement.clientWidth;
            y = document.documentElement.clientHeight;
        } else {
            if(document.body && (document.body.clientWidth || document.body.clientHeight)) {
                x = document.body.clientWidth;
                y = document.body.clientHeight;
            }
        }
    }
    return [x, y];
}

// browser independent method to get the scroll top and left values
function scrollXY(){
    var x = 0;
    var y = 0;
    if (typeof (window.pageYOffset) == "number"){
        x = window.pageXOffset;
        y = window.pageYOffset;
    } else {
        if(document.body && (document.body.scrollLeft || document.body.scrollTop)) {
            x = document.body.scrollLeft;
            y = document.body.scrollTop;
        } else {
            if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
                x = document.documentElement.scrollLeft;
                y = document.documentElement.scrollTop;
            }
        }
    }
    return [x, y];
}


// function triggers hiding the hover map. its starts a timeout instead of closing it instantly
function hideHoverMap(obj) {
	obj.hasFocus = false;
	if (STTAF.isButtonExpandable) {
	    STTAF.to = setTimeout(function() {checkAndHide(obj)}, 500);
	} else {
	    return;
	}
}

// function checks certain conditions before hiding the map
function checkAndHide(obj) {
	var sswid = document.getElementById('divSSWidget');
    if (sswid && STTAF.alertOn) {
        STTAF.to = setTimeout(function() {checkAndHide(obj)}, 500);
        return false;
    }

    var hd = document.getElementById('hoverDiv');
    var hdd = document.getElementById('hoverDivDiv');
    if (!obj.hasFocus && hdd && !hdd.hasFocus) {
        //hd.style.display = 'none';
        return false;
    } else {
        STTAF.to = setTimeout(function() {checkAndHide(obj)}, 500);
        return false;
    }

}

// this method changes the background image for the hover div icons to the hover effect
function chgImage(obj) {
	obj.style.backgroundImage = "url(" + STTAF.hih.src + ")";
	obj.style.backgroundRepeat = "no-repeat";
}

// this method changes the background image for the hover div icons to the non-hover effect
function chgImageBack(obj) {
	obj.style.backgroundImage = "url(" + STTAF.hig.src + ")";
	obj.style.backgroundRepeat = "no-repeat";
}

// this is called on the click of the hover map's icons
function setAndFire(t, l, obj, ch, pr) {
	var sideBar = document.getElementById('sidebar-wrapper');
	if(sideBar){
		sideBar.style.overflow = 'visible';
	}

    STTAF.userid=200812275858
    //STTAF.userid=200812265803

	cw(obj, {id: STTAF.userid, ch: ch, pr: pr, link: l, title: t});
}

// method called to show the widget
function cw(obj, o) {

    // get the data, create and show the widget
	var e = eval (o);
	var cha = e.ch;
	var pr = e.pr;
	var c = e.id + "-cd";

	if (e.link != "") {
	    if (!clickOnButton) {
            if (e.link.toString().indexOf('http%3A%2F%2F') == 0 || e.link.toString().indexOf('https%3A%2F%2F') == 0) {
                // nothing;
            } else {
                e.link = encodeURIComponent(e.link);
            }
		} else {
            // nothing
        }
    }

	if (e.title != "") {
	    if (!clickOnButton) {
	        // nothing
	    } else {
            e.title = escape(e.title);
	    }
    }

    if (STTAF.isPopupMode) {
        var popupH = (GetHeight()/2) - (STTAF.frameHeight/2);
        var popupW = (GetWidth()/2) - (STTAF.frameWidth/2);
        var testJsp = STTAF.widgetUrl + "/widget.jsp?provider=" + pr + "&channel=" + cha + "&id=" + e.id + "&link=" + e.link + "&title=" + e.title;
        var attributes = 'left=' + popupW + ',top=' + popupH + ',width=477,height=517,toolbar=0,resizable=no';
        window.open(testJsp, 'socialtwistPopup', attributes);
        return;
    }

    var hd = document.getElementById('hoverDiv');

    // check if an instance of the widget is already open
    var sswid = document.getElementById('divSSWidget');
    if (sswid) {
        STTAF.alertOn = true;
        if (confirm('An instance of the widget is already open. Discard changes and open a new widget?')) {
            sswid.parentNode.removeChild(sswid);
            STTAF.alertOn = false;
        } else {
            //hd.parentNode.removeChild(hd);
            STTAF.alertOn = false;
            return false;
        }
    }

	// figure out if the button is clicked or something in the hovermap is clicked
	var clickOnButton = false;
    if (hd) {
        clickOnButton = true;
    }

    var cRef = document.createElement('div');
	var divIdName = 'divSSWidget';
	cRef.setAttribute('id', divIdName);

    var cs = cRef.style;

	cRef.innerHTML = "<div id='drag' class='draggable' style='position: absolute; top: 3px; left: 3px; cursor: move; z-index:1000; width: 99%; height: 70px;'>&nbsp;</div>"
				   + "<div id='cb' class='cbutton' align='right' style='position: absolute; top: 11px; right: 8px; cursor: pointer; z-index: 1000; border: 0;'><img style='border:0;' src='" + STTAF.closeButtonUrl + "' onclick='closeWidget(this);'/></div>"
				   + "<iframe id='stcontent' name='stcontent' src='" + STTAF.widgetUrl + "/widget.jsp?provider=" + pr + "&channel=" + cha + "&id=" + e.id + "&link=" + e.link + "&title=" + e.title
				   + "' width='" + STTAF.frameWidth + "px' height='" + STTAF.frameHeight + "px' style='display: block; overflow-x: hidden; overflow-y: hidden;' marginwidth='0' marginheight='0' frameborder='0' scrolling='no' />";

	divCount = '';
	isHoverDiv = false;

    cs.className = 'draggable';
    cs.backgroundColor = 'white';
    cs.position = 'absolute';
    cs.overflowX = "hidden";
	cs.overflowY = "hidden";
	cs.border = '1px solid ' + STTAF.frameBorderColor;
	cs.outline = 'none';
    cs.visibilty = 'visible';
	cs.display = 'block';
	cs.zIndex = 9999;

    if (STTAF.isOverlaySelected) {
        // lets create the overlay
        var overlay = document.createElement('div');
        overlay.setAttribute('id', 'st-overlay');
        var ocs = overlay.style;
        ocs.position = 'fixed';
        ocs.zIndex = 100;
        ocs.top = 0;
        ocs.left = 0;
        ocs.height = '100%';
        ocs.width = '100%';
        ocs.backgroundColor = 'black';
        ocs.filter = 'alpha(opacity: 75)';
        ocs.MozOpacity = 0.75;
        ocs.opacity = 0.75;
        document.body.insertBefore(overlay, document.body.firstChild);
    }

    if (STTAF.isHideFlashSelected) {
        // lets see if we can tackle flash objects
        // hide the flash objects which are visible
        var allEmbeds = document.getElementsByTagName('embed');
        STTAF.embedArray = new Array();
        for (i = 0; i < allEmbeds.length; i++) {
            if (allEmbeds [i].style.visibility = 'visible') {
                allEmbeds[i].style.visibility = 'hidden';
                STTAF.embedArray[i] = allEmbeds[i];
            }
        }
    }

	// now show the widget in the child node depending upon whether the button was clicked
	// or something in the hover map was
	if (clickOnButton) {

		if (document.getElementById('st-root-div-set-wid')) {
            document.getElementById('st-root-div-set-wid').appendChild(cRef);
        } else {
            var cMain = document.createElement('div');
            cMain.setAttribute('id', 'st-root-div-set-wid');
            cMain.appendChild(cRef);
            document.body.insertBefore(cMain, document.body.firstChild);
        }

		//document.getElementById('hoverDiv').parentNode.removeChild(document.getElementById('hoverDiv'));
	} else {
		if (!STTAF.isButtonExpandable) {
		    if (document.getElementById('st-root-div-set-wid')) {
                document.getElementById('st-root-div-set-wid').appendChild(cRef);
            } else {
                var cMain = document.createElement('div');
                cMain.setAttribute('id', 'st-root-div-set-wid');
                cMain.appendChild(cRef);
                document.body.insertBefore(cMain, document.body.firstChild);
            }
		} else {
            if (document.getElementById('st-root-div-set-wid')) {
                document.getElementById('st-root-div-set-wid').appendChild(cRef);
            } else {
                var cMain = document.createElement('div');
                cMain.setAttribute('id', 'st-root-div-set-wid');
                cMain.appendChild(cRef);
                document.body.insertBefore(cMain, document.body.firstChild);
            }
            //document.getElementById('hoverDiv').parentNode.removeChild(document.getElementById('hoverDiv'));
		}
	}

	// get the height and width of the window so that the widget comes up
	// centered
	var h = (GetHeight()/2) - (cRef.offsetHeight/2);
	var w = (GetWidth()/2) - (cRef.offsetWidth/2);

	cs.top = "225px";
	cs.left = "519px";

	Drag.init(cRef);

}

// gets the width of the window
function GetWidth() {
	var x = 0;
	if (self.innerWidth) {
		x = self.innerWidth;
	}
	else if (document.documentElement && document.documentElement.clientHeight) {
   		x = document.documentElement.clientWidth;
	}
	else if (document.body) {
    	x = document.body.clientWidth;
	}
	return x;
}


// gets the height of the window
function GetHeight() {
	var y = 0;
	if (self.innerHeight) {
		y = self.innerHeight + document.documentElement.scrollTop*2;
	}
	else if (document.documentElement && document.documentElement.clientHeight) {
		y = document.documentElement.clientHeight + document.documentElement.scrollTop*2;
	}
	else if (document.body) {
		y = document.body.clientHeight + document.documentElement.scrollTop*2;
	}
	return y;
}

// this method is used by the blogger.com code.
function createWidget(obj, id, link, title, desc){
	var sideBar = document.getElementById('sidebar-wrapper');
	if(sideBar){
		sideBar.style.overflow = 'visible';
	}
	cw(obj, {id: id, link: link, title: title});
}

// returns true for a null/undefined/blank object
function IN(s){
	if(s==N || s==UD || s==B) return T;
	return F;
}

// close the widget when the cross icon is clicked
function closeWidget(obj){
	obj.parentNode.parentNode.parentNode.removeChild(obj.parentNode.parentNode);
	var sideBar = document.getElementById('sidebar-wrapper');
	if(sideBar){
		sideBar.style.overflow = 'hidden';
	}

    if (STTAF.isHideFlashSelected) {
        if (STTAF.embedArray && STTAF.embedArray.length) {
            for (i = 0; i < STTAF.embedArray.length; i++) {
                STTAF.embedArray[i].style.visibility = 'visible';
            }
        }
    }

    if (STTAF.isOverlaySelected) {
        document.getElementById('st-overlay').parentNode.removeChild(document.getElementById('st-overlay'));
    }
}

function prevS(elem) {
    elem = elem.previousSibling;
    STTAF.isEscaped = "true";
    if (elem.tagName == 'A' || elem.tagName == 'a') {
        return escape(elem.innerHTML);
    } else {
        elem = elem.previousSibling;
        return escape(elem.innerHTML);
    }
}

/**************************************************
 * dom-drag.js
 * 09.25.2001
 * www.youngpup.net
 * Script featured on Dynamic Drive (http://www.dynamicdrive.com) 12.08.2005
 **************************************************
 * 10.28.2001 - fixed minor bug where events
 * sometimes fired off the handle, not the root.
 **************************************************/
var Drag = {

	obj : null,

	init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
	{
		o.onmousedown	= Drag.start;

		o.hmode			= bSwapHorzRef ? false : true ;
		o.vmode			= bSwapVertRef ? false : true ;

		o.root = oRoot && oRoot != null ? oRoot : o ;

		if (o.hmode  && isNaN(parseInt(o.root.style.left  ))) o.root.style.left   = "0px";
		if (o.vmode  && isNaN(parseInt(o.root.style.top   ))) o.root.style.top    = "0px";
		if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right  = "0px";
		if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";

		o.minX	= typeof minX != 'undefined' ? minX : null;
		o.minY	= typeof minY != 'undefined' ? minY : null;
		o.maxX	= typeof maxX != 'undefined' ? maxX : null;
		o.maxY	= typeof maxY != 'undefined' ? maxY : null;

		o.xMapper = fXMapper ? fXMapper : null;
		o.yMapper = fYMapper ? fYMapper : null;

		o.root.onDragStart	= new Function();
		o.root.onDragEnd	= new Function();
		o.root.onDrag		= new Function();
	},

	start : function(e)
	{
		var o = Drag.obj = this;
		e = Drag.fixE(e);
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		o.root.onDragStart(x, y);

		o.lastMouseX	= e.clientX;
		o.lastMouseY	= e.clientY;

		if (o.hmode) {
			if (o.minX != null)	o.minMouseX	= e.clientX - x + o.minX;
			if (o.maxX != null)	o.maxMouseX	= o.minMouseX + o.maxX - o.minX;
		} else {
			if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
			if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
		}

		if (o.vmode) {
			if (o.minY != null)	o.minMouseY	= e.clientY - y + o.minY;
			if (o.maxY != null)	o.maxMouseY	= o.minMouseY + o.maxY - o.minY;
		} else {
			if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
			if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
		}

		document.onmousemove = Drag.drag;
		document.onmouseup = Drag.end;

		return false;
	},

	drag : function(e)
	{
		e = Drag.fixE(e);
		var o = Drag.obj;

		var ey	= e.clientY;
		var ex	= e.clientX;
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		var nx, ny;

		if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
		if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
		if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
		if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);

		nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
		ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));

		if (o.xMapper) nx = o.xMapper(y)
		else if (o.yMapper)	ny = o.yMapper(x)

        // adding this code to limit the widget within the browser viewport
        // start here
		var startDrag = true;

        if (ny < 4 || nx < 4) {
            startDrag = false;
        }

		if (startDrag) {
            Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
            Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
		}
        // ends here

		Drag.obj.lastMouseX	= ex;
		Drag.obj.lastMouseY	= ey;

		Drag.obj.root.onDrag(nx, ny);
		return false;
	},

	end : function()
	{
		document.onmousemove = null;
		document.onmouseup   = null;
		Drag.obj.root.onDragEnd(parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]), parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]));
		Drag.obj = null;
	},

	fixE : function(e)
	{
		if (typeof e == 'undefined') e = window.event;
		if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
		if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
		return e;
	}
};
