var neoglobal = '';
neoglobal = 
{
	scrollbarWidth: null,
	getScrollbarWidth: function()
	{
		if (this.scrollbarWidth !== null)	{
			return this.scrollbarWidth;
		}		
		var iDiv = new Element('div');
		iDiv.setStyle({height:'100px'});
		var oDiv = new Element('div');
		oDiv.setStyle({width:'50px',height:'50px',overflow:'hidden',position:'absolute',top:'-200px',left:'-200px'})
		$(document.body).insert({top:oDiv});
		oDiv.insert({top:iDiv});
		var w1 = iDiv.getWidth();
		oDiv.setStyle({overflow:'auto'});
		var w2 = iDiv.getWidth();
		if (Prototype.Browser.IE)	{
			w2 = iDiv.getWidth() //for ie have to do it again O_O no clue why
		}
		oDiv.remove();
		this.scrollbarWidth = w1 - w2;
		return this.scrollbarWidth;
		
	},

	xDateTo: function( tDate,to )
	{
		//format of to 0 = real to neodate so tDate = 'January 1, 2007';
		//format of to 1 = neo to real date so tDate = '31st day of Eating, Y12';

		var neoOfReal = {January:'Sleeping',February:'Awakening',March:'Running',April:'Eating',May:'Hunting',June:'Relaxing',July:'Swimming',August:'Hiding',September:'Gathering',October:'Collecting',November:'Storing',December:'Celebrating'};

		if (to == 0){
			var bits = /([^ ]+) (\d+),.*?(\d+)/.exec(tDate);
			return this.ordinal(bits[2])+' day of '+neoOfReal[bits[1]]+', Y'+(parseInt(bits[3])-1998);
		} else {
			var bits = /(\d+).. day of ([^ ]+), Y(\d+)/.exec(tDate);
			for(var m in neoOfReal){
				if (neoOfReal[m] == bits[2]){
					return m+' '+bits[1]+', '+(parseInt(bits[3])+1998);
				}
			}
		}
		return null;

	},

ordinal: function(v)
{
	return v + (
		(v % 10 == 1 && v % 100 != 11) ? 'st' :
		(v % 10 == 2 && v % 100 != 12) ? 'nd' :
		(v % 10 == 3 && v % 100 != 13) ? 'rd' : 'th'
	);
},

	CountIt: function( target_str, str_to_count )
	{
		var temp = new Array();
		temp = target_str.split(str_to_count);
		return temp.length - 1;
	},

	RandBW: function( minInt, maxInt)
	{
		return (Math.floor(Math.random() * (maxInt - minInt + 1) + minInt));		
	},

	toggleview: function(id,no_toggle)
	{
		if ( ! id ) return;
		if ( ! no_toggle) no_toggle = ""; //noit edit
		var itm;
		if ( itm = document.getElementById(id) )
		{
			if (no_toggle == "show_only" || no_toggle == "show")
			{
				if (itm.style.display == "none")
				{
					itm.style.display = '';
				}
			}
			else if (no_toggle == "hide_only" || no_toggle == "hide")
			{
				if (itm.style.display != "none")
				{
					itm.style.display = 'none';
				}
			}
			else
			{
				if (itm.style.display == "none")
				{
					itm.style.display = '';
				}
				else
				{
					itm.style.display = 'none';
				}
			}
		}
	},
	
	trim: function(stringToTrim)
	{
		return stringToTrim.replace(/^\s+|\s+$/g,'');
	},

	ltrim: function(stringToTrim) {
		return stringToTrim.replace(/^\s+/,'');
	},

	rtrim: function(stringToTrim)
	{
		return stringToTrim.replace(/\s+$/,'');
	},
	
	in_array: function(needle, haystack, argStrict) {
		// http://kevin.vanzonneveld.net
		// +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
		// +   improved by: vlado houba
		// *     example 1: in_array('van', ['Kevin', 'van', 'Zonneveld']);
		// *     returns 1: true
		// *     example 2: in_array('vlado', {0: 'Kevin', vlado: 'van', 1: 'Zonneveld'});
		// *     returns 2: false
		// *     example 3: in_array(1, ['1', '2', '3']);
		// *     returns 3: true
		// *     example 3: in_array(1, ['1', '2', '3'], false);
		// *     returns 3: true
		// *     example 4: in_array(1, ['1', '2', '3'], true);
		// *     returns 4: false
	 
		var key = '', strict = !!argStrict;
		
		if (strict) {
			for (key in haystack) {
				if (haystack[key] === needle) {
					return true;
				}
			}
		} else {
			for (key in haystack) {
				if (haystack[key] == needle) {
					return true;
				}
			}
		}
		
		return false;
	},
	
	delayedClick: function(elemId,delay,obj,func,event)
	{
		//func must be in onmousedown of the element
		//func is the function to execute after delay (ms) is up
		//delay is in ms
		//obj can contain function
		//give obj a preFunc if you want it to do something if they mouseUp for delay is over
		if (typeof(obj) != 'object')	{
			eval('obj = new Object();');
			obj = eval('obj');
		}
		obj['elemId'] = elemId;
		if (func)	{
			obj['func'] = func;
		} else	{
			if (typeof(obj['func']) != 'function')	{
				alert('Delayed Click Error - Obj does not have "function" to do after delay is up');
				return;
			}
		}

		obj['mtimeout'] = window.setTimeout(function(){ 
														 obj.clearAllFunc();
														 obj.func(); 
													  },delay);
		obj['clearFuncMove'] = function(event)	{
			var cx = Event.pointerX(event);
			var cy = Event.pointerY(event);
			if (Math.abs(obj.x-cx) <= 2 || Math.abs(obj.x-cx) <= 2) {
				return;
			}
			clearTimeout(obj.mtimeout);
			$(obj.elemId).stopObserving(obj.clearFuncMove);
			$(obj.elemId).stopObserving(obj.clearFunc);
		}
		obj['clearFunc'] = function()	{
			clearTimeout(obj.mtimeout);
			$(obj.elemId).stopObserving(obj.clearFunc);
			$(obj.elemId).stopObserving(obj.clearFuncMove);
		}
		obj['clearAllFunc'] = function()	{
			clearTimeout(obj.mtimeout);
			$(obj.elemId).stopObserving();
		}
		
		if (event){
			obj.x=Event.pointerX(event);
			obj.y=Event.pointerY(event);
			$(elemId).observe('mousemove', obj.clearFuncMove);
		} else {
			$(elemId).observe('mousemove', obj.clearFunc);
		}
		
		$(elemId).observe('mouseup', obj.clearFunc);
		if (typeof(obj.preFunc) == 'function')	{
			$(elemId).observe('mouseup', obj.preFunc);
		}
		
		$(elemId).observe('mouseout', obj.clearAllFunc);
	},
	
	calenderPicker: function(id)
	{
			$(id).innerHTML += '';
	},
	
	//safe stuff
	
	safeLinkDomain: 'http://www.neocodex.us/api/safelink.php?link=',
	safeImgDomain: 'http://www.etsadmin.com/safeimg.php?img=',
	
	safeLink: function(tag,http)
	{
		if (!http)	{
			http = tag;
		}
		var noHttp = http.replace(/http:\/\//i,'');
		var newHttp = this.safeLinkDomain+noHttp;
		tag = tag.replace(http,newHttp);
		return tag;
		
	},
	
	safeImg: function(tag,http)
	{
		if (!http)	{
			http = tag;
		}
		var noHttp = http.replace(/http:\/\//i,'');
		var newHttp = this.safeImgDomain+noHttp;
		tag = tag.replace(http,newHttp);
		return tag;
	},
	
	safeImgNOTAG: function(http)
	{
		var noHttp = http.replace(/http:\/\//i,'');
		var newHttp = this.safeImgDomain+noHttp;
		return newHttp;
	}
	
	/*
		instructions = instructions.replace(/<A.*?href=["\' ]?([^ \'"]+neopets\.[^ \'"]+).*?>/gi,function($0,$1){return neoglobal.safeLink($0,$1)});
		image = image.replace(/<A.*?href=["\' ]?([^ \'"]+neopets\.[^ \'"]+).*?>/gi,function($0,$1){return neoglobal.safeLink($0,$1)});
	*/
	
	//end safe stuff
	
}

//PROTOTYPE EXTEND
var ElementExtensions = {
		center: function ( element, parent, returnCoordsOnly, additionalOffsetX, additionalOffsetY )
		{
			//additionalOffsets currently not in use. can mess with that 7/30/2010
			//element MUST be position absolute
			if (!additionalOffsetX)	{
				 additionalOffsetX = 0;
			}
			if (!additionalOffsetY)	{
				 additionalOffsetY = 0;
			}
			element = $(element);
			
			var elementDims = element.getDimensions();
			if (!parent)	{
				//use window
				var viewPort = document.viewport.getDimensions();
				var offsets = document.viewport.getScrollOffsets();
				var centerX = ((viewPort.width / 2) + offsets.left) - (elementDims.width / 2);
				var centerY = ((viewPort.height / 2) + offsets.top) - (elementDims.height);
			} else	{
				//use parent element
				//parent element is position relative with element inside contained as position absolute
				if (typeof(parent) == 'string')	{
					parent = $(parent);
				}
				var viewPort = parent.getDimensions();
				var offsets = parent.cumulativeOffset();//{left:0,top:0};
				var centerX = (viewPort.width / 2) + offsets.left + additionalOffsetX - (elementDims.width / 2);
				var centerY = (viewPort.height / 2) + offsets.top + additionalOffsetY - (elementDims.height / 2);
			}
			/*
			if ( limitX && centerX < limitX )
			{
				centerX = parseInt(limitX);
			}
			if ( limitY && centerY < limitY )
			{
				centerY = parseInt(limitY);
			}
			*/
			
			if (!returnCoordsOnly)	{
				element.setStyle( { top: Math.floor(centerY) + 'px', left: Math.floor(centerX) + 'px' } );
			}
			return {x:centerX,y:centerY}
			
			//return element; //noit i commented this out because why return element? O_O
		}
	}
Element.addMethods(ElementExtensions);

/**
 * @author Ryan Johnson <http://syntacticx.com/>
 * @copyright 2008 PersonalGrid Corporation <http://personalgrid.com/>
 * @package LivePipe UI
 * @license MIT
 * @url http://livepipe.net/extra/hotkey
 * @require prototype.js, livepipe.js
 */

/*global document, Prototype, Class, Event, $ */

if(typeof(Prototype) == "undefined") {
    throw "HotKey requires Prototype to be loaded."; }
if(typeof(Event) == "undefined") {
    throw "HotKey requires Event to be loaded."; }

var HotKey = Class.create({
    initialize: function(letter,callback,options){
        letter = letter.toUpperCase();
        HotKey.hotkeys.push(this);
        this.options = Object.extend({
            element: false,
            shiftKey: false,
            altKey: false,
            ctrlKey: false,
            bubbleEvent : true,
            fireOnce : false // Keep repeating event while key is pressed?
        },options || {});
        this.letter = letter;

        // All custom hotkey events should stop after their custom actions.
        this.callback = function (event) {
            if (!(this.options.fireOnce && this.fired) && Object.isFunction(callback)) { 
                callback(event); 
            }
            if (!this.options.bubbleEvent) { event.stop(); }
            this.fired = true;
        };

        this.element = $(this.options.element || document);
        this.handler = function(event){
            if(!event || (
                (Event['KEY_' + this.letter] || this.letter.charCodeAt(0)) == event.keyCode &&
                ((!this.options.shiftKey || (this.options.shiftKey && event.shiftKey)) &&
                    (!this.options.altKey || (this.options.altKey && event.altKey)) &&
                    (!this.options.ctrlKey || (this.options.ctrlKey && event.ctrlKey))
                )
            )){
                //if(this.notify('beforeCallback',event) === false) {return; }
                this.callback(event);
                //this.notify('afterCallback',event);
            }
        }.bind(this);
        this.enable();
    },
    trigger: function(){
        this.handler();
    },
    enable: function(){
        this.element.observe('keydown',this.handler);
    },
    disable: function(){
        this.element.stopObserving('keydown',this.handler);
    },
    destroy: function(){
        this.disable();
        HotKey.hotkeys = HotKey.hotkeys.without(this);
    }
});

Object.extend(HotKey,{
    hotkeys: []
});
Event.extend(HotKey);

