var map;
var window_width = 963;

// GMAP változói
//var zoomManager;
var smallMarker, bigMarker; 
var smallMarkerArray = new Array();
var bigMarkerArray = new Array();
var shortInfos = new Array();
var mapTrayShadow;
var mapTrayFloat;
var mapTryMarker;
var small_src, big_src;
var small_img = ROOT + 'css/haz_tavol_arany.gif';
var big_img = ROOT + 'css/haz_kozel_arany.gif';
var colors = {E:ROOT+'css/haz_nagy_kek.gif', K:ROOT+'css/haz_nagy_piros.gif' , P:ROOT+'css/haz_nagy_arany.gif'};
var estateID = null;
var smallMarkerZoom = 9;
var bigMarkerZoom = 14;

// infóablakok kezeléséhez szükséges változók
var colorToBuy = 'rgb(75,165,191)';
var colorToLet = 'rgb(254,0,0)';
var infoWindowWidth = '390px';
var infoWindowHeight = '78px';
var infoWindowInnerHTML = '';
var infoImg = null;
var iw_width = 195;
var iw_height = 39;

// megjelennítő függvény a labelhez és a kisablakhoz
function showInfo(id, top, left, content)
{		
	var div = $(id);
	var first = '';
	var spl = content.split('|');
	var type = (spl[0] == 'E')? $lang('map.forsale') + ' ' : $lang('map.forrent') + ' ';
	var felszoba = (spl[5] != 0) ? '+' + spl[5] + ' ' + $lang('map.half') : '';
	var szoba = spl[4] + felszoba + ' ' + $lang('map.room') + ' ';
	if(spl[1] == 'telek')
	{
		szoba = '';
	}
	szoba = (spl[4] != '')? szoba : '';
	var fotok = (spl[13] == 0)? '' : spl[14];
	if(lang == 'hu')
	{
		first = type +  spl[1];
	}
	else
	{
		first = spl[1] + ' ' + type; 
	}
	div.innerHTML =  first + ', ' + szoba +  spl[7] + spl[8] + spl[9] + ' ' + fotok;//spl[13];
	div.style.top = top + 'px';
	div.style.left =left + 'px';
	div.style.display = 'block';
}

