YAHOO.namespace('Rmindr');

var Rmindr = YAHOO.Rmindr;

Rmindr.baseUrl = window.location.protocol +"//"+ window.location.hostname;
//YAHOO.widget.Logger.reset();

YAHOO.widget.Logger.enableBrowserConsole();

/**
 * A function to be used to translate javascript strings to the language of the current locale.
 * To speed things up a bit, the dictionary is already loaded with the current language
 * 
 * @param translation | The english string to translate
 */
 function _(translation) {
 	if((hasKey = eval("Language.dictionary.db[translation]")) != undefined) {
              return hasKey;
        } else return translation;
 }
 
 Rmindr.inArray = function(arr, val) {
    if (arr instanceof Array) {
        for (var i = (arr.length -1); i >= 0; i--) {
            if (arr[i] === val) {
                return true;
            }
        }
    }
    return false;
}

 
 
 /**
  * function that performs bucket sort
  *
  * @param int[] a
  * @param int m
  *
  */
 Rmindr.bucketSort = function(a,m) {
 	var buckets = new Array(m);
 	for(var j=0; j<m; ++j)
 		buckets[j] = 0;
 	for(var i = 0; i < a.length; ++i)
 		++buckets [a [i]];
	for(var i = 0, j = 0; j < m; ++j)
		for(k = buckets [j]; k > 0; --k)
			a [i++] = j;
			
	return a;
 }
 
 

/**
 * Perform a close function when the user clicks outside of an element
 *
 * @author Jimmy Stridh
 * @since 2007-07-23
 * @param HtmlElement elementToWatch the element to ignore clicks on
 * @param function closeFunction the function to execute on outside clicks
 * @param HtmlElement elementToIgnore element to also ignore clicks on or Array of HtmlElement
 * @return false if the click was on an element that should be ignored, true otherwise.
 */
Rmindr.closeOnOutsideClick = function(elementToWatch,closeFunction,elementToIgnore,scope) {
    this.closeFunction = closeFunction;
    this.elementToWatch = elementToWatch;
    this.elementToIgnore = elementToIgnore;
    this.scope = scope;
    //Bind onclick listener to the document
    this.active = true;
    this.bindListener();
    
}

Rmindr.closeOnOutsideClick.prototype = {
    _outSideClickCheck : function(ev,obj) {
    	
        var el = YAHOO.util.Event.getTarget(ev);
        //Walk up the tree from the clicked node
        while(el.parentNode){
        	if(el==this.elementToWatch){
        		//We had a click on an element that should be ignored
				return false;
            } else if (typeof(this.elementToIgnore) == 'object' && typeof(this.elementToIgnore.length) == 'undefined' && el == this.elementToIgnore) {
            	return false;
            } else if (typeof(this.elementToIgnore) == 'object' && typeof(this.elementToIgnore.length) == 'number') {
            	for (var i = 0; i < this.elementToIgnore.length; i++) {
            		if (el == this.elementToIgnore[i])
            			return false;
            	}
            }
            el = el.parentNode;
        }
        this.closeFunction();
        
        //Stop listening to clicks on the Document object
        this.removeListener();
    },
    
    bindListener: function() {
    	this.callback = Rmindr.FunctionStuff.bind(this._outSideClickCheck, this);
    	YAHOO.util.Event.addListener(document.body, 'click', this.callback,this);
    },
    
    /**
     * Removes listener on the document object
     */
    removeListener : function() {
        YAHOO.util.Event.removeListener(document.body,'click');
        this.active = false;
    }
}

/**
 * Bind a function to a new scope.
 */
Rmindr.FunctionStuff = {
		bind: function (func, scope) {
		return function () {
			return func.apply (scope, arguments);
		}
	}
}


/*
Browser = new BrowserUtils();

function PNGswap(myID)
{
	var strOver  = "_over";
	var strOff = "_up";
	var oImg = document.getElementById(myID);
	if(Browser.isIE && Browser.version < 7) {
		var currentAlphaImg = oImg.filters(0).src;
		if (currentAlphaImg.indexOf(strOver) != -1)
			oImg.filters(0).src = currentAlphaImg.replace(strOver,strOff);
		else
			oImg.filters(0).src = currentAlphaImg.replace(strOff,strOver);
	} else {
		var strImg = oImg.src
		if (strImg.indexOf(strOver) != -1) 
			oImg.src = strImg.replace(strOver,strOff)
		else
			oImg.src = strImg.replace(strOff,strOver)
	}
}

*/