// JavaScript Document
function showGalleryPrevious(articleId,imageId)
{
	var url = "get_gallery_image.php";
	url+="?article_id="+articleId;
	url+="&image_id="+imageId;
	url+="&prev=1";
	url+="&r="+Math.random();
	
	//alert(url);
	
	//send async GET request
    dhtmlxAjax.get(url,imageReady);	
}

function showGalleryNext(articleId,imageId)
{
	var url = "get_gallery_image.php";
	url+="?article_id="+articleId;
	url+="&image_id="+imageId;
	url+="&next=1";
	url+="&r="+Math.random();
	
	//alert(url);
	
	//send async GET request
    dhtmlxAjax.get(url,imageReady);	
}

function imageReady(loader)
{
	var response = loader.xmlDoc.responseText;
	
	
	var response_arr = response.split(',');
	
	var result = response_arr[0];
	var imageId = response_arr[1];
	var filename = response_arr[2];
	var large_width = response_arr[3];
	var large_height = response_arr[4];
	var comment = response_arr[5];
	var dir = response_arr[6];
	var is_last = response_arr[7];
	
	if(result=="img")
	{
		//alert(imageId+"\r\n"+filename+"\r\n"+large_width+"\r\n"+large_height);
		
		show_large_image(imageId,filename,large_width,large_height,comment);
		
		if(dir=="P" && is_last=="L")
		{//the first button must be greyed out
			var btn = document.getElementById('gallery_nav_prev');
			btn.style.color="#666666";
		}else
		{
			var btn = document.getElementById('gallery_nav_prev');
			btn.style.color="#FFFFFF";
		}
		
		if(dir=="N" && is_last=="L")
		{//the first button must be greyed out
			var btn = document.getElementById('gallery_nav_next');
			btn.style.color="#666666";
		}else
		{
			var btn = document.getElementById('gallery_nav_next');
			btn.style.color="#FFFFFF";
		}
	}
	
	
}

function show_large_image(imageId,filename,width,height,comment)
{
	var img = document.getElementById('large_image_holder');
	img.src = ""; //so as to remove the original image
	
	var img_div = document.getElementById('large_image_div');
	document.getElementById('gallery_imageId').value = imageId;
	
	var comment_div  = document.getElementById('large_image_comment');
	comment_div.innerHTML = comment;
	comment_div.style.width = width+'px';
	comment_div.style.display='block';
	var cmt_width = comment_div.clientWidth;
	var cmt_height = comment_div.clientHeight;
	comment_div.style.display='none';
	
	
	
	
	img.src = filename;
	
	if(width>0 && height>0)
	{
		img.style.width=width + 'px';
		img.style.height=height + 'px';
	}
	
	img_div.style.visibility='visible';
		
	var screen_width = document.body.clientWidth; 
	var screen_height = document.body.clientHeight;
	
	var div_width = img_div.clientWidth;
	var div_height = img_div.clientHeight;
	
	var x = Math.round(screen_width/2) - Math.round(div_width/2);
	var y = 10;
	
	img_div.style.left=x+'px';
	img_div.style.top = y+'px';
	
	
	//we will put the comment at the bottom of the picture
	var img_x = findPosX(img);
	var img_y = findPosY(img);
	
	
	
	var cmt_x = img_x;
	var cmt_y = (parseInt(img_y)+parseInt(height))-parseInt(cmt_height);
	
	//alert("img_x:"+img_x+" img_y:"+img_y+" img_height:"+height+" cmt_height:"+cmt_height+" cmt_y:"+cmt_y);
	comment_div.style.left=cmt_x+'px';
	comment_div.style.top=cmt_y+'px';
	
	large_image_comment_visible = false;
	large_image_mousemove();
	
	
	
	//alert('screen: '+screen_width+','+screen_height+' \r\n div: '+div_width+','+div_height);
}

var large_image_comment_timer;
var large_image_comment_visible=false;

function large_image_mousemove()
{
	clearTimeout(large_image_comment_timer);
	large_image_comment_timer = setTimeout("fade_large_image_comment()",5000);
	
	if(large_image_comment_visible!=true)
	{	
		if(document.getElementById('large_image_comment')!=null)
		{
			Effect.Appear('large_image_comment',{ duration: 1.0, from: 0, to: 0.8 });
		}
		
		large_image_comment_visible = true;
	}
	
}

function fade_large_image_comment()
{
	clearTimeout(large_image_comment_timer);
	
	if(large_image_comment_visible==true)
	{
		if(document.getElementById('large_image_comment')!=null)
		{
			Effect.Fade('large_image_comment');
		}
		
		large_image_comment_visible=false;
	}
}
 
function hide_large_image()
{
	clearTimeout(large_image_comment_timer);
	
	var img_div = document.getElementById('large_image_div');
	img_div.style.visibility='hidden';
}
 
