

var fixGlobals = function() {
    window['$'] = function(element) 
    { 
        if (typeof element == 'string') 
            return document.getElementById(element) 
        else 
            return element; 
    }
};
    var originalWindow = window;
    var originalTop = top;

try { //thwart frame busters
    window.originalTop = window.top;
    window.top = window;
    window.parent = window;
} catch (err) { 	//create a dummy window so that we can overwrite the properties

    try
    {
        eval('var window = new Object();');

        var c=0;
        for (var i in originalWindow)
        {
            //screenTop & screenLeft causes a memory leak in IE
            if (i != 'screenTop')            
                if (i != 'screenLeft')            
                    window[i]=originalWindow[i];
        }    
    
        originalWindow.originalTop = originalWindow.top;
        window.self = window;
        window.top = window;
        window.parent = window;

        window.setInterval = function(a,b) { originalWindow.setInterval(a,b); }
        window.setTimeout = function(a,b) { originalWindow.setTimeout(a,b); }
        window.clearInterval = function(a) { originalWindow.clearInterval(a); }
        window.clearTimeout = function(a) { originalWindow.clearTimeout(a); }
        window.attachEvent = function(a,b) { originalWindow.attachEvent(a,b); }

        if (originalWindow.ActiveXObject)
            window.ActiveXObject = originalWindow.ActiveXObject;

        window.event = new Object();

        //some scripts (google video), will add properties to the window
        // object and expect them to be globally available - this
        // will copy properties from our copied window object into the
        // global scope
        fixGlobals = function()
        {
            for (var i in window)
            {
                if (typeof(originalWindow[i]) == "undefined")
                    originalWindow[i] = window[i];
            }	

            //compatibility function for prototype.js
            originalWindow['$'] = function(element) 
            { 
                if (typeof element == 'string') 
                    return document.getElementById(element) 
                else 
                    return element; 
            }

            if (typeof(Element) == "object")
                Element.setStyle = function(element,style)
                {
                    for (var name in style) {
                      element.style[name.camelize()] = style[name];
                    }               
                }
        }
        
    } catch (ex) {
    	originalTop = originalWindow;
    }
}; 
//filter out iframes written by javascript
if (typeof(originalWrite) == "undefined") //don't replace twice
{
	var originalWrite = window.document.write;
	window.document.write = function(val)
	{
		if (!val) { return; }
        if (pageParsed) { return; }
		var lowerVal = val.toString().toLowerCase();

		//don't allow iframes to be added to the page
		if (lowerVal.indexOf("iframe") != -1) return;
		try
		{
			originalWrite(val);
		} catch(ex) { ; } //script has been freed
	}
}