
var SNSupport = {};



var showvideo = function(url, title) {
    // Set up the fadeout div
    var bodies = getElementsByTagAndClassName('body');
    var bodysize = getElementDimensions(bodies[0]);
    var newwidth = bodysize.w;
    var newheight = bodysize.h + 16;
    var newsize = new Dimensions(newwidth, newheight);
    setElementDimensions('fadeout', newsize);
    // Get the size of the viewable area and position the player
    var portsize = getViewportDimensions();
    var portpos = getViewportPosition();
    var newtop = portpos.y + 0.5*(portsize.h - 388);
    var newleft = portpos.x + 0.5*(portsize.w - 435);
    var newposition = new Coordinates(newleft, newtop);
    setElementPosition('lightbox-controls', newposition);
    // Write out the player
    var so = new SWFObject(url, "flash-video", "425", "350", "8", "#423E3D");
    getElement('video-player').innerHTML = so.getSWFHTML();
    getElement('lightbox-controls-title').innerHTML = unescape(title);
    // Boom!
    showElement('fadeout');
    showElement('lightbox-controls');
};

var hidevideo = function() {
    hideElement('fadeout');
    hideElement('lightbox-controls');
    getElement('video-player').innerHTML = '';
};

var getScrollingPosition = function() {
    var position = [0, 0];
    if (typeof window.pageYOffset != 'undefined') {
        position = [window.pageXOffset, window.pageYOffset];
    } else if (typeof document.documentElement.scrollTop != 'undefined'
               && document.documentElement.scrollTop > 0) {
        position = [document.documentElement.scrollLeft, document.documentElement.scrollTop];
    } else if (typeof document.body.scrollTop != 'undefined') {
        position = [document.body.scrollLeft, document.body.scrollTop];
    };
    return position;
};

var getCursorPosition = function(event) {
    if (typeof event == "undefined") {
        event = window.event;
    };
    
    var scrollingPosition = getScrollingPosition();
    var cursorPosition = [0, 0];
    
    if (typeof event.pageX != "undefined" && typeof event.x != "undefined") {
        cursorPosition = [event.pageX, event.pageY];
    } else {
        cursorPosition[0] = event.clientX + scrollingPosition[0];
        cursorPosition[1] = event.clientY + scrollingPosition[1];
    };
    return cursorPosition;
};

var getEventTarget = function(evt) {
    var el;
    if (window.event && window.event.srcElement) {
        el = window.event.srcElement;
    }
    if (evt && evt.target) {
        el = evt.target;
    }
    return el;
};

SNSupport.Padding = function(node) {
    // While this looks like an horrendous kludge that will fail when the
    // padding or border of a node is set in a measure other than pixels it
    // isn't, as Mochikit.DOM.computedStyle(node, style) always returns pixels
    var stripPx = function(px) {
        alert("stripPx() has been called with " + px);
        if (typeof px == 'undefined' || isNaN(parseInt(px.substring(0, px.length - 2)))) {
            return 0;
        } else {
            return parseInt(px.substring(0, px.length - 2));
        }
    };
    this.top = stripPx(computedStyle(node, 'padding-top')) + stripPx(computedStyle(node, 'border-top'));
    alert("WE have been asked to make a padding");
    this.right = stripPx(computedStyle(node, 'padding-right')) + stripPx(computedStyle(node, 'border-right'));
    this.bottom = stripPx(computedStyle(node, 'padding-bottom')) + stripPx(computedStyle(node, 'border-bottom'));
    this.left = stripPx(computedStyle(node, 'padding-left')) + stripPx(computedStyle(node, 'border-left'));
    this.width = this.left + this.right;
    this.height = this.top + this.bottom;
};

var Padding = SNSupport.Padding;



var UsernameWidgetHandler = function (ev) {
    alert("gotcha");
    alert(ev);
};

