/* ---------------------------------------------
 * kUI - K2 User Interface Library
 * Copyright (c) 2008-2010 Edulence Corp.
 * Developed by Ran Baron, rbaron@edulence.com
 * ---------------------------------------------
 * 
 * coRe classes included with special license for use exclusively within the 
 * K2 System, as an enhancement to the kUI core class.
 * Developed by Ran Baron, core@flyingbaron.com
 * 
 * For details, see the 'coRe' project web site: http://core.flyingbaron.com/
 * -- Last Updated: 2010.02.17
 */

Element.addMethods({
    appendText: function(element, text) {
        element = $(element);
        text = String.interpret(text);
        element.appendChild(document.createTextNode(text));
        return element;
    },
    setScrollOffset: function(element, offset) {
        element = $(element);
        if (arguments.length == 3) { offset = { left: offset, top: arguments[2] }; }
        element.scrollLeft = offset.left;
        element.scrollTop  = offset.top;
        return element;
    },
    getScrollDimensions: function(element) { 
        return { width:$(element).scrollWidth, height:$(element).scrollHeight };
    }
});

Object.extend(document.viewport, {
    getScrollOffset: document.viewport.getScrollOffsets,
    setScrollOffset: function(offset) { Element.setScrollOffset(Prototype.Browser.WebKit ? document.body : document.documentElement, offset); },
    getScrollDimensions: function() { return Element.getScrollDimensions(Prototype.Browser.WebKit ? document.body : document.documentElement); }
});

Prototype.Browser.IE6 = Prototype.Browser.IE && parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5),10)==6;
Prototype.Browser.IE7 = Prototype.Browser.IE && !Prototype.Browser.IE6;

var uiClass = Class.create({
    
    options: {},
    msgs: {
        defBusyMsg : 'Processing, Please Wait...',
        busyMsg    : ''
    },

    initialize: function(options) {    
        this.options = Object.extend(this.options, options || {});
    },
    
    gotoUrl: function (Url, win) { if (win) { newWin = top.window.open(Url,'_blank'); } else { self.location.href = Url; } },
    topGoto: function (Url) { if (top) {  if (kui.win.active()) { setTimeout(kui.cancel,10); } top.location.href = Url; } else { self.location.href = Url; } },

    cancel : function (options) {
        var activeWin = kui.win.active();
        if (activeWin) {
            activeWin.options.reload = (options && options.reload===true) ? true : false;
            activeWin.close(null, options);
        }
        if (options && options.msg) { klGeneric.alert({msg:options.msg, timer:options.timer||2500}) }; 
    }
};

var kui = new uiClass();
var player;
document.observe("dom:loaded", function(){
    try { document.execCommand('BackgroundImageCache', false, true); } catch(e) {}
    Ajax.Responders.register({
        onCreate : function() {
            Ajax.activeRequestCount++;
            var procTxt = (klGeneric.busyMsg.empty()) ? klGeneric.defBusyMsg : klGeneric.busyMsg;
            klGeneric.inAction(procTxt, 1);
        },
        
        onComplete : function() {
            Ajax.activeRequestCount--;
            klGeneric.inAction('', 0);
            klGeneric.busyMsg = '';
        }
    });
    playerReady=function(obj){player=$(obj['id']);} //JW Flash Player
});