// címke megjelenítése
function showInfoWindow(id, top, left, content)
{	

	var div = $('MAP_infoWindow');
	div.innerHTML = infoWindowInnerHTML;
	$('iw_openerspan').innerHTML = $lang('map.details');
	var leftdiv = $('MAP_detailDivLeft');		

    $('MAP_infoWindow').style.height = infoWindowHeight;
	$('MAP_infoWindow').style.width = infoWindowWidth;
		
	var innerDiv = document.createElement('div');
	innerDiv.id="MAP_infoImageDivInner";
	innerDiv.appendChild(document.createTextNode($lang('map.foto')));
	$('iw_infoImageDiv').appendChild(innerDiv);
	
	var infos = content.split('|');	
  
    var classNameTop = '';
	var classNameBody = '';
	var classNameClose = '';
	var classNameOpener = '';

	switch(infos[0])
	{
		case 'E' : classNameTop = 'topelado';
				   classNameBody = 'bodyelado';
				   classNameClose = 'closeelado_off';
				   classNameOpener = 'opener_elado';
		           break;

		case 'K' : classNameTop = 'topkiado';
				   classNameBody = 'bodykiado';
				   classNameClose = 'closekiado_off';
				   classNameOpener = 'opener_kiado';
		           break;		           
	}

	if(infos[16] == 'G')
	{		
		classNameOpener = 'opener_premier';
	}

	$('iw_top').className = classNameTop;
	$('iw_mostright').className = classNameBody;
	$('iw_mostright_closediv').className = classNameClose;

	if(lang == 'hu')
	{
		$('iw_infoHeaderSaleType').innerHTML = (infos[0] == 'E')? $lang('map.forsale') + ' ' : $lang('map.forrent') + ' ';	
		$('iw_infoHeaderType').innerHTML = infos[1];	
	}
	else
	{
		$('iw_infoHeaderType').innerHTML = (infos[0] == 'E')? $lang('map.forsale') + ' ' : $lang('map.forrent') + ' ';	
		$('iw_infoHeaderSaleType').innerHTML = infos[1];		
	}

    // close gomb eseményei
	$('iw_mostright_closediv').onclick = function()
	{
		hideInfo('MAP_infoWindow');
	}

	$('iw_mostright_closediv').onmouseover = function()
	{
		this.className = this.className.replace('off','on'); 
	}

	$('iw_mostright_closediv').onmouseout = function()
	{
		this.className = this.className.replace('on','off'); 
	}
       

	if(infos[2] == '')
	{		
		$('iw_infoSubtitle').style.display = 'none';		
	}
	else
	{
		$('iw_infoSubtitle').innerHTML = infos[2];		
	}

    var fotos  = (infos[13] == '0')? $lang('map.none') : infos[13];
	$('iw_fotos').innerHTML = fotos + ' ' + $lang('map.foto2');
	$('iw_datum').innerHTML = $lang('map.posted') + ' ' + infos[15];
	$('iw_refnum').innerHTML = $lang('map.ref') + ' ' + infos[10];
	
		
	var szoba = infos[4] + (infos[5] == '0' ? '' : ' + ' + infos[5]);
	if(infos[1] != 'telek')
	{
		$('iw_rooms').innerHTML = szoba + ' ' + $lang('map.room') + ' ';
		$('iw_homeArea').innerHTML = infos[6] + ' m2 ';	
	}
	if(infos[0] == 'E')
		$('iw_flatPrice').innerHTML = $lang('map.price') + ' ' + infos[7] + ' ' + $lang('map.million');			
	if(infos[0] == 'K')
		$('iw_flatPrice').innerHTML = $lang('map.price') + ' ' + infos[7] + ' ' + $lang('map.thousand');	

    $('iw_adatlap_opener').className = classNameOpener;


	$('iw_openerspan').onclick = function()
	{
		window.open(ROOT + '/' + infos[10],'','width=950,height=700,scrollbars=yes');		
	}	

	if(!infos[12].match('ip_logo'))
	{
		$('iw_left').style.width = '75px';
		$('iw_infoImageDiv').style.display = 'block';
		infoImg = new Image(65,65);	
		infoImg.onload = function()	
		{	
			$('iw_infoImageDiv').innerHTML = '';		
			$('iw_infoImageDiv').appendChild(this);
		}	
		infoImg.src = infos[12];
	}	
	else
	{
		$('iw_left').style.width = '1px';
		$('iw_infoImageDiv').style.display = 'none';
	}
		

	div.style.background = 'none';
	div.style.border = 'none';
	div.style.top = top + 'px';
	div.style.left =left + 'px';
	div.style.display = 'block';
	
	if(infos[2] == '')
	{
		$('iw_infoSubtitle').style.display = 'block';
	}
}


//kisablak létrhozása
function createInfoWindow()
{
	var div = document.createElement('div');
	div.setAttribute('id','MAP_infoWindow');
	div.style.display = 'none';
	div.style.position = 'absolute';
	div.style.color = 'rgb(100,100,100)';
	div.style.zIndex = 10;
	div.style.background = '#fff';
	div.style.border = 'rgb(187,187,187) 1px solid';
	div.style.padding = '1px';
	div.style.width = '270px';
	div.style.height = '170px';
	div.style.top = 0;
	div.style.left = 0;		

	document.body.appendChild(div);
	return div;
}

// kisablak eseményeinek lekezelése
function createDetailWindow()
{	
	var div = $('MAP_detailWindow');				
	div.style.top = '-1px';
	div.style.left ='-1px';

	var txt = '';	 
	txt += '<div id="MAP_mainDetailContainer">';
	txt += '</div>';	
	div.innerHTML = txt;		
}

// a kívánt marker azonosító kiszedése, felhasználás: események hozzáadásánál a különböző jelölőknél
function getMarkerNum(arr, item)
{
	for(var i=0; i<arr.length; i++)
	{
		if(arr[i] == item)
		{
			return i;
		}
	}
}

