//////////////////////////////////////////////////////////////////////////
//Получение положения скролла                                          //
//////////////////////////////////////////////////////////////////////////

function get_scroll_position()
{
	var t = self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
	var l = self.pageXOffset || (document.documentElement && document.documentElement.scrollLeft) || (document.body && document.body.scrollLeft);
	
	return { "left": l, "top" : t };
}

//////////////////////////////////////////////////////////////////////////
//Размер тела                                                          //
//////////////////////////////////////////////////////////////////////////

function get_body_size()
{
	var w = (window.innerWidth ? window.innerWidth : (document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.offsetWidth));
 	var h = (window.innerHeight ? window.innerHeight : (document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.offsetHeight));
 
 	return { "width": w, "height": h }; 
}

function get_element_bounds( element )
{
    var w = element.offsetWidth;
    var h = element.offsetHeight;
	
    var l = 0;
    var t = 0;
	
	while ( element )
    {
		l += element.offsetLeft;
		t += element.offsetTop;
		element = element.offsetParent;
    }

    return { "left": l, "top": t, "width": w, "height": h};
}

function pop_image_show(link)
{
	
		//var background = document.getElementById("pop_image_background");
		
		var background = document.createElement("div");
		background.id = "pop_image_background";
		document.body.appendChild(background);
		
		var temp_top = get_element_bounds(background).top;
				
		background.style.left = "0px";
		background.style.top = "0px";
		background.style.width = "100%";
		background.style.height = temp_top;
			
		container = document.createElement("div");
		container.id = "pop_image_container";
		
		document.body.appendChild(container);
		
		//TODO переписать на DOM-модель.
		container.innerHTML = "<table id=\"pop_image_table\"><tr><td><img id=\"pop_image_img\" src=\""+ "/resources/common/images/ajax.gif" +"\"></td></tr></table>";
			
		var img = document.getElementById("pop_image_img");
		img.src = link.href;
		
		container.style.left = "0px";
		container.style.top = "0px";
		container.style.width = "100%";
		container.style.height = temp_top;
		container.onclick = pop_image_hide;
		
		var table = document.getElementById("pop_image_table");
		
		table.style.left = get_scroll_position().left; 
		table.style.top = get_scroll_position().top;
		table.style.width = get_body_size().width;
		table.style.height = get_body_size().height;
		table.onclick = pop_image_hide;
	
		return false;
}

function pop_image_hide()
{
	var background = document.getElementById("pop_image_background");
	var container = document.getElementById("pop_image_container");
	document.body.removeChild(background);
	document.body.removeChild(container);

} 