var cur_head_pict_index = 1;

window.addEvent('domready', function() {
   //chg_head_pic();   
});

function encomment_map(targetDivId){
		var gMapCode = $(targetDivId).innerHTML;
		/*alert(gMapCode);
		gMapCode = gMapCode.substr(4,gMapCode.length-7);
		alert(gMapCode);*/
		if(gMapCode.indexOf('<!--')==0){
			$(targetDivId).innerHTML = gMapCode.substr(4,gMapCode.length-7);
		}
}

function showMap(m_num){

		var tmpThis = this;
				var req = new Request.JSON(
			 			{
			 				method: 'get',
			 				url: 'getMap.php',
			 				data: 'id='+m_num,
							onComplete: function(){
								
								//alert(this.response.text);
								var ans = JSON.decode(this.response.text);	
								if(ans != null){								
									$('mapHolder').innerHTML = ans.m_code;	
									$('mapDescrHolder').innerHTML = ans.descr;										
								}
								
							},
							onFailure: function(){
								loadEnd();
								alert("Error communicating with server");
							}
			 	}).send();			
		//}
/*
	var str = '';
	//else open map
	switch(m_num){
		case 1:
		//Riga
			str='<iframe width="450" height="300" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps?f=q&amp;hl=en&amp;geocode=&amp;q=riga&amp;ie=UTF8&amp;s=AARTsJpU4qbvg3TB3zAqiL5q26CC4BHibg&amp;ll=56.950217,24.110184&amp;spn=0.028086,0.077248&amp;z=13&amp;output=embed"></iframe><br /><small><a href="http://maps.google.com/maps?f=q&amp;hl=en&amp;geocode=&amp;q=riga&amp;ie=UTF8&amp;ll=56.950217,24.110184&amp;spn=0.028086,0.077248&amp;z=13&amp;source=embed" style="color:#0000FF;text-align:left">View Larger Map</a></small>';
		break;
		case 2:
		//Jurmala
			str='<iframe width="450" height="300" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps?f=q&amp;hl=en&amp;geocode=&amp;q=jurmala&amp;ie=UTF8&amp;s=AARTsJrtILoKs1drGCjGgcJpdqHOQTBAbA&amp;ll=56.967439,23.791237&amp;spn=0.056145,0.154495&amp;z=12&amp;output=embed"></iframe><br /><small><a href="http://maps.google.com/maps?f=q&amp;hl=en&amp;geocode=&amp;q=jurmala&amp;ie=UTF8&amp;ll=56.967439,23.791237&amp;spn=0.056145,0.154495&amp;z=12&amp;source=embed" style="color:#0000FF;text-align:left">View Larger Map</a></small>';
		break;
		case 3:
		//Berlin
			str='<iframe width="450" height="300" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps?f=q&amp;hl=en&amp;geocode=&amp;q=berlin&amp;ie=UTF8&amp;s=AARTsJrg6M-lTEHedtmtjHsngAaNNO5-8A&amp;ll=52.520817,13.414307&amp;spn=0.125342,0.30899&amp;z=11&amp;output=embed"></iframe><br /><small><a href="http://maps.google.com/maps?f=q&amp;hl=en&amp;geocode=&amp;q=berlin&amp;ie=UTF8&amp;ll=52.520817,13.414307&amp;spn=0.125342,0.30899&amp;z=11&amp;source=embed" style="color:#0000FF;text-align:left">View Larger Map</a></small>';
		break;				
		
	}
	
	$('mapHolder').innerHTML = str;		
	*/
}

function toggleChild(obj){
	
	real_togle_element($(obj));
	
	/*
	var childTable = $(obj).getNext('table');
	if(childTable != null){
		if(childTable.style.display == 'inline'){
			childTable.style.display = 'none';
		}else{
			childTable.style.display = 'inline';
		}
	}
	*/
}


/*
function chg_head_pic(){
	
	if(headPics<0){
		headPics = 1;
	}
	
	cur_head_pict_index = Math.round(Math.random()*(headPics-1))+1;
	
/*
	//for normal, not random order
	cur_head_pict_index++;
	if(cur_head_pict_index > headPics){
		cur_head_pict_index = 1;
	}
*/
/*
	
	$('header').style.background = "url('images/top_photos/"+cur_head_pict_index+"x.jpg')";
	window.setTimeout("chg_head_pic()",7000);
	
}
*/

function loadAndShowPlaceData(pID,lng){
	
			$('preloader_img').style.display = 'inline';
			$("place_info_"+pID).innerHTML = "";
			
			new Request.JSON(
		 			{
		 				method: "get",
		 				url: "include/get_place_info.php",
		 				data: "pID="+pID+"&lng="+lng,
						onComplete: function(){


							//alert(this.response.xml);//IN OPERA 9.52 NULLLLLL :(
							if(this.response.text != null){
								//alert(this.response.text);
								//var ans = JSON.decode(this.response.text);
								$("place_info_"+pID).innerHTML = this.response.text;
							}

							$('preloader_img').style.display = 'none';
							thumbnailviewer.init();
							
						},
						onFailure: function(){
							$('preloader_img').style.display = 'none';
							
							alert("Error communicating with server");
						}
		 	}).send();
	}	


function toggleChildSpec(el,locker_num,lng){	
	
		if($(el).style.display=="inline"){
			togle_element(el,false);
			$("lock_"+locker_num).src="images/corners/1/open.png";			
			return false;
		}else{
			togle_element(el,true);
			$("lock_"+locker_num).src="images/corners/1/close.png";
			//also, load AJAX info for this place			
			loadAndShowPlaceData(locker_num,lng);
			return true;
		}
}

function real_togle_element(el){
	
		if($(el).style.display=="inline"){
			togle_element(el,false);
			return false;
		}else{
			togle_element(el,true);
			return true;
		}
}
function togle_element(el,bFlag){
	//better name for this function is switch_element
	if(el != null){
		try{
			//alert(el);
			if(bFlag){
				$(el).style.display="inline";
			}else{
				$(el).style.display="none";
			}
		}catch(err){alert("Error toggling element: "+el);}		
	}
}