// label és kisablak elrejtése
function hideInfo(id)
{
	var div = $(id);
	div.style.display = 'none';					
}

// mouseover-es címke létrehozása
function createInfoLabel()
{
	var label=document.createElement('div');
	label.setAttribute('id','MAP_infoLabel');
	label.style.display = 'none';
	document.body.appendChild(label);
	label.style.position = 'absolute';
	label.style.color = '#000';
	label.style.zIndex = 2;
	label.style.background = "url('szurke_hatter.gif') top repeat-x #fff";
	label.style.height = '15px';
	label.style.fontSize = '95%';
	label.style.whiteSpace = 'nowrap';	
	label.style.border = '#777 1px solid';
	label.style.padding = '2px 8px 0px 8px';
	return label;	
}

function loadmap()
{	
	if(!map)
	{
		if (GBrowserIsCompatible()) 
		{
			if(data.length == 0) return;
			map = new GMap2(document.getElementById("listmap"));
			bounds = new GLatLngBounds(new GLatLng(maxlat, minlng), new GLatLng(minlat,maxlng));
			var zoom = map.getBoundsZoomLevel(bounds);
			zoom = (zoom < 6)? 6 : zoom;
			map.setCenter(bounds.getCenter(),zoom-1); 
			map.addControl(new GLargeMapControl());
   			map.enableDoubleClickZoom();
		    map.enableContinuousZoom();	
			
		    // infoLabel hozzáadása
			mapTrayShadow = map.getPane(G_MAP_FLOAT_SHADOW_PANE);
		    mapTrayShadow.appendChild(createInfoLabel());

	        //infoWindow hozzáadása
		    mapTrayFloat = map.getPane(G_MAP_FLOAT_PANE);
		    mapTrayFloat.appendChild(createInfoWindow());

			GEvent.addListener(map, 'movestart', function(){		  				
			});	  

		    GEvent.addListener(map, 'dragstart', function(){		     				
	        });

		    GEvent.addListener(map, 'zoomend', function(){
				var zoom = map.getZoom();				
				if(zoom < smallMarkerZoom)
				{
					map.setZoom(smallMarkerZoom);
				}
				if(zoom < bigMarkerZoom)
				{
					hideBigMarkers();
				}
				else
				{
					hideSmallMarkers();
				}
	        });
			setMarkers(data);
		}
	}	
}

function hideBigMarkers()
{	
	for(var i=0; i<bigMarkerArray.length; i++)
	{
		bigMarkerArray[i].hide();
	}
	for(var i=0; i<smallMarkerArray.length; i++)
	{
		smallMarkerArray[i].show();
	}		
}

function hideSmallMarkers()
{	
	for(var i=0; i<smallMarkerArray.length; i++)
	{
		smallMarkerArray[i].hide();
	}
	for(var i=0; i<bigMarkerArray.length; i++)
	{		
		bigMarkerArray[i].show();
	}		
}

