Global = {
	Url:new String(),
	Id:Object(),
	Item:function(){
		switch(typeof this.Id){
			case "string" :
				this.Id = document.getElementById(this.Id);
				break;
			case "object" :
				this.Id = this.Id
				break;
			default :
				alert("Problems! Check this.Id Type references");
		}
		return this.Id;
	},
	Name:function(e){
		return document.getElementsByTagName(e);
	},
	Discard:function(){
		var msg = confirm("Please press OK to confirm Delete");
		if (msg){
			window.location = this.Url;
		}
	}
}

Ajax = {
	Url:new String(),
	Fields:new Array(),
	Request:new Object(),
	BaseUrl:new String(),
	Execute:Function(),
	Init:function(){
		if(window.XMLHttpRequest) {
	        try {
				this.Request = new XMLHttpRequest();
	        } catch(e) {
				return false;
			}
		}else{
			try {
				this.Request = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					this.Request = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {
					this.Request = false;
				}
			}
		}
	},
	Fetch:function(){
		this.Init();
		r = this.Request;
		r.open("GET",this.Url,true);
		r.onreadystatechange = this.Objectize;
		r.send(null);
	},
	Send:function(){
		this.Init();
		r = this.Request;
		r.open("GET",this.Url,true);
		r.send(null);
	},
	Post:function(){
		this.Init();
		r = this.Request;
		this.PostableItems();
		r.open('POST', Ajax.BaseUrl+Ajax.Url, false);
		r.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		//r.setRequestHeader("Content-length", Ajax.Data.length);
		//r.setRequestHeader("Connection", "close");
		r.send(Ajax.Data);
	},
	PostableItems:function(){
		i=0;
		_tmp_ = new Array();
		while(i < Ajax.Fields.length){
			Global.Id = Ajax.Fields[i];
			Global.Item();
			_tmp_.push(Ajax.Fields[i]+'='+escape(encodeURI(Global.Id.value)));
			i++;
		}
		Ajax.Data = _tmp_.join("&");
		Ajax.Fields = new Array();
	},
	Objectize:function(){
		if(r.readyState == 4){
			if(Ajax.Fields.length > 0){
				Ajax.Data = new Function("return "+r.responseText)();
			}else{
				Ajax.Data = r.responseText;
			}
			Ajax.Execute();
		}
	},
	ParseContent:function(){
		Global.Id = 'content-holder';
		Global.Item();
		Global.Id.innerHTML = Ajax.Data;
	}
}

Swapper = {
	ItemSuffix:String("-content"),
	ItemList:Array(),
	Pointer:Object(),
	SelectedItem:Object(),
	Counter:Number(0),
	Top:Number(0),
	Left:Number(0),		

/*----------------------------------------------------------------------------- 
	Special functions: Showing-Hiding Block items
-----------------------------------------------------------------------------*/	
	Objectize:function(){
		Global.Item();
		var tmp;
		if(Global.Id.id.match(this.ItemSuffix) == null){
			tmp = Global.Id.id+this.ItemSuffix;
			if(document.getElementById(tmp) != null){
				Global.Id = Global.Id.id+this.ItemSuffix;
				Global.Item();
			}
		}
	},
	Show:function(){
		this.Objectize();
		Global.Id.style.display = "block";
	},
	Hide:function(){
		this.Objectize();
		Global.Id.style.display = "none";
	},
	Swap:function(){
		this.Objectize();
		switch(Global.Id.style.display){
			case "none" :
				this.Show();
				break;
			case "block" :
				this.Hide();
				break;
		}
	},
	InputValue:function(text){
		switch(Global.Id.value){
			case "" :
				Global.Id.type='text';
				Global.Id.value = text;
			break;
			case text :
				Global.Id.type='text';
				Global.Id.value = "";
			break;			
		}
	},		
	SwapContent:function(item){
		Global.Id = 'image-preview';
		Global.Item();
		Global.Id.innerHTML = '<img src="'+item+'" name="" title="" border="" />';
	},	
	SwapBetween:function(){
		item = Global.Id.title;
		this.Objectize();
		this.Show();
	},
	Esc:function(event){
		switch(event.keyCode){
			case 27:
				i = 0;
				while(i < this.ItemList.length){
					Global.Id = this.ItemList[i];
					this.Hide();
					i++;
				}
			break;
		}
	},
/*----------------------------------------------------------------------------- 
	Special functions: tab related functions
-----------------------------------------------------------------------------*/
	Tabbing:function(){
		Global.Item();
		this.CreateItemsList();
		i = 0;
		current = Global.Id.id;
		while(i < this.ItemList.length){
			Global.Id = this.ItemList[i];
			if(this.ItemList[i] == current){
				this.Show();	
			}else{
				this.Hide();
			}
			i++;
		}
	},
	PositionTabbing:function(){
		this.Pointer = Global.Id;
		this.CreateItemsList();
		i = 0;
		current = Global.Id.id;
		while(i < this.ItemList.length){
			Global.Id = this.ItemList[i];
			if(this.ItemList[i] == current){
				this.Show();
				this.Position();
			}else{
				this.Hide();
			}
			i++;
		}
	},	
	CreateItemsList:function(){
		list = Global.Name("a");
		while(this.Counter < list.length){
			if(list[this.Counter].getAttribute("rel") == "tab-item"){
				this.ItemList.push(list[this.Counter].id);
			}
			this.Counter++;
		}		
	},
	Position:function(){
		_coordinates = Coordinates.northwestOffset(this.Pointer,true);
		Global.Id.style.top = _coordinates.y+this.Top+'px';
		Global.Id.style.left = _coordinates.x+this.Left+'px';
	}	
}