// JavaScript Document
//utf8 УТФ8 кодировка lietuviškai ąčęėįšųūž

function _obj(id)
{
	if ((id != undefined)&&(id != '')) { return document.getElementById(id); } else { return ''; }
}

function _url(path)
{
	var real_link = path;
	real_link = real_link.replace(/&amp;/g,'&');
	window.location = real_link;	
}

function pausecomp(millis)
{
	var date = new Date();
	var curDate = null;

	do { curDate = new Date(); }
	while(curDate-date < millis);
} 



//====================
//Map
//====================
//map_cont

var marker_cnt = 0;
var markers = new Array();
var temp_marker = null;
var temp_x = null;
var temp_y = null;
var current_state = '';
//markers = new Array(id,type[1:current news,0:other news],x,y,pav,apr,obj);
var mouselat; 
var mouselng; 

var map;
var baseIcon = null;
function createMarker(lat, lng, featured, text, image, index) 
{
	baseIcon.iconSize = new GSize(32, 32);
	var icon = new GIcon(baseIcon);
	icon.image = 'images/'+image;
	function orderOfCreation(marker, b) { return featured; }
	var m = new GMarker(new GLatLng(lat, lng), { icon:icon,zIndexProcess:orderOfCreation });
	if (index > -1)
	{
		GEvent.addListener(m, 'click', function() 
			{ 
				//map.panTo(new GLatLng(lat, lng),true); 
				//m.openInfoWindowHtml(text); 
				var iwAnchor = m.getIcon().infoWindowAnchor;
				var iconAnchor = m.getIcon().iconAnchor;
				var offset = new GSize(iwAnchor.x-iconAnchor.x,iwAnchor.y-iconAnchor.y);
				map.openInfoWindow(m.getLatLng(), text, {pixelOffset:offset});
			});
	}
	return m;
}

function MapInitialize()
{
	function wheelZoom(a) 
	{ 
		if (a.cancelable) a.preventDefault(); 
		if (a.detail || -a.wheelDelta) 
		{ 
			var m = map.fromLatLngToDivPixel(new GLatLng(mouselat,mouselng)); 
			var c = map.fromLatLngToDivPixel(map.getCenter()); 
			if ((a.detail || -a.wheelDelta) < 0) 
			{ 
				var x = c.x - ((m.x - c.x) * -.5); 
				var y = c.y - ((m.y - c.y) * -.5); 
				var n = map.fromDivPixelToLatLng(new GPoint(x,y)); 
				map.setCenter(n); 
				map.zoomIn(); 
			}
			else if ((a.detail || -a.wheelDelta) > 0) 
			{ 
				var x = c.x - (m.x - c.x); 
				var y = c.y - (m.y - c.y); 
				var n = map.fromDivPixelToLatLng(new GPoint(x,y)); 
				map.setCenter(n); 
				map.zoomOut(); 
			} 
		} 
	} 

	if (GBrowserIsCompatible()) 
	{
		baseIcon = new GIcon(G_DEFAULT_ICON);
		baseIcon.shadow           = "";
		//baseIcon.shadowSize       = new GSize(32, 30);
		baseIcon.iconSize         = new GSize(32, 32)
		baseIcon.iconAnchor       = new GPoint(32, 32);
		baseIcon.infoWindowAnchor = new GPoint(16, 16);
		
		map = new GMap2(_obj("map_cont"));
		
		//map.setCenter(new GLatLng(55.229023, 23.884277), 2);
		map.setCenter(new GLatLng(37.996163, 2.460938), 2);
		map.addControl(new GLargeMapControl());
		//map.addControl(new GMapTypeControl());
		//map.addControl(new GScaleControl());
		//map.disableDoubleClickZoom();
		map.setMapType(G_HYBRID_MAP);
	
		//rodom is pakrautu tasku
		for(c=0;c<markers.length;c++)
		{
			if (markers[c]!= null)	
			{
				if (markers[c][1] == 0) 
				{ markers[c][6] = createMarker(markers[c][2], markers[c][3], 0, "<div class='marker_cont'><div class='marker_cap'>"+markers[c][4]+"</div><div class='marker_apr'>"+markers[c][5]+'</div></div>', 'dot-small.png',c); }
				else 
				{ markers[c][6] = createMarker(markers[c][2], markers[c][3], 0, "<div class='marker_cont'><div class='marker_cap'>"+markers[c][4]+"</div><div class='marker_apr'>"+markers[c][5]+'</div></div>', 'dot-big.png',c); }
				map.addOverlay(markers[c][6]);
			}
		}
		
		//GEvent.addDomListener(_obj("map_cont"), 'DOMMouseScroll', wheelZoom); // ff 
		//GEvent.addDomListener(_obj("map_cont"), 'mousewheel',     wheelZoom); // ie 
		GEvent.addListener(map, 'mousemove', function(point) { mouselat = point.y.toFixed(6); mouselng = point.x.toFixed(6); }); 
	}
}





