	var DIVElementById = "";
	var imagex;
	var ElementOpacityLevel;
	var xmlhttp=getrequestobject();
	var random_xmlhttp;
	var old_width;
	var old_height;
	
	
	var rows;
		
		
	function eco_fader(ElementID, action)
	{
		if (ElementID != 'image')
			show_hourglass();
		DIVElementById = document.getElementById(ElementID);
		if (action == "hide")
 		{
    		ElementOpacityLevel = 100;
    		reduceOpacity();
  		}
  		if (action == "show")
		{	
			ElementOpacityLevel = 0;
			increaseOpacity();
		}
	}
	function delete_comment(photoid, commentid)
	{
		var xmlhttp=getrequestobject();
		xmlhttp.open("GET", "delete_comment.php?&photoID=" + photoid + "&commentID=" + commentid, true);
		xmlhttp.send(null);
		eco_fader(commentid, "hide");
	}
	function add_comment(photoid)
	{
		document.getElementById('comment_table').style.visibility = 'visible';
		var comment = encodeURIComponent(document.getElementById("photo_comment").value);
		var p = "comment=" + comment + "&photoid="+photoid;
		xmlhttp.open("POST", "process_comments.php", true);
		xmlhttp.onreadystatechange = callbackFunction;
		xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlhttp.setRequestHeader("Content-length", p.length);
		xmlhttp.send(p);
		document.getElementById("photo_comment").value = '';
	}
	function hide_hourglass()
	{
		document.getElementById("comment_hourglass").style.visibility = "hidden";
	}
	function show_hourglass()
	{
		document.getElementById("comment_hourglass").style.visibility = "visible";
	}
	function callbackFunction()
	{
		if (xmlhttp.readyState == 4)
		{	
			var comment_array=xmlhttp.responseText.split("\r\n");
			if (comment_array.length == 6)
			{
				var _newrow		= 	document.getElementById('comment_table').insertRow(document.getElementById('comment_table').rows.length);
				_newrow.id		= 	comment_array[2];
				var pID			=	comment_array[3];
				var cell0		= 	_newrow.insertCell(0);
				var cell1 		= 	_newrow.insertCell(1);
				var cell2 		= 	_newrow.insertCell(2);
				var date_text	=	'On ' + comment_array[4] + ', <b>' + comment_array[5] + '</b> wrote:<br /><br />';
				cell0.setAttribute("width", 100);
				cell1.setAttribute("class", "comment_theme");
				//cell1.setAttribute("style", 'height:60px');
				cell0.innerHTML = comment_array[0]
				cell1.innerHTML = date_text + comment_array[1];
				cell2.innerHTML = '<img src="ecofiles/pictures/commentclose.png" title="Click to remove your comment" align="right" onClick="delete_comment(' + pID + ',' + _newrow.id + '); return true" />';
				//eco_fader(_newrow.id, "show");
			}
		}
	}
	function increaseOpacity() 
	{
		if (ElementOpacityLevel < 100)
		{
			ElementOpacityLevel += 5;
			DIVElementById.style.MozOpacity = ""+(ElementOpacityLevel/100);
			DIVElementById.style.opacity = ""+(ElementOpacityLevel/100);
			DIVElementById.style.filter = 'alpha(opacity='+ElementOpacityLevel+')';
			setTimeout("increaseOpacity()", 30);
		}
		else
			hide_hourglass();	
	}
	function reduceOpacity() 
	{
		if (ElementOpacityLevel > 0) 
		{
			ElementOpacityLevel -= 5;
			DIVElementById.style.MozOpacity = "" + (ElementOpacityLevel/100);
			DIVElementById.style.opacity = "" + (ElementOpacityLevel/100);
			DIVElementById.style.filter = 'alpha(opacity='+ElementOpacityLevel+')';
			setTimeout("reduceOpacity()", 30);
		}
		else
		{
	  		ElementOpacityLevel = 100;
  			DIVElementById.parentNode.removeChild(DIVElementById);
			hide_hourglass();	
  		}
		rows = document.getElementById('comment_table').rows.length;
		if (rows == 0)
			document.getElementById('comment_table').style.visibility = "hidden";
	}
	function random_photo()
	{
		//eco_fader('main_image', "hide")
		random_xmlhttp=getrequestobject();
		random_xmlhttp.open("GET", "get_random_photo.php?&iebug=" + Math.random()*1000, true);
		random_xmlhttp.send();
		random_xmlhttp.onreadystatechange = random_callbackFunction;
		//eco_fader('main_image', "show")

	}
	function random_callbackFunction()
	{
		if (random_xmlhttp.readyState == 4)
		{
			var photo_array	=	random_xmlhttp.responseText.split("\r\n");
			var image 		=	document.getElementById('main_image');
			var width 		=	photo_array[0];
			var height		=	photo_array[1];
			var filename 	=	photo_array[2];
			var title		=	photo_array[3];
			var location	=	photo_array[4];
			var description	=	photo_array[5];
			var date		=	photo_array[6];
			var photophotog	=	photo_array[7];
			var views		=	photo_array[8];
			var modifylinks	=	photo_array[9];
			var save_link	=	photo_array[10];
			var link_bar	=	photo_array[11];
			var follower	=	photo_array[12];
			var category	=	photo_array[13];
			var full_image	=	photo_array[14];
			var comments	=	photo_array[15];
			var new_width;

			//alert(old_width);
			
			image.setAttribute("src", filename);
			//setTimeout(expand_width('main_image',old_width),5000);
			
			if (width > height)
			{	
				if (width >= 800)
					new_width = 800;
			}
			else
			{
				if (width <= 475)
					new_width = 475;
			}
			
			image.setAttribute("width", new_width);
			//image.setAttribute("height", height);	
			document.getElementById('photo_title').innerHTML 		= title;
			document.getElementById('photo_location').innerHTML 	= location;
			document.getElementById('photo_description').innerHTML 	= description;
			document.getElementById('photo_date').innerHTML 		= date;
			document.getElementById('photo_photog').innerHTML 		= photophotog;
			document.getElementById('photo_views').innerHTML 		= views;
			document.getElementById('photo_modifylinks').innerHTML 	= modifylinks;
			document.getElementById('save_link').innerHTML 			= save_link;
			document.getElementById('link_bar').innerHTML 			= link_bar;
			document.getElementById('photo_follow').innerHTML		= follower;
			document.getElementById('photo_category').innerHTML		= category;
			//document.getElementById('show_full_image').innerHTML	= full_image;
			document.getElementById('outer_comment_table').innerHTML= comments;
			
			//alert(follower);
			//old_height 	=	height;
			//old_width 	=	width;
			hide_hourglass();	
		}
	}
	function expand_width(id,oldwidth)
	{
		//alert(id + oldwidth);
	}
	function showfile()
	{
		document.getElementById('test').innerHTML = document.getElementById('upload_one').value;
		
	}