function setMarkers()
{
	var info = '';
	shortInfos = new Array();
	smallMarkerArray = new Array();
	bigMarkerArray = new Array();
	datalength = data.length;

	map.clearOverlays();

	bounds = new GLatLngBounds(new GLatLng(maxlat, minlng), new GLatLng(minlat,maxlng));
	var zoom = map.getBoundsZoomLevel(bounds);
	zoom = (zoom < 6)? 6 : zoom;
	map.setCenter(bounds.getCenter(),zoom-1); 

	for(var i=0; i<datalength; i++)
	{
	    var smallicon = new GIcon();
	    var bigicon = new GIcon();

		if(data[i].type == 'K')
		{
			if(data[i].golden != 'N')
			{
			    if(data[i].id == estateID)
			    {
				    smallicon.image = (colors.P);
			        smallicon.iconSize = new GSize(32,34);
			        smallicon.iconAnchor = new GPoint(16,17);

				    bigicon.image = (colors.P);
			        bigicon.iconSize = new GSize(32,34);
			        bigicon.iconAnchor = new GPoint(16,17);						 
			    }
			    else
			    {
				    smallicon.image = ROOT + 'css/haz_tavol_arany.gif';
			        smallicon.iconSize = new GSize(18,17);
			        smallicon.iconAnchor = new GPoint(5,20);

				    bigicon.image = ROOT + 'css/haz_kozel_arany.gif';
				    bigicon.iconSize = new GSize(23,24);
				    bigicon.iconAnchor = new GPoint(8,24);
			    }								
			}
			else
			{
				if(data[i].id == estateID)
				{
					smallicon.image = (colors.K);
			        smallicon.iconSize = new GSize(32,34);
			        smallicon.iconAnchor = new GPoint(16,17);

				    bigicon.image = (colors.P);
			        bigicon.iconSize = new GSize(32,34);
			        bigicon.iconAnchor = new GPoint(16,17);
				}
				else
				{
					smallicon.image = ROOT + 'css/haz_tavol_piros.gif';
			        smallicon.iconSize = new GSize(18,17);
			        smallicon.iconAnchor = new GPoint(5,20);

				    bigicon.image = ROOT + 'css/haz_kozel_piros.gif';
				    bigicon.iconSize = new GSize(23,24);
				    bigicon.iconAnchor = new GPoint(8,24);
				}
			}													
		}
		else
		{   
			if(data[i].golden != 'N')
			{   					   
			    if(data[i].id == estateID)
			    {
				    smallicon.image = (colors.P);
			        smallicon.iconSize = new GSize(32,34);
			        smallicon.iconAnchor = new GPoint(16,17);

				    bigicon.image = (colors.P);
			        bigicon.iconSize = new GSize(32,34);
			        bigicon.iconAnchor = new GPoint(16,17);	
			    }
			    else
				{
				    smallicon.image = ROOT + 'css/haz_tavol_arany.gif';
				    smallicon.iconSize = new GSize(18,17);
				    smallicon.iconAnchor = new GPoint(5,20);

				    bigicon.image = ROOT + 'css/haz_kozel_arany.gif';
				    bigicon.iconSize = new GSize(23,24);
				    bigicon.iconAnchor = new GPoint(8,24);
				}			
		    }
			else
			{
			   if(data[i].id == estateID)
			   {
				  smallicon.image = (colors.E);
				  smallicon.iconSize = new GSize(32,34);
				  smallicon.iconAnchor = new GPoint(16,17);

				  bigicon.image = (colors.E);
				  bigicon.iconSize = new GSize(32,34);
				  bigicon.iconAnchor = new GPoint(16,17);
			  }
			  else
			  {
				  smallicon.image = ROOT + 'css/haz_tavol_kek.gif';
			      smallicon.iconSize = new GSize(18,17);
			      smallicon.iconAnchor = new GPoint(5,20);

				  bigicon.image = ROOT + 'css/haz_kozel_kek.gif';
				  bigicon.iconSize = new GSize(23,24);
				  bigicon.iconAnchor = new GPoint(8,24);
			   }					 
		   }				   
 	   }

	   var kep = (data[i].kep1 == '' )?  '../css/spacer.gif' : '' + data[i].kep1;

	   info = data[i].type + '|' + data[i].tipus + '|' + data[i].title + '|' + data[i].address + '|' + data[i].rooms + '|' +  data[i].halfrooms + '|' + data[i].size + '|' + data[i].price + '|' + data[i].unit + '|' + data[i].currency + '|';
	   info += data[i].id + '|' + data[i].futes + '|' + kep + '|' + data[i].foto;
	   info += '|' + '<img src="' + ROOT + 'css/fotoicon.gif" width="15" height="13" alt="" style="margin:0 0 2px 5px; vertical-align:top"/>' + ' (' + data[i].foto + ')';			  
	   info += '|' + data[i].datumstring;
	   info += '|' + data[i].golden;		  
	   shortInfos.push(info);

	   smallMarker = new GMarker(new GLatLng(data[i].lat , data[i].long), {icon:smallicon});	
	   
	   //if(data[i].id != estateID)
	   //{
		  smallMarkerArray.push(smallMarker);	 	  
		  map.addOverlay(smallMarker);
	   //}
	   //else
	   //{
		 // extraSmallMarker = smallMarker;
	   //}
		  		  
	   bigMarker = new GMarker(new GLatLng(data[i].lat , data[i].long), {icon:bigicon});
	   //if(data[i].id != estateID)
	   //{
		  bigMarkerArray.push(bigMarker);	 	  
		  map.addOverlay(bigMarker);
	   //}
	   //else
	   //{
		  //extraBigMarker = bigMarker;
	   //}	  
	   bigMarker.hide();
	}
	// a kiemelt markert utolsónak adja jozzá, hogy ne legyen átfedés
	/*
	if(typeof extraSmallMarker != 'undefined')
	{
		smallMarkerArray.push(extraSmallMarker);
		map.addOverlay(extraSmallMarker);
	}

	if(typeof extraBigMarker != 'undefined')
	{
		bigMarkerArray.push(extraBigMarker);
		map.addOverlay(extraBigMarker);
	}
	*/
	
	for(i=0; i<datalength; i++)
	{
	   // kicsi jelölők eseményei		  
	   GEvent.addListener(smallMarkerArray[i], 'mouseover', function()
	   {					  			  
		   var num = getMarkerNum(smallMarkerArray, this);
		   var point = this.getLatLng();
		   var coords = map.fromLatLngToDivPixel(point);		  		  		  
		   hideInfo('MAP_infoLabel');
		   showInfo('MAP_infoLabel', parseInt(coords.y)-15, parseInt(coords.x)+15, shortInfos[num]);			   
		});	
          
		GEvent.addListener(smallMarkerArray[i], 'mouseout', function()
		{		
		   hideInfo('MAP_infoLabel');			  		  
		});

		GEvent.addListener(smallMarkerArray[i], 'click', function()
		{						 
		   var num = getMarkerNum(smallMarkerArray, this);
		   var point = this.getLatLng();
		   var coords = map.fromLatLngToDivPixel(point);		  		  		  
		   hideInfo('MAP_infoWindow');
		   hideInfo('MAP_infoLabel');				  
		   var width = iw_width;//(parseInt($('MAP_infoWindow').style.width)/2);
  		   var height = iw_height;//(parseInt($('MAP_infoWindow').style.height)/2);					  
		   showInfoWindow('MAP_infoWindow', (parseInt(coords.y)+19)-height, (parseInt(coords.x)+62)-width, shortInfos[num]);					 
		   map.panTo(new GLatLng(point.y, point.x));
				 
		});	        			  

		// nagy jelölők eseményei
		GEvent.addListener(bigMarkerArray[i], 'mouseover', function()
		{					  			  
		   var num = getMarkerNum(bigMarkerArray, this);
		   var point = this.getLatLng();
		   var coords = map.fromLatLngToDivPixel(point);		  		  		  
		   hideInfo('MAP_infoLabel');
		   showInfo('MAP_infoLabel', parseInt(coords.y)-15, parseInt(coords.x)+15, shortInfos[num]);			  		  
		});	
          
		GEvent.addListener(bigMarkerArray[i], 'mouseout', function()
		{		
			  hideInfo('MAP_infoLabel');			  		  
		});

		GEvent.addListener(bigMarkerArray[i], 'click', function()
		{					  			  				  
		   var num = getMarkerNum(bigMarkerArray, this);
		   var point = this.getLatLng();
		   var coords = map.fromLatLngToDivPixel(point);		  		  		  
		   hideInfo('MAP_infoWindow');
		   hideInfo('MAP_infoLabel');
		   var width = (parseInt($('MAP_infoWindow').style.width)/2);
  		   var height = (parseInt($('MAP_infoWindow').style.height)/2);				  				  
		   showInfoWindow('MAP_infoWindow', (parseInt(coords.y)-23), (parseInt(coords.x)-137), shortInfos[num]);	
		   map.panTo(new GLatLng(point.y, point.x));	
		});	          
	}		  		   		  			
}

