image_attach = new attachment;
link_attach  = new link_attachment; 
link_attach.onRemove = delete_link;


/*******************************************************************************************
	view_image
********************************************************************************************/
function view_image(id)
{
	function run()
	{
	
		black_div = document.createElement("div"); 
		
		//getting with and height
		
		//mozilla/opera
		width  = window.innerWidth; 
		height = window.innerHeight; 
		
		//ie
		
		
		black_div.id = "black_div"; 
		black_div.style.position 	 = "absolute"; 
		black_div.style.top = "0"; 
		black_div.style.zIndex 		 = "2"; 
		black_div.style.background 	 = "#000"; 
		black_div.style.width 	 	 = "99%"; 
		black_div.style.height	 	 = "99%"; 
		black_div.style.filter 		 = "alpha(opacity=70)";
		black_div.style.opacity 	 = "0.70";
		
		
		container = document.createElement("div"); 
		container.id = "container";
		
		container.innerHTML = this.responseText; 
	
		document.body.appendChild(black_div); 
		document.body.appendChild(container); 
		
	}

	request = new ajax_request; 
	request.enable_loader_screen(); 
	request.process("index.php?module=view_image&id="+id); 
	request.onreadystatechange(run);
} 
/*******************************************************************************************
	close_image
********************************************************************************************/
function close_image()
{
	var container = document.getElementById("container"); 
	var black_div = document.getElementById("black_div"); 
	document.body.removeChild(black_div); 
	document.body.removeChild(container); 
}
/*******************************************************************************************
	delete_image
********************************************************************************************/
function delete_image(id)
{

	function go()
	{
	
		var current_images = document.getElementById("current_images");
		current_images.innerHTML = this.response.images; 

	}
	
	var conf = confirm("Warning: This action is permanent, are you sure you want to do this?"); 
	if(conf==true)
	{	
		var request = new ajax_request; 
		request.process("index.php?ajax=register&image_id="+id); 
		request.onreadystatechange(go);
	}
	
}
/*******************************************************************************************
	get_links
********************************************************************************************/
function get_links()
{
	function run()
	{
		var my_array = new Array; 
		var index = 0; 
		var response = this.parse_response(); 
		for (prop in response)
		{
			var id = prop.substr(prop.indexOf("_")+1); 
			var string = response[prop]; 
			var title  = string.substr(0, string.indexOf(";")); 
			var url    = string.substr(string.indexOf(";")+1); 
			
			my_array[index] = new Object; 
			my_array[index].id    = id; 
			my_array[index].title = title; 
			my_array[index].url   = url; 
			index++; 
		}
		link_attach.autoAttach(my_array); 
	}

	
	var loc = window.location.toString();
	if(loc.indexOf("edit")>-1)
	{
		var id = loc.substr(loc.indexOf("id=")+3); 
		
		var request = new ajax_request; 
		request.process("index.php?do=edit&id="+id+"&get_links=true");
		request.onreadystatechange(run);
	}	
}
/*******************************************************************************************
	delete link
********************************************************************************************/
	function delete_link()
	{
		function run(){
			//alert(this.responseText); 
		}
		var request = new ajax_request;
	 
		request.process("index.php?ajax=register&link_id="+this.value); 
		request.onreadystatechange(run); 
	}
/*******************************************************************************************
	delete link
********************************************************************************************/
	function delete_store(id)
	{
		function run()
		{
			content = document.getElementById("body"); 
			content.innerHTML = this.responseText; 
		}
		var conf = confirm("Warning: this action is permanent, are you sure you want to do this?"); 
		if(conf==true)
		{
			request = new ajax_request; 
			request.process("index.php?do=delete&id="+id); 
			request.onreadystatechange(run); 
		}
	}
/*******************************************************************************************
	init
********************************************************************************************/
function init()
{
	get_links(); 
}