$ = function(e){
	switch(typeof e){
		case "string":
			return document.getElementById(e);
		break;
		default:
			return e;
		break;
	}
}

var Glry = {
	Handlers:new Object(),
	Linky:function(e){
		var Container,Item;
		if(e == undefined){
			Container = document.links;
		}else{
			Container = e.getElementsByTagName("A");
		}
		for(var Index = 0;Index < Container.length;Index++){
			Item = Container[Index];
			if(Item.getAttribute('enabled') !== null){
				if(Item.getAttribute('enabled') == "true"){
					Container[Index].onclick = Glry.Clicky;
				}
			}
		}
	},
	Clicky:function(e){
		switch(this.getAttribute('action').toLowerCase()){
			case "get":
				Ajax.Get(this.href);
				return false;
			break;
		}
	}
}
Glry.Activity = {
	Param:Object(),
	Repost:function(Id){
		Ajax.Get('?fetch@user-repost-activity:'+Id);
		Ajax.Handlers.before = function(){};
		Ajax.Handlers.after = function(){
			//Glry.Display.Hide($('Entry-'+Id))
		}
	},
	Delete:function(Id){
		if(Glry.Confirm.Delete()){
			Ajax.Get('?fetch@delete-user-activity:'+Id);
			Ajax.Handlers.before = function(){};
			Ajax.Handlers.after = function(){
				Glry.Display.Hide($('Entry-'+Id))
			}
		}
		return;
	},
	Load:function(Url,ResponseContainer){
		if(Glry.Activity.Param.ActiveItem !== undefined){
			Glry.Display.Hide(Glry.Activity.Param.ActiveItem);
		}
		Glry.Display.Show(ResponseContainer);
		var Pattern = new RegExp("/loading/","gi");
		Ajax.Get(Url);
		Ajax.Handlers.before = function(){
			if(ResponseContainer.className.match(Pattern) == null){
				ResponseContainer.className = ResponseContainer.className+' loading';
			}
		}
		Ajax.Handlers.after = function(){
			ResponseContainer.className = ResponseContainer.className.replace('loading','');
			ResponseContainer.innerHTML = Ajax.Request.responseText;
		}
		Glry.Activity.Param.ActiveItem = ResponseContainer;
	},
	Search:function(Url,Field,Container){
		Ajax.Handlers.ResultBox = Container;
		Field.onkeyup = function(){
			if(Field.value.length >= 2){
				Ajax.Get(Url+':'+escape(Field.value));
				Ajax.Handlers.after = function(){
					Ajax.Handlers.ResultBox.innerHTML = Ajax.Request.responseText;
				}
				Ajax.Handlers.before = function(){
					Glry.Display.Show(Ajax.Handlers.ResultBox);
				}
			}else{
				Glry.Display.Hide(Ajax.Handlers.ResultBox);
			}
		}
	},
	Radio:function(RadioName,Check){
		var RadioList = document.getElementsByName(RadioName);
		var Checkable = Check;
		var Node;
		for(var Index = 0; Index < RadioList.length; Index++){
			Node = RadioList[Index];
			if(Node.nodeName.toLowerCase() != "input"){
				if(Node.id == Check.id){
					Node.className = 'left action radiochecked';
				}else{
					Node.className = 'left action radio';
				}
			}
		}
	},
	Check:function(Node,Check){
		var Pattern = new RegExp('checkbox');
		if(Pattern.test(Node.className) == true){
			Node.className = "left action checked";
			$('PageTags').value = Node.title;
			return;
		}
		$('PageTags').value = '';
		Node.className = "left action checkbox";
		return;
	}
};
Glry.Util = {
	Param:Object(),
	CreateInterval:function(ActiveFunction,Timer){
		var Id = setInterval(ActiveFunction,Timer);
		window.onunload = function(){
			clearInterval(Glry.Util.Param.IntervalId);
		}
		Glry.Util.Param.IntervalId = Id;
		return Id;
	},
	CreateObject:function(Tag){
		if(Tag == undefined){
			Tag = "DIV";
		}
		var Item = document.createElement(Tag);
		if(Glry.Util.Param.Attr !== undefined){
			for(var Index in Glry.Util.Param.Attr){
				Item.setAttribute(Index,Glry.Util.Param.Attr[Index]);
			}
		}
		Glry.Util.Param = new Object();
		return Item;
	},
	GetCenter:function(Item){
		var Position = {
			scrollX : Glry.Util.ScrollX(),
			scrollY : Glry.Util.ScrollY(),
			viewPortWidth : Glry.Util.ClientWidth(),
			viewPortHeight : Glry.Util.ClientHeight(),
			elementHeight : Item.offsetHeight,
			elementWidth : Item.offsetWidth
		}
		this.x = (Position.viewPortWidth / 2) - (Position.elementWidth / 2) + Position.scrollX;
		this.y = (Position.viewPortHeight / 2) - (Position.elementHeight / 2) + Position.scrollY;
		if(Position.elementHeight >= Position.viewPortHeight){
			this.y = Position.scrollY;
		}
		return this;
	},
	GetMouse:function(e){
		Glry.Util.Param.MouseX = 0;
		Glry.Util.Param.MouseX = 0;
		if (!e) var e = window.event;
		if (e.pageX || e.pageY){
			Glry.Util.Param.MouseX = e.pageX;
			Glry.Util.Param.MouseY = e.pageY;
		}else if (e.clientX || e.clientY) 	{
			Glry.Util.Param.MouseX = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
			Glry.Util.Param.MouseY = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
		}
		return {
			x:Glry.Util.Param.MouseX,
			y:Glry.Util.Param.MouseY
		}
	},
	DocumentWidth:function(){
		return document.documentElement.offsetWidth || document.body.offsetWidth;
	},
	DocumentHeight:function(){
		return document.documentElement.offsetHeight || document.body.offsetHeight;
	},
	ClientWidth:function(){
		return window.innerWidth || document.documentElement.clientWidth;
	},
	ClientHeight:function(){
		return window.innerHeight || document.documentElement.clientHeight;
	},
	ScrollX:function(){
		return document.documentElement.scrollLeft || document.body.scrollLeft;
	},
	ScrollY:function(){
		return document.documentElement.scrollTop || document.body.scrollTop;
	},
	Position:function(Item){
		var left = 0,top = 0;
		var parent = Item;
		while (parent) {
			left += parent.offsetLeft;
			top += parent.offsetTop;
			parent = parent.offsetParent;
		}
		return {
			x:left,
			y:top,
			width:Item.offsetWidth,
			height:Item.offsetHeight
		};
	}
}


Glry.Confirm = {
	Delete:function(Url){
		if(Url == undefined){
			var msg = confirm("Press OK to Delete.\nPress Cancel to return");
			if (msg){
				return true;
			}
			return false;
		}
		var msg = confirm("Press OK to Delete.\nPress Cancel to return");
		if (msg){
			window.location = Url;
		}
	},
	Get:function(Url,Message){
		var msg = confirm(Message);
		if (msg){
			window.location = Url;
		}
	}
}