function setShowTitles(className)
{
	var items = document.getElementsByClassName(className);
	for(var i=0; i<items.length; i++)
	{		
		items[i].onclick = function(e)
		{								
			var id = this.id.split('_')[1];
			window.open(ROOT + id, '', 'width=' + window_width + ',height=700,scrollbars=yes,menubar=yes,resizable=no');			
			return false;
		}
	}
}

function scroll(item, targetTop, origTop)
{		
	if((targetTop) <= origTop-5 || (targetTop) >= origTop+5)
	{
		if(origTop > targetTop)
		{
			origTop -= 5;
			item.style.top = origTop + 'px';
		}
		else
		{
			origTop += 5;
			item.style.top = origTop + 'px';
		}				
		setTimeout(function(){scroll(item, targetTop, origTop)},1);	
	}
	else
	{
		return;
	}
}

var setItemSelect = Class.create();
setItemSelect.prototype = {
   initialize:function(select, url){
      this.select = $(select);              
      this.url = url;
      Event.observe(this.select,'change',this.change.bind(this));         
   },     
      
   change:function(e){          
      var myVars = 'item_per_page=' + this.select.value;                                                               
      var myAjax = new Ajax.Request(
	     this.url, 
	     {
	       method: 'get', 
	       parameters: myVars, 
	       onComplete: this.loadPage.bind(this),
           onFailure:function(){
              alert('A listázandó elemek számát nem sikerült beállítani.');
           }.bind(this)                            		
	  });               	                                    
      Event.stop(e);
   },
      
   loadPage:function(resp,json){
      var txt = resp.responseText;
	  if(txt == 'success')
	  {
		  location.reload(true);
	  }
   }	 
}