//======================
// KOMENTARAI
//======================
var ajax = null;

function comments_loading()
{
	_obj('comments_cont').innerHTML = '<table cellspacing="5" cellpadding="0" width="100%"><tr><td align="center">'+lng_loading+'</td></tr><tr><td align="center"><img src="admin/images/loading2.gif" alt="" /></td></tr></table>';
}

function show_comments(id,sub1,sub2,page)
{
	ajax = new GLM.AJAX();
	comments_loading();
	setTimeout("get_comments("+id+","+sub1+","+sub2+","+page+");",1000);
}

function get_comments(id,sub1,sub2,page)
{
	ajax.callPage('komentarai.php?act=list&id='+id+'&sub='+sub1+'&sub2='+sub2+'&page='+page, echo_comments);
}

function echo_comments(responce)
{
	_obj('comments_cont').innerHTML = responce;
	_obj('links_cont').innerHTML = '&nbsp;&nbsp;&nbsp;<a href="javascript:scroll(0,0);">'+lng_top+'</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="javascript:history.go(-1);">'+lng_atgal+'</a>';
}








function analize_ffoter_position()
{
	var screen_height = 0;
	if (document.documentElement.clientHeight) { screen_height = document.documentElement.clientHeight; }
	else if (document.body.clientHeight) { screen_height = document.body.clientHeight; }
	else if (window.innerHeight) { screen_height = window.innerHeight; }

	alert('screen_height='+screen_height);
}


function adjust_footer_position(footer_height)
{
	var footer_top = 0;
	var screen_height = 0;
	var footer_offset = 0;
	var offset_t = 0;
	if (document.documentElement.clientHeight) { screen_height = document.documentElement.clientHeight; }
	else if (document.body.clientHeight) { screen_height = document.body.clientHeight; }
	else if (window.innerHeight) { screen_height = window.innerHeight; }

	footer_top = (screen_height -  footer_height);
	offset_t = _obj('footer_start').offsetTop;
	footer_offset = footer_top - offset_t;
	if (footer_offset < 0) { footer_offset = 0; }
	//_obj('footer_start').style.marginTop = footer_offset + 'px';
	//_obj('footer_wrapper').style.height = footer_offset + 'px';
	alert('screen_height='+screen_height+' offset_t='+offset_t+' footer_top='+footer_top+' footer_offset='+footer_offset);
}


var myWidth = 0, myHeight = 0;
function getClientSize() {
	if( typeof( window.innerWidth ) == 'number' ) {
		myWidth = window.innerWidth; myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth ||document.documentElement.clientHeight ) ) {
		myWidth = document.documentElement.clientWidth; myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		myWidth = document.body.clientWidth; myHeight = document.body.clientHeight;
	}
}
var scrOfX = 0, scrOfY = 0;
function getScrollXY() {
	if( typeof( window.pageYOffset ) == 'number' ) { scrOfY = window.pageYOffset; scrOfX = window.pageXOffset; } 
	else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) { scrOfY = document.body.scrollTop; scrOfX = document.body.scrollLeft; } 
	else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) { scrOfY = document.documentElement.scrollTop; scrOfX = document.documentElement.scrollLeft; }
}


function enlarge_thumb(obj)
{
	_obj('bdy').style.overflow = 'hidden';

	getScrollXY();
	scroll(scrOfX+1,scrOfY+1);
	scroll(scrOfX,scrOfY);

	getClientSize();
	getScrollXY();
	//myWidth = myWidth - 30;
	
	var img = obj.src.replace(/_thumb100/g,'');
	last_img_src = img;

	_obj('img_enlarge_bg').style.top = (scrOfY + 'px');
	_obj('img_enlarge_bg').style.left = (scrOfX + 'px');
	_obj('img_enlarge_bg').style.width = (myWidth + 'px');
	_obj('img_enlarge_bg').style.height = (myHeight + 'px');


	_obj('img_enlarge').style.top = (scrOfY + 'px');
	_obj('img_enlarge').style.left = (scrOfX + 'px');
	_obj('img_enlarge').style.width = (myWidth + 'px');
	_obj('img_enlarge').style.height = (myHeight + 'px');

	_obj('img_enlarge_bg').style.display = 'block';

	var data = '<table width="100%" height="'+myHeight+'" onclick="hide_enlarger();"><tr><td align="center" valign="middle"><img class="img_enl_border" onclick="hide_enlarger();" src="'+img+'" alt="" /></td></tr></table>';

	_obj('img_enlarge').innerHTML = data;
	_obj('img_enlarge').style.display = 'block';
	
}

function hide_enlarger()
{
	_obj('img_enlarge_bg').style.display = 'none';
	_obj('img_enlarge').style.display = 'none';
	_obj('bdy').style.overflow = 'auto';
	getScrollXY();
	scroll(scrOfX+1,scrOfY+1);
	scroll(scrOfX,scrOfY);
}