var showOnMap = Class.create()
showOnMap.prototype = {
	initialize:function(className,mapLayer,mapShadowLayer,map_closer, maplink){
		this.className = className;
		this.mapLayer = $(mapLayer);
		this.mapShadowLayer = $(mapShadowLayer);		
		this.map_closer = $(map_closer);
		this.mapOpen = false;
		this.maplink = $(maplink);
		this.init();
	},

	init:function(){
		var maplinks = $A(document.getElementsByClassName(this.className));
		maplinks.each(
			function(item){		
				Event.observe(item, 'click', this.click.bindAsEventListener(this));				
		    }.bind(this)
		)
		Event.observe(this.map_closer, 'click', this.closemap.bind(this));
		Event.observe(this.maplink, 'click', this.openmap.bind(this));
	},

	click:function(e){
		var src = Event.element(e);
		estateID = src.id.split('_')[1];
		hideSelects();
		if(!this.mapOpen)
		{
			this.mapOpen = true;
			Scroller.setPosition(this.mapLayer, 700,490);			
			this.mapLayer.style.display = 'block';		
			loadmap();
		}
		else
		{	
			Scroller.setPosition(this.mapLayer, 700,490);
			hideInfo('MAP_infoWindow');
			this.mapLayer.style.display = 'block';	
			setMarkers();
			//navigateToEstate();
		}
	},
		
	openmap:function(e){
		Event.stop(e);
		estateID = null;	
		hideSelects();
		if(!this.mapOpen)
		{
			this.mapOpen = true;
			Scroller.setPosition(this.mapLayer, 700,490);			
			this.mapLayer.style.display = 'block';		
			loadmap();
		}
		else
		{	
			Scroller.setPosition(this.mapLayer, 700,490);
			hideInfo('MAP_infoWindow');
			this.mapLayer.style.display = 'block';	
			setMarkers();			
		}		
	},

	closemap:function(){
		showSelects();
		this.mapLayer.style.display = 'none';	
	}
}

var setLinks = Class.create();
setLinks.prototype = {
	initialize:function(parent, img){
		this.parent = $(parent);
		this.img = img;
		this.init();
		this.actClass = document.body.className;
	},

	init:function(){
		var as = $A(this.parent.getElementsByTagName('a'));		
		as.each(
			function(item){
				Event.observe(item,'mouseover',this.over.bindAsEventListener(this));
				Event.observe(item,'mouseout',this.out.bindAsEventListener(this));						
			}.bind(this)
		)					
	},

	over:function(e){
		var src = Event.element(e);				
		if(this.actClass == src.id) return;
		src.style.backgroundImage = 'url(' + ROOT + 'css/'+LANG+'/' + src.id + '_ON.gif)';
	},

	out:function(e){
		var src = Event.element(e);
		if(this.actClass == src.id) return;
		src.style.backgroundImage = 'url(' + ROOT + 'css/'+LANG+'/' + src.id + '_OFF.gif)';		
	}	
}

function hideSelects()
{
	var selects = document.getElementsByTagName('select');
	for(var i=0; i<selects.length; i++)
	{
		selects[i].style.visibility = 'hidden';
	}
}

function showSelects()
{
	var selects = document.getElementsByTagName('select');
	for(var i=0; i<selects.length; i++)
	{
		selects[i].style.visibility = 'visible';
	}
}

function cssPreloadImages() 
{ 
	var i, j, img; 	
	var pos = document.styleSheets[0].href.lastIndexOf("/"); 
	var cssDir = (pos != -1) ? document.styleSheets[0].href.substring(0, pos + 1) : ""; 
	var rules = document.styleSheets[0].cssRules ? document.styleSheets[0].cssRules : document.styleSheets[0].rules; 
	for (j=0; j<rules.length; j++) 
	{ 
		var style = rules[j].style; 
		if (style.backgroundImage.toLowerCase().substr(0,4) == "url(") 
		{ 
			var filename = style.backgroundImage.substring(4, style.backgroundImage.length - 1); 
			if (filename.indexOf("http://") != 0 && filename.indexOf("/") != 0) 
				filename = cssDir + filename; 
			var img = new Image(); 
			img.src = filename; 
		} 
	} 
} 

function setBgImages()
{
	var imgs = $('menuheader_main_menu').getElementsByTagName('a');
	for(var i=0; i<imgs.length; i++)
	{
		var img = new Image();
		img.src = '../css/' + imgs[i].id + 'ON.gif';
		img.src = '../css/' + imgs[i].id + 'OFF.gif';		
	}
}

function setOpacity(obj, value) 
{
	obj.style.opacity = value/10;
	obj.style.filter = 'alpha(opacity=' + value*10 + ')';
}

function setPopups()
{
	try
	{
		$('main_login').onclick = function()
		{
			window.open(URLROOT + '/login_popup', '', 'width=400,height=150,scrollbars=no');	
			return false;
		}

		$('main_forgotpass').onclick = function()
		{
			window.open(URLROOT + '/lostpass', '', 'width=400,height=230,scrollbars=no');	
		}
	}
	catch(e){}
}

var language = null;
function $lang(n)
{
	var l = language.SelectSingleNode("/doc/lang[@name='"+n+"']")
	return (l?l.firstChild.nodeValue:n)
}

function unloadmap()
{
	GUnload();
}

function initialize()
{			
	setShowTitles('detailsDisplayer');	
	setShowTitles('imageDisplayer');	
	setShowTitles('mainTextTitleLink');
	setShowTitles('premierlink');	
	new setLinks('menuheader_main','css/links_mainpage.gif');
	GDownloadUrl(ROOT + "infoWindow.html" , function(text){infoWindowInnerHTML = text});
	new setItemSelect('item_per_page',ROOT + 'set_list_num.php');
	new showOnMap('listItemLinksMap','mapLayer','map_shadow','closemap','show_on_map');
	var mapDragger = new Dragger([['mapLayer']]);
	$('maplegend').onmousedown = function(e){
		Event.stop(e);
		return false;
	}		
	setBgImages();
	setPopups();
}


window.onload = function()
{
   var oXML = new FCKXml();
   oXML.LoadUrl(ROOT + 'data/language_' + lang + '.xml', function(xml){ 	   
	   language = xml;	   
	   initialize();	   
   })
}

window.onunload = function()
{
	unloadmap();
